Skip to content

Commit

Permalink
When clicking on a window to give it focus, don't pass the mouse clic…
Browse files Browse the repository at this point in the history
…k to the application.
  • Loading branch information
slouken committed Sep 29, 2016
1 parent f33c58b commit 8ddb432
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/video/windows/SDL_windowswindow.h
Expand Up @@ -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;
Expand Down

0 comments on commit 8ddb432

Please sign in to comment.