summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-03-31 15:55:33 -0400
committerKacper Michajłow <kasper93@gmail.com>2024-04-18 01:03:33 +0200
commit7cfd369ffb8cb5ddfe2e88d10d6d648f8a9db60a (patch)
tree223b9feb263917589ff86d40ba0d5ce1fccdfc19 /osdep
parent8a2892a68fa0f166a69f8887edb6b86373b0ab1a (diff)
downloadmpv-7cfd369ffb8cb5ddfe2e88d10d6d648f8a9db60a.tar.bz2
mpv-7cfd369ffb8cb5ddfe2e88d10d6d648f8a9db60a.tar.xz
terminal-win: support mouse input events
The mouse input information is available from the INPUT_RECORD with MOUSE_EVENT event type.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/terminal-win.c103
1 files changed, 74 insertions, 29 deletions
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c
index 2846463038..435354155a 100644
--- a/osdep/terminal-win.c
+++ b/osdep/terminal-win.c
@@ -159,35 +159,80 @@ static void read_input(HANDLE in)
break;
// Only key-down events are interesting to us
- if (event.EventType != KEY_EVENT)
- continue;
- KEY_EVENT_RECORD *record = &event.Event.KeyEvent;
- if (!record->bKeyDown)
- continue;
-
- UINT vkey = record->wVirtualKeyCode;
- bool ext = record->dwControlKeyState & ENHANCED_KEY;
-
- int mods = 0;
- if (record->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
- mods |= MP_KEY_MODIFIER_ALT;
- if (record->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
- mods |= MP_KEY_MODIFIER_CTRL;
- if (record->dwControlKeyState & SHIFT_PRESSED)
- mods |= MP_KEY_MODIFIER_SHIFT;
-
- int mpkey = mp_w32_vkey_to_mpkey(vkey, ext);
- if (mpkey) {
- mp_input_put_key(input_ctx, mpkey | mods);
- } else {
- // Only characters should be remaining
- int c = record->uChar.UnicodeChar;
- // The ctrl key always produces control characters in the console.
- // Shift them back up to regular characters.
- if (c > 0 && c < 0x20 && (mods & MP_KEY_MODIFIER_CTRL))
- c += (mods & MP_KEY_MODIFIER_SHIFT) ? 0x40 : 0x60;
- if (c >= 0x20)
- mp_input_put_key(input_ctx, c | mods);
+ switch (event.EventType)
+ {
+ case KEY_EVENT: {
+ KEY_EVENT_RECORD *record = &event.Event.KeyEvent;
+ if (!record->bKeyDown)
+ continue;
+
+ UINT vkey = record->wVirtualKeyCode;
+ bool ext = record->dwControlKeyState & ENHANCED_KEY;
+
+ int mods = 0;
+ if (record->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
+ mods |= MP_KEY_MODIFIER_ALT;
+ if (record->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
+ mods |= MP_KEY_MODIFIER_CTRL;
+ if (record->dwControlKeyState & SHIFT_PRESSED)
+ mods |= MP_KEY_MODIFIER_SHIFT;
+
+ int mpkey = mp_w32_vkey_to_mpkey(vkey, ext);
+ if (mpkey) {
+ mp_input_put_key(input_ctx, mpkey | mods);
+ } else {
+ // Only characters should be remaining
+ int c = record->uChar.UnicodeChar;
+ // The ctrl key always produces control characters in the console.
+ // Shift them back up to regular characters.
+ if (c > 0 && c < 0x20 && (mods & MP_KEY_MODIFIER_CTRL))
+ c += (mods & MP_KEY_MODIFIER_SHIFT) ? 0x40 : 0x60;
+ if (c >= 0x20)
+ mp_input_put_key(input_ctx, c | mods);
+ }
+ break;
+ }
+ case MOUSE_EVENT: {
+ MOUSE_EVENT_RECORD *record = &event.Event.MouseEvent;
+ int mods = 0;
+ if (record->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
+ mods |= MP_KEY_MODIFIER_ALT;
+ if (record->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
+ mods |= MP_KEY_MODIFIER_CTRL;
+ if (record->dwControlKeyState & SHIFT_PRESSED)
+ mods |= MP_KEY_MODIFIER_SHIFT;
+
+ switch (record->dwEventFlags) {
+ case MOUSE_MOVED: {
+ int w = 0, h = 0;
+ if (get_font_size(&w, &h)) {
+ mp_input_set_mouse_pos(input_ctx, w * (record->dwMousePosition.X + 0.5),
+ h * (record->dwMousePosition.Y + 0.5));
+ }
+ break;
+ }
+ case MOUSE_HWHEELED: {
+ int button = (int16_t)HIWORD(record->dwButtonState) > 0 ? MP_WHEEL_RIGHT : MP_WHEEL_LEFT;
+ mp_input_put_key(input_ctx, button | mods);
+ break;
+ }
+ case MOUSE_WHEELED: {
+ int button = (int16_t)HIWORD(record->dwButtonState) > 0 ? MP_WHEEL_UP : MP_WHEEL_DOWN;
+ mp_input_put_key(input_ctx, button | mods);
+ break;
+ }
+ default: {
+ int left_button_state = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED ?
+ MP_KEY_STATE_DOWN : MP_KEY_STATE_UP;
+ mp_input_put_key(input_ctx, MP_MBTN_LEFT | mods | left_button_state);
+ int right_button_state = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED ?
+ MP_KEY_STATE_DOWN : MP_KEY_STATE_UP;
+ mp_input_put_key(input_ctx, MP_MBTN_RIGHT | mods | right_button_state);
+ break;
+ }
+ }
+ break;
+ }
}
}
}