aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-23 10:54:54 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-25 13:27:08 +0100
commita223030b70c8e360f81b820244705e007e3ac1ec (patch)
tree4e38abb2e27cb567760bab659546ff7176fe49fa /sway/input/cursor.c
parentsway(5): document tiling_drag (diff)
downloadsway-a223030b70c8e360f81b820244705e007e3ac1ec.tar.gz
sway-a223030b70c8e360f81b820244705e007e3ac1ec.tar.zst
sway-a223030b70c8e360f81b820244705e007e3ac1ec.zip
Change mouse buttons to x11 map and libevdev names
This modifies the way mouse bindings are parsed. Instead of adding to BTN_LEFT, which results in button numbers that may not be expected, buttons will be parsed in one of the following ways: 1. `button[1-9]` will now map to their x11 equivalents. This is already the case for bar bindings. This adds support for binding to axis events, which was not possible in the previous approach. 2. Anything that starts with `BTN_` will be parsed as an event code name using `libevdev_event_code_from_name`. This allows for any button to be mapped to instead of limiting usage to the ones near BTN_LEFT. This also adds a dependency on libevdev, but since libevdev is already a dependency of libinput, this should be fine. If needed, this option can have dependency guards added. Binding changes: - button1: BTN_LEFT -> BTN_LEFT - button2: BTN_RIGHT -> BTN_MIDDLE - button3: BTN_MIDDLE -> BTN_RIGHT - button4: BTN_SIDE -> SWAY_SCROLL_UP - button5: BTN_EXTRA -> SWAY_SCROLL_DOWN - button6: BTN_FORWARD -> SWAY_SCROLL_LEFT - button7: BTN_BACK -> SWAY_SCROLL_RIGHT - button8: BTN_TASK -> BTN_SIDE - button9: BTN_JOYSTICK -> BTN_EXTRA Since the axis events need to be mapped to an event code, this uses the following mappings to avoid any conflicts: - SWAY_SCROLL_UP: KEY_MAX + 1 - SWAY_SCROLL_DOWN: KEY_MAX + 2 - SWAY_SCROLL_LEFT: KEY_MAX + 3 - SWAY_SCROLL_RIGHT: KEY_MAX + 4
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index ad9b9835..444fe81d 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -1,5 +1,6 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <math.h> 2#include <math.h>
3#include <libevdev/libevdev.h>
3#ifdef __linux__ 4#ifdef __linux__
4#include <linux/input-event-codes.h> 5#include <linux/input-event-codes.h>
5#elif __FreeBSD__ 6#elif __FreeBSD__
@@ -982,6 +983,18 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
982 transaction_commit_dirty(); 983 transaction_commit_dirty();
983} 984}
984 985
986static uint32_t wl_axis_to_button(struct wlr_event_pointer_axis *event) {
987 switch (event->orientation) {
988 case WLR_AXIS_ORIENTATION_VERTICAL:
989 return event->delta < 0 ? SWAY_SCROLL_UP : SWAY_SCROLL_DOWN;
990 case WLR_AXIS_ORIENTATION_HORIZONTAL:
991 return event->delta < 0 ? SWAY_SCROLL_LEFT : SWAY_SCROLL_RIGHT;
992 default:
993 wlr_log(WLR_DEBUG, "Unknown axis orientation");
994 return 0;
995 }
996}
997
985static void dispatch_cursor_axis(struct sway_cursor *cursor, 998static void dispatch_cursor_axis(struct sway_cursor *cursor,
986 struct wlr_event_pointer_axis *event) { 999 struct wlr_event_pointer_axis *event) {
987 struct sway_seat *seat = cursor->seat; 1000 struct sway_seat *seat = cursor->seat;
@@ -998,11 +1011,32 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
998 enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE; 1011 enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE;
999 bool on_border = edge != WLR_EDGE_NONE; 1012 bool on_border = edge != WLR_EDGE_NONE;
1000 bool on_titlebar = cont && !on_border && !surface; 1013 bool on_titlebar = cont && !on_border && !surface;
1014 bool on_contents = cont && !on_border && surface;
1001 float scroll_factor = 1015 float scroll_factor =
1002 (ic == NULL || ic->scroll_factor == FLT_MIN) ? 1.0f : ic->scroll_factor; 1016 (ic == NULL || ic->scroll_factor == FLT_MIN) ? 1.0f : ic->scroll_factor;
1003 1017
1004 // Scrolling on a tabbed or stacked title bar 1018 bool handled = false;
1005 if (on_titlebar) { 1019
1020 // Gather information needed for mouse bindings
1021 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
1022 uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
1023 struct wlr_input_device *device = input_device->wlr_device;
1024 char *dev_id = device ? input_device_get_identifier(device) : strdup("*");
1025 uint32_t button = wl_axis_to_button(event);
1026
1027 // Handle mouse bindings - x11 mouse buttons 4-7 - press event
1028 struct sway_binding *binding = NULL;
1029 state_add_button(cursor, button);
1030 binding = get_active_mouse_binding(cursor,
1031 config->current_mode->mouse_bindings, modifiers, false,
1032 on_titlebar, on_border, on_contents, dev_id);
1033 if (binding) {
1034 seat_execute_command(seat, binding);
1035 handled = true;
1036 }
1037
1038 // Scrolling on a tabbed or stacked title bar (handled as press event)
1039 if (!handled && on_titlebar) {
1006 enum sway_container_layout layout = container_parent_layout(cont); 1040 enum sway_container_layout layout = container_parent_layout(cont);
1007 if (layout == L_TABBED || layout == L_STACKED) { 1041 if (layout == L_TABBED || layout == L_STACKED) {
1008 struct sway_node *tabcontainer = node_get_parent(node); 1042 struct sway_node *tabcontainer = node_get_parent(node);
@@ -1029,13 +1063,26 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
1029 seat_set_raw_focus(seat, new_focus); 1063 seat_set_raw_focus(seat, new_focus);
1030 seat_set_raw_focus(seat, old_focus); 1064 seat_set_raw_focus(seat, old_focus);
1031 } 1065 }
1032 return; 1066 handled = true;
1033 } 1067 }
1034 } 1068 }
1035 1069
1036 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, 1070 // Handle mouse bindings - x11 mouse buttons 4-7 - release event
1037 event->orientation, scroll_factor * event->delta, 1071 binding = get_active_mouse_binding(cursor,
1038 round(scroll_factor * event->delta_discrete), event->source); 1072 config->current_mode->mouse_bindings, modifiers, true,
1073 on_titlebar, on_border, on_contents, dev_id);
1074 state_erase_button(cursor, button);
1075 if (binding) {
1076 seat_execute_command(seat, binding);
1077 handled = true;
1078 }
1079 free(dev_id);
1080
1081 if (!handled) {
1082 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec,
1083 event->orientation, scroll_factor * event->delta,
1084 round(scroll_factor * event->delta_discrete), event->source);
1085 }
1039} 1086}
1040 1087
1041static void handle_cursor_axis(struct wl_listener *listener, void *data) { 1088static void handle_cursor_axis(struct wl_listener *listener, void *data) {