Commit Graph

194 Commits

Author SHA1 Message Date
Ozkan Sezer
31751bdcce wmmsg.h: constified wmtab 2021-01-05 15:15:37 +03:00
Ozkan Sezer
390fd14f54 SDL_windowswindow.c (SDL_HelperWindowCreate): adjust for ANSI/UNICODE:
change SDL_HelperWindowClassName and SDL_HelperWindowName from WCHAR *
to be const TCHAR*

cf. bug #5435.
2021-01-04 01:23:50 +03:00
Ozkan Sezer
01a2f27679 consistently use TEXT() macro with LoadLibrary() and GetModuleHandle()
cf. bug #5435.
2021-01-04 01:23:50 +03:00
Cameron Gutman
6cbd4417f0 Add a hint for D3D9Ex to avoid having to choose at compile-time 2021-01-02 14:45:15 -06:00
Sam Lantinga
9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Ozkan Sezer
10625f9d89 SDL_windowsmessagebox.c: go back to hg rev 14458 state.
encountering a NULL caption in AddDialogString() is intended, i.e.
AddDialogStaticIcon() sends it as NULL on purpose.
2020-12-17 23:50:00 +03:00
Ozkan Sezer
4d6eb30523 SDL_windowsmessagebox.c (AddDialogControl): add back NULL caption check.
because AddDialogStaticIcon() sends a NULL caption -- fixes bug #5401.
2020-12-17 23:28:20 +03:00
Ozkan Sezer
5c212cb0c5 remove a few stale NULL message/title checks after commit e2b729b1756a
top-level guarantees non-NULL message / title passed in messageboxdata
2020-12-10 12:24:24 +03:00
Ozkan Sezer
f1cab8aea6 fix bug #5253: handle NULL title or message fields in SDL_MessageBoxData
- SDL_video.c (SDL_ShowMessageBox): replace messageboxdata, set title
  or message field to "" if either of them is NULL.
- SDL_video.c (SDL_ShowSimpleMessageBox):  set title or message to ""
  if either of them is NULL for EMSCRIPTEN builds.
- SDL_bmessagebox.cc: add empty string check along with NULL check for
  title and message fields.
- SDL_windowsmessagebox.c (AddDialogString): remove NULL string check
- SDL_windowsmessagebox.c (AddDialogControl):  add empty string check
  along with the NULL check.
- SDL_x11messagebox.c: revert commit 677c4cd68069
- SDL_os2messagebox.c: revert commit 2c2a489d76e7
- test/testmessage.c: Add NULL title and NULL message tests.
2020-12-10 11:20:56 +03:00
Sam Lantinga
cb36189692 Fixed bug 5235 - All internal sources should include SDL_assert.h
Ryan C. Gordon

We should really stick this in SDL_internal.h or something so it's always available.
2020-12-09 07:16:22 -08:00
Sam Lantinga
50203d58b3 Fixed bug 5329 - SDL_SetWindowGrab(SDL_FALSE) fails to unlock cursor if window is partially offscreen
Ivan Mogilko

With SDL 2.0.12 under MS Windows, if the window is partially offscreen calling SDL_SetWindowGrab(w, SDL_TRUE) works, but subsequent call to SDL_SetWindowGrab(w, SDL_FALSE) does not work.

I tested this in both real program, and a small test app, where unlocking cursor worked perfectly while window is fully in desktop bounds, but did not work if it was at least few pixels outside.

For the reference, following code is enough to reproduce the issue:

#include <windows.h>
#include <SDL.h>

int WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpCmdLine,
    int       nShowCmd)
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* w = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 400, 0);

    bool grabbed = false;
    bool want_quit = false;
    while (!want_quit)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT: want_quit = true; break;
            case SDL_KEYDOWN:
                if (event.key.keysym.scancode == SDL_SCANCODE_SPACE)
                {
                    SDL_SetWindowGrab(w, static_cast<SDL_bool>(!grabbed));
                    grabbed = !grabbed;
                }
            }
        }
    }

    SDL_DestroyWindow(w);
    SDL_Quit();
    return 0;
}
2020-12-08 22:00:06 -08:00
Sam Lantinga
a0c5bfa3bd Moved raw input event processing from the main thread to the joystick thread
This allows fast joystick event delivery regardless of what the main thread is doing.
2020-11-27 13:08:40 -08:00
Cameron Gutman
72379ba510 windows: Fix handling of swapped mouse buttons
GetAsyncKeyState() and GetRawInputData() report the state of the physical
buttons without applying the user's primary/secondary mouse button swap
preference. Swap the buttons returned from these functions, so we expose a
consistent view of the buttons to SDL callers. This new behavior also matches
the behavior of macOS and X11 backends.

