mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +00:00
[client] imgui: add mode to forward mouse input to imgui
This commit is contained in:
parent
6c64965703
commit
065d90c3f7
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ struct AppState
|
||||
struct ll * overlays;
|
||||
char * fontName;
|
||||
ImFont * fontLarge;
|
||||
bool overlayInput;
|
||||
|
||||
bool alertShow;
|
||||
char * alertMessage;
|
||||
|
Loading…
Reference in New Issue
Block a user