[client] main: don't use Linux keybinds if the guest is not Linux

This commit is contained in:
Geoffrey McRae 2022-01-17 20:26:45 +11:00
parent afd5e2d057
commit 5a3fe151e4
6 changed files with 122 additions and 32 deletions

View File

@ -162,4 +162,11 @@ void app_releaseKeybind(KeybindHandle * handle);
*/ */
void app_releaseAllKeybinds(void); void app_releaseAllKeybinds(void);
bool app_guestIsLinux(void);
bool app_guestIsWindows(void);
bool app_guestIsOSX(void);
bool app_guestIsBSD(void);
bool app_guestIsOther(void);
#endif #endif

View File

@ -948,3 +948,28 @@ void app_invalidateOverlay(bool renderTwice)
g_state.renderImGuiTwice = true; g_state.renderImGuiTwice = true;
app_invalidateWindow(false); app_invalidateWindow(false);
} }
bool app_guestIsLinux(void)
{
return g_state.guestOS == KVMFR_OS_LINUX;
}
bool app_guestIsWindows(void)
{
return g_state.guestOS == KVMFR_OS_WINDOWS;
}
bool app_guestIsOSX(void)
{
return g_state.guestOS == KVMFR_OS_OSX;
}
bool app_guestIsBSD(void)
{
return g_state.guestOS == KVMFR_OS_BSD;
}
bool app_guestIsOther(void)
{
return g_state.guestOS == KVMFR_OS_OTHER;
}

View File

@ -139,38 +139,83 @@ static void bind_toggleKey(int sc, void * opaque)
purespice_keyUp((uintptr_t) opaque); purespice_keyUp((uintptr_t) opaque);
} }
void keybind_register(void) void keybind_commonRegister(void)
{ {
app_registerKeybind(KEY_F, bind_fullscreen , NULL, "Full screen toggle"); app_registerKeybind(KEY_F, bind_fullscreen , NULL,
app_registerKeybind(KEY_V, bind_video , NULL, "Video stream toggle"); "Full screen toggle");
app_registerKeybind(KEY_R, bind_rotate , NULL, "Rotate the output clockwise by 90° increments"); app_registerKeybind(KEY_V, bind_video , NULL,
app_registerKeybind(KEY_Q, bind_quit , NULL, "Quit"); "Video stream toggle");
app_registerKeybind(KEY_O, bind_toggleOverlay, NULL, "Toggle overlay"); app_registerKeybind(KEY_R, bind_rotate , NULL,
"Rotate the output clockwise by 90° increments");
app_registerKeybind(KEY_Q, bind_quit , NULL,
"Quit");
app_registerKeybind(KEY_O, bind_toggleOverlay, NULL,
"Toggle overlay");
}
if (g_params.useSpiceInput) void keybind_spiceRegister(void)
{
/* register the common keybinds for spice */
static bool firstTime = true;
if (firstTime)
{ {
app_registerKeybind(KEY_I , bind_input , NULL , "Spice keyboard & mouse toggle"); app_registerKeybind(KEY_I, bind_input, NULL,
app_registerKeybind(KEY_INSERT, bind_mouseSens, (void*)true , "Increase mouse sensitivity in capture mode"); "Spice keyboard & mouse toggle");
app_registerKeybind(KEY_DELETE, bind_mouseSens, (void*)false, "Descrease mouse sensitivity in capture mode");
app_registerKeybind(KEY_F1 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F1 to the guest"); app_registerKeybind(KEY_INSERT, bind_mouseSens, (void *) true ,
app_registerKeybind(KEY_F2 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F2 to the guest"); "Increase mouse sensitivity in capture mode");
app_registerKeybind(KEY_F3 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F3 to the guest"); app_registerKeybind(KEY_DELETE, bind_mouseSens, (void *) false,
app_registerKeybind(KEY_F4 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F4 to the guest"); "Descrease mouse sensitivity in capture mode");
app_registerKeybind(KEY_F5 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F5 to the guest");
app_registerKeybind(KEY_F6 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F6 to the guest");
app_registerKeybind(KEY_F7 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F7 to the guest");
app_registerKeybind(KEY_F8 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F8 to the guest");
app_registerKeybind(KEY_F9 , bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F9 to the guest");
app_registerKeybind(KEY_F10, bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F10 to the guest");
app_registerKeybind(KEY_F11, bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F11 to the guest");
app_registerKeybind(KEY_F12, bind_ctrlAltFn, NULL, "Send Ctrl+Alt+F12 to the guest");
app_registerKeybind(KEY_LEFTMETA , bind_passthrough, NULL, "Send LWin to the guest"); app_registerKeybind(KEY_UP , bind_toggleKey, (void *) PS2_VOLUME_UP ,
app_registerKeybind(KEY_RIGHTMETA, bind_passthrough, NULL, "Send RWin to the guest"); "Send volume up to the guest");
app_registerKeybind(KEY_DOWN, bind_toggleKey, (void *) PS2_VOLUME_DOWN,
"Send volume down to the guest");
app_registerKeybind(KEY_M , bind_toggleKey, (void *) PS2_MUTE ,
"Send mute to the guest");
app_registerKeybind(KEY_UP , bind_toggleKey, (void *) PS2_VOLUME_UP , "Send volume up to the guest"); app_registerKeybind(KEY_LEFTMETA , bind_passthrough, NULL,
app_registerKeybind(KEY_DOWN, bind_toggleKey, (void *) PS2_VOLUME_DOWN, "Send volume down to the guest"); "Send LWin to the guest");
app_registerKeybind(KEY_M , bind_toggleKey, (void *) PS2_MUTE , "Send mute to the guest"); app_registerKeybind(KEY_RIGHTMETA, bind_passthrough, NULL,
"Send RWin to the guest");
firstTime = false;
}
/* release any OS based keybinds that have been bound */
static KeybindHandle handles[32] = { 0 }; // increase size as needed
static int handleCount = 0;
for(int i = 0; i < handleCount; ++i)
app_releaseKeybind(&handles[i]);
handleCount = 0;
/* register OS based keybinds */
if (app_guestIsLinux())
{
handles[handleCount++] = app_registerKeybind(KEY_F1 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F1 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F2 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F2 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F3 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F3 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F4 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F4 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F5 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F5 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F6 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F6 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F7 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F7 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F8 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F8 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F9 , bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F9 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F10, bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F10 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F11, bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F11 to the guest");
handles[handleCount++] = app_registerKeybind(KEY_F12, bind_ctrlAltFn, NULL,
"Send Ctrl+Alt+F12 to the guest");
} }
} }

View File

@ -21,6 +21,7 @@
#ifndef _H_LG_KEYBIND_ #ifndef _H_LG_KEYBIND_
#define _H_LG_KEYBIND_ #define _H_LG_KEYBIND_
void keybind_register(void); void keybind_commonRegister(void);
void keybind_spiceRegister(void);
#endif #endif

View File

@ -798,7 +798,7 @@ int main_frameThread(void * unused)
static void checkUUID(void) static void checkUUID(void)
{ {
if (!g_state.spiceUUIDValid || !g_state.guestUUIDValid) if (!g_state.spiceReady || !g_state.guestUUIDValid)
return; return;
if (memcmp(g_state.spiceUUID, g_state.guestUUID, if (memcmp(g_state.spiceUUID, g_state.guestUUID,
@ -836,9 +836,12 @@ void spiceReady(void)
return; return;
memcpy(g_state.spiceUUID, info.uuid, sizeof(g_state.spiceUUID)); memcpy(g_state.spiceUUID, info.uuid, sizeof(g_state.spiceUUID));
g_state.spiceUUIDValid = true; g_state.spiceReady = true;
checkUUID(); checkUUID();
if (g_params.useSpiceInput)
keybind_spiceRegister();
purespice_freeServerInfo(&info); purespice_freeServerInfo(&info);
} }
@ -1034,6 +1037,9 @@ static int lg_run(void)
initImGuiKeyMap(g_state.io->KeyMap); initImGuiKeyMap(g_state.io->KeyMap);
// unknown guest OS at this time
g_state.guestOS = KVMFR_OS_OTHER;
// search for the best displayserver ops to use // search for the best displayserver ops to use
for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i) for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i)
if (LG_DisplayServers[i]->probe()) if (LG_DisplayServers[i]->probe())
@ -1179,7 +1185,7 @@ static int lg_run(void)
// interactivity. // interactivity.
g_state.overlayFrameTime = min(g_state.frameTime, 1000000000ULL / 60ULL); g_state.overlayFrameTime = min(g_state.frameTime, 1000000000ULL / 60ULL);
keybind_register(); keybind_commonRegister();
// setup the startup condition // setup the startup condition
if (!(e_startup = lgCreateEvent(false, 0))) if (!(e_startup = lgCreateEvent(false, 0)))
@ -1449,6 +1455,11 @@ restart:
DEBUG_INFO("OS : %s", type); DEBUG_INFO("OS : %s", type);
if (osInfo->name[0]) if (osInfo->name[0])
DEBUG_INFO("OS Name : %s", osInfo->name); DEBUG_INFO("OS Name : %s", osInfo->name);
g_state.guestOS = osInfo->os;
if (g_state.spiceReady && g_params.useSpiceInput)
keybind_spiceRegister();
break; break;
} }

View File

@ -70,9 +70,10 @@ struct AppState
bool jitRender; bool jitRender;
uint8_t spiceUUID[16]; uint8_t spiceUUID[16];
bool spiceUUIDValid; bool spiceReady;
uint8_t guestUUID[16]; uint8_t guestUUID[16];
bool guestUUIDValid; bool guestUUIDValid;
KVMFROS guestOS;
bool stopVideo; bool stopVideo;
bool ignoreInput; bool ignoreInput;