Unified · Split
| @@ -115,7 +115,7 @@ static void terminate_cocoa_application(void) · 114 unmodified lines | ||
| 115 | 115 | |
| 116 | 116 | - (void)sendEvent:(NSEvent *)event |
| 117 | 117 | { |
| 118 | − if ([self modalWindow] || ![_eventsResponder processKeyEvent:event]) | |
| 118 | + if ([self modalWindow] || ![_eventsResponder.inputHelper processKeyWithEvent:event]) | |
| 119 | 119 | [super sendEvent:event]; |
| 120 | 120 | [_eventsResponder.inputHelper wakeup]; |
| 121 | 121 | } |
| @@ -19,7 +19,6 @@ · 18 unmodified lines | ||
| 19 | 19 | |
| 20 | 20 | #ifndef MAC_EVENTS |
| 21 | 21 | #define MAC_EVENTS |
| 22 | −#include "input/keycodes.h" | |
| 23 | 22 | |
| 24 | 23 | struct input_ctx; |
| 25 | 24 | struct mpv_handle; |
| @@ -17,21 +17,12 @@ · 16 unmodified lines | ||
| 17 | 17 | * License along with mpv. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | −// Carbon header is included but Carbon is NOT linked to mpv's binary. This | |
| 21 | −// file only needs this include to use the keycode definitions in keymap. | |
| 22 | −#import <Carbon/Carbon.h> | |
| 23 | − | |
| 24 | −// Media keys definitions | |
| 25 | −#import <IOKit/hidsystem/ev_keymap.h> | |
| 26 | 20 | #import <Cocoa/Cocoa.h> |
| 27 | 21 | |
| 28 | 22 | #include "mpv_talloc.h" |
| 29 | 23 | #include "input/event.h" |
| 30 | 24 | #include "input/input.h" |
| 31 | 25 | #include "player/client.h" |
| 32 | −#include "input/keycodes.h" | |
| 33 | −// doesn't make much sense, but needed to access keymap functionality | |
| 34 | −#include "video/out/vo.h" | |
| 35 | 26 | |
| 36 | 27 | #import "osdep/mac/events_objc.h" |
| 37 | 28 | #import "osdep/mac/application_objc.h" |
| @@ -48,77 +39,13 @@ · 10 unmodified lines | ||
| 48 | 39 | BOOL _is_application; |
| 49 | 40 | } |
| 50 | 41 | |
| 51 | −- (NSEvent *)handleKey:(NSEvent *)event; | |
| 52 | 42 | - (BOOL)setMpvHandle:(struct mpv_handle *)ctx; |
| 53 | 43 | - (void)initCocoaCb; |
| 54 | 44 | - (void)readEvents; |
| 55 | 45 | - (void)startMediaKeys; |
| 56 | 46 | - (void)stopMediaKeys; |
| 57 | −- (int)mapKeyModifiers:(int)cocoaModifiers; | |
| 58 | −- (int)keyModifierMask:(NSEvent *)event; | |
| 59 | 47 | @end |
| 60 | 48 | |
| 61 | − | |
| 62 | −#define NSLeftAlternateKeyMask (0x000020 | NSEventModifierFlagOption) | |
| 63 | −#define NSRightAlternateKeyMask (0x000040 | NSEventModifierFlagOption) | |
| 64 | − | |
| 65 | −static bool LeftAltPressed(int mask) | |
| 66 | −{ | |
| 67 | − return (mask & NSLeftAlternateKeyMask) == NSLeftAlternateKeyMask; | |
| 68 | −} | |
| 69 | − | |
| 70 | −static bool RightAltPressed(int mask) | |
| 71 | −{ | |
| 72 | − return (mask & NSRightAlternateKeyMask) == NSRightAlternateKeyMask; | |
| 73 | −} | |
| 74 | − | |
| 75 | −static const struct mp_keymap keymap[] = { | |
| 76 | − // special keys | |
| 77 | − {kVK_Return, MP_KEY_ENTER}, {kVK_Escape, MP_KEY_ESC}, | |
| 78 | − {kVK_Delete, MP_KEY_BACKSPACE}, {kVK_Option, MP_KEY_BACKSPACE}, | |
| 79 | − {kVK_Control, MP_KEY_BACKSPACE}, {kVK_Shift, MP_KEY_BACKSPACE}, | |
| 80 | − {kVK_Tab, MP_KEY_TAB}, | |
| 81 | − | |
| 82 | − // cursor keys | |
| 83 | − {kVK_UpArrow, MP_KEY_UP}, {kVK_DownArrow, MP_KEY_DOWN}, | |
| 84 | − {kVK_LeftArrow, MP_KEY_LEFT}, {kVK_RightArrow, MP_KEY_RIGHT}, | |
| 85 | − | |
| 86 | − // navigation block | |
| 87 | − {kVK_Help, MP_KEY_INSERT}, {kVK_ForwardDelete, MP_KEY_DELETE}, | |
| 88 | − {kVK_Home, MP_KEY_HOME}, {kVK_End, MP_KEY_END}, | |
| 89 | − {kVK_PageUp, MP_KEY_PAGE_UP}, {kVK_PageDown, MP_KEY_PAGE_DOWN}, | |
| 90 | − | |
| 91 | − // F-keys | |
| 92 | − {kVK_F1, MP_KEY_F + 1}, {kVK_F2, MP_KEY_F + 2}, {kVK_F3, MP_KEY_F + 3}, | |
| 93 | − {kVK_F4, MP_KEY_F + 4}, {kVK_F5, MP_KEY_F + 5}, {kVK_F6, MP_KEY_F + 6}, | |
| 94 | − {kVK_F7, MP_KEY_F + 7}, {kVK_F8, MP_KEY_F + 8}, {kVK_F9, MP_KEY_F + 9}, | |
| 95 | − {kVK_F10, MP_KEY_F + 10}, {kVK_F11, MP_KEY_F + 11}, {kVK_F12, MP_KEY_F + 12}, | |
| 96 | − {kVK_F13, MP_KEY_F + 13}, {kVK_F14, MP_KEY_F + 14}, {kVK_F15, MP_KEY_F + 15}, | |
| 97 | − {kVK_F16, MP_KEY_F + 16}, {kVK_F17, MP_KEY_F + 17}, {kVK_F18, MP_KEY_F + 18}, | |
| 98 | − {kVK_F19, MP_KEY_F + 19}, {kVK_F20, MP_KEY_F + 20}, | |
| 99 | − | |
| 100 | − // numpad | |
| 101 | − {kVK_ANSI_KeypadPlus, '+'}, {kVK_ANSI_KeypadMinus, '-'}, | |
| 102 | − {kVK_ANSI_KeypadMultiply, '*'}, {kVK_ANSI_KeypadDivide, '/'}, | |
| 103 | − {kVK_ANSI_KeypadEnter, MP_KEY_KPENTER}, | |
| 104 | − {kVK_ANSI_KeypadDecimal, MP_KEY_KPDEC}, | |
| 105 | − {kVK_ANSI_Keypad0, MP_KEY_KP0}, {kVK_ANSI_Keypad1, MP_KEY_KP1}, | |
| 106 | − {kVK_ANSI_Keypad2, MP_KEY_KP2}, {kVK_ANSI_Keypad3, MP_KEY_KP3}, | |
| 107 | − {kVK_ANSI_Keypad4, MP_KEY_KP4}, {kVK_ANSI_Keypad5, MP_KEY_KP5}, | |
| 108 | − {kVK_ANSI_Keypad6, MP_KEY_KP6}, {kVK_ANSI_Keypad7, MP_KEY_KP7}, | |
| 109 | − {kVK_ANSI_Keypad8, MP_KEY_KP8}, {kVK_ANSI_Keypad9, MP_KEY_KP9}, | |
| 110 | − | |
| 111 | − {0, 0} | |
| 112 | −}; | |
| 113 | − | |
| 114 | −static int convert_key(unsigned key, unsigned charcode) | |
| 115 | −{ | |
| 116 | − int mpkey = lookup_keymap_table(keymap, key); | |
| 117 | − if (mpkey) | |
| 118 | − return mpkey; | |
| 119 | − return charcode; | |
| 120 | −} | |
| 121 | − | |
| 122 | 49 | void cocoa_init_media_keys(void) |
| 123 | 50 | { |
| 124 | 51 | [[EventsResponder sharedInstance] startMediaKeys]; |
| @@ -255,77 +182,4 @@ void cocoa_init_cocoa_cb(void) · 130 unmodified lines | ||
| 255 | 182 | [_remoteCommandCenter stop]; |
| 256 | 183 | } |
| 257 | 184 | |
| 258 | −- (int)mapKeyModifiers:(int)cocoaModifiers | |
| 259 | −{ | |
| 260 | − int mask = 0; | |
| 261 | − if (cocoaModifiers & NSEventModifierFlagShift) | |
| 262 | − mask |= MP_KEY_MODIFIER_SHIFT; | |
| 263 | − if (cocoaModifiers & NSEventModifierFlagControl) | |
| 264 | − mask |= MP_KEY_MODIFIER_CTRL; | |
| 265 | − if (LeftAltPressed(cocoaModifiers) || | |
| 266 | − (RightAltPressed(cocoaModifiers) && ![_inputHelper useAltGr])) | |
| 267 | − mask |= MP_KEY_MODIFIER_ALT; | |
| 268 | − if (cocoaModifiers & NSEventModifierFlagCommand) | |
| 269 | − mask |= MP_KEY_MODIFIER_META; | |
| 270 | − return mask; | |
| 271 | −} | |
| 272 | − | |
| 273 | −- (int)mapTypeModifiers:(NSEventType)type | |
| 274 | −{ | |
| 275 | − NSDictionary *map = @{ | |
| 276 | − @(NSEventTypeKeyDown) : @(MP_KEY_STATE_DOWN), | |
| 277 | − @(NSEventTypeKeyUp) : @(MP_KEY_STATE_UP), | |
| 278 | − }; | |
| 279 | − return [map[@(type)] intValue]; | |
| 280 | −} | |
| 281 | − | |
| 282 | −- (int)keyModifierMask:(NSEvent *)event | |
| 283 | −{ | |
| 284 | − return [self mapKeyModifiers:[event modifierFlags]] | | |
| 285 | − [self mapTypeModifiers:[event type]]; | |
| 286 | −} | |
| 287 | − | |
| 288 | −-(BOOL)handleMPKey:(int)key withMask:(int)mask | |
| 289 | −{ | |
| 290 | − if (key > 0) { | |
| 291 | − [_inputHelper putKey:key | mask modifiers:0]; | |
| 292 | − if (mask & MP_KEY_STATE_UP) | |
| 293 | − [_inputHelper putKey:MP_INPUT_RELEASE_ALL modifiers:0]; | |
| 294 | − return YES; | |
| 295 | − } else { | |
| 296 | − return NO; | |
| 297 | − } | |
| 298 | −} | |
| 299 | − | |
| 300 | −- (NSEvent*)handleKey:(NSEvent *)event | |
| 301 | −{ | |
| 302 | − if ([event isARepeat]) return nil; | |
| 303 | − | |
| 304 | − NSString *chars; | |
| 305 | − | |
| 306 | − if ([_inputHelper useAltGr] && RightAltPressed([event modifierFlags])) { | |
| 307 | − chars = [event characters]; | |
| 308 | − } else { | |
| 309 | − chars = [event charactersIgnoringModifiers]; | |
| 310 | − } | |
| 311 | − | |
| 312 | − struct bstr t = bstr0([chars UTF8String]); | |
| 313 | − int key = convert_key([event keyCode], bstr_decode_utf8(t, &t)); | |
| 314 | − | |
| 315 | − if (key > -1) | |
| 316 | − [self handleMPKey:key withMask:[self keyModifierMask:event]]; | |
| 317 | − | |
| 318 | − return nil; | |
| 319 | −} | |
| 320 | − | |
| 321 | −- (bool)processKeyEvent:(NSEvent *)event | |
| 322 | −{ | |
| 323 | − if (event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp){ | |
| 324 | − if (![[NSApp mainMenu] performKeyEquivalent:event]) | |
| 325 | − [self handleKey:event]; | |
| 326 | − return true; | |
| 327 | − } | |
| 328 | − return false; | |
| 329 | −} | |
| 330 | − | |
| 331 | 185 | @end |
| @@ -29,10 +29,6 @@ struct input_ctx; · 28 unmodified lines | ||
| 29 | 29 | + (EventsResponder *)sharedInstance; |
| 30 | 30 | - (void)setIsApplication:(BOOL)isApplication; |
| 31 | 31 | |
| 32 | −- (bool)processKeyEvent:(NSEvent *)event; | |
| 33 | − | |
| 34 | −- (BOOL)handleMPKey:(int)key withMask:(int)mask; | |
| 35 | − | |
| 36 | 32 | @property(nonatomic, retain) RemoteCommandCenter *remoteCommandCenter; |
| 37 | 33 | @property(nonatomic, retain) InputHelper *inputHelper; |
| 38 | 34 | |
| @@ -15,21 +15,130 @@ · 14 unmodified lines | ||
| 15 | 15 | * License along with mpv. If not, see <http://www.gnu.org/licenses/>. |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | +import Carbon.HIToolbox | |
| 19 | + | |
| 18 | 20 | class InputHelper: NSObject { |
| 19 | 21 | var mpv: MPVHelper? |
| 20 | 22 | var lock = NSCondition() |
| 21 | 23 | private var input: OpaquePointer? |
| 22 | 24 | |
| 25 | + let keymap: [mp_keymap] = [ | |
| 26 | + // special keys | |
| 27 | + mp_keymap(from: Int32(kVK_Return), to: MP_KEY_ENTER), | |
| 28 | + mp_keymap(from: Int32(kVK_Escape), to: MP_KEY_ESC), | |
| 29 | + mp_keymap(from: Int32(kVK_Delete), to: MP_KEY_BACKSPACE), | |
| 30 | + mp_keymap(from: Int32(kVK_Option), to: MP_KEY_BACKSPACE), | |
| 31 | + mp_keymap(from: Int32(kVK_Control), to: MP_KEY_BACKSPACE), | |
| 32 | + mp_keymap(from: Int32(kVK_Shift), to: MP_KEY_BACKSPACE), | |
| 33 | + mp_keymap(from: Int32(kVK_Tab), to: MP_KEY_TAB), | |
| 34 | + | |
| 35 | + // cursor keys | |
| 36 | + mp_keymap(from: Int32(kVK_UpArrow), to: MP_KEY_UP), | |
| 37 | + mp_keymap(from: Int32(kVK_DownArrow), to: MP_KEY_DOWN), | |
| 38 | + mp_keymap(from: Int32(kVK_LeftArrow), to: MP_KEY_LEFT), | |
| 39 | + mp_keymap(from: Int32(kVK_RightArrow), to: MP_KEY_RIGHT), | |
| 40 | + | |
| 41 | + // navigation block | |
| 42 | + mp_keymap(from: Int32(kVK_Help), to: MP_KEY_INSERT), | |
| 43 | + mp_keymap(from: Int32(kVK_ForwardDelete), to: MP_KEY_DELETE), | |
| 44 | + mp_keymap(from: Int32(kVK_Home), to: MP_KEY_HOME), | |
| 45 | + mp_keymap(from: Int32(kVK_End), to: MP_KEY_END), | |
| 46 | + mp_keymap(from: Int32(kVK_PageUp), to: MP_KEY_PAGE_UP), | |
| 47 | + mp_keymap(from: Int32(kVK_PageDown), to: MP_KEY_PAGE_DOWN), | |
| 48 | + | |
| 49 | + // F-keys | |
| 50 | + mp_keymap(from: Int32(kVK_F1), to: MP_KEY_F + 1), | |
| 51 | + mp_keymap(from: Int32(kVK_F2), to: MP_KEY_F + 2), | |
| 52 | + mp_keymap(from: Int32(kVK_F3), to: MP_KEY_F + 3), | |
| 53 | + mp_keymap(from: Int32(kVK_F4), to: MP_KEY_F + 4), | |
| 54 | + mp_keymap(from: Int32(kVK_F5), to: MP_KEY_F + 5), | |
| 55 | + mp_keymap(from: Int32(kVK_F6), to: MP_KEY_F + 6), | |
| 56 | + mp_keymap(from: Int32(kVK_F7), to: MP_KEY_F + 7), | |
| 57 | + mp_keymap(from: Int32(kVK_F8), to: MP_KEY_F + 8), | |
| 58 | + mp_keymap(from: Int32(kVK_F9), to: MP_KEY_F + 9), | |
| 59 | + mp_keymap(from: Int32(kVK_F10), to: MP_KEY_F + 10), | |
| 60 | + mp_keymap(from: Int32(kVK_F11), to: MP_KEY_F + 11), | |
| 61 | + mp_keymap(from: Int32(kVK_F12), to: MP_KEY_F + 12), | |
| 62 | + mp_keymap(from: Int32(kVK_F13), to: MP_KEY_F + 13), | |
| 63 | + mp_keymap(from: Int32(kVK_F14), to: MP_KEY_F + 14), | |
| 64 | + mp_keymap(from: Int32(kVK_F15), to: MP_KEY_F + 15), | |
| 65 | + mp_keymap(from: Int32(kVK_F16), to: MP_KEY_F + 16), | |
| 66 | + mp_keymap(from: Int32(kVK_F17), to: MP_KEY_F + 17), | |
| 67 | + mp_keymap(from: Int32(kVK_F18), to: MP_KEY_F + 18), | |
| 68 | + mp_keymap(from: Int32(kVK_F19), to: MP_KEY_F + 19), | |
| 69 | + mp_keymap(from: Int32(kVK_F20), to: MP_KEY_F + 20), | |
| 70 | + | |
| 71 | + // numpad | |
| 72 | + mp_keymap(from: Int32(kVK_ANSI_KeypadPlus), to: Int32(Character("+").asciiValue ?? 0)), | |
| 73 | + mp_keymap(from: Int32(kVK_ANSI_KeypadMinus), to: Int32(Character("-").asciiValue ?? 0)), | |
| 74 | + mp_keymap(from: Int32(kVK_ANSI_KeypadMultiply), to: Int32(Character("*").asciiValue ?? 0)), | |
| 75 | + mp_keymap(from: Int32(kVK_ANSI_KeypadDivide), to: Int32(Character("/").asciiValue ?? 0)), | |
| 76 | + mp_keymap(from: Int32(kVK_ANSI_KeypadEnter), to: MP_KEY_KPENTER), | |
| 77 | + mp_keymap(from: Int32(kVK_ANSI_KeypadDecimal), to: MP_KEY_KPDEC), | |
| 78 | + mp_keymap(from: Int32(kVK_ANSI_Keypad0), to: MP_KEY_KP0), | |
| 79 | + mp_keymap(from: Int32(kVK_ANSI_Keypad1), to: MP_KEY_KP1), | |
| 80 | + mp_keymap(from: Int32(kVK_ANSI_Keypad2), to: MP_KEY_KP2), | |
| 81 | + mp_keymap(from: Int32(kVK_ANSI_Keypad3), to: MP_KEY_KP3), | |
| 82 | + mp_keymap(from: Int32(kVK_ANSI_Keypad4), to: MP_KEY_KP4), | |
| 83 | + mp_keymap(from: Int32(kVK_ANSI_Keypad5), to: MP_KEY_KP5), | |
| 84 | + mp_keymap(from: Int32(kVK_ANSI_Keypad6), to: MP_KEY_KP6), | |
| 85 | + mp_keymap(from: Int32(kVK_ANSI_Keypad7), to: MP_KEY_KP7), | |
| 86 | + mp_keymap(from: Int32(kVK_ANSI_Keypad8), to: MP_KEY_KP8), | |
| 87 | + mp_keymap(from: Int32(kVK_ANSI_Keypad9), to: MP_KEY_KP9), | |
| 88 | + | |
| 89 | + mp_keymap(from: 0, to: 0) | |
| 90 | + ] | |
| 91 | + | |
| 23 | 92 | @objc init(_ input: OpaquePointer? = nil, _ mpv: MPVHelper? = nil) { |
| 24 | 93 | super.init() |
| 25 | 94 | self.input = input |
| 26 | 95 | self.mpv = mpv |
| 27 | 96 | } |
| 28 | 97 | |
| 29 | − @objc func putKey(_ key: Int32, modifiers: NSEvent.ModifierFlags = .init(rawValue: 0)) { | |
| 98 | + @objc func put( | |
| 99 | + key: Int32, | |
| 100 | + modifiers: NSEvent.ModifierFlags = .init(rawValue: 0), | |
| 101 | + type: NSEvent.EventType = .applicationDefined | |
| 102 | + ) { | |
| 30 | 103 | lock.withLock { |
| 31 | − guard let input = input else { return } | |
| 32 | − mp_input_put_key(input, key | mapModifier(modifiers)) | |
| 104 | + putKey(key, modifiers: modifiers, type: type) | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + private func putKey( | |
| 109 | + _ key: Int32, | |
| 110 | + modifiers: NSEvent.ModifierFlags = .init(rawValue: 0), | |
| 111 | + type: NSEvent.EventType = .applicationDefined | |
| 112 | + ) { | |
| 113 | + if key < 1 { return } | |
| 114 | + | |
| 115 | + guard let input = input else { return } | |
| 116 | + let code = key | mapModifier(modifiers) | mapType(type) | |
| 117 | + mp_input_put_key(input, code) | |
| 118 | + | |
| 119 | + if type == .keyUp { | |
| 120 | + mp_input_put_key(input, MP_INPUT_RELEASE_ALL) | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 124 | + @objc func processKey(event: NSEvent) -> Bool { | |
| 125 | + if event.type != .keyDown && event.type != .keyUp { return false } | |
| 126 | + if NSApp.mainMenu?.performKeyEquivalent(with: event) ?? false || event.isARepeat { return true } | |
| 127 | + | |
| 128 | + return lock.withLock { | |
| 129 | + let mpkey = lookup_keymap_table(keymap, Int32(event.keyCode)) | |
| 130 | + if mpkey > 0 { | |
| 131 | + putKey(mpkey, modifiers: event.modifierFlags, type: event.type) | |
| 132 | + return true | |
| 133 | + } | |
| 134 | + | |
| 135 | + guard let chars = event.characters, let charsNoMod = event.charactersIgnoringModifiers else { return false } | |
| 136 | + let key = (useAltGr() && event.modifierFlags.contains(.optionRight)) ? chars : charsNoMod | |
| 137 | + key.withCString { | |
| 138 | + var bstr = bstr0($0) | |
| 139 | + putKey(bstr_decode_utf8(bstr, &bstr), modifiers: event.modifierFlags, type: event.type) | |
| 140 | + } | |
| 141 | + return true | |
| 33 | 142 | } |
| 34 | 143 | } |
| 35 | 144 | |
| @@ -72,9 +181,17 @@ class InputHelper: NSObject { · 36 unmodified lines | ||
| 72 | 181 | } |
| 73 | 182 | } |
| 74 | 183 | |
| 184 | + private func mapType(_ type: NSEvent.EventType) -> Int32 { | |
| 185 | + let typeMapping: [NSEvent.EventType:UInt32] = [ | |
| 186 | + .keyDown: MP_KEY_STATE_DOWN, | |
| 187 | + .keyUp: MP_KEY_STATE_UP, | |
| 188 | + ] | |
| 189 | + | |
| 190 | + return Int32(typeMapping[type] ?? 0); | |
| 191 | + } | |
| 192 | + | |
| 75 | 193 | private func mapModifier(_ modifiers: NSEvent.ModifierFlags) -> Int32 { |
| 76 | 194 | var mask: UInt32 = 0; |
| 77 | − guard let input = input else { return Int32(mask) } | |
| 78 | 195 | |
| 79 | 196 | if modifiers.contains(.shift) { |
| 80 | 197 | mask |= MP_KEY_MODIFIER_SHIFT |
| @@ -85,9 +202,7 @@ class InputHelper: NSObject { · 4 unmodified lines | ||
| 85 | 202 | if modifiers.contains(.command) { |
| 86 | 203 | mask |= MP_KEY_MODIFIER_META |
| 87 | 204 | } |
| 88 | − if modifiers.contains(.optionLeft) || | |
| 89 | − modifiers.contains(.optionRight) && !mp_input_use_alt_gr(input) | |
| 90 | − { | |
| 205 | + if modifiers.contains(.optionLeft) || modifiers.contains(.optionRight) && !useAltGr() { | |
| 91 | 206 | mask |= MP_KEY_MODIFIER_ALT |
| 92 | 207 | } |
| 93 | 208 | |
| @@ -111,11 +226,9 @@ class InputHelper: NSObject { · 17 unmodified lines | ||
| 111 | 226 | } |
| 112 | 227 | } |
| 113 | 228 | |
| 114 | − @objc func useAltGr() -> Bool { | |
| 115 | − lock.withLock { | |
| 116 | − guard let input = input else { return false } | |
| 117 | − return mp_input_use_alt_gr(input) | |
| 118 | − } | |
| 229 | + private func useAltGr() -> Bool { | |
| 230 | + guard let input = input else { return false } | |
| 231 | + return mp_input_use_alt_gr(input) | |
| 119 | 232 | } |
| 120 | 233 | |
| 121 | 234 | @objc func wakeup() { |
| @@ -155,7 +155,7 @@ class RemoteCommandCenter: NSObject { · 154 unmodified lines | ||
| 155 | 155 | self.configs[event.command]?.state = state |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | − EventsResponder.sharedInstance().handleMPKey(config.key, withMask: Int32(state)) | |
| 158 | + EventsResponder.sharedInstance().inputHelper.put(key: config.key | Int32(state)) | |
| 159 | 159 | |
| 160 | 160 | return .success |
| 161 | 161 | } |
| @@ -28,6 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "player/core.h" |
| 29 | 29 | #include "input/input.h" |
| 30 | 30 | #include "input/event.h" |
| 31 | +#include "input/keycodes.h" | |
| 31 | 32 | #include "video/out/win_state.h" |
| 32 | 33 | |
| 33 | 34 | #include "osdep/mac/application_objc.h" |
| @@ -53,7 +53,7 @@ class View: NSView, CALayerDelegate { · 52 unmodified lines | ||
| 53 | 53 | addTrackingArea(tracker!) |
| 54 | 54 | |
| 55 | 55 | if containsMouseLocation() { |
| 56 | − input?.putKey(SWIFT_KEY_MOUSE_LEAVE) | |
| 56 | + input?.put(key: SWIFT_KEY_MOUSE_LEAVE) | |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| @@ -118,14 +118,14 @@ class View: NSView, CALayerDelegate { · 58 unmodified lines | ||
| 118 | 118 | |
| 119 | 119 | override func mouseEntered(with event: NSEvent) { |
| 120 | 120 | if input?.mouseEnabled() ?? true { |
| 121 | − input?.putKey(SWIFT_KEY_MOUSE_ENTER) | |
| 121 | + input?.put(key: SWIFT_KEY_MOUSE_ENTER) | |
| 122 | 122 | } |
| 123 | 123 | common.updateCursorVisibility() |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | override func mouseExited(with event: NSEvent) { |
| 127 | 127 | if input?.mouseEnabled() ?? true { |
| 128 | − input?.putKey(SWIFT_KEY_MOUSE_LEAVE) | |
| 128 | + input?.put(key: SWIFT_KEY_MOUSE_LEAVE) | |
| 129 | 129 | } |
| 130 | 130 | common.titleBar?.hide() |
| 131 | 131 | common.setCursorVisibility(true) |
| @@ -202,7 +202,7 @@ class View: NSView, CALayerDelegate { · 70 unmodified lines | ||
| 202 | 202 | func signalMouseEvent(_ event: NSEvent, _ state: UInt32) { |
| 203 | 203 | hasMouseDown = state == MP_KEY_STATE_DOWN |
| 204 | 204 | let mpkey = getMpvButton(event) |
| 205 | − input?.putKey((mpkey | Int32(state)), modifiers: event.modifierFlags) | |
| 205 | + input?.put(key: (mpkey | Int32(state)), modifiers: event.modifierFlags) | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | func signalMouseMovement(_ event: NSEvent) { |
| @@ -250,7 +250,7 @@ class View: NSView, CALayerDelegate { · 41 unmodified lines | ||
| 250 | 250 | mpkey = deltaX > 0 ? SWIFT_WHEEL_LEFT : SWIFT_WHEEL_RIGHT |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | − input?.putKey(mpkey, modifiers: modifiers) | |
| 253 | + input?.put(key: mpkey, modifiers: modifiers) | |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
| @@ -556,7 +556,7 @@ class Window: NSWindow, NSWindowDelegate { · 555 unmodified lines | ||
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | func windowShouldClose(_ sender: NSWindow) -> Bool { |
| 559 | − input?.putKey(MP_KEY_CLOSE_WIN) | |
| 559 | + input?.put(key: MP_KEY_CLOSE_WIN) | |
| 560 | 560 | return false |
| 561 | 561 | } |
| 562 | 562 | |