mirror of https://github.com/mpv-player/mpv
osx: never expose input_ctx from EventsResponder
Keep it internal, so we can synchronize access to it properly.
This commit is contained in:
parent
39a339c813
commit
2dd904289d
|
@ -77,8 +77,7 @@ static void terminate_cocoa_application(void)
|
|||
{
|
||||
[super sendEvent:event];
|
||||
|
||||
if (_eventsResponder.inputContext)
|
||||
mp_input_wakeup(_eventsResponder.inputContext);
|
||||
[_eventsResponder wakeup];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
|
@ -167,16 +166,10 @@ static void terminate_cocoa_application(void)
|
|||
|
||||
- (void)stopMPV:(char *)cmd
|
||||
{
|
||||
struct input_ctx *inputContext = _eventsResponder.inputContext;
|
||||
if (inputContext) {
|
||||
mp_cmd_t *cmdt = mp_input_parse_cmd(inputContext, bstr0(cmd), "");
|
||||
mp_input_queue_cmd(inputContext, cmdt);
|
||||
} else {
|
||||
if (![_eventsResponder queueCommand:cmd])
|
||||
terminate_cocoa_application();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)registerMenuItem:(NSMenuItem*)menuItem forKey:(MPMenuKey)key
|
||||
{
|
||||
[self.menuItems setObject:menuItem forKey:[NSNumber numberWithInt:key]];
|
||||
|
|
|
@ -188,9 +188,7 @@ void cocoa_uninit_media_keys(void) {
|
|||
|
||||
void cocoa_put_key(int keycode)
|
||||
{
|
||||
struct input_ctx *inputContext = [EventsResponder sharedInstance].inputContext;
|
||||
if (inputContext)
|
||||
mp_input_put_key(inputContext, keycode);
|
||||
[[EventsResponder sharedInstance] putKey:keycode];
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
[EventsResponder sharedInstance].inputContext = input_context;
|
||||
[[EventsResponder sharedInstance] setInputContext:input_context];
|
||||
}
|
||||
|
||||
@implementation EventsResponder
|
||||
|
@ -233,7 +231,7 @@ void cocoa_set_input_context(struct input_ctx *input_context)
|
|||
- (void)waitForInputContext
|
||||
{
|
||||
[_input_ready lock];
|
||||
while (!self.inputContext)
|
||||
while (!_inputContext)
|
||||
[_input_ready wait];
|
||||
[_input_ready unlock];
|
||||
}
|
||||
|
@ -246,15 +244,31 @@ void cocoa_set_input_context(struct input_ctx *input_context)
|
|||
[_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
|
||||
{
|
||||
if (self.inputContext)
|
||||
return mp_input_use_alt_gr(self.inputContext);
|
||||
if (_inputContext)
|
||||
return mp_input_use_alt_gr(_inputContext);
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,17 @@ struct input_ctx;
|
|||
|
||||
+ (EventsResponder *)sharedInstance;
|
||||
|
||||
- (void)setInputContext:(struct input_ctx *)ctx;
|
||||
|
||||
/// Blocks until inputContext is present.
|
||||
- (void)waitForInputContext;
|
||||
|
||||
- (void)wakeup;
|
||||
|
||||
- (bool)queueCommand:(char *)cmd;
|
||||
|
||||
- (void)putKey:(int)keycode;
|
||||
|
||||
- (void)handleFilesArray:(NSArray *)files;
|
||||
|
||||
@property(nonatomic, assign) struct input_ctx *inputContext;
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue