Skip to content

Commit

Permalink
Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whe…
Browse files Browse the repository at this point in the history
…ther ctrl+click should emulate a right click on OSX.
  • Loading branch information
slouken committed Nov 8, 2013
1 parent 493fadd commit 621c7f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -341,7 +348,8 @@ - (void)mouseDown:(NSEvent *)theEvent

switch ([theEvent buttonNumber]) {
case 0:
if ([theEvent modifierFlags] & NSControlKeyMask) {
if (([theEvent modifierFlags] & NSControlKeyMask) &&
GetHintCtrlClickEmulateRightClick()) {
wasCtrlLeft = YES;
button = SDL_BUTTON_RIGHT;
} else {
Expand Down

0 comments on commit 621c7f8

Please sign in to comment.