diff --git a/lcl/interfaces/cocoa/cocoaconfig.inc b/lcl/interfaces/cocoa/cocoaconfig.inc index c0b995d81a..8b08d6a751 100644 --- a/lcl/interfaces/cocoa/cocoaconfig.inc +++ b/lcl/interfaces/cocoa/cocoaconfig.inc @@ -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 diff --git a/lcl/interfaces/cocoa/cocoaconfig.pas b/lcl/interfaces/cocoa/cocoaconfig.pas index 0373e48789..4192009756 100644 --- a/lcl/interfaces/cocoa/cocoaconfig.pas +++ b/lcl/interfaces/cocoa/cocoaconfig.pas @@ -302,6 +302,11 @@ type classicFrame3d: Boolean; end; +type + TCocoaConfigMouse = record + controlLeftToRightClick: Boolean; + end; + type TCocoaConfigNotification = record alwaysPresent: Boolean; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index d539a89da0..fab503f094 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -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