From f13f0db33a18040e660b6ed76ad43d1870f096a2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 2 Jun 2013 17:39:05 +0200 Subject: osx: create macosx_events to deal with keyDown events On OSX with Cocoa enabled keyDown events are now handled with addLocalMonitorForEventsMatchingMask:handler:. This allows to respond to events even when there is no VO initialized but the GUI is focused. --- Makefile | 6 +- core/input/input.c | 7 ++ core/mplayer.c | 1 + osdep/macosx_application.h | 1 + osdep/macosx_application.m | 109 ++++++++++++++++++++++++------- osdep/macosx_application_objc.h | 16 ++++- osdep/macosx_events.h | 27 ++++++++ osdep/macosx_events.m | 141 ++++++++++++++++++++++++++++++++++++++++ video/out/cocoa_common.m | 115 +++----------------------------- video/out/osx_common.c | 64 ------------------ video/out/osx_common.h | 24 ------- 11 files changed, 288 insertions(+), 223 deletions(-) create mode 100644 osdep/macosx_events.h create mode 100644 osdep/macosx_events.m delete mode 100644 video/out/osx_common.c delete mode 100644 video/out/osx_common.h diff --git a/Makefile b/Makefile index 1c6da641f1..40d1c71d72 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,9 @@ SOURCES-$(LIBPOSTPROC) += video/filter/vf_pp.c SOURCES-$(LIBSMBCLIENT) += stream/stream_smb.c SOURCES-$(MACOSX_BUNDLE) += osdep/macosx_bundle.m -SOURCES-$(COCOA) += video/out/osx_common.c \ - video/out/cocoa_common.m \ - osdep/macosx_application.m +SOURCES-$(COCOA) += video/out/cocoa_common.m \ + osdep/macosx_application.m \ + osdep/macosx_events.m SOURCES-$(MNG) += demux/demux_mng.c SOURCES-$(MPG123) += audio/decode/ad_mpg123.c diff --git a/core/input/input.c b/core/input/input.c index c9958753cd..0154fa11aa 100644 --- a/core/input/input.c +++ b/core/input/input.c @@ -61,6 +61,10 @@ #include #endif +#ifdef CONFIG_COCOA +#include "osdep/macosx_events.h" +#endif + #define MP_MAX_KEY_DOWN 4 struct cmd_bind { @@ -1474,6 +1478,9 @@ static void read_all_fd_events(struct input_ctx *ictx, int time) static void read_all_events(struct input_ctx *ictx, int time) { getch2_poll(); +#ifdef CONFIG_COCOA + cocoa_check_events(); +#endif read_all_fd_events(ictx, time); } diff --git a/core/mplayer.c b/core/mplayer.c index 52aa34058c..89e79ef044 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -3999,6 +3999,7 @@ static void init_input(struct MPContext *mpctx) #ifdef CONFIG_COCOA cocoa_set_input_context(mpctx->input); + cocoa_set_key_fifo(mpctx->key_fifo); #endif } diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 372a57a566..0334771892 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -48,6 +48,7 @@ void cocoa_stop_runloop(void); void cocoa_post_fake_event(void); void cocoa_set_input_context(struct input_ctx *input_context); +void cocoa_set_key_fifo(struct mp_fifo *key_fifo); void macosx_finder_args_preinit(int *argc, char ***argv); diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 81fff99a73..598941490d 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -20,14 +20,11 @@ #include "talloc.h" #include "core/mp_msg.h" -#include "core/mp_fifo.h" #include "core/input/input.h" #include "core/input/keycodes.h" #include "osdep/macosx_application_objc.h" -#include "video/out/osx_common.h" -static Application *app; static pthread_t playback_thread_id; @interface Application (PrivateMethods) @@ -49,14 +46,51 @@ static pthread_t playback_thread_id; - (void)setAppleMenu:(NSMenu *)aMenu; @end -@implementation Application -@synthesize files = _files; -@synthesize argumentsList = _arguments_list; -@synthesize willStopOnOpenEvent = _will_stop_on_open_event; +@implementation InputQueue { + NSMutableArray *_fifo; +} -@synthesize inputContext = _input_context; -@synthesize keyFIFO = _key_fifo; -@synthesize menuItems = _menu_items; +- (id)init +{ + if (self = [super init]) { + self->_fifo = [[NSMutableArray alloc] init]; + } + + return self; +} + +- (void)push:(int)keycode +{ + @synchronized (_fifo) { + [_fifo addObject:[NSNumber numberWithInt:keycode]]; + } +} + +- (int)pop +{ + int r = -1; + + @synchronized (_fifo) { + if ([_fifo count] > 0) { + r = [[_fifo objectAtIndex:0] intValue]; + [_fifo removeObjectAtIndex:0]; + } + } + + return r; +} + +- (void)dealloc +{ + [self->_fifo release]; + [super dealloc]; +} +@end + +Application *mpv_shared_app(void) +{ + return (Application *)[Application sharedApplication]; +} static NSString *escape_loadfile_name(NSString *input) { @@ -73,13 +107,32 @@ static NSString *escape_loadfile_name(NSString *input) return input; } +@implementation Application +@synthesize files = _files; +@synthesize argumentsList = _arguments_list; +@synthesize willStopOnOpenEvent = _will_stop_on_open_event; + +@synthesize inputContext = _input_context; +@synthesize keyFIFO = _key_fifo; +@synthesize iqueue = _iqueue; +@synthesize eventsResponder = _events_responder; +@synthesize menuItems = _menu_items; + - (id)init { if (self = [super init]) { self.menuItems = [[[NSMutableDictionary alloc] init] autorelease]; self.files = nil; self.argumentsList = [[[NSMutableArray alloc] init] autorelease]; + self.iqueue = [[[InputQueue alloc] init] autorelease]; + self.eventsResponder = [[[EventsResponder alloc] init] autorelease]; self.willStopOnOpenEvent = NO; + + [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask + handler:^(NSEvent *event) { + return [self.eventsResponder handleKeyDown:event]; + }]; + } return self; @@ -129,23 +182,23 @@ static NSString *escape_loadfile_name(NSString *input) [NSApp setMainMenu:main_menu]; [NSApp setAppleMenu:[self appleMenuWithMainMenu:main_menu]]; - [app mainMenuItemWithParent:main_menu child:[self movieMenu]]; - [app mainMenuItemWithParent:main_menu child:[self windowMenu]]; + [NSApp mainMenuItemWithParent:main_menu child:[self movieMenu]]; + [NSApp mainMenuItemWithParent:main_menu child:[self windowMenu]]; } #undef _R - (void)stopPlayback { - [self stop:"quit"]; + [self stopMPV:"quit"]; } - (void)stopPlaybackAndRememberPosition { - [self stop:"quit_watch_later"]; + [self stopMPV:"quit_watch_later"]; } -- (void)stop:(char *)cmd +- (void)stopMPV:(char *)cmd { if (self.inputContext) { mp_cmd_t *cmdt = mp_input_parse_cmd(bstr0(cmd), ""); @@ -206,6 +259,7 @@ static NSString *escape_loadfile_name(NSString *input) - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { + Application *app = mpv_shared_app(); NSMutableArray *filesToOpen = [[[NSMutableArray alloc] init] autorelease]; [filenames enumerateObjectsUsingBlock:^(id obj, NSUInteger i, BOOL *_) { @@ -284,15 +338,14 @@ int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]) void cocoa_register_menu_item_action(MPMenuKey key, void* action) { - [app registerSelector:(SEL)action forKey:key]; + [NSApp registerSelector:(SEL)action forKey:key]; } void init_cocoa_application(void) { - NSApp = [NSApplication sharedApplication]; - app = [[Application alloc] init]; - [NSApp setDelegate:app]; - [app initialize_menu]; + NSApp = mpv_shared_app(); + [NSApp setDelegate:NSApp]; + [NSApp initialize_menu]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; atexit_b(^{ @@ -305,8 +358,8 @@ void init_cocoa_application(void) void terminate_cocoa_application(void) { - [NSApp hide:app]; - [NSApp terminate:app]; + [NSApp hide:NSApp]; + [NSApp terminate:NSApp]; } void cocoa_run_runloop() @@ -326,8 +379,12 @@ void cocoa_stop_runloop(void) void cocoa_set_input_context(struct input_ctx *input_context) { - [NSApp setDelegate:app]; - app.inputContext = input_context; + mpv_shared_app().inputContext = input_context; +} + +void cocoa_set_key_fifo(struct mp_fifo *key_fifo) +{ + mpv_shared_app().keyFIFO = key_fifo; } void cocoa_post_fake_event(void) @@ -346,7 +403,7 @@ void cocoa_post_fake_event(void) static void macosx_wait_fileopen_events() { - app.willStopOnOpenEvent = YES; + mpv_shared_app().willStopOnOpenEvent = YES; cocoa_run_runloop(); // block until done } @@ -374,6 +431,8 @@ static bool psn_matches_current_process(char *psn_arg_to_check) void macosx_finder_args_preinit(int *argc, char ***argv) { + Application *app = mpv_shared_app(); + if (*argc==2 && psn_matches_current_process((*argv)[1])) { macosx_redirect_output_to_logfile("mpv"); macosx_wait_fileopen_events(); diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index b569d60f25..7c87ce6fa5 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -19,16 +19,30 @@ #import #include "osdep/macosx_application.h" -@interface Application : NSObject +struct cocoa_input_queue; + +@interface InputQueue : NSObject +- (void)push:(int)keycode; +- (int) pop; +@end + +@interface EventsResponder : NSResponder +- (NSEvent *)handleKeyDown:(NSEvent *)event; +@end + +@interface Application : NSApplication - (void)initialize_menu; - (void)registerSelector:(SEL)selector forKey:(MPMenuKey)key; - (void)stopPlayback; @property(nonatomic, assign) struct input_ctx *inputContext; @property(nonatomic, assign) struct mp_fifo *keyFIFO; +@property(nonatomic, retain) InputQueue *iqueue; +@property(nonatomic, retain) EventsResponder *eventsResponder; @property(nonatomic, retain) NSMutableDictionary *menuItems; @property(nonatomic, retain) NSArray *files; @property(nonatomic, retain) NSMutableArray *argumentsList; @property(nonatomic, assign) BOOL willStopOnOpenEvent; @end +Application *mpv_shared_app(void); diff --git a/osdep/macosx_events.h b/osdep/macosx_events.h new file mode 100644 index 0000000000..70656e28fd --- /dev/null +++ b/osdep/macosx_events.h @@ -0,0 +1,27 @@ +/* + * Cocoa Application Event Handling + * + * This file is part of mpv. + * + * mplayer2 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mplayer2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see . + */ + +#ifndef MACOSX_EVENTS_H +#define MACOSX_EVENTS_H +#include "core/input/keycodes.h" + +void cocoa_put_key(int keycode); +void cocoa_check_events(void); + +#endif diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m new file mode 100644 index 0000000000..434fc0cb3b --- /dev/null +++ b/osdep/macosx_events.m @@ -0,0 +1,141 @@ +/* + * Cocoa Application Event Handling + * + * This file is part of mpv. + * + * mplayer2 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mplayer2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see . + */ + +// Carbon header is included but Carbon is NOT linked to mpv's binary. This +// file only needs this include to use the keycode definitions in keymap. +#import +#import + +#include "talloc.h" +#include "core/input/input.h" +#include "core/mp_fifo.h" +// doesn't make much sense, but needed to access keymap functionality +#include "video/out/vo.h" +#include "osdep/macosx_events.h" +#import "osdep/macosx_application_objc.h" + +#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) +#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) + +static bool LeftAltPressed(NSEvent *event) +{ + return ([event modifierFlags] & NSLeftAlternateKeyMask) == + NSLeftAlternateKeyMask; +} + +static bool RightAltPressed(NSEvent *event) +{ + return ([event modifierFlags] & NSRightAlternateKeyMask) == + NSRightAlternateKeyMask; +} + +static const struct mp_keymap keymap[] = { + // special keys + {kVK_Return, MP_KEY_ENTER}, {kVK_Escape, MP_KEY_ESC}, + {kVK_Delete, MP_KEY_BACKSPACE}, {kVK_Option, MP_KEY_BACKSPACE}, + {kVK_Control, MP_KEY_BACKSPACE}, {kVK_Shift, MP_KEY_BACKSPACE}, + {kVK_Tab, MP_KEY_TAB}, + + // cursor keys + {kVK_UpArrow, MP_KEY_UP}, {kVK_DownArrow, MP_KEY_DOWN}, + {kVK_LeftArrow, MP_KEY_LEFT}, {kVK_RightArrow, MP_KEY_RIGHT}, + + // navigation block + {kVK_Help, MP_KEY_INSERT}, {kVK_ForwardDelete, MP_KEY_DELETE}, + {kVK_Home, MP_KEY_HOME}, {kVK_End, MP_KEY_END}, + {kVK_PageUp, MP_KEY_PAGE_UP}, {kVK_PageDown, MP_KEY_PAGE_DOWN}, + + // F-keys + {kVK_F1, MP_KEY_F + 1}, {kVK_F2, MP_KEY_F + 2}, {kVK_F3, MP_KEY_F + 3}, + {kVK_F4, MP_KEY_F + 4}, {kVK_F5, MP_KEY_F + 5}, {kVK_F6, MP_KEY_F + 6}, + {kVK_F7, MP_KEY_F + 7}, {kVK_F8, MP_KEY_F + 8}, {kVK_F9, MP_KEY_F + 9}, + {kVK_F10, MP_KEY_F + 10}, {kVK_F11, MP_KEY_F + 11}, {kVK_F12, MP_KEY_F + 12}, + + // numpad + {kVK_ANSI_KeypadPlus, '+'}, {kVK_ANSI_KeypadMinus, '-'}, + {kVK_ANSI_KeypadMultiply, '*'}, {kVK_ANSI_KeypadDivide, '/'}, + {kVK_ANSI_KeypadEnter, MP_KEY_KPENTER}, + {kVK_ANSI_KeypadDecimal, MP_KEY_KPDEC}, + {kVK_ANSI_Keypad0, MP_KEY_KP0}, {kVK_ANSI_Keypad1, MP_KEY_KP1}, + {kVK_ANSI_Keypad2, MP_KEY_KP2}, {kVK_ANSI_Keypad3, MP_KEY_KP3}, + {kVK_ANSI_Keypad4, MP_KEY_KP4}, {kVK_ANSI_Keypad5, MP_KEY_KP5}, + {kVK_ANSI_Keypad6, MP_KEY_KP6}, {kVK_ANSI_Keypad7, MP_KEY_KP7}, + {kVK_ANSI_Keypad8, MP_KEY_KP8}, {kVK_ANSI_Keypad9, MP_KEY_KP9}, + + {0, 0} +}; + +static int convert_key(unsigned key, unsigned charcode) +{ + int mpkey = lookup_keymap_table(keymap, key); + if (mpkey) + return mpkey; + return charcode; +} + +void cocoa_check_events(void) +{ + Application *app = mpv_shared_app(); + int key = [app.iqueue pop]; + if (key >= 0) mplayer_put_key(app.keyFIFO, key); +} + +void cocoa_put_key(int keycode) +{ + [mpv_shared_app().iqueue push:keycode]; +} + +@implementation EventsResponder +- (NSArray *) keyEquivalents +{ + return @[@"h", @"q", @"Q", @"0", @"1", @"2"]; +} +- (NSEvent*)handleKeyDown:(NSEvent *)event +{ + NSString *chars; + + if (RightAltPressed(event)) + chars = [event characters]; + else + chars = [event charactersIgnoringModifiers]; + + int key = convert_key([event keyCode], *[chars UTF8String]); + + if (key > -1) { + if ([event modifierFlags] & NSShiftKeyMask) + key |= MP_KEY_MODIFIER_SHIFT; + if ([event modifierFlags] & NSControlKeyMask) + key |= MP_KEY_MODIFIER_CTRL; + if (LeftAltPressed(event)) + key |= MP_KEY_MODIFIER_ALT; + if ([event modifierFlags] & NSCommandKeyMask) { + // propagate the event in case this is a menu key equivalent + for(NSString *c in [self keyEquivalents]) + if ([chars isEqualToString:c]) + return event; + + key |= MP_KEY_MODIFIER_META; + } + + cocoa_put_key(key); + } + + return nil; +} +@end diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 28dbf58923..8c57ce53dc 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -34,27 +34,10 @@ #include "core/mp_fifo.h" #include "talloc.h" -#include "core/input/input.h" -#include "core/input/keycodes.h" -#include "osx_common.h" #include "core/mp_msg.h" #include "osdep/macosx_application.h" - -#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) -#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) - -static bool LeftAltPressed(NSEvent *event) -{ - return ([event modifierFlags] & NSLeftAlternateKeyMask) == - NSLeftAlternateKeyMask; -} - -static bool RightAltPressed(NSEvent *event) -{ - return ([event modifierFlags] & NSRightAlternateKeyMask) == - NSRightAlternateKeyMask; -} +#include "osdep/macosx_events.h" @interface GLMPlayerWindow : NSWindow - (BOOL)canBecomeKeyWindow; @@ -79,48 +62,6 @@ static bool RightAltPressed(NSEvent *event) - (BOOL)hasMenubar; @end -struct vo_cocoa_input_queue { - NSMutableArray *fifo; -}; - -static int vo_cocoa_input_queue_free(void *ptr) -{ - struct vo_cocoa_input_queue *iq = ptr; - [iq->fifo release]; - return 0; -} - -static struct vo_cocoa_input_queue *vo_cocoa_input_queue_init(void *talloc_ctx) -{ - struct vo_cocoa_input_queue *iq = talloc_ptrtype(talloc_ctx, iq); - *iq = (struct vo_cocoa_input_queue) { - .fifo = [[NSMutableArray alloc] init], - }; - talloc_set_destructor(iq, vo_cocoa_input_queue_free); - return iq; -} - -static void cocoa_async_put_key(struct vo_cocoa_input_queue *iq, int key) -{ - @synchronized (iq->fifo) { - [iq->fifo addObject:[NSNumber numberWithInt:key]]; - } -} - -static int cocoa_sync_get_key(struct vo_cocoa_input_queue *iq) -{ - int r = -1; - - @synchronized (iq->fifo) { - if ([iq->fifo count] > 0) { - r = [[iq->fifo objectAtIndex:0] intValue]; - [iq->fifo removeObjectAtIndex:0]; - } - } - - return r; -} - struct vo_cocoa_state { GLMPlayerWindow *window; GLMPlayerOpenGLView *view; @@ -148,8 +89,6 @@ struct vo_cocoa_state { NSLock *lock; bool enable_resize_redraw; void (*resize_redraw)(struct vo *vo, int w, int h); - - struct vo_cocoa_input_queue *input_queue; }; static struct vo_cocoa_state *vo_cocoa_init_state(struct vo *vo) @@ -164,7 +103,6 @@ static struct vo_cocoa_state *vo_cocoa_init_state(struct vo *vo) .power_mgmt_assertion = kIOPMNullAssertionID, .accumulated_scroll = 0, .lock = [[NSLock alloc] init], - .input_queue = vo_cocoa_input_queue_init(s), .enable_resize_redraw = NO, }; return s; @@ -568,9 +506,6 @@ int vo_cocoa_check_events(struct vo *vo) { struct vo_cocoa_state *s = vo->cocoa; - int key = cocoa_sync_get_key(s->input_queue); - if (key >= 0) mplayer_put_key(vo->key_fifo, key); - if (s->did_resize) { s->did_resize = NO; resize_window(vo); @@ -762,8 +697,7 @@ int vo_cocoa_cgl_color_size(struct vo *vo) - (BOOL)canBecomeKeyWindow { return YES; } - (BOOL)windowShouldClose:(id)sender { - struct vo_cocoa_state *s = self.videoOutput->cocoa; - cocoa_async_put_key(s->input_queue, MP_KEY_CLOSE_WIN); + cocoa_put_key(MP_KEY_CLOSE_WIN); // We have to wait for MPlayer to handle this, // otherwise we are in trouble if the // MP_KEY_CLOSE_WIN handler is disabled @@ -867,32 +801,6 @@ int vo_cocoa_cgl_color_size(struct vo *vo) - (BOOL)becomeFirstResponder { return YES; } - (BOOL)resignFirstResponder { return YES; } - - (void)keyDown:(NSEvent *)theEvent -{ - struct vo_cocoa_state *s = self.videoOutput->cocoa; - NSString *chars; - - if (RightAltPressed(theEvent)) - chars = [theEvent characters]; - else - chars = [theEvent charactersIgnoringModifiers]; - - int key = convert_key([theEvent keyCode], *[chars UTF8String]); - - if (key > -1) { - if ([theEvent modifierFlags] & NSShiftKeyMask) - key |= MP_KEY_MODIFIER_SHIFT; - if ([theEvent modifierFlags] & NSControlKeyMask) - key |= MP_KEY_MODIFIER_CTRL; - if (LeftAltPressed(theEvent)) - key |= MP_KEY_MODIFIER_ALT; - if ([theEvent modifierFlags] & NSCommandKeyMask) - key |= MP_KEY_MODIFIER_META; - - cocoa_async_put_key(s->input_queue, key); - } -} - - (NSPoint) mouseLocation { NSPoint mLoc = [NSEvent mouseLocation]; @@ -946,24 +854,23 @@ int vo_cocoa_cgl_color_size(struct vo *vo) static const CGFloat threshold = 10; while (s->accumulated_scroll >= threshold) { s->accumulated_scroll -= threshold; - cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN3); + cocoa_put_key(MP_MOUSE_BTN3); } while (s->accumulated_scroll <= -threshold) { s->accumulated_scroll += threshold; - cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN4); + cocoa_put_key(MP_MOUSE_BTN4); } } else { if (delta > 0) - cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN3); + cocoa_put_key(MP_MOUSE_BTN3); else - cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN4); + cocoa_put_key(MP_MOUSE_BTN4); } } - (void)mouseEvent:(NSEvent *)theEvent { if ([theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9) { - struct vo_cocoa_state *s = self.videoOutput->cocoa; int buttonNumber = [theEvent buttonNumber]; // Fix to mplayer defined button order: left, middle, right if (buttonNumber == 1) buttonNumber = 2; @@ -972,24 +879,20 @@ int vo_cocoa_cgl_color_size(struct vo *vo) case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: - cocoa_async_put_key( - s->input_queue, - (MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_DOWN); + cocoa_put_key((MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_DOWN); self.mouseDown = YES; // Looks like Cocoa doesn't create MouseUp events when we are // doing the second click in a double click. Put in the key_fifo // the key that would be put from the MouseUp handling code. if([theEvent clickCount] == 2) { - cocoa_async_put_key(s->input_queue, - MP_MOUSE_BTN0 + buttonNumber); + cocoa_put_key(MP_MOUSE_BTN0 + buttonNumber); self.mouseDown = NO; } break; case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: - cocoa_async_put_key(s->input_queue, - MP_MOUSE_BTN0 + buttonNumber); + cocoa_put_key(MP_MOUSE_BTN0 + buttonNumber); self.mouseDown = NO; break; } diff --git a/video/out/osx_common.c b/video/out/osx_common.c deleted file mode 100644 index a81217aace..0000000000 --- a/video/out/osx_common.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#include "config.h" - -// only to get keycode definitions from HIToolbox/Events.h -#include -#include -#include "osx_common.h" -#include "video/out/vo.h" -#include "core/input/keycodes.h" -#include "core/input/input.h" -#include "core/mp_msg.h" - -static const struct mp_keymap keymap[] = { - // special keys - {kVK_Return, MP_KEY_ENTER}, - {kVK_Escape, MP_KEY_ESC}, - {kVK_Delete, MP_KEY_BACKSPACE}, {kVK_Option, MP_KEY_BACKSPACE}, {kVK_Control, MP_KEY_BACKSPACE}, {kVK_Shift, MP_KEY_BACKSPACE}, - {kVK_Tab, MP_KEY_TAB}, - - // cursor keys - {kVK_UpArrow, MP_KEY_UP}, {kVK_DownArrow, MP_KEY_DOWN}, {kVK_LeftArrow, MP_KEY_LEFT}, {kVK_RightArrow, MP_KEY_RIGHT}, - - // navigation block - {kVK_Help, MP_KEY_INSERT}, {kVK_ForwardDelete, MP_KEY_DELETE}, {kVK_Home, MP_KEY_HOME}, - {kVK_End, MP_KEY_END}, {kVK_PageUp, MP_KEY_PAGE_UP}, {kVK_PageDown, MP_KEY_PAGE_DOWN}, - - // F-keys - {kVK_F1, MP_KEY_F + 1}, {kVK_F2, MP_KEY_F + 2}, {kVK_F3, MP_KEY_F + 3}, {kVK_F4, MP_KEY_F + 4}, - {kVK_F5, MP_KEY_F + 5}, {kVK_F6, MP_KEY_F + 6}, {kVK_F7, MP_KEY_F + 7}, {kVK_F8, MP_KEY_F + 8}, - {kVK_F9, MP_KEY_F + 9}, {kVK_F10, MP_KEY_F + 10}, {kVK_F11, MP_KEY_F + 11}, {kVK_F12, MP_KEY_F + 12}, - - // numpad - {kVK_ANSI_KeypadPlus, '+'}, {kVK_ANSI_KeypadMinus, '-'}, {kVK_ANSI_KeypadMultiply, '*'}, - {kVK_ANSI_KeypadDivide, '/'}, {kVK_ANSI_KeypadEnter, MP_KEY_KPENTER}, {kVK_ANSI_KeypadDecimal, MP_KEY_KPDEC}, - {kVK_ANSI_Keypad0, MP_KEY_KP0}, {kVK_ANSI_Keypad1, MP_KEY_KP1}, {kVK_ANSI_Keypad2, MP_KEY_KP2}, {kVK_ANSI_Keypad3, MP_KEY_KP3}, - {kVK_ANSI_Keypad4, MP_KEY_KP4}, {kVK_ANSI_Keypad5, MP_KEY_KP5}, {kVK_ANSI_Keypad6, MP_KEY_KP6}, {kVK_ANSI_Keypad7, MP_KEY_KP7}, - {kVK_ANSI_Keypad8, MP_KEY_KP8}, {kVK_ANSI_Keypad9, MP_KEY_KP9}, - - {0, 0} -}; - -int convert_key(unsigned key, unsigned charcode) -{ - int mpkey = lookup_keymap_table(keymap, key); - if (mpkey) - return mpkey; - return charcode; -} diff --git a/video/out/osx_common.h b/video/out/osx_common.h deleted file mode 100644 index 3c4855fde3..0000000000 --- a/video/out/osx_common.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_OSX_COMMON_H -#define MPLAYER_OSX_COMMON_H - -int convert_key(unsigned key, unsigned charcode); - -#endif /* MPLAYER_OSX_COMMON_H */ -- cgit v1.2.3