osx: never expose input_ctx from EventsResponder

Keep it internal, so we can synchronize access to it properly.
This commit is contained in:
wm4 2015-05-26 22:39:04 +02:00
parent 39a339c813
commit 2dd904289d
3 changed files with 33 additions and 20 deletions

View File

@ -77,8 +77,7 @@ static void terminate_cocoa_application(void)
{ {
[super sendEvent:event]; [super sendEvent:event];
if (_eventsResponder.inputContext) [_eventsResponder wakeup];
mp_input_wakeup(_eventsResponder.inputContext);
} }
- (id)init - (id)init
@ -167,16 +166,10 @@ static void terminate_cocoa_application(void)
- (void)stopMPV:(char *)cmd - (void)stopMPV:(char *)cmd
{ {
struct input_ctx *inputContext = _eventsResponder.inputContext; if (![_eventsResponder queueCommand:cmd])
if (inputContext) {
mp_cmd_t *cmdt = mp_input_parse_cmd(inputContext, bstr0(cmd), "");
mp_input_queue_cmd(inputContext, cmdt);
} else {
terminate_cocoa_application(); terminate_cocoa_application();
}
} }
- (void)registerMenuItem:(NSMenuItem*)menuItem forKey:(MPMenuKey)key - (void)registerMenuItem:(NSMenuItem*)menuItem forKey:(MPMenuKey)key
{ {
[self.menuItems setObject:menuItem forKey:[NSNumber numberWithInt:key]]; [self.menuItems setObject:menuItem forKey:[NSNumber numberWithInt:key]];

View File

@ -188,9 +188,7 @@ void cocoa_uninit_media_keys(void) {
void cocoa_put_key(int keycode) void cocoa_put_key(int keycode)
{ {
struct input_ctx *inputContext = [EventsResponder sharedInstance].inputContext; [[EventsResponder sharedInstance] putKey:keycode];
if (inputContext)
mp_input_put_key(inputContext, keycode);
} }
void cocoa_put_key_event(void *event) void cocoa_put_key_event(void *event)
@ -206,7 +204,7 @@ void cocoa_put_key_with_modifiers(int keycode, int modifiers)
void cocoa_set_input_context(struct input_ctx *input_context) void cocoa_set_input_context(struct input_ctx *input_context)
{ {
[EventsResponder sharedInstance].inputContext = input_context; [[EventsResponder sharedInstance] setInputContext:input_context];
} }
@implementation EventsResponder @implementation EventsResponder
@ -233,7 +231,7 @@ void cocoa_set_input_context(struct input_ctx *input_context)
- (void)waitForInputContext - (void)waitForInputContext
{ {
[_input_ready lock]; [_input_ready lock];
while (!self.inputContext) while (!_inputContext)
[_input_ready wait]; [_input_ready wait];
[_input_ready unlock]; [_input_ready unlock];
} }
@ -246,15 +244,31 @@ void cocoa_set_input_context(struct input_ctx *input_context)
[_input_ready unlock]; [_input_ready unlock];
} }
- (struct input_ctx *)inputContext - (void)wakeup
{ {
return _inputContext; mp_input_wakeup(_inputContext);
}
- (bool)queueCommand:(char *)cmd
{
if (!_inputContext)
return false;
mp_cmd_t *cmdt = mp_input_parse_cmd(_inputContext, bstr0(cmd), "");
mp_input_queue_cmd(_inputContext, cmdt);
return true;
}
- (void)putKey:(int)keycode
{
if (_inputContext)
mp_input_put_key(_inputContext, keycode);
} }
- (BOOL)useAltGr - (BOOL)useAltGr
{ {
if (self.inputContext) if (_inputContext)
return mp_input_use_alt_gr(self.inputContext); return mp_input_use_alt_gr(_inputContext);
else else
return YES; return YES;
} }

View File

@ -27,11 +27,17 @@ struct input_ctx;
+ (EventsResponder *)sharedInstance; + (EventsResponder *)sharedInstance;
- (void)setInputContext:(struct input_ctx *)ctx;
/// Blocks until inputContext is present. /// Blocks until inputContext is present.
- (void)waitForInputContext; - (void)waitForInputContext;
- (void)wakeup;
- (bool)queueCommand:(char *)cmd;
- (void)putKey:(int)keycode;
- (void)handleFilesArray:(NSArray *)files; - (void)handleFilesArray:(NSArray *)files;
@property(nonatomic, assign) struct input_ctx *inputContext;
@end @end