Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 01399b6..8e561fb 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -283,6 +283,14 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
+/**
+ * \brief A variable that determines whether ctrl+click should generate a right-click event on Mac
+ *
+ * If present, holding ctrl while left clicking will generate a right click
+ * event when on Mac.
+ */
+#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"
+
/**
* \brief An enumeration of hint priorities
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 5529983..b73a837 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -24,6 +24,7 @@
#include "SDL_syswm.h"
#include "SDL_timer.h" /* For SDL_GetTicks() */
+#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
@@ -59,6 +60,12 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
}
}
+static int GetHintCtrlClickEmulateRightClick()
+{
+ const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
+ return hint != NULL && *hint != '0';
+}
+
@implementation Cocoa_WindowListener
- (void)listen:(SDL_WindowData *)data
@@ -341,7 +348,8 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
switch ([theEvent buttonNumber]) {
case 0:
- if ([theEvent modifierFlags] & NSControlKeyMask) {
+ if (([theEvent modifierFlags] & NSControlKeyMask) &&
+ GetHintCtrlClickEmulateRightClick()) {
wasCtrlLeft = YES;
button = SDL_BUTTON_RIGHT;
} else {