From b13c14b039aff89ef503dbab30a8148256b6c04f Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Wed, 12 Jan 2022 19:39:17 +0200 Subject: [PATCH] Exit full screen mode if changing window with alt-tab etc. unintended way. --- src/win/win_opengl.c | 14 ++++++++++++++ src/win/win_ui.c | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/win/win_opengl.c b/src/win/win_opengl.c index 228cbb56f..99843cd9f 100644 --- a/src/win/win_opengl.c +++ b/src/win/win_opengl.c @@ -258,6 +258,13 @@ static int handle_window_messages(UINT message, WPARAM wParam, LPARAM lParam, in free(raw); } return 1; + case WM_MOUSELEAVE: + if (fullscreen) + { + /* Leave fullscreen if mouse leaves the renderer window. */ + PostMessage(GetAncestor(parent, GA_ROOT), WM_LEAVEFULLSCREEN, 0, 0); + } + return 0; } return 0; @@ -726,7 +733,14 @@ static void opengl_main(void* param) { SetForegroundWindow(window_hwnd); SetFocus(window_hwnd); + + /* Clip cursor to prevent it moving to another monitor. */ + RECT rect; + GetWindowRect(window_hwnd, &rect); + ClipCursor(&rect); } + else + ClipCursor(NULL); } if (fullscreen) diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 97084858c..c2740f0c7 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -961,6 +961,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_WINDOWPOSCHANGED: + if (video_fullscreen & 1) + PostMessage(hwndMain, WM_LEAVEFULLSCREEN, 0, 0); + pos = (WINDOWPOS*)lParam; GetClientRect(hwndMain, &rect); @@ -1160,6 +1163,13 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } break; + case WM_ACTIVATEAPP: + /* Leave full screen on switching application except + for OpenGL Core and VNC renderers. */ + if (video_fullscreen & 1 && wParam == FALSE && vid_api < 3) + PostMessage(hwndMain, WM_LEAVEFULLSCREEN, 0, 0); + break; + case WM_ENTERSIZEMOVE: user_resize = 1; break;