See the Remarks section of the GetAsyncKeyState() function on MSDN.
2020-08-25 21:22:00 -07:00
Cameron Gutman
771732ed32 windows: Fix numpad arrow key scancodes with numlock off
We should only perform the VK_LEFT, VK_UP, etc. mapping if none of the other
special mappings apply. This allows the scancode normalization for the number
pad to take place as intended.
2020-08-27 17:54:52 -07:00
Ozkan Sezer
53b166797d SIZE_MAX need not be defined in limits.h
it can be in limits.h (windows) or stdint.h.
2020-11-11 12:33:55 +03:00
Sam Lantinga
b9cbea354f video: Refresh Windows display list on WM_DISPLAYCHANGE
- Displays may have been added, removed or changed and all cached monitor
  handles are invalidated as a result.

- Display events are handled in three steps:
  1. Mark all currently know displays as invalid
  2. Enumerate all displays, adding new ones and marking known displays as valid
  3. Remove all displays still invalid after enumeration

- Display connect/disconnect events are sent when displays are added or removed
  after initial setup
2020-10-13 21:08:20 -07:00
Sam Lantinga
76980e30f2 Added events for dynamically connecting and disconnecting displays, with an iOS implementation 2020-10-08 16:42:20 -07:00
Ryan C. Gordon
b5affd12e6 Patched to compile. 2020-07-16 13:28:59 -04:00
Ryan C. Gordon
8babda2c20 egl: SDL_EGL_LoadLibaryOnly() shouldn't set _this->gl_config.driver_loaded = 1
This is handled in in the higher-level SDL_GL_LoadLibrary().

All uses of SDL_EGL_LoadLibrary (which calls the Only version) are just
target-specific wrappers for their own GL_LoadLibrary hook, with two
exceptions which now handle driver_loaded correctly (although it's
questionable if these init-if-no-one-did-it-correctly-already code blocks
should exist at all, fwiw).

Fixes Bugzilla #5190.
2020-07-16 13:18:19 -04:00
M Stoeckl
052a13738d Merge VideoBootStrap::available into VideoBootStrap::create
The two are only ever called together, and combining them makes it possible
to eliminate redundant symbol loading and redundant attempts to connect
to a display server.
2020-07-12 19:11:15 -04:00
Sam Lantinga
44f50c647e Fixed bug 5171 - PollEvent impacts performance in 2.0.12
On some systems, GetClipCursor() impacts performance when called frequently, so only call it every once in a while to make sure we haven't lost our capture.
2020-06-09 21:47:41 -07:00
Sam Lantinga
511a9702fc Fixed whitespace 2020-06-09 21:43:00 -07:00
Sam Lantinga
9325b22ef0 Fixed bug 5113 - SDL_UpdateWindowSurfaceRects BitBlt the entire surface on Win32
Ryan C. Gordon

As discussed here:
https://discourse.libsdl.org/t/question-about-implementation-of-sdl-updatewindowsurfacerects/27561

"As you can see this function [WIN_UpdateWindowFramebuffer, in src/video/windows/SDL_windowsframebuffer.c] calls BitBlt on entire screen, even though it accepts the rects. Rects variable is not even used in this function at all. Now my question is why is that the case?"
2020-05-29 21:26:32 -07:00
Sam Lantinga
b6afbe6317 Added SDL_log.h to SDL_internal.h so logging is available everywhere 2020-04-07 09:38:57 -07:00
Sam Lantinga
488b94cb40 Don't interpret raw input messages with no mouse position
This happens occasionally on touch devices when raw input is enabled
2020-04-07 09:18:19 -07:00
Sam Lantinga
0721931f5b Avoid sending regular mouse messages for touch input 2020-04-06 19:21:56 -07:00
Sam Lantinga
4dea340ca7 Fixed bug 4477 - Support more than 4 XInput-capable devices on Windows
Jimb Esser

