Inputs: Treat ctrl-left-click as right click when ConfigMacOSXBehaviors is set. (#2343)

This commit is contained in:
ocornut
2024-05-17 15:24:11 +02:00
parent b4f564c1ed
commit 25e279ee73
3 changed files with 27 additions and 1 deletions

View File

@@ -1608,12 +1608,36 @@ void ImGuiIO::AddMouseButtonEvent(int mouse_button, bool down)
if (!AppAcceptingEvents)
return;
// On MacOS X: Convert Ctrl(Super)+Left click into Right-click: handle held button.
if (ConfigMacOSXBehaviors && mouse_button == 0 && MouseCtrlLeftAsRightClick)
{
// Order of both statements matterns: this event will still release mouse button 1
mouse_button = 1;
if (!down)
MouseCtrlLeftAsRightClick = false;
}
// Filter duplicate
const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_MouseButton, (int)mouse_button);
const bool latest_button_down = latest_event ? latest_event->MouseButton.Down : g.IO.MouseDown[mouse_button];
if (latest_button_down == down)
return;
// On MacOS X: Convert Ctrl(Super)+Left click into Right-click.
// - Note that this is actual physical Ctrl which is ImGuiMod_Super for us.
// - At this point we want from !down to down, so this is handling the initial press.
if (ConfigMacOSXBehaviors && mouse_button == 0 && down)
{
const ImGuiInputEvent* latest_super_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)ImGuiMod_Super);
if (latest_super_event ? latest_super_event->Key.Down : g.IO.KeySuper)
{
IMGUI_DEBUG_LOG_IO("[io] Super+Left Click aliased into Right Click\n");
MouseCtrlLeftAsRightClick = true;
AddMouseButtonEvent(1, true); // This is just quicker to write that passing through, as we need to filter duplicate again.
return;
}
}
ImGuiInputEvent e;
e.Type = ImGuiInputEventType_MouseButton;
e.Source = ImGuiInputSource_Mouse;