From 7ea7625db5fff1ebf0f9bb2dff9225c8621cdec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 15 Dec 2015 08:32:48 +0100 Subject: [PATCH] osx: correct modifier key --- src/platform/platform.h | 6 ++++++ src/platform/shared.c | 25 +++++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/platform/platform.h b/src/platform/platform.h index aace0e42dc..f0956231b3 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -33,6 +33,12 @@ #define MAX_PATH 260 #endif +#if defined(__APPLE__) && defined(__MACH__) +#define KEYBOARD_PRIMARY_MODIFIER KMOD_GUI +#else +#define KEYBOARD_PRIMARY_MODIFIER KMOD_CTRL +#endif + #define INVALID_HANDLE -1 typedef struct { diff --git a/src/platform/shared.c b/src/platform/shared.c index 4185c57b8a..b1a981842a 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -531,16 +531,14 @@ void platform_process_messages() // Text input - // Clear the input on Backspace - if (gTextInput != NULL - && e.key.keysym.sym == SDLK_BACKSPACE - && e.key.keysym.mod & KMOD_CTRL) { - memset(gTextInput, '\0', gTextInputMaxLength); - gTextInputCursorPosition = 0; - gTextInputLength = 0; - console_refresh_caret(); - window_update_textbox(); - } + // Clear the input on Backspace (Windows/Linux) or Backspace (OS X) + if (gTextInput != NULL && e.key.keysym.sym == SDLK_BACKSPACE && (e.key.keysym.mod & KEYBOARD_PRIMARY_MODIFIER)) { + memset(gTextInput, '\0', gTextInputMaxLength); + gTextInputCursorPosition = 0; + gTextInputLength = 0; + console_refresh_caret(); + window_update_textbox(); + } // If backspace and we have input text with a cursor position none zero if (e.key.keysym.sym == SDLK_BACKSPACE && gTextInputLength > 0 && gTextInput != NULL && gTextInputCursorPosition) { @@ -601,12 +599,7 @@ void platform_process_messages() } while (!utf8_is_codepoint_start(&gTextInput[gTextInputCursorPosition])); console_refresh_caret(); } - // Checks GUI modifier key for MACs otherwise CTRL key -#ifdef MAC - else if (e.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_GUI && gTextInput != NULL) { -#else - else if (e.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL && gTextInput != NULL) { -#endif + else if (e.key.keysym.sym == SDLK_v && (SDL_GetModState() & KEYBOARD_PRIMARY_MODIFIER) && gTextInput != NULL) { if (SDL_HasClipboardText()) { utf8 *text = SDL_GetClipboardText(); for (int i = 0; text[i] != '\0' && gTextInputLength < gTextInputMaxLength; i++) {