Skip to content

Commit

Permalink
Mouse capture improvements on Windows #641 #656
Browse files Browse the repository at this point in the history
  • Loading branch information
matlo committed Apr 24, 2020
1 parent fa715b1 commit 581955c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 47 deletions.
62 changes: 25 additions & 37 deletions core/gimx.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ s_gimx_params gimx_params =
.skip_leds = 0,
.ff_conv = 0,
.inactivity_timeout = 0,
.focus_lost = 0,
.clock_source = CLOCK_TIMER,
};

Expand Down Expand Up @@ -95,14 +94,22 @@ void terminate(int sig __attribute__((unused)))
set_done();
}

void grab()
{
if(gimx_params.grab)
{
ginput_grab();
}
}

int ignore_event(GE_Event* event __attribute__((unused)))
{
return 0;
}

int process_event(GE_Event* event)
{
if (!gimx_params.config_file)
if (!gimx_params.config_file || get_done())
{
return 0;
}
Expand All @@ -124,13 +131,6 @@ 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 @@ -212,29 +212,6 @@ void show_config()
}
}

void grab()
{
if(gimx_params.autograb)
{
gimx_params.grab = 0;
int i;
for (i = 0; i < MAX_CONTROLLERS; ++i)
{
// check if config has a keyboard binding or a mouse binding
// in most cases window focus is required for getting keyboard/mouse events
// 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)
{
gimx_params.grab = 1;
}
}
}
if(gimx_params.grab)
{
ginput_grab();
}
}

int main(int argc, char *argv[])
{
e_gimx_status status = E_GIMX_STATUS_SUCCESS;
Expand Down Expand Up @@ -426,6 +403,22 @@ int main(int argc, char *argv[])

cfg_pair_mouse_mappers();

if(gimx_params.autograb)
{
gimx_params.grab = 0;
int i;
for (i = 0; i < MAX_CONTROLLERS; ++i)
{
// check if config has a keyboard binding or a mouse binding
// in most cases window focus is required for getting keyboard/mouse events
// 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)
{
gimx_params.grab = 1;
}
}
}

grab();

ginput_release_unused();
Expand Down Expand Up @@ -500,11 +493,6 @@ int main(int argc, char *argv[])

gprio_clean();

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

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

QUIT: ;
Expand Down
3 changes: 1 addition & 2 deletions core/gimx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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_FOCUS_LOST = -6, // mouse was grabbed and focus was lost (no more returned, deprecated)

E_GIMX_STATUS_AUTH_MISSING_X360 = 1, // auth source missing
E_GIMX_STATUS_AUTH_MISSING_PS4 = 2, // auth source missing
Expand Down Expand Up @@ -88,7 +88,6 @@ typedef struct
int ff_conv;
unsigned int inactivity_timeout; // minutes, 0 means not defined
int autograb;
int focus_lost;
enum {
CLOCK_TIMER,
CLOCK_TARGET,
Expand Down
6 changes: 1 addition & 5 deletions launcher/gimx-launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,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_FOCUS_LOST = -6, // mouse was grabbed and focus was lost (no more returned, deprecated)

E_GIMX_STATUS_AUTH_MISSING_X360 = 1, // auth source missing
E_GIMX_STATUS_AUTH_MISSING_PS4 = 2, // auth source missing
Expand Down Expand Up @@ -1733,10 +1733,6 @@ 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/gimxcommon
Submodule gimxcommon updated 1 files
+16 −3 test/input.c
2 changes: 1 addition & 1 deletion shared/gimxpoll

0 comments on commit 581955c

Please sign in to comment.