From 916d7502c8b225b0c73d5c8cad12b5d3099f8c47 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Wed, 16 Apr 2014 18:39:07 +0300 Subject: [PATCH] Lilypad: Better focus/capture/uncapture handling. 1. After ALT-Tab to another window and back, now it accepts PCSX2 shortcuts properly (e.g. Esc or F6 etc) - focus changes were not always recognized before. 2. If Lilypad is set to capture mouse, now it releases it on Escape. This part is a small hack because the code looks as if it should handle it, but in practice doesn't. This adds explicit uncapture on Escape. --- plugins/LilyPad/LilyPad.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/plugins/LilyPad/LilyPad.cpp b/plugins/LilyPad/LilyPad.cpp index 40e7065492..58725ccb41 100644 --- a/plugins/LilyPad/LilyPad.cpp +++ b/plugins/LilyPad/LilyPad.cpp @@ -868,6 +868,16 @@ ExtraWndProcResult TitleHackWndProc(HWND hWndTop, UINT uMsg, WPARAM wParam, LPAR return CONTINUE_BLISSFULLY; } +// Useful sequence before changing into active/inactive state. +// Handles hooking/unhooking of mouse and KB and also mouse cursor visibility. +// towardsActive==true indicates we're gaining activity (on focus etc), false is for losing activity (on close, kill focus, etc). +void PrepareActivityState(bool towardsActive) { + if (!towardsActive) + ReleaseModifierKeys(); + activeWindow = towardsActive; + UpdateEnabledDevices(); +} + // responsible for monitoring device addition/removal, focus changes, and viewport closures. ExtraWndProcResult StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) { switch (uMsg) { @@ -887,11 +897,8 @@ ExtraWndProcResult StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa case WM_ACTIVATE: // Release any buttons PCSX2 may think are down when // losing/gaining focus. - if (!wParam) { - ReleaseModifierKeys(); - } - activeWindow = (LOWORD(wParam) != WA_INACTIVE); - UpdateEnabledDevices(); + // Note - I never managed to see this case entered, but SET/KILLFOCUS are entered. - avih 2014-04-16 + PrepareActivityState(LOWORD(wParam) != WA_INACTIVE); break; case WM_CLOSE: if (config.closeHacks & 1) { @@ -906,6 +913,12 @@ ExtraWndProcResult StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa case WM_DESTROY: QueueKeyEvent(VK_ESCAPE, KEYPRESS); break; + case WM_KILLFOCUS: + PrepareActivityState(false); + break; + case WM_SETFOCUS: + PrepareActivityState(true); + break; default: break; } @@ -1386,6 +1399,19 @@ keyEvent* CALLBACK PADkeyEvent() { static char altDown = 0; static keyEvent ev; if (!GetQueuedKeyEvent(&ev)) return 0; + + if (miceEnabled && (ev.key == VK_ESCAPE || (int)ev.key == -2) && ev.evt == KEYPRESS) { + // Disable mouse/KB hooks on escape (before going into paused mode). + // This is a hack, since PADclose (which is called on pause) should enevtually also deactivate the + // mouse/kb capture. In practice, WindowsMessagingMouse::Deactivate is called from PADclose, but doesn't + // manage to release the mouse, maybe due to the thread from which it's called or some + // state or somehow being too late. + // This explicitly triggers inactivity (releasing mouse/kb hooks) before PCSX2 starts to close the plugins. + // Regardless, the mouse/kb hooks will get re-enabled on resume if required without need for further hacks. + + PrepareActivityState(false); + } + if ((ev.key == VK_ESCAPE || (int)ev.key == -2) && ev.evt == KEYPRESS && config.escapeFullscreenHack) { static int t; if ((int)ev.key != -2 && IsWindowMaximized(hWndTop)) {