mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
w32_common: handle media keys
This was attempted before infc9695e63b, but it was reverted in1b7ce759b1because it caused conflicts with other software watching the same keys (See #2041.) It seems like some PCs ship with OEM software that watches the volume keys without consuming key events and this causes them to be handled twice, once by mpv and once by the other software. In order to prevent conflicts like this, use the WM_APPCOMMAND message to handle media keys. Returning TRUE from the WM_APPCOMMAND handler should indicate to the operating system that we consumed the key event and it should not be propogated to the shell. Also, we now only listen for keys that are directly related to multimedia playback (eg. the APPCOMMAND_MEDIA_* keys.) Keys like APPCOMMAND_VOLUME_* are ignored, so they can be handled by the shell, or by other mixer software.
This commit is contained in:
@@ -200,9 +200,9 @@ const struct m_sub_options input_config = {
|
||||
OPT_INTRANGE("input-key-fifo-size", key_fifo_size, 0, 2, 65000),
|
||||
OPT_FLAG("input-cursor", enable_mouse_movements, 0),
|
||||
OPT_FLAG("input-vo-keyboard", vo_key_input, 0),
|
||||
OPT_FLAG("input-media-keys", use_media_keys, 0),
|
||||
#if HAVE_COCOA
|
||||
OPT_FLAG("input-appleremote", use_appleremote, 0),
|
||||
OPT_FLAG("input-media-keys", use_media_keys, 0),
|
||||
#endif
|
||||
OPT_FLAG("window-dragging", allow_win_drag, 0),
|
||||
OPT_REPLACED("input-x11-keyboard", "input-vo-keyboard"),
|
||||
@@ -216,9 +216,9 @@ const struct m_sub_options input_config = {
|
||||
.ar_rate = 40,
|
||||
.use_alt_gr = 1,
|
||||
.enable_mouse_movements = 1,
|
||||
.use_media_keys = 1,
|
||||
#if HAVE_COCOA
|
||||
.use_appleremote = 1,
|
||||
.use_media_keys = 1,
|
||||
#endif
|
||||
.default_bindings = 1,
|
||||
.vo_key_input = 1,
|
||||
@@ -1441,6 +1441,14 @@ bool mp_input_use_alt_gr(struct input_ctx *ictx)
|
||||
return r;
|
||||
}
|
||||
|
||||
bool mp_input_use_media_keys(struct input_ctx *ictx)
|
||||
{
|
||||
input_lock(ictx);
|
||||
bool r = ictx->opts->use_media_keys;
|
||||
input_unlock(ictx);
|
||||
return r;
|
||||
}
|
||||
|
||||
struct mp_cmd *mp_input_parse_cmd(struct input_ctx *ictx, bstr str,
|
||||
const char *location)
|
||||
{
|
||||
|
||||
@@ -250,6 +250,9 @@ void mp_input_set_cancel(struct input_ctx *ictx, void (*cb)(void *c), void *c);
|
||||
// characters. If false, count Right Alt as the modifier Alt key.
|
||||
bool mp_input_use_alt_gr(struct input_ctx *ictx);
|
||||
|
||||
// Return true if mpv should intercept keyboard media keys
|
||||
bool mp_input_use_media_keys(struct input_ctx *ictx);
|
||||
|
||||
// Like mp_input_parse_cmd_strv, but also run the command.
|
||||
void mp_input_run_cmd(struct input_ctx *ictx, const char **cmd);
|
||||
|
||||
|
||||
@@ -159,6 +159,9 @@ static const struct key_name key_names[] = {
|
||||
{ MP_KEY_SEARCH, "SEARCH" },
|
||||
{ MP_KEY_SLEEP, "SLEEP" },
|
||||
{ MP_KEY_CANCEL, "CANCEL" },
|
||||
{ MP_KEY_RECORD, "RECORD" },
|
||||
{ MP_KEY_CHANNEL_UP, "CHANNEL_UP" },
|
||||
{ MP_KEY_CHANNEL_DOWN,"CHANNEL_DOWN" },
|
||||
|
||||
// These are kept for backward compatibility
|
||||
{ MP_KEY_PAUSE, "XF86_PAUSE" },
|
||||
|
||||
@@ -73,6 +73,9 @@
|
||||
#define MP_KEY_SEARCH (MP_KEY_MM_BASE+17)
|
||||
#define MP_KEY_SLEEP (MP_KEY_MM_BASE+18)
|
||||
#define MP_KEY_CANCEL (MP_KEY_MM_BASE+19)
|
||||
#define MP_KEY_RECORD (MP_KEY_MM_BASE+20)
|
||||
#define MP_KEY_CHANNEL_UP (MP_KEY_MM_BASE+21)
|
||||
#define MP_KEY_CHANNEL_DOWN (MP_KEY_MM_BASE+22)
|
||||
|
||||
/* Function keys */
|
||||
#define MP_KEY_F (MP_KEY_BASE+0x40)
|
||||
|
||||
Reference in New Issue
Block a user