Skip to content

Commit

Permalink
Lilypad: Better focus/capture/uncapture handling.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
avih committed Apr 16, 2014
1 parent da4a785 commit 916d750
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions plugins/LilyPad/LilyPad.cpp
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down

1 comment on commit 916d750

@ramapcsx2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks man :p

Please sign in to comment.