21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_WINDOWS 32 #include "../../events/SDL_events_c.h" 33 #include "../../events/SDL_touch_c.h" 34 #include "../../events/scancodes_windows.h" 51 #define MOUSEEVENTF_FROMTOUCH 0xFF515700 54 #define REPEATED_KEYMASK (1<<30) 55 #define EXTENDED_KEYMASK (1<<24) 58 #ifndef VK_OEM_NEC_EQUAL 59 #define VK_OEM_NEC_EQUAL 0x92 63 #ifndef WM_XBUTTONDOWN 64 #define WM_XBUTTONDOWN 0x020B 67 #define WM_XBUTTONUP 0x020C 69 #ifndef GET_XBUTTON_WPARAM 70 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) 73 #define WM_INPUT 0x00ff 76 #define WM_TOUCH 0x0240 78 #ifndef WM_MOUSEHWHEEL 79 #define WM_MOUSEHWHEEL 0x020E 82 #define WM_UNICHAR 0x0109 86 VKeytoScancode(WPARAM vkey)
144 WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
147 int nScanCode = (lParam >> 16) & 0xFF;
148 SDL_bool bIsExtended = (lParam & (1 << 24)) != 0;
150 code = VKeytoScancode(wParam);
219 WIN_ShouldIgnoreFocusClick()
229 if (!bwParamMousePressed) {
235 if (WIN_ShouldIgnoreFocusClick()) {
240 if (bwParamMousePressed && !bSDLMousePressed) {
242 }
else if (!bwParamMousePressed && bSDLMousePressed) {
271 if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN))
273 if ((rawButtons & RI_MOUSE_BUTTON_1_UP))
275 if ((rawButtons & RI_MOUSE_BUTTON_2_DOWN))
277 if ((rawButtons & RI_MOUSE_BUTTON_2_UP))
279 if ((rawButtons & RI_MOUSE_BUTTON_3_DOWN))
281 if ((rawButtons & RI_MOUSE_BUTTON_3_UP))
283 if ((rawButtons & RI_MOUSE_BUTTON_4_DOWN))
285 if ((rawButtons & RI_MOUSE_BUTTON_4_UP))
287 if ((rawButtons & RI_MOUSE_BUTTON_5_DOWN))
289 if ((rawButtons & RI_MOUSE_BUTTON_5_UP))
306 keyState = GetAsyncKeyState(VK_LBUTTON);
307 if (!(keyState & 0x8000)) {
310 keyState = GetAsyncKeyState(VK_RBUTTON);
311 if (!(keyState & 0x8000)) {
314 keyState = GetAsyncKeyState(VK_MBUTTON);
315 if (!(keyState & 0x8000)) {
318 keyState = GetAsyncKeyState(VK_XBUTTON1);
319 if (!(keyState & 0x8000)) {
322 keyState = GetAsyncKeyState(VK_XBUTTON2);
323 if (!(keyState & 0x8000)) {
330 WIN_ConvertUTF32toUTF8(UINT32 codepoint,
char *
text)
332 if (codepoint <= 0x7F) {
333 text[0] = (char) codepoint;
335 }
else if (codepoint <= 0x7FF) {
336 text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
337 text[1] = 0x80 | (char) (codepoint & 0x3F);
339 }
else if (codepoint <= 0xFFFF) {
340 text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
341 text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
342 text[2] = 0x80 | (char) (codepoint & 0x3F);
344 }
else if (codepoint <= 0x10FFFF) {
345 text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
346 text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
347 text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
348 text[3] = 0x80 | (char) (codepoint & 0x3F);
357 ShouldGenerateWindowCloseOnAltF4(
void)
371 LRESULT returnCode = -1;
379 wmmsg.
msg.win.hwnd = hwnd;
381 wmmsg.
msg.win.wParam = wParam;
382 wmmsg.
msg.win.lParam = lParam;
389 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
396 SDL_snprintf(message,
sizeof(message),
"Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
398 SDL_snprintf(message,
sizeof(message),
"Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd,
wmtab[msg], wParam, lParam);
400 OutputDebugStringA(message);
424 minimized = HIWORD(wParam);
425 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
426 if (LOWORD(wParam) == WA_CLICKACTIVE) {
427 if (GetAsyncKeyState(VK_LBUTTON)) {
430 if (GetAsyncKeyState(VK_RBUTTON)) {
433 if (GetAsyncKeyState(VK_MBUTTON)) {
436 if (GetAsyncKeyState(VK_XBUTTON1)) {
439 if (GetAsyncKeyState(VK_XBUTTON2)) {
449 GetCursorPos(&cursorPos);
450 ScreenToClient(hwnd, &cursorPos);
453 WIN_CheckAsyncMouseRelease(data);
489 int center_x = 0, center_y = 0;
503 case WM_LBUTTONDBLCLK:
505 case WM_RBUTTONDBLCLK:
507 case WM_MBUTTONDBLCLK:
509 case WM_XBUTTONDBLCLK:
514 WIN_CheckWParamMouseButtons(wParam, data, mouseID);
522 HRAWINPUT hRawInput = (HRAWINPUT)lParam;
534 GetRawInputData(hRawInput, RID_INPUT, &inp, &size,
sizeof(RAWINPUTHEADER));
537 if (inp.header.dwType == RIM_TYPEMOUSE) {
539 RAWMOUSE* rawmouse = &inp.data.mouse;
541 if ((rawmouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) {
546 if (initialMousePoint.
x == 0 && initialMousePoint.
y == 0) {
547 initialMousePoint.
x = rawmouse->lLastX;
548 initialMousePoint.
y = rawmouse->lLastY;
553 initialMousePoint.
x = rawmouse->lLastX;
554 initialMousePoint.
y = rawmouse->lLastY;
556 WIN_CheckRawMouseButtons(rawmouse->usButtonFlags, data);
557 }
else if (isCapture) {
564 currentHnd = WindowFromPoint(pt);
565 ScreenToClient(hwnd, &pt);
566 GetClientRect(hwnd, &hwndRect);
569 if(currentHnd != hwnd || pt.x < 0 || pt.y < 0 || pt.x > hwndRect.right || pt.y > hwndRect.right) {
587 short amount = GET_WHEEL_DELTA_WPARAM(wParam);
588 float fAmount = (float) amount / WHEEL_DELTA;
589 if (msg == WM_MOUSEWHEEL)
599 if (!IsIconic(hwnd)) {
601 GetCursorPos(&cursorPos);
602 ScreenToClient(hwnd, &cursorPos);
614 SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
636 SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
651 if ( wParam == UNICODE_NOCHAR ) {
659 if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
666 #ifdef WM_INPUTLANGCHANGE 667 case WM_INPUTLANGCHANGE:
676 case WM_NCLBUTTONDOWN:
682 case WM_CAPTURECHANGED:
687 WIN_CheckAsyncMouseRelease(data);
691 #ifdef WM_GETMINMAXINFO 692 case WM_GETMINMAXINFO:
700 BOOL constrain_max_size;
711 GetWindowRect(hwnd, &size);
724 if (max_w && max_h) {
727 constrain_max_size =
TRUE;
729 constrain_max_size =
FALSE;
733 LONG style = GetWindowLong(hwnd, GWL_STYLE);
739 BOOL menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
745 AdjustWindowRectEx(&size, style, menu, 0);
746 w = size.right - size.left;
747 h = size.bottom - size.top;
751 info = (MINMAXINFO *) lParam;
753 info->ptMinTrackSize.x = w + min_w;
754 info->ptMinTrackSize.y = h + min_h;
755 if (constrain_max_size) {
756 info->ptMaxTrackSize.x = w + max_w;
757 info->ptMaxTrackSize.y = h + max_h;
760 info->ptMaxSize.x =
w;
761 info->ptMaxSize.y =
h;
762 info->ptMaxPosition.x =
x;
763 info->ptMaxPosition.y =
y;
764 info->ptMinTrackSize.x =
w;
765 info->ptMinTrackSize.y =
h;
766 info->ptMaxTrackSize.x =
w;
767 info->ptMaxTrackSize.y =
h;
774 case WM_WINDOWPOSCHANGING:
781 case WM_WINDOWPOSCHANGED:
791 if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) {
794 ClientToScreen(hwnd, (LPPOINT) & rect);
795 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
803 w = rect.right - rect.left;
804 h = rect.bottom - rect.top;
838 hittest = LOWORD(lParam);
839 if (hittest == HTCLIENT) {
853 if (GetUpdateRect(hwnd, &rect,
FALSE)) {
854 ValidateRect(hwnd,
NULL);
870 if ((wParam & 0xFFF0) == SC_KEYMENU) {
874 #if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER) 876 if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
877 (wParam & 0xFFF0) == SC_MONITORPOWER) {
895 UINT i, num_inputs = LOWORD(wParam);
897 if (data->
videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs,
sizeof(
TOUCHINPUT))) {
901 if (!GetClientRect(hwnd, &rect) ||
902 (rect.right == rect.left && rect.bottom == rect.top)) {
908 ClientToScreen(hwnd, (LPPOINT) & rect);
909 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
915 for (i = 0; i < num_inputs; ++
i) {
924 x = (float)(input->x - rect.left)/(rect.right - rect.left);
925 y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
940 data->
videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
948 HDROP drop = (HDROP) wParam;
950 for (i = 0; i <
count; ++
i) {
951 UINT size = DragQueryFile(drop, i,
NULL, 0) + 1;
954 if (DragQueryFile(drop, i, buffer, size)) {
975 NCCALCSIZE_PARAMS *
params = (NCCALCSIZE_PARAMS *)lParam;
978 params->rgrc[0].right = params->rgrc[0].left +
w;
979 params->rgrc[0].bottom = params->rgrc[0].top +
h;
990 POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
991 if (ScreenToClient(hwnd, &winpoint)) {
992 const SDL_Point point = { (
int) winpoint.
x, (
int) winpoint.y };
995 #define POST_HIT_TEST(ret) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0); return ret; } 1005 #undef POST_HIT_TEST 1017 return CallWindowProc(data->
wndproc, hwnd, msg, wParam, lParam);
1018 }
else if (returnCode >= 0) {
1021 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
1027 static void *g_WindowsMessageHookData =
NULL;
1032 g_WindowsMessageHookData = userdata;
1038 const Uint8 *keystate;
1040 DWORD start_ticks = GetTickCount();
1043 while (PeekMessage(&msg,
NULL, 0, 0, PM_REMOVE)) {
1044 if (g_WindowsMessageHook) {
1045 g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
1049 TranslateMessage(&msg);
1050 DispatchMessage(&msg);
1076 struct SDL_WIN_OSVERSIONINFOW {
1077 ULONG dwOSVersionInfoSize;
1078 ULONG dwMajorVersion;
1079 ULONG dwMinorVersion;
1080 ULONG dwBuildNumber;
1082 WCHAR szCSDVersion[128];
1086 IsWin10FCUorNewer(
void)
1088 HMODULE
handle = GetModuleHandleW(L
"ntdll.dll");
1090 typedef LONG(WINAPI* RtlGetVersionPtr)(
struct SDL_WIN_OSVERSIONINFOW*);
1091 RtlGetVersionPtr getVersionPtr = (RtlGetVersionPtr)GetProcAddress(handle,
"RtlGetVersion");
1092 if (getVersionPtr !=
NULL) {
1093 struct SDL_WIN_OSVERSIONINFOW info;
1095 info.dwOSVersionInfoSize =
sizeof(info);
1096 if (getVersionPtr(&info) == 0) {
1097 if ( (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299)
1098 || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0)
1099 || (info.dwMajorVersion > 10) )
1109 static int app_registered = 0;
1120 TCHAR
path[MAX_PATH];
1123 if (app_registered) {
1127 if (!name && !SDL_Appname) {
1129 #if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC) 1130 SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
1132 SDL_Instance = hInst ? hInst : GetModuleHandle(
NULL);
1137 SDL_Appstyle = style;
1138 SDL_Instance = hInst ? hInst : GetModuleHandle(
NULL);
1142 wcex.cbSize =
sizeof(WNDCLASSEX);
1143 wcex.hCursor =
NULL;
1145 wcex.hIconSm =
NULL;
1146 wcex.lpszMenuName =
NULL;
1149 wcex.hbrBackground =
NULL;
1152 wcex.cbClsExtra = 0;
1153 wcex.cbWndExtra = 0;
1156 if (hint && *hint) {
1157 wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(
SDL_atoi(hint)));
1160 if (hint && *hint) {
1161 wcex.hIconSm = LoadIcon(SDL_Instance, MAKEINTRESOURCE(
SDL_atoi(hint)));
1165 GetModuleFileName(SDL_Instance, path, MAX_PATH);
1166 ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
1169 if (!RegisterClassEx(&wcex)) {
1170 return SDL_SetError(
"Couldn't register application class");
1173 isWin10FCUorNewer = IsWin10FCUorNewer();
1186 if (!app_registered) {
1190 if (app_registered == 0) {
1192 if (GetClassInfoEx(SDL_Instance, SDL_Appname, &wcex)) {
1193 UnregisterClass(SDL_Appname, SDL_Instance);
1194 if (wcex.hIcon) DestroyIcon(wcex.hIcon);
1195 if (wcex.hIconSm) DestroyIcon(wcex.hIconSm);
#define WIN_UTF8ToString(S)
SDL_Mouse * SDL_GetMouse(void)
SDL_bool g_WindowFrameUsableWhileCursorHidden
#define SDL_HINT_WINDOWS_INTRESOURCE_ICON
A variable to specify custom icon resource id from RC file on Windows platform.
#define SDL_IsShapedWindow
void SDL_SetKeyboardFocus(SDL_Window *window)
int Win32_ResizeWindowShape(SDL_Window *window)
GLint GLint GLint GLint GLint x
GLuint GLsizei const GLchar * message
SDL_bool relative_mode_warp
GLuint GLuint GLsizei count
int SDL_SendDropFile(SDL_Window *window, const char *file)
#define SDL_BUTTON_X2MASK
LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
GLfloat GLfloat GLfloat GLfloat h
The structure that defines a point.
void WIN_ResetDeadKeys(void)
#define SDL_GetWindowFlags
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_SetMouseFocus(SDL_Window *window)
#define SDL_GetKeyboardFocus
#define SDL_TOUCH_MOUSEID
union SDL_SysWMmsg::@16 msg
SDL_bool g_WindowsEnableMessageLoop
int SDL_SendDropComplete(SDL_Window *window)
int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
GLuint const GLchar * name
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
#define SDL_GetHintBoolean
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
void SDL_UnregisterApp(void)
#define SDL_GetWindowSize
SDL_bool in_border_change
GLenum GLenum GLenum input
#define SDL_GetEventState(type)
EGLImageKHR EGLint EGLint * handle
#define SDL_GetKeyboardState
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
struct SDL_VideoData * videodata
int SDL_SendKeyboardText(const char *text)
#define SDL_stack_alloc(type, count)
#define SDL_BUTTON_X1MASK
GLubyte GLubyte GLubyte GLubyte w
void WIN_UpdateClipCursor(SDL_Window *window)
#define WIN_StringToUTF8(S)
static Uint32 callback(Uint32 interval, void *param)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
#define SDL_GetWindowMinimumSize
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
BOOL(WINAPI *CloseTouchInputHandle)(HTOUCHINPUT)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
#define SDL_assert(condition)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
#define SDL_GetMouseFocus
#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL
void WIN_UpdateKeymap(void)
static char text[MAX_TEXT_LENGTH]
void WIN_PumpEvents(_THIS)
int SDL_SendKeymapChangedEvent(void)
EGLSurface EGLNativeWindowType * window
static const SDL_Scancode windows_scancode_table[]
The type used to identify a window.
void(* SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam)
Set a function that is called for every windows message, before TranslateMessage() ...
SDL_VideoDevice * SDL_GetVideoDevice(void)
#define SDL_GetWindowMaximumSize
SDL_bool in_window_deactivation
GLsizei const GLchar *const * path
void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata)
#define SDL_stack_free(data)
void WIN_CheckClipboardUpdate(struct SDL_VideoData *data)
WPARAM mouse_button_flags
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
Allow mouse click events when clicking to focus an SDL window.
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
SDL_Scancode
The SDL keyboard scancode representation.
#define SDL_GetMouseState
int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4
Tell SDL not to generate window-close events for Alt+F4 on Windows.
Uint8 focus_click_pending
SDL_bool IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, struct SDL_VideoData *videodata)