mirror of
https://github.com/mpv-player/mpv
synced 2025-02-22 15:56:59 +00:00
libmpv/cocoa: don't start the event monitor
The event monitor is used to get keyboard events when there is no window, but since it is a global monitor to the current process, we don't want it in a library setting.
This commit is contained in:
parent
58f62891fa
commit
dba2b90d9a
@ -2228,6 +2228,11 @@ Input
|
||||
|
||||
(This option was renamed from ``--input-x11-keyboard``.)
|
||||
|
||||
``--input-app-events=<yes|no>``
|
||||
(OS X only)
|
||||
Enable/disable application wide keyboard events so that keyboard shortcuts
|
||||
can be processed without a window. Enabled by default (except for libmpv).
|
||||
|
||||
OSD
|
||||
---
|
||||
|
||||
|
@ -173,6 +173,7 @@ struct input_opts {
|
||||
int use_alt_gr;
|
||||
int use_appleremote;
|
||||
int use_media_keys;
|
||||
int use_app_events;
|
||||
int default_bindings;
|
||||
int enable_mouse_movements;
|
||||
int vo_key_input;
|
||||
@ -204,6 +205,7 @@ const struct m_sub_options input_config = {
|
||||
#if HAVE_COCOA
|
||||
OPT_FLAG("appleremote", use_appleremote, CONF_GLOBAL),
|
||||
OPT_FLAG("media-keys", use_media_keys, CONF_GLOBAL),
|
||||
OPT_FLAG("app-events", use_app_events, CONF_GLOBAL),
|
||||
#endif
|
||||
{0}
|
||||
},
|
||||
@ -219,6 +221,7 @@ const struct m_sub_options input_config = {
|
||||
#if HAVE_COCOA
|
||||
.use_appleremote = 1,
|
||||
.use_media_keys = 1,
|
||||
.use_app_events = 1,
|
||||
#endif
|
||||
.default_bindings = 1,
|
||||
.vo_key_input = 1,
|
||||
@ -1276,6 +1279,10 @@ void mp_input_load(struct input_ctx *ictx)
|
||||
}
|
||||
|
||||
#if HAVE_COCOA
|
||||
if (input_conf->use_app_events) {
|
||||
cocoa_start_event_monitor();
|
||||
}
|
||||
|
||||
if (input_conf->use_appleremote) {
|
||||
cocoa_init_apple_remote();
|
||||
ictx->using_ar = true;
|
||||
|
@ -26,6 +26,8 @@ struct input_ctx;
|
||||
void cocoa_put_key(int keycode);
|
||||
void cocoa_put_key_with_modifiers(int keycode, int modifiers);
|
||||
|
||||
void cocoa_start_event_monitor(void);
|
||||
|
||||
void cocoa_init_apple_remote(void);
|
||||
void cocoa_uninit_apple_remote(void);
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
- (BOOL)handleMediaKey:(NSEvent *)event;
|
||||
- (NSEvent *)handleKey:(NSEvent *)event;
|
||||
- (void)startEventMonitor;
|
||||
- (void)startAppleRemote;
|
||||
- (void)stopAppleRemote;
|
||||
- (void)startMediaKeys;
|
||||
@ -112,6 +113,11 @@ static int convert_key(unsigned key, unsigned charcode)
|
||||
return charcode;
|
||||
}
|
||||
|
||||
void cocoa_start_event_monitor(void)
|
||||
{
|
||||
[[EventsResponder sharedInstance] startEventMonitor];
|
||||
}
|
||||
|
||||
void cocoa_init_apple_remote(void)
|
||||
{
|
||||
[[EventsResponder sharedInstance] startAppleRemote];
|
||||
@ -211,16 +217,6 @@ void cocoa_set_input_context(struct input_ctx *input_context)
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_input_ready = [NSCondition new];
|
||||
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask
|
||||
handler:^(NSEvent *event) {
|
||||
BOOL equivalent = [[NSApp mainMenu] performKeyEquivalent:event];
|
||||
if (equivalent) {
|
||||
return (NSEvent *)nil;
|
||||
} else {
|
||||
return [self handleKey:event];
|
||||
}
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -254,6 +250,19 @@ void cocoa_set_input_context(struct input_ctx *input_context)
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)startEventMonitor
|
||||
{
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask
|
||||
handler:^(NSEvent *event) {
|
||||
BOOL equivalent = [[NSApp mainMenu] performKeyEquivalent:event];
|
||||
if (equivalent) {
|
||||
return (NSEvent *)nil;
|
||||
} else {
|
||||
return [self handleKey:event];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)startAppleRemote
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
@ -405,8 +405,9 @@ mpv_handle *mpv_create(void)
|
||||
mpv_set_option_string(ctx, "input-default-bindings", "no");
|
||||
mpv_set_option_string(ctx, "input-vo-keyboard", "no");
|
||||
mpv_set_option_string(ctx, "input-lirc", "no");
|
||||
mpv_set_option_string(ctx, "input-media-keys", "no");
|
||||
mpv_set_option_string(ctx, "input-appleremote", "no");
|
||||
mpv_set_option_string(ctx, "input-media-keys", "no");
|
||||
mpv_set_option_string(ctx, "input-app-events", "no");
|
||||
} else {
|
||||
mp_destroy(mpctx);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user