summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/options.rst2
-rw-r--r--input/input.c12
-rw-r--r--input/input.h3
-rw-r--r--input/keycodes.c3
-rw-r--r--input/keycodes.h3
-rw-r--r--osdep/w32_keyboard.c20
-rw-r--r--osdep/w32_keyboard.h3
-rw-r--r--video/out/w32_common.c15
8 files changed, 58 insertions, 3 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index 7f8c94816a..2372f04139 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -2986,7 +2986,7 @@ Input
Support depends on the VO in use.
``--input-media-keys=<yes|no>``
- (OS X only)
+ (OS X and Windows only)
Enable/disable media keys support. Enabled by default (except for libmpv).
``--input-right-alt-gr``, ``--no-input-right-alt-gr``
diff --git a/input/input.c b/input/input.c
index 4a20ab1311..ed7c1ec160 100644
--- a/input/input.c
+++ b/input/input.c
@@ -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)
{
diff --git a/input/input.h b/input/input.h
index 00f5473f7b..0ea054d21b 100644
--- a/input/input.h
+++ b/input/input.h
@@ -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);
diff --git a/input/keycodes.c b/input/keycodes.c
index b518a81443..cb446f5069 100644
--- a/input/keycodes.c
+++ b/input/keycodes.c
@@ -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" },
diff --git a/input/keycodes.h b/input/keycodes.h
index d7c1b8450f..fe22e8d140 100644
--- a/input/keycodes.h
+++ b/input/keycodes.h
@@ -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)
diff --git a/osdep/w32_keyboard.c b/osdep/w32_keyboard.c
index edb6acf10e..c298f1f6bd 100644
--- a/osdep/w32_keyboard.c
+++ b/osdep/w32_keyboard.c
@@ -69,6 +69,21 @@ static const struct keymap vk_map[] = {
{0, 0}
};
+static const struct keymap appcmd_map[] = {
+ {APPCOMMAND_MEDIA_NEXTTRACK, MP_KEY_NEXT},
+ {APPCOMMAND_MEDIA_PREVIOUSTRACK, MP_KEY_PREV},
+ {APPCOMMAND_MEDIA_STOP, MP_KEY_STOP},
+ {APPCOMMAND_MEDIA_PLAY_PAUSE, MP_KEY_PLAYPAUSE},
+ {APPCOMMAND_MEDIA_PLAY, MP_KEY_PLAY},
+ {APPCOMMAND_MEDIA_PAUSE, MP_KEY_PAUSE},
+ {APPCOMMAND_MEDIA_RECORD, MP_KEY_RECORD},
+ {APPCOMMAND_MEDIA_FAST_FORWARD, MP_KEY_FORWARD},
+ {APPCOMMAND_MEDIA_REWIND, MP_KEY_REWIND},
+ {APPCOMMAND_MEDIA_CHANNEL_UP, MP_KEY_CHANNEL_UP},
+ {APPCOMMAND_MEDIA_CHANNEL_DOWN, MP_KEY_CHANNEL_DOWN},
+ {0, 0}
+};
+
static int lookup_keymap(const struct keymap *map, int key)
{
while (map->from && map->from != key) map++;
@@ -89,3 +104,8 @@ int mp_w32_vkey_to_mpkey(UINT vkey, bool extended)
return mpkey;
}
+
+int mp_w32_appcmd_to_mpkey(UINT appcmd)
+{
+ return lookup_keymap(appcmd_map, appcmd);
+}
diff --git a/osdep/w32_keyboard.h b/osdep/w32_keyboard.h
index 218454322d..b06cdee50c 100644
--- a/osdep/w32_keyboard.h
+++ b/osdep/w32_keyboard.h
@@ -23,4 +23,7 @@
/* Convert a Windows virtual key code to an mpv key */
int mp_w32_vkey_to_mpkey(UINT vkey, bool extended);
+/* Convert a WM_APPCOMMAND value to an mpv key */
+int mp_w32_appcmd_to_mpkey(UINT appcmd);
+
#endif
diff --git a/video/out/w32_common.c b/video/out/w32_common.c
index 221f0b37dc..26edde17eb 100644
--- a/video/out/w32_common.c
+++ b/video/out/w32_common.c
@@ -354,6 +354,17 @@ static int decode_key(struct vo_w32_state *w32, UINT vkey, UINT scancode)
return c;
}
+static bool handle_appcommand(struct vo_w32_state *w32, UINT cmd)
+{
+ if (!mp_input_use_media_keys(w32->input_ctx))
+ return false;
+ int mpkey = mp_w32_appcmd_to_mpkey(cmd);
+ if (!mpkey)
+ return false;
+ mp_input_put_key(w32->input_ctx, mpkey | mod_state(w32));
+ return true;
+}
+
static void handle_key_down(struct vo_w32_state *w32, UINT vkey, UINT scancode)
{
// Ignore key repeat
@@ -1020,6 +1031,10 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
GET_Y_LPARAM(lParam));
}
break;
+ case WM_APPCOMMAND:
+ if (handle_appcommand(w32, GET_APPCOMMAND_LPARAM(lParam)))
+ return TRUE;
+ break;
case WM_SYSKEYDOWN:
// Open the window menu on Alt+Space. Normally DefWindowProc opens the
// window menu in response to WM_SYSCHAR, but since mpv translates its