Skip to content

Commit

Permalink
#602 Exit on focus lost when mouse capture is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Laurendeau committed Dec 22, 2018
1 parent f599196 commit aa3db4e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void control_key(int sym, int down) {
}
}

if (lalt && ralt) {
ginput_grab_toggle();
if (lalt && ralt && gimx_params.config_file) {
gimx_params.grab = ginput_grab_toggle();
}
}
22 changes: 15 additions & 7 deletions core/gimx.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ s_gimx_params gimx_params =
.skip_leds = 0,
.ff_conv = 0,
.inactivity_timeout = 0,
.focus_lost = 0,
};

#ifdef WIN32
Expand Down Expand Up @@ -108,6 +109,13 @@ int process_event(GE_Event* event)
case GE_JOYRUMBLE:
cfg_process_rumble_event(event);
break;
case GE_FOCUS_LOST:
if (gimx_params.grab)
{
gimx_params.focus_lost = 1;
set_done();
}
break;
default:
if (!cal_skip_event(event))
{
Expand Down Expand Up @@ -193,7 +201,6 @@ void grab()
{
if(gimx_params.autograb)
{
int grab = 0;
int i;
for (i = 0; i < MAX_CONTROLLERS; ++i)
{
Expand All @@ -202,15 +209,11 @@ void grab()
// if config only has joystick bindings, window focus is not required, and grabbing mouse is not needed
if(adapter_get_device(E_DEVICE_TYPE_MOUSE, i) != -1 || adapter_get_device(E_DEVICE_TYPE_KEYBOARD, i) != -1)
{
grab = 1;
gimx_params.grab = 1;
}
}
if (grab)
{
ginput_grab();
}
}
else if(gimx_params.grab)
if(gimx_params.grab)
{
ginput_grab();
}
Expand Down Expand Up @@ -484,6 +487,11 @@ int main(int argc, char *argv[])
status = mstatus;
}

if (gimx_params.focus_lost)
{
status = E_GIMX_STATUS_FOCUS_LOST;
}

ginfo(_("Exiting\n"));

QUIT: ;
Expand Down
2 changes: 2 additions & 0 deletions core/include/gimx.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef enum {
E_GIMX_STATUS_NO_ACTIVATION = -3, // user did not activate the controller
E_GIMX_STATUS_INACTIVITY_TIMEOUT = -4, // no user input during defined time
E_GIMX_STATUS_AUTH_CONTROLLER_ERROR = -5, // connection issue with the authentication controller
E_GIMX_STATUS_FOCUS_LOST = -6, // mouse was grabbed and focus was lost

E_GIMX_STATUS_AUTH_MISSING_X360 = 1, // auth source missing
E_GIMX_STATUS_AUTH_MISSING_PS4 = 2, // auth source missing
Expand Down Expand Up @@ -78,6 +79,7 @@ typedef struct
int ff_conv;
unsigned int inactivity_timeout; // minutes, 0 means not defined
int autograb;
int focus_lost;
} s_gimx_params;

extern s_gimx_params gimx_params;
Expand Down
5 changes: 5 additions & 0 deletions launcher/gimx-launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@ typedef enum {
E_GIMX_STATUS_NO_ACTIVATION = -3, // user did not activate the controller
E_GIMX_STATUS_INACTIVITY_TIMEOUT = -4, // no user input during defined time
E_GIMX_STATUS_AUTH_CONTROLLER_ERROR = -5, // connection issue with the authentication controller
E_GIMX_STATUS_FOCUS_LOST = -6, // mouse was grabbed and focus was lost

E_GIMX_STATUS_AUTH_MISSING_X360 = 1, // auth source missing
E_GIMX_STATUS_AUTH_MISSING_PS4 = 2, // auth source missing
Expand Down Expand Up @@ -1737,6 +1738,10 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused
". make sure the cable is not bad (try another one)\n"
". make sure to turn controller off before connection."), _("Error"), wxICON_ERROR);
break;
case E_GIMX_STATUS_FOCUS_LOST:
wxMessageBox( _("Mouse was captured, input was \"physical devices\", and focus was lost. "
"Either you pressed alt+tab or some other app took focus.\n"), _("Error"), wxICON_ERROR);
break;
}

if(openLog)
Expand Down
2 changes: 1 addition & 1 deletion shared/gimxpoll

0 comments on commit aa3db4e

Please sign in to comment.