aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-22 10:42:59 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-22 10:42:59 +1000
commitbf5933c501a3c1705715b62dc1507df2bf0a4d2b (patch)
treeb95e6a1f8f3352c3fe93cf405108f6f6652f3947 /sway/input/cursor.c
parentMerge pull request #2666 from emersion/swaybar-hotplug (diff)
downloadsway-bf5933c501a3c1705715b62dc1507df2bf0a4d2b.tar.gz
sway-bf5933c501a3c1705715b62dc1507df2bf0a4d2b.tar.zst
sway-bf5933c501a3c1705715b62dc1507df2bf0a4d2b.zip
Implement tab cycling using mouse wheel
Firstly, a change had to be made to the container_at functions. If you create layout `T[view H[view view]]` and hover the second tab, the container_at functions would return the focus_inactive child. They now return the split container itself. To compensate for this, dispatch_cursor_button has been adjusted to find the focus_inactive child before focusing it. The actual implementation of wheel scrolling is pretty straightforward. This uses handle_cursor_axis, so I took a similar approach to handle_cursor_button (ie. creating a dispatch_cursor_axis function).
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 85951c09..5111e8e5 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -911,9 +911,10 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
911 return; 911 return;
912 } 912 }
913 913
914 // Handle clicking a container surface 914 // Handle clicking a container surface or decorations
915 if (cont) { 915 if (cont) {
916 seat_set_focus_container(seat, cont); 916 node = seat_get_focus_inactive(seat, &cont->node);
917 seat_set_focus(seat, node);
917 seat_pointer_notify_button(seat, time_msec, button, state); 918 seat_pointer_notify_button(seat, time_msec, button, state);
918 return; 919 return;
919 } 920 }
@@ -930,12 +931,52 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
930 transaction_commit_dirty(); 931 transaction_commit_dirty();
931} 932}
932 933
934static void dispatch_cursor_axis(struct sway_cursor *cursor,
935 struct wlr_event_pointer_axis *event) {
936 struct sway_seat *seat = cursor->seat;
937
938 // Determine what's under the cursor
939 struct wlr_surface *surface = NULL;
940 double sx, sy;
941 struct sway_node *node = node_at_coords(seat,
942 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
943 struct sway_container *cont = node && node->type == N_CONTAINER ?
944 node->sway_container : NULL;
945 enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE;
946 bool on_border = edge != WLR_EDGE_NONE;
947 bool on_titlebar = cont && !on_border && !surface;
948
949 // Scrolling on a tabbed or stacked title bar
950 if (on_titlebar) {
951 enum sway_container_layout layout = container_parent_layout(cont);
952 if (layout == L_TABBED || layout == L_STACKED) {
953 struct sway_node *active =
954 seat_get_active_tiling_child(seat, node_get_parent(node));
955 list_t *siblings = container_get_siblings(cont);
956 int desired = list_find(siblings, active->sway_container) +
957 event->delta_discrete;
958 if (desired < 0) {
959 desired = 0;
960 } else if (desired >= siblings->length) {
961 desired = siblings->length - 1;
962 }
963 struct sway_container *new_focus = siblings->items[desired];
964 node = seat_get_focus_inactive(seat, &new_focus->node);
965 seat_set_focus(seat, node);
966 return;
967 }
968 }
969
970 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec,
971 event->orientation, event->delta, event->delta_discrete, event->source);
972}
973
933static void handle_cursor_axis(struct wl_listener *listener, void *data) { 974static void handle_cursor_axis(struct wl_listener *listener, void *data) {
934 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); 975 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
935 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); 976 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
936 struct wlr_event_pointer_axis *event = data; 977 struct wlr_event_pointer_axis *event = data;
937 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, 978 dispatch_cursor_axis(cursor, event);
938 event->orientation, event->delta, event->delta_discrete, event->source); 979 transaction_commit_dirty();
939} 980}
940 981
941static void handle_touch_down(struct wl_listener *listener, void *data) { 982static void handle_touch_down(struct wl_listener *listener, void *data) {