From 8ddb4328b5c17876bfae0affc861f461007ef0bc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 29 Sep 2016 03:59:04 -0700 Subject: [PATCH] When clicking on a window to give it focus, don't pass the mouse click to the application. --- src/video/windows/SDL_windowsevents.c | 30 ++++++++++++++++++++++----- src/video/windows/SDL_windowswindow.h | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index ee08de1be..31ecc7152 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -202,9 +202,15 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam) void WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button, SDL_MouseID mouseID) { - if (data->focus_click_pending && button == SDL_BUTTON_LEFT && !bwParamMousePressed) { - data->focus_click_pending = SDL_FALSE; - WIN_UpdateClipCursor(data->window); + if (data->focus_click_pending & SDL_BUTTON(button)) { + /* Ignore the button click for activation */ + if (!bwParamMousePressed) { + data->focus_click_pending &= ~SDL_BUTTON(button); + if (!data->focus_click_pending) { + WIN_UpdateClipCursor(data->window); + } + } + return; } if (bwParamMousePressed && !bSDLMousePressed) { @@ -398,8 +404,22 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) minimized = HIWORD(wParam); if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { - data->focus_click_pending = (GetAsyncKeyState(VK_LBUTTON) != 0); - + if (GetAsyncKeyState(VK_LBUTTON)) { + data->focus_click_pending |= SDL_BUTTON_LMASK; + } + if (GetAsyncKeyState(VK_RBUTTON)) { + data->focus_click_pending |= SDL_BUTTON_RMASK; + } + if (GetAsyncKeyState(VK_MBUTTON)) { + data->focus_click_pending |= SDL_BUTTON_MMASK; + } + if (GetAsyncKeyState(VK_XBUTTON1)) { + data->focus_click_pending |= SDL_BUTTON_X1MASK; + } + if (GetAsyncKeyState(VK_XBUTTON2)) { + data->focus_click_pending |= SDL_BUTTON_X2MASK; + } + SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); if (SDL_GetKeyboardFocus() != data->window) { SDL_SetKeyboardFocus(data->window); diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index e7b13c747..0f6a87e34 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -41,7 +41,7 @@ typedef struct SDL_bool expected_resize; SDL_bool in_border_change; SDL_bool in_title_click; - SDL_bool focus_click_pending; + Uint8 focus_click_pending; SDL_bool windowed_mode_was_maximized; SDL_bool in_window_deactivation; struct SDL_VideoData *videodata;