Cocoa: Treat control-left mouse click same as right mouse click to bring up context menu

This commit is contained in:
David Jenkins 2024-10-23 16:26:04 +00:00 committed by rich2014
parent 06bfb3b56a
commit 6fc0212b11
3 changed files with 29 additions and 0 deletions

View File

@ -158,6 +158,13 @@ var
classicFrame3d: False;
);
var
CocoaConfigMouse: TCocoaConfigMouse = (
// False: Control-Left-Click passes straight through
// True: Control-Left-Click will become Right Click
controlLeftToRightClick: False;
);
var
CocoaConfigNotification: TCocoaConfigNotification = (
// by default on macOS, Notification is only Presented when the APP is

View File

@ -302,6 +302,11 @@ type
classicFrame3d: Boolean;
end;
type
TCocoaConfigMouse = record
controlLeftToRightClick: Boolean;
end;
type
TCocoaConfigNotification = record
alwaysPresent: Boolean;

View File

@ -226,6 +226,7 @@ type
var
LastMouse: TLastMouseInfo;
LastMouseLeftButtonAsRight: Boolean;
function ButtonStateToShiftState(BtnState: PtrUInt): TShiftState;
begin
@ -964,6 +965,22 @@ begin
if AForceAsMouseUp then
lEventType := NSLeftMouseUp;
if CocoaConfigMouse.controlLeftToRightClick then begin
// treat ctrl+left button as right button
if (lEventType = NSLeftMouseDown) and
(Event.modifierFlags and NSControlKeyMask <> 0) then
LastMouseLeftButtonAsRight := True;
if LastMouseLeftButtonAsRight then
begin
if MButton = 0 then
MButton := 1;
if Msg.Keys and MK_LBUTTON <> 0 then
Msg.Keys := (Msg.Keys or MK_RBUTTON) and not MK_LBUTTON;
if lEventType = NSLeftMouseUp then
LastMouseLeftButtonAsRight := False;
end;
end;
Result := Result or (BlockCocoaUpDown and not AOverrideBlock);
mc := CocoaWidgetSet.ModalCounter;
case lEventType of