Add new RawInput controller API, and improved correlation with XInput/WGI

Reorder joystick init so drivers can ask the others if they handle a device reliably
Do not poll disconnected XInput devices (major perf issue)
Fix various cases where incorrect correlation could happen
Simple mechanism for propagating unhandled Guide button presses even before guaranteed correlation
Correlate by axis motion as well as button presses
Fix failing to zero other trigger
Fix SDL_HINT_JOYSTICK_HIDAPI not working if set before calling SDL_Init()
Add missing device to device names
Disable RawInput if we have a mismatch of XInput-capable but not RawInput-capable devices

Updated to SDL 2.0.13 code with the following notes:
New HID driver: xbox360w - no idea what that is, hopefully urelated
SDL_hidapijoystick.c had been refactored to couple data handling logic with device opening logic and device lists caused some problems, yields slightly uglier integration than previously when the 360 HID device driver was just handling the data.
SDL_hidapijoystick.c now often pulls the device off of the joystick_hwdata structure for some rumble logic, but it appears that code path is never reached, so probably not a problem.
Looks like joystick_hwdata was refactored to not include a mutex in other drivers, maintainers may want to do the same refactor here if that's useful for some reason.
Something changed in how devices get names, so getting generic names.
Had to fix a (new?) bug where removing an XInput controller caused existing controllers (that moved to a new XInput index) to get identified as 0x045e/0x02fd ("it's probably Bluetooth" in code), rendering the existing HIDAPI_IsDevicePresent and new RAWINPUT_IsDevicePresent unreliable.
2020-03-16 12:23:38 -07:00
Sam Lantinga
e261bd4205 Improved fix for bug 4748 - Calling WIN_UpdateClipCursor() / WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work 2020-02-12 12:26:27 -08:00
Sam Lantinga
6fe6946a2f Fixed relative mode mouse events stopping if you click on the title bar 2020-02-11 21:19:05 -08:00
Sam Lantinga
c31727c7e7 Fixed bug 4748 - Calling WIN_UpdateClipCursor() / WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work
The problem here was calling ClipCursor() continuously in a tight loop. Fixed by only calling ClipCursor() if the clip area needs to be updated.
2020-02-11 10:08:22 -08:00
Sam Lantinga
668276fe81 Don't add a frame to borderless windows.
It was done to allow hotkey resizing of borderless windows, but Windows will sometimes draw it, regardless of our WM_* message handling. See bug 4466 for more details.
2020-02-11 09:41:55 -08:00
Sam Lantinga
f867cebbd4 Fixed bug 4709 - incorrect (not) handling of windows on-screen cursor keys
Alex Denisov

When using Win10 on-screen keyboard (tooltip.exe), the left and right cursor keys in it do not produce SDLK_LEFT and SDLK_RIGHT events.

Windows messages generated by the on-screen keyboard, for some reason, have their scancodes set to zeroes. Here is the log from Spy++:

WM_KEYDOWN nVirtKey:VK_LEFT cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
WM_KEYUP nVirtKey:VK_LEFT cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Regular physical keyboard produces VK_LEFT (ScanCode:4B) and VK_RIGHT (ScanCode:4D) which are interpreted correctly.

