[client] add new option input:captureOnFocus

This option allows the client to automatically enter capture mode if the
window is focused.

Closes #1088
This commit is contained in:
Geoffrey McRae 2023-09-11 21:01:19 +10:00
parent 219c73edbe
commit 193977895b
3 changed files with 15 additions and 0 deletions

View file

@ -95,6 +95,9 @@ void app_updateCursorPos(double x, double y)
void app_handleFocusEvent(bool focused) void app_handleFocusEvent(bool focused)
{ {
if (g_state.focused == focused)
return;
g_state.focused = focused; g_state.focused = focused;
// release any imgui buttons/keys if we lost focus // release any imgui buttons/keys if we lost focus
@ -126,6 +129,9 @@ void app_handleFocusEvent(bool focused)
if (g_params.minimizeOnFocusLoss) if (g_params.minimizeOnFocusLoss)
g_state.ds->minimize(); g_state.ds->minimize();
} }
else
if (g_params.captureOnFocus)
core_setGrab(true);
g_cursor.realign = true; g_cursor.realign = true;
g_state.ds->realignPointer(); g_state.ds->realignPointer();

View file

@ -297,6 +297,13 @@ static struct Option options[] =
}, },
// input options // input options
{
.module = "input",
.name = "captureOnFocus",
.description = "Enable capture mode when the window becomes focused",
.type = OPTION_TYPE_BOOL,
.value.x_bool = false
},
{ {
.module = "input", .module = "input",
.name = "grabKeyboard", .name = "grabKeyboard",
@ -664,6 +671,7 @@ bool config_load(int argc, char * argv[])
case 270: g_params.winRotate = LG_ROTATE_270; break; case 270: g_params.winRotate = LG_ROTATE_270; break;
} }
g_params.captureOnFocus = option_get_bool("input", "captureOnFocus" );
g_params.grabKeyboard = option_get_bool("input", "grabKeyboard" ); g_params.grabKeyboard = option_get_bool("input", "grabKeyboard" );
g_params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus" ); g_params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus" );
g_params.releaseKeysOnFocusLoss = option_get_bool("input", "releaseKeysOnFocusLoss"); g_params.releaseKeysOnFocusLoss = option_get_bool("input", "releaseKeysOnFocusLoss");

View file

@ -186,6 +186,7 @@ struct AppParams
bool ignoreQuit; bool ignoreQuit;
bool noScreensaver; bool noScreensaver;
bool autoScreensaver; bool autoScreensaver;
bool captureOnFocus;
bool grabKeyboard; bool grabKeyboard;
bool grabKeyboardOnFocus; bool grabKeyboardOnFocus;
int escapeKey; int escapeKey;