diff options
author | James Ross-Gowan <rossy@jrg.systems> | 2017-08-08 21:34:38 +1000 |
---|---|---|
committer | James Ross-Gowan <rossy@jrg.systems> | 2017-09-03 20:31:44 +1000 |
commit | 957e9a37db6611fe0879bd2097131df5e09afd47 (patch) | |
tree | b346371417acd0476a60e2c1ecde20c8548d14ba /video/out | |
parent | 449d9725c91af467b154817dfd0603d80ba7f00b (diff) | |
download | mpv-957e9a37db6611fe0879bd2097131df5e09afd47.tar.bz2 mpv-957e9a37db6611fe0879bd2097131df5e09afd47.tar.xz |
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
Diffstat (limited to 'video/out')
-rw-r--r-- | video/out/cocoa/events_view.m | 6 | ||||
-rw-r--r-- | video/out/vo_caca.c | 4 | ||||
-rw-r--r-- | video/out/vo_sdl.c | 4 | ||||
-rw-r--r-- | video/out/w32_common.c | 27 | ||||
-rw-r--r-- | video/out/wayland_common.c | 8 | ||||
-rw-r--r-- | video/out/x11_common.c | 4 |
6 files changed, 27 insertions, 26 deletions
diff --git a/video/out/cocoa/events_view.m b/video/out/cocoa/events_view.m index 4050e59d04..7a95bb9442 100644 --- a/video/out/cocoa/events_view.m +++ b/video/out/cocoa/events_view.m @@ -266,9 +266,9 @@ int mpkey; if (fabs(deltaY) >= fabs(deltaX)) { - mpkey = deltaY > 0 ? MP_MOUSE_BTN3 : MP_MOUSE_BTN4; + mpkey = deltaY > 0 ? MP_WHEEL_UP : MP_WHEEL_DOWN; } else { - mpkey = deltaX > 0 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6; + mpkey = deltaX > 0 ? MP_WHEEL_LEFT : MP_WHEEL_RIGHT; } [self.adapter putKey:mpkey withModifiers:modifiers]; @@ -291,7 +291,7 @@ - (void)putMouseEvent:(NSEvent *)event withState:(int)state { self.hasMouseDown = (state == MP_KEY_STATE_DOWN); - int mpkey = (MP_MOUSE_BTN0 + [self mpvButtonNumber:event]); + int mpkey = (MP_MOUSE_BASE + [self mpvButtonNumber:event]); [self.adapter putKey:(mpkey | state) withModifiers:[event modifierFlags]]; } diff --git a/video/out/vo_caca.c b/video/out/vo_caca.c index 4c5da598e9..942c0aa37d 100644 --- a/video/out/vo_caca.c +++ b/video/out/vo_caca.c @@ -179,11 +179,11 @@ static void check_events(struct vo *vo) break; case CACA_EVENT_MOUSE_PRESS: mp_input_put_key(vo->input_ctx, - (MP_MOUSE_BTN0 + cev.data.mouse.button - 1) | MP_KEY_STATE_DOWN); + (MP_MOUSE_BASE + cev.data.mouse.button - 1) | MP_KEY_STATE_DOWN); break; case CACA_EVENT_MOUSE_RELEASE: mp_input_put_key(vo->input_ctx, - (MP_MOUSE_BTN0 + cev.data.mouse.button - 1) | MP_KEY_STATE_UP); + (MP_MOUSE_BASE + cev.data.mouse.button - 1) | MP_KEY_STATE_UP); break; case CACA_EVENT_KEY_PRESS: { diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c index d902c09cad..a99eebd46d 100644 --- a/video/out/vo_sdl.c +++ b/video/out/vo_sdl.c @@ -608,11 +608,11 @@ static void wait_events(struct vo *vo, int64_t until_time_us) break; case SDL_MOUSEBUTTONDOWN: mp_input_put_key(vo->input_ctx, - (MP_MOUSE_BTN0 + ev.button.button - 1) | MP_KEY_STATE_DOWN); + (MP_MOUSE_BASE + ev.button.button - 1) | MP_KEY_STATE_DOWN); break; case SDL_MOUSEBUTTONUP: mp_input_put_key(vo->input_ctx, - (MP_MOUSE_BTN0 + ev.button.button - 1) | MP_KEY_STATE_UP); + (MP_MOUSE_BASE + ev.button.button - 1) | MP_KEY_STATE_UP); break; case SDL_MOUSEWHEEL: break; diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 26edde17eb..e0b26b1183 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -413,13 +413,13 @@ static bool handle_mouse_down(struct vo_w32_state *w32, int btn, int x, int y) btn |= mod_state(w32); mp_input_put_key(w32->input_ctx, btn | MP_KEY_STATE_DOWN); - if (btn == MP_MOUSE_BTN0 && !w32->current_fs && + if (btn == MP_MBTN_LEFT && !w32->current_fs && !mp_input_test_dragging(w32->input_ctx, x, y)) { // Window dragging hack ReleaseCapture(); SendMessage(w32->window, WM_NCLBUTTONDOWN, HTCAPTION, 0); - mp_input_put_key(w32->input_ctx, MP_MOUSE_BTN0 | MP_KEY_STATE_UP); + mp_input_put_key(w32->input_ctx, MP_MBTN_LEFT | MP_KEY_STATE_UP); // Indicate the message was handled, so DefWindowProc won't be called return true; @@ -1096,26 +1096,26 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, break; } case WM_LBUTTONDOWN: - if (handle_mouse_down(w32, MP_MOUSE_BTN0, GET_X_LPARAM(lParam), - GET_Y_LPARAM(lParam))) + if (handle_mouse_down(w32, MP_MBTN_LEFT, GET_X_LPARAM(lParam), + GET_Y_LPARAM(lParam))) return 0; break; case WM_LBUTTONUP: - handle_mouse_up(w32, MP_MOUSE_BTN0); + handle_mouse_up(w32, MP_MBTN_LEFT); break; case WM_MBUTTONDOWN: - handle_mouse_down(w32, MP_MOUSE_BTN1, GET_X_LPARAM(lParam), - GET_Y_LPARAM(lParam)); + handle_mouse_down(w32, MP_MBTN_MID, GET_X_LPARAM(lParam), + GET_Y_LPARAM(lParam)); break; case WM_MBUTTONUP: - handle_mouse_up(w32, MP_MOUSE_BTN1); + handle_mouse_up(w32, MP_MBTN_MID); break; case WM_RBUTTONDOWN: - handle_mouse_down(w32, MP_MOUSE_BTN2, GET_X_LPARAM(lParam), + handle_mouse_down(w32, MP_MBTN_RIGHT, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); break; case WM_RBUTTONUP: - handle_mouse_up(w32, MP_MOUSE_BTN2); + handle_mouse_up(w32, MP_MBTN_RIGHT); break; case WM_MOUSEWHEEL: handle_mouse_wheel(w32, false, GET_WHEEL_DELTA_WPARAM(wParam)); @@ -1127,11 +1127,12 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, return TRUE; case WM_XBUTTONDOWN: handle_mouse_down(w32, - HIWORD(wParam) == 1 ? MP_MOUSE_BTN7 : MP_MOUSE_BTN8, - GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + HIWORD(wParam) == 1 ? MP_MBTN_BACK : MP_MBTN_FORWARD, + GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); break; case WM_XBUTTONUP: - handle_mouse_up(w32, HIWORD(wParam) == 1 ? MP_MOUSE_BTN7 : MP_MOUSE_BTN8); + handle_mouse_up(w32, + HIWORD(wParam) == 1 ? MP_MBTN_BACK : MP_MBTN_FORWARD); break; case WM_DISPLAYCHANGE: force_update_display_info(w32); diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 63f7ac235e..22cf23dfa6 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -403,7 +403,7 @@ static void pointer_handle_enter(void *data, /* Release the left button on pointer enter again * because after moving the shell surface no release event is sent */ mp_input_put_key(wl->vo->input_ctx, MP_KEY_MOUSE_ENTER); - mp_input_put_key(wl->vo->input_ctx, MP_MOUSE_BTN0 | MP_KEY_STATE_UP); + mp_input_put_key(wl->vo->input_ctx, MP_MBTN_LEFT | MP_KEY_STATE_UP); show_cursor(wl); } @@ -448,13 +448,13 @@ static void pointer_handle_button(void *data, state = state == WL_POINTER_BUTTON_STATE_PRESSED ? MP_KEY_STATE_DOWN : MP_KEY_STATE_UP; - button = button == BTN_LEFT ? MP_MOUSE_BTN0 : - button == BTN_MIDDLE ? MP_MOUSE_BTN1 : MP_MOUSE_BTN2; + button = button == BTN_LEFT ? MP_MBTN_LEFT : + button == BTN_MIDDLE ? MP_MBTN_MID : MP_MBTN_RIGHT; mp_input_put_key(wl->vo->input_ctx, button | state); if (!mp_input_test_dragging(wl->vo->input_ctx, wl->window.mouse_x, wl->window.mouse_y) && - (button == MP_MOUSE_BTN0) && (state == MP_KEY_STATE_DOWN)) + (button == MP_MBTN_LEFT) && (state == MP_KEY_STATE_DOWN)) window_move(wl, serial); } diff --git a/video/out/x11_common.c b/video/out/x11_common.c index ffb97d5516..6fb4e94995 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -1136,7 +1136,7 @@ void vo_x11_check_events(struct vo *vo) if (Event.xbutton.button == 1) x11->win_drag_button1_down = true; mp_input_put_key(x11->input_ctx, - (MP_MOUSE_BTN0 + Event.xbutton.button - 1) | + (MP_MOUSE_BASE + Event.xbutton.button - 1) | get_mods(Event.xbutton.state) | MP_KEY_STATE_DOWN); long msg[4] = {XEMBED_REQUEST_FOCUS}; vo_x11_xembed_send_message(x11, msg); @@ -1145,7 +1145,7 @@ void vo_x11_check_events(struct vo *vo) if (Event.xbutton.button == 1) x11->win_drag_button1_down = false; mp_input_put_key(x11->input_ctx, - (MP_MOUSE_BTN0 + Event.xbutton.button - 1) | + (MP_MOUSE_BASE + Event.xbutton.button - 1) | get_mods(Event.xbutton.state) | MP_KEY_STATE_UP); break; case MapNotify: |