With on-screen keyboard, the switch statement in VKeytoScancode() does not check for VK_LEFT and VK_RIGHT, returning SDL_SCANCODE_UNKNOWN, which in turn does not get mapped to anything (because the scan codes are zeroes).
2020-02-11 08:36:13 -08:00
Sam Lantinga
a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Sylvain Becker
c9d0e2ae0a Fixed bug 4840 - Read of uninitialized memory in DXGI_LoadDLL (Thanks!) 2019-10-23 09:26:27 +02:00
Sylvain Becker
d5d34de4db Fixed bug 4839 - Read of uninitialized memory in Win32_ResizeWindowShape
(Thanks!)
2019-10-23 09:17:53 +02:00
Sylvain Becker
758badffa5 Fixed bug 4841 - Misplaced parenthesis WIN_WindowProc / WM_ACTIVATE / ClipCursor
(Thanks!)
2019-10-23 08:58:52 +02:00
Ozkan Sezer
8a394209c4 SDL_windowsevents.c: remove isVistaOrNewer (not used since 8cb1dc50bb28) 2019-09-05 20:47:20 +03:00
Sylvain Becker
bf2f4703f2 SDL_windowsmessagebox.c: remove unused variable 2019-09-05 10:49:53 +02:00
Sam Lantinga
cc64b369fb Allow mouse messages from Wacom pens, e.g. right click pen buttons, etc. 2019-08-30 15:32:15 -07:00
Sam Lantinga
afb9ff9507 Fixed bug where the Steam overlay would generate an event and stop input processing for the frame. 2019-08-30 08:03:19 -07:00
Sam Lantinga
13c4d5e7e3 Fixed Windows relative mouse coordinates when capturing the mouse over RDP 2019-08-26 17:43:01 -07:00
Sam Lantinga
63197c4338 Fix bug where the wrong button was the default in the old message box because buttons were added backwards, breaking the indexing used by GetButtonIndex.
Add messagebox flags to explicilty request left-to-right button order or right-to-left.  If neither is specified it'll be some platform default.
2019-08-02 17:19:50 -07:00
Alex Szpakowski
d5ec735a33 Add a windowID field to SDL_TouchFingerEvent (bug #4331).
This is unimplemented on some platforms and will cause compile errors when building those platform backends for now.
2019-08-01 18:22:12 -03:00
Ozkan Sezer
c37c6cbbca use WIN_IsWindowsVistaOrGreater() from core/windows for isVistaOrNewer 2019-07-31 23:37:02 +03:00
Ozkan Sezer
4953e050f5 use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
Sam Lantinga
e7c2cf107a Fixed bug 4704 - SDL_HINT_ANDROID_SEPERATE_MOUSE_AND_TOUCH on Windows?
superfury

I notice that, somehow, when locking the mouse into place(using SDL_SetRelativeMouseMode), somehow at least the movement information gets through to both mouse movement and touch movement events?

My app handles both, so when moving a touched finger accross the app(using RDP from an Android device) I see the mouse moving inside the app when it shouldn't(meaning that the touch movement is ignored properly by the app(press-location dependant) but the mouse movement is still performed due to the mouse movement events)?
2019-07-15 09:36:53 -07:00
Cameron Gutman
7e09718dfe Ignore synthetic mouse events generated for touchscreens
Windows generates fake raw mouse events for touchscreens for compatibility
with legacy apps that predate touch support in Windows. We already handle
touch events explicitly, so drop the synthetic events to avoid duplicates.
2019-07-07 11:23:16 -07:00
Ryan C. Gordon
0beadea574 windows: Call GetWindowText() with the correct parameters (thanks, Zebediah!)
GetWindowText() wants you to tell it the size of the buffer--including the
terminating NULL char--but we weren't counting that last char, losing the
last char of the string in the process. This was only seen with the special
case of SDL_CreateWindowFrom() to use an existing native window, not
the usual SDL_CreateWindow() codepath.

Fixes Bugzilla #4696.
2019-06-26 01:29:01 -04:00
Ryan C. Gordon
399df540e3 windows: Drop WM_ACTIVATE when window is hidden, but only if being activated.
Fixes Bugzilla #4571.
2019-06-11 01:14:24 -04:00
Sam Lantinga
f2c8d8e9c4 Fixed bug 4443 - Incorrect scan code reported for numpad 5
bplu4t2f

When num lock is on, the scancode reported for numpad 5 is SDL_SCANCODE_KP_5, which is correct. However, when num lock is off, windows reports the VK_CLEAR virtual key code, which is incorrectly translated into SDL_SCANCODE_CLEAR inside of the VKeytoScancode(WPARAM vkey) function.
2019-06-08 10:47:43 -07:00