summaryrefslogtreecommitdiff
path: root/src/video/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/video/cocoa')
-rw-r--r--src/video/cocoa/cocoa_keys.h122
-rw-r--r--src/video/cocoa/cocoa_wnd.mm173
-rw-r--r--src/video/cocoa/event.mm297
3 files changed, 302 insertions, 290 deletions
diff --git a/src/video/cocoa/cocoa_keys.h b/src/video/cocoa/cocoa_keys.h
index def145d24..e09fe3c8a 100644
--- a/src/video/cocoa/cocoa_keys.h
+++ b/src/video/cocoa/cocoa_keys.h
@@ -131,4 +131,126 @@
#define QZ_IBOOK_DOWN 0x3D
#define QZ_IBOOK_UP 0x3E
+
+struct VkMapping {
+ unsigned short vk_from;
+ byte map_to;
+};
+
+#define AS(x, z) {x, z}
+
+static const VkMapping _vk_mapping[] = {
+ AS(QZ_BACKQUOTE, WKC_BACKQUOTE), // key left of '1'
+ AS(QZ_BACKQUOTE2, WKC_BACKQUOTE), // some keyboards have it on another scancode
+
+ /* Pageup stuff + up/down */
+ AS(QZ_PAGEUP, WKC_PAGEUP),
+ AS(QZ_PAGEDOWN, WKC_PAGEDOWN),
+
+ AS(QZ_UP, WKC_UP),
+ AS(QZ_DOWN, WKC_DOWN),
+ AS(QZ_LEFT, WKC_LEFT),
+ AS(QZ_RIGHT, WKC_RIGHT),
+
+ AS(QZ_HOME, WKC_HOME),
+ AS(QZ_END, WKC_END),
+
+ AS(QZ_INSERT, WKC_INSERT),
+ AS(QZ_DELETE, WKC_DELETE),
+
+ /* Letters. QZ_[a-z] is not in numerical order so we can't use AM(...) */
+ AS(QZ_a, 'A'),
+ AS(QZ_b, 'B'),
+ AS(QZ_c, 'C'),
+ AS(QZ_d, 'D'),
+ AS(QZ_e, 'E'),
+ AS(QZ_f, 'F'),
+ AS(QZ_g, 'G'),
+ AS(QZ_h, 'H'),
+ AS(QZ_i, 'I'),
+ AS(QZ_j, 'J'),
+ AS(QZ_k, 'K'),
+ AS(QZ_l, 'L'),
+ AS(QZ_m, 'M'),
+ AS(QZ_n, 'N'),
+ AS(QZ_o, 'O'),
+ AS(QZ_p, 'P'),
+ AS(QZ_q, 'Q'),
+ AS(QZ_r, 'R'),
+ AS(QZ_s, 'S'),
+ AS(QZ_t, 'T'),
+ AS(QZ_u, 'U'),
+ AS(QZ_v, 'V'),
+ AS(QZ_w, 'W'),
+ AS(QZ_x, 'X'),
+ AS(QZ_y, 'Y'),
+ AS(QZ_z, 'Z'),
+ /* Same thing for digits */
+ AS(QZ_0, '0'),
+ AS(QZ_1, '1'),
+ AS(QZ_2, '2'),
+ AS(QZ_3, '3'),
+ AS(QZ_4, '4'),
+ AS(QZ_5, '5'),
+ AS(QZ_6, '6'),
+ AS(QZ_7, '7'),
+ AS(QZ_8, '8'),
+ AS(QZ_9, '9'),
+
+ AS(QZ_ESCAPE, WKC_ESC),
+ AS(QZ_PAUSE, WKC_PAUSE),
+ AS(QZ_BACKSPACE, WKC_BACKSPACE),
+
+ AS(QZ_SPACE, WKC_SPACE),
+ AS(QZ_RETURN, WKC_RETURN),
+ AS(QZ_TAB, WKC_TAB),
+
+ /* Function keys */
+ AS(QZ_F1, WKC_F1),
+ AS(QZ_F2, WKC_F2),
+ AS(QZ_F3, WKC_F3),
+ AS(QZ_F4, WKC_F4),
+ AS(QZ_F5, WKC_F5),
+ AS(QZ_F6, WKC_F6),
+ AS(QZ_F7, WKC_F7),
+ AS(QZ_F8, WKC_F8),
+ AS(QZ_F9, WKC_F9),
+ AS(QZ_F10, WKC_F10),
+ AS(QZ_F11, WKC_F11),
+ AS(QZ_F12, WKC_F12),
+
+ /* Numeric part */
+ AS(QZ_KP0, '0'),
+ AS(QZ_KP1, '1'),
+ AS(QZ_KP2, '2'),
+ AS(QZ_KP3, '3'),
+ AS(QZ_KP4, '4'),
+ AS(QZ_KP5, '5'),
+ AS(QZ_KP6, '6'),
+ AS(QZ_KP7, '7'),
+ AS(QZ_KP8, '8'),
+ AS(QZ_KP9, '9'),
+ AS(QZ_KP_DIVIDE, WKC_NUM_DIV),
+ AS(QZ_KP_MULTIPLY, WKC_NUM_MUL),
+ AS(QZ_KP_MINUS, WKC_NUM_MINUS),
+ AS(QZ_KP_PLUS, WKC_NUM_PLUS),
+ AS(QZ_KP_ENTER, WKC_NUM_ENTER),
+ AS(QZ_KP_PERIOD, WKC_NUM_DECIMAL),
+
+ /* Other non-letter keys */
+ AS(QZ_SLASH, WKC_SLASH),
+ AS(QZ_SEMICOLON, WKC_SEMICOLON),
+ AS(QZ_EQUALS, WKC_EQUALS),
+ AS(QZ_LEFTBRACKET, WKC_L_BRACKET),
+ AS(QZ_BACKSLASH, WKC_BACKSLASH),
+ AS(QZ_RIGHTBRACKET, WKC_R_BRACKET),
+
+ AS(QZ_QUOTE, WKC_SINGLEQUOTE),
+ AS(QZ_COMMA, WKC_COMMA),
+ AS(QZ_MINUS, WKC_MINUS),
+ AS(QZ_PERIOD, WKC_PERIOD)
+};
+
+#undef AS
+
#endif
diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm
index e9ea69705..2755b26ff 100644
--- a/src/video/cocoa/cocoa_wnd.mm
+++ b/src/video/cocoa/cocoa_wnd.mm
@@ -34,6 +34,10 @@
#include "../../window_gui.h"
+/* Table data for key mapping. */
+#include "cocoa_keys.h"
+
+
/**
* Important notice regarding all modifications!!!!!!!
* There are certain limitations because the file is objective C++.
@@ -47,6 +51,8 @@
NSString *OTTDMainLaunchGameEngine = @"ottdmain_launch_game_engine";
+bool _tab_is_down;
+
static bool _cocoa_video_dialog = false;
static OTTDMain *_ottd_main;
@@ -89,6 +95,31 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
return str;
}
+/**
+ * Convert a NSString to an UTF-32 encoded string.
+ * @param s String to convert.
+ * @return Vector of UTF-32 characters.
+ */
+static std::vector<WChar> NSStringToUTF32(NSString *s)
+{
+ std::vector<WChar> unicode_str;
+
+ unichar lead = 0;
+ for (NSUInteger i = 0; i < s.length; i++) {
+ unichar c = [ s characterAtIndex:i ];
+ if (Utf16IsLeadSurrogate(c)) {
+ lead = c;
+ continue;
+ } else if (Utf16IsTrailSurrogate(c)) {
+ if (lead != 0) unicode_str.push_back(Utf16DecodeSurrogate(lead, c));
+ } else {
+ unicode_str.push_back(c);
+ }
+ }
+
+ return unicode_str;
+}
+
/**
* The main class of the application, the application's delegate.
@@ -419,6 +450,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
@implementation OTTD_CocoaView {
float _current_magnification;
+ NSUInteger _current_mods;
}
/**
@@ -614,6 +646,147 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
}
+- (BOOL)internalHandleKeycode:(unsigned short)keycode unicode:(WChar)unicode pressed:(BOOL)down modifiers:(NSUInteger)modifiers
+{
+ switch (keycode) {
+ case QZ_UP: SB(_dirkeys, 1, 1, down); break;
+ case QZ_DOWN: SB(_dirkeys, 3, 1, down); break;
+ case QZ_LEFT: SB(_dirkeys, 0, 1, down); break;
+ case QZ_RIGHT: SB(_dirkeys, 2, 1, down); break;
+
+ case QZ_TAB: _tab_is_down = down; break;
+
+ case QZ_RETURN:
+ case QZ_f:
+ if (down && (modifiers & NSCommandKeyMask)) {
+ VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
+ }
+ break;
+
+ case QZ_v:
+ if (down && EditBoxInGlobalFocus() && (modifiers & (NSCommandKeyMask | NSControlKeyMask))) {
+ HandleKeypress(WKC_CTRL | 'V', unicode);
+ }
+ break;
+ case QZ_u:
+ if (down && EditBoxInGlobalFocus() && (modifiers & (NSCommandKeyMask | NSControlKeyMask))) {
+ HandleKeypress(WKC_CTRL | 'U', unicode);
+ }
+ break;
+ }
+
+ BOOL interpret_keys = YES;
+ if (down) {
+ /* Map keycode to OTTD code. */
+ auto vk = std::find_if(std::begin(_vk_mapping), std::end(_vk_mapping), [=](const VkMapping &m) { return m.vk_from == keycode; });
+ uint32 pressed_key = vk != std::end(_vk_mapping) ? vk->map_to : 0;
+
+ if (modifiers & NSShiftKeyMask) pressed_key |= WKC_SHIFT;
+ if (modifiers & NSControlKeyMask) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_CTRL : WKC_META);
+ if (modifiers & NSAlternateKeyMask) pressed_key |= WKC_ALT;
+ if (modifiers & NSCommandKeyMask) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL);
+
+ static bool console = false;
+
+ /* The second backquote may have a character, which we don't want to interpret. */
+ if (pressed_key == WKC_BACKQUOTE && (console || unicode == 0)) {
+ if (!console) {
+ /* Backquote is a dead key, require a double press for hotkey behaviour (i.e. console). */
+ console = true;
+ return YES;
+ } else {
+ /* Second backquote, don't interpret as text input. */
+ interpret_keys = NO;
+ }
+ }
+ console = false;
+
+ /* Don't handle normal characters if an edit box has the focus. */
+ if (!EditBoxInGlobalFocus() || IsInsideMM(pressed_key & ~WKC_SPECIAL_KEYS, WKC_F1, WKC_PAUSE + 1)) {
+ HandleKeypress(pressed_key, unicode);
+ }
+ DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key);
+ } else {
+ DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode);
+ }
+
+ return interpret_keys;
+}
+
+- (void)keyDown:(NSEvent *)event
+{
+ /* Quit, hide and minimize */
+ switch (event.keyCode) {
+ case QZ_q:
+ case QZ_h:
+ case QZ_m:
+ if (event.modifierFlags & NSCommandKeyMask) {
+ [ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
+ }
+ break;
+ }
+
+ /* Convert UTF-16 characters to UCS-4 chars. */
+ std::vector<WChar> unicode_str = NSStringToUTF32([ event characters ]);
+ if (unicode_str.empty()) unicode_str.push_back(0);
+
+ if (EditBoxInGlobalFocus()) {
+ if ([ self internalHandleKeycode:event.keyCode unicode:unicode_str[0] pressed:YES modifiers:event.modifierFlags ]) {
+ [ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
+ }
+ } else {
+ [ self internalHandleKeycode:event.keyCode unicode:unicode_str[0] pressed:YES modifiers:event.modifierFlags ];
+ for (size_t i = 1; i < unicode_str.size(); i++) {
+ [ self internalHandleKeycode:0 unicode:unicode_str[i] pressed:YES modifiers:event.modifierFlags ];
+ }
+ }
+}
+
+- (void)keyUp:(NSEvent *)event
+{
+ /* Quit, hide and minimize */
+ switch (event.keyCode) {
+ case QZ_q:
+ case QZ_h:
+ case QZ_m:
+ if (event.modifierFlags & NSCommandKeyMask) {
+ [ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
+ }
+ break;
+ }
+
+ /* Convert UTF-16 characters to UCS-4 chars. */
+ std::vector<WChar> unicode_str = NSStringToUTF32([ event characters ]);
+ if (unicode_str.empty()) unicode_str.push_back(0);
+
+ [ self internalHandleKeycode:event.keyCode unicode:unicode_str[0] pressed:NO modifiers:event.modifierFlags ];
+}
+
+- (void)flagsChanged:(NSEvent *)event
+{
+ const int mapping[] = { QZ_CAPSLOCK, QZ_LSHIFT, QZ_LCTRL, QZ_LALT, QZ_LMETA };
+
+ NSUInteger newMods = event.modifierFlags;
+ if (self->_current_mods == newMods) return;
+
+ /* Iterate through the bits, testing each against the current modifiers */
+ for (unsigned int i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
+ unsigned int currentMask, newMask;
+
+ currentMask = self->_current_mods & bit;
+ newMask = newMods & bit;
+
+ if (currentMask && currentMask != newMask) { // modifier up event
+ [ self internalHandleKeycode:mapping[i] unicode:0 pressed:NO modifiers:newMods ];
+ } else if (newMask && currentMask != newMask) { // modifier down event
+ [ self internalHandleKeycode:mapping[i] unicode:0 pressed:YES modifiers:newMods ];
+ }
+ }
+
+ _current_mods = newMods;
+}
+
+
/** Insert the given text at the given range. */
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
{
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index d6c4e5552..17d4c437d 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -28,7 +28,6 @@
#include "../../core/geometry_type.hpp"
#include "cocoa_v.h"
#include "cocoa_wnd.h"
-#include "cocoa_keys.h"
#include "../../blitter/factory.hpp"
#include "../../gfx_func.h"
#include "../../network/network.h"
@@ -48,9 +47,8 @@
* Read http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html for more information.
*/
+extern bool _tab_is_down;
-static unsigned int _current_mods;
-static bool _tab_is_down;
#ifdef _DEBUG
static uint32 _tEvent;
#endif
@@ -64,236 +62,6 @@ static uint32 GetTick()
return tim.tv_usec / 1000 + tim.tv_sec * 1000;
}
-struct VkMapping {
- unsigned short vk_from;
- byte map_to;
-};
-
-#define AS(x, z) {x, z}
-
-static const VkMapping _vk_mapping[] = {
- AS(QZ_BACKQUOTE, WKC_BACKQUOTE), // key left of '1'
- AS(QZ_BACKQUOTE2, WKC_BACKQUOTE), // some keyboards have it on another scancode
-
- /* Pageup stuff + up/down */
- AS(QZ_PAGEUP, WKC_PAGEUP),
- AS(QZ_PAGEDOWN, WKC_PAGEDOWN),
-
- AS(QZ_UP, WKC_UP),
- AS(QZ_DOWN, WKC_DOWN),
- AS(QZ_LEFT, WKC_LEFT),
- AS(QZ_RIGHT, WKC_RIGHT),
-
- AS(QZ_HOME, WKC_HOME),
- AS(QZ_END, WKC_END),
-
- AS(QZ_INSERT, WKC_INSERT),
- AS(QZ_DELETE, WKC_DELETE),
-
- /* Letters. QZ_[a-z] is not in numerical order so we can't use AM(...) */
- AS(QZ_a, 'A'),
- AS(QZ_b, 'B'),
- AS(QZ_c, 'C'),
- AS(QZ_d, 'D'),
- AS(QZ_e, 'E'),
- AS(QZ_f, 'F'),
- AS(QZ_g, 'G'),
- AS(QZ_h, 'H'),
- AS(QZ_i, 'I'),
- AS(QZ_j, 'J'),
- AS(QZ_k, 'K'),
- AS(QZ_l, 'L'),
- AS(QZ_m, 'M'),
- AS(QZ_n, 'N'),
- AS(QZ_o, 'O'),
- AS(QZ_p, 'P'),
- AS(QZ_q, 'Q'),
- AS(QZ_r, 'R'),
- AS(QZ_s, 'S'),
- AS(QZ_t, 'T'),
- AS(QZ_u, 'U'),
- AS(QZ_v, 'V'),
- AS(QZ_w, 'W'),
- AS(QZ_x, 'X'),
- AS(QZ_y, 'Y'),
- AS(QZ_z, 'Z'),
- /* Same thing for digits */
- AS(QZ_0, '0'),
- AS(QZ_1, '1'),
- AS(QZ_2, '2'),
- AS(QZ_3, '3'),
- AS(QZ_4, '4'),
- AS(QZ_5, '5'),
- AS(QZ_6, '6'),
- AS(QZ_7, '7'),
- AS(QZ_8, '8'),
- AS(QZ_9, '9'),
-
- AS(QZ_ESCAPE, WKC_ESC),
- AS(QZ_PAUSE, WKC_PAUSE),
- AS(QZ_BACKSPACE, WKC_BACKSPACE),
-
- AS(QZ_SPACE, WKC_SPACE),
- AS(QZ_RETURN, WKC_RETURN),
- AS(QZ_TAB, WKC_TAB),
-
- /* Function keys */
- AS(QZ_F1, WKC_F1),
- AS(QZ_F2, WKC_F2),
- AS(QZ_F3, WKC_F3),
- AS(QZ_F4, WKC_F4),
- AS(QZ_F5, WKC_F5),
- AS(QZ_F6, WKC_F6),
- AS(QZ_F7, WKC_F7),
- AS(QZ_F8, WKC_F8),
- AS(QZ_F9, WKC_F9),
- AS(QZ_F10, WKC_F10),
- AS(QZ_F11, WKC_F11),
- AS(QZ_F12, WKC_F12),
-
- /* Numeric part */
- AS(QZ_KP0, '0'),
- AS(QZ_KP1, '1'),
- AS(QZ_KP2, '2'),
- AS(QZ_KP3, '3'),
- AS(QZ_KP4, '4'),
- AS(QZ_KP5, '5'),
- AS(QZ_KP6, '6'),
- AS(QZ_KP7, '7'),
- AS(QZ_KP8, '8'),
- AS(QZ_KP9, '9'),
- AS(QZ_KP_DIVIDE, WKC_NUM_DIV),
- AS(QZ_KP_MULTIPLY, WKC_NUM_MUL),
- AS(QZ_KP_MINUS, WKC_NUM_MINUS),
- AS(QZ_KP_PLUS, WKC_NUM_PLUS),
- AS(QZ_KP_ENTER, WKC_NUM_ENTER),
- AS(QZ_KP_PERIOD, WKC_NUM_DECIMAL),
-
- /* Other non-letter keys */
- AS(QZ_SLASH, WKC_SLASH),
- AS(QZ_SEMICOLON, WKC_SEMICOLON),
- AS(QZ_EQUALS, WKC_EQUALS),
- AS(QZ_LEFTBRACKET, WKC_L_BRACKET),
- AS(QZ_BACKSLASH, WKC_BACKSLASH),
- AS(QZ_RIGHTBRACKET, WKC_R_BRACKET),
-
- AS(QZ_QUOTE, WKC_SINGLEQUOTE),
- AS(QZ_COMMA, WKC_COMMA),
- AS(QZ_MINUS, WKC_MINUS),
- AS(QZ_PERIOD, WKC_PERIOD)
-};
-
-
-static uint32 QZ_MapKey(unsigned short sym)
-{
- uint32 key = 0;
-
- for (const VkMapping *map = _vk_mapping; map != endof(_vk_mapping); ++map) {
- if (sym == map->vk_from) {
- key = map->map_to;
- break;
- }
- }
-
- if (_current_mods & NSShiftKeyMask) key |= WKC_SHIFT;
- if (_current_mods & NSControlKeyMask) key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_CTRL : WKC_META);
- if (_current_mods & NSAlternateKeyMask) key |= WKC_ALT;
- if (_current_mods & NSCommandKeyMask) key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL);
-
- return key;
-}
-
-static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL down)
-{
- bool interpret_keys = true;
-
- switch (keycode) {
- case QZ_UP: SB(_dirkeys, 1, 1, down); break;
- case QZ_DOWN: SB(_dirkeys, 3, 1, down); break;
- case QZ_LEFT: SB(_dirkeys, 0, 1, down); break;
- case QZ_RIGHT: SB(_dirkeys, 2, 1, down); break;
-
- case QZ_TAB: _tab_is_down = down; break;
-
- case QZ_RETURN:
- case QZ_f:
- if (down && (_current_mods & NSCommandKeyMask)) {
- VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
- }
- break;
-
- case QZ_v:
- if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) {
- HandleKeypress(WKC_CTRL | 'V', unicode);
- }
- break;
- case QZ_u:
- if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) {
- HandleKeypress(WKC_CTRL | 'U', unicode);
- }
- break;
- }
-
- if (down) {
- uint32 pressed_key = QZ_MapKey(keycode);
-
- static bool console = false;
-
- /* The second backquote may have a character, which we don't want to interpret. */
- if (pressed_key == WKC_BACKQUOTE && (console || unicode == 0)) {
- if (!console) {
- /* Backquote is a dead key, require a double press for hotkey behaviour (i.e. console). */
- console = true;
- return true;
- } else {
- /* Second backquote, don't interpret as text input. */
- interpret_keys = false;
- }
- }
- console = false;
-
- /* Don't handle normal characters if an edit box has the focus. */
- if (!EditBoxInGlobalFocus() || IsInsideMM(pressed_key & ~WKC_SPECIAL_KEYS, WKC_F1, WKC_PAUSE + 1)) {
- HandleKeypress(pressed_key, unicode);
- }
- DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key);
- } else {
- DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode);
- }
-
- return interpret_keys;
-}
-
-static void QZ_DoUnsidedModifiers(unsigned int newMods)
-{
- const int mapping[] = { QZ_CAPSLOCK, QZ_LSHIFT, QZ_LCTRL, QZ_LALT, QZ_LMETA };
-
- if (_current_mods == newMods) return;
-
- /* Iterate through the bits, testing each against the current modifiers */
- for (unsigned int i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
- unsigned int currentMask, newMask;
-
- currentMask = _current_mods & bit;
- newMask = newMods & bit;
-
- if (currentMask && currentMask != newMask) { // modifier up event
- /* If this was Caps Lock, we need some additional voodoo to make SDL happy (is this needed in ottd?) */
- if (bit == NSAlphaShiftKeyMask) QZ_KeyEvent(mapping[i], 0, YES);
- QZ_KeyEvent(mapping[i], 0, NO);
- } else if (newMask && currentMask != newMask) { // modifier down event
- QZ_KeyEvent(mapping[i], 0, YES);
- /* If this was Caps Lock, we need some additional voodoo to make SDL happy (is this needed in ottd?) */
- if (bit == NSAlphaShiftKeyMask) QZ_KeyEvent(mapping[i], 0, NO);
- }
- }
-
- _current_mods = newMods;
-}
-
-
-
-
bool VideoDriver_Cocoa::PollEvent()
{
#ifdef _DEBUG
@@ -307,61 +75,8 @@ bool VideoDriver_Cocoa::PollEvent()
#endif
if (event == nil) return false;
- if (!this->active) {
- [ NSApp sendEvent:event ];
- return true;
- }
-
- QZ_DoUnsidedModifiers( [ event modifierFlags ] );
-
- NSString *chars;
- switch ([ event type ]) {
- case NSKeyDown: {
- /* Quit, hide and minimize */
- switch ([ event keyCode ]) {
- case QZ_q:
- case QZ_h:
- case QZ_m:
- if ([ event modifierFlags ] & NSCommandKeyMask) {
- [ NSApp sendEvent:event ];
- }
- break;
- }
- chars = [ event characters ];
- unsigned short unicode = [ chars length ] > 0 ? [ chars characterAtIndex:0 ] : 0;
- if (EditBoxInGlobalFocus()) {
- if (QZ_KeyEvent([ event keyCode ], unicode, YES)) {
- [ this->cocoaview interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
- }
- } else {
- QZ_KeyEvent([ event keyCode ], unicode, YES);
- for (uint i = 1; i < [ chars length ]; i++) {
- QZ_KeyEvent(0, [ chars characterAtIndex:i ], YES);
- }
- }
- break;
- }
-
- case NSKeyUp:
- /* Quit, hide and minimize */
- switch ([ event keyCode ]) {
- case QZ_q:
- case QZ_h:
- case QZ_m:
- if ([ event modifierFlags ] & NSCommandKeyMask) {
- [ NSApp sendEvent:event ];
- }
- break;
- }
-
- chars = [ event characters ];
- QZ_KeyEvent([ event keyCode ], [ chars length ] ? [ chars characterAtIndex:0 ] : 0, NO);
- break;
-
- default:
- [ NSApp sendEvent:event ];
- }
+ [ NSApp sendEvent:event ];
return true;
}
@@ -410,8 +125,10 @@ void VideoDriver_Cocoa::GameLoop()
break;
}
+ NSUInteger cur_mods = [ NSEvent modifierFlags ];
+
#if defined(_DEBUG)
- if (_current_mods & NSShiftKeyMask)
+ if (cur_mods & NSShiftKeyMask)
#else
if (_tab_is_down)
#endif
@@ -429,8 +146,8 @@ void VideoDriver_Cocoa::GameLoop()
bool old_ctrl_pressed = _ctrl_pressed;
- _ctrl_pressed = !!(_current_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask));
- _shift_pressed = !!(_current_mods & NSShiftKeyMask);
+ _ctrl_pressed = !!(cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask));
+ _shift_pressed = !!(cur_mods & NSShiftKeyMask);
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();