summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-26 22:39:04 +0200
committerwm4 <wm4@nowhere>2015-05-26 22:39:04 +0200
commit2dd904289dcaf7b11b30ec362288f9af90531879 (patch)
treea024ffe4631bd5c3b8ad8cdbbda675d045902128 /osdep
parent39a339c813ee3bb7f8e1f65dcf325e7f0db110a2 (diff)
downloadmpv-2dd904289dcaf7b11b30ec362288f9af90531879.tar.bz2
mpv-2dd904289dcaf7b11b30ec362288f9af90531879.tar.xz
osx: never expose input_ctx from EventsResponder
Keep it internal, so we can synchronize access to it properly.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_application.m11
-rw-r--r--osdep/macosx_events.m32
-rw-r--r--osdep/macosx_events_objc.h10
3 files changed, 33 insertions, 20 deletions
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m
index 595c47e3c6..6e91809464 100644
--- a/osdep/macosx_application.m
+++ b/osdep/macosx_application.m
@@ -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]];
diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m
index 23a3e02355..6ae5e6d900 100644
--- a/osdep/macosx_events.m
+++ b/osdep/macosx_events.m
@@ -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;
}
diff --git a/osdep/macosx_events_objc.h b/osdep/macosx_events_objc.h
index e9b14ed079..70a058e651 100644
--- a/osdep/macosx_events_objc.h
+++ b/osdep/macosx_events_objc.h
@@ -27,11 +27,17 @@ struct input_ctx;
+ (EventsResponder *)sharedInstance;
+- (void)setInputContext:(struct input_ctx *)ctx;
+
/// Blocks until inputContext is present.
- (void)waitForInputContext;
-- (void)handleFilesArray:(NSArray *)files;
+- (void)wakeup;
+
+- (bool)queueCommand:(char *)cmd;
-@property(nonatomic, assign) struct input_ctx *inputContext;
+- (void)putKey:(int)keycode;
+
+- (void)handleFilesArray:(NSArray *)files;
@end