diff --git a/client/src/app.c b/client/src/app.c index 3f49f87d..2849e5b1 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -68,6 +68,9 @@ void app_updateCursorPos(double x, double y) g_cursor.pos.x = x; g_cursor.pos.y = y; g_cursor.valid = true; + + if (g_state.overlayInput) + g_state.io->MousePos = (ImVec2) { x * g_state.windowScale, y * g_state.windowScale }; } void app_handleFocusEvent(bool focused) @@ -214,10 +217,34 @@ void spiceClipboardNotice(const SpiceDataType type) g_state.ds->cbNotice(cb_spiceTypeToLGType(type)); } +static int mapSpiceToImGuiButton(uint32_t button) +{ + switch (button) + { + case 1: // SPICE_MOUSE_BUTTON_LEFT + return ImGuiMouseButton_Left; + case 2: // SPICE_MOUSE_BUTTON_MIDDLE + return ImGuiMouseButton_Middle; + case 3: // SPICE_MOUSE_BUTTON_RIGHT + return ImGuiMouseButton_Right; + } + + return -1; +} + void app_handleButtonPress(int button) { g_cursor.buttons |= (1U << button); + if (g_state.overlayInput) + { + int igButton = mapSpiceToImGuiButton(button); + if (igButton != -1) + g_state.io->MouseDown[igButton] = true; + if (g_state.io->WantCaptureMouse) + return; + } + if (!core_inputEnabled() || !g_cursor.inView) return; @@ -229,6 +256,15 @@ void app_handleButtonRelease(int button) { g_cursor.buttons &= ~(1U << button); + if (g_state.overlayInput) + { + int igButton = mapSpiceToImGuiButton(button); + if (igButton != -1) + g_state.io->MouseDown[igButton] = false; + if (g_state.io->WantCaptureMouse) + return; + } + if (!core_inputEnabled()) return; diff --git a/client/src/keybind.c b/client/src/keybind.c index 1aa43b0e..5d57407c 100644 --- a/client/src/keybind.c +++ b/client/src/keybind.c @@ -133,14 +133,30 @@ static void bind_passthrough(int sc, void * opaque) spice_key_up (sc); } +static void bind_toggleOverlay(int sc, void * opaque) +{ + g_state.overlayInput ^= true; + if (g_state.overlayInput) + { + g_state.io->ConfigFlags &= ~ImGuiConfigFlags_NoMouse; + app_alert(LG_ALERT_INFO, "Overlay input enabled"); + } + else + { + g_state.io->ConfigFlags |= ImGuiConfigFlags_NoMouse; + app_alert(LG_ALERT_INFO, "Overlay input disabled"); + } +} + void keybind_register(void) { - app_registerKeybind(KEY_F, bind_fullscreen, NULL, "Full screen toggle"); - app_registerKeybind(KEY_V, bind_video , NULL, "Video stream toggle"); - app_registerKeybind(KEY_D, bind_showFPS , NULL, "FPS display toggle"); - app_registerKeybind(KEY_T, bind_showTiming, NULL, "Show frame timing information"); - 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_F, bind_fullscreen , NULL, "Full screen toggle"); + app_registerKeybind(KEY_V, bind_video , NULL, "Video stream toggle"); + app_registerKeybind(KEY_D, bind_showFPS , NULL, "FPS display toggle"); + app_registerKeybind(KEY_T, bind_showTiming , NULL, "Show frame timing information"); + 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) { diff --git a/client/src/main.h b/client/src/main.h index 8f166152..01e73cee 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -53,6 +53,7 @@ struct AppState struct ll * overlays; char * fontName; ImFont * fontLarge; + bool overlayInput; bool alertShow; char * alertMessage;