diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-22 10:42:59 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-22 10:42:59 +1000 |
commit | bf5933c501a3c1705715b62dc1507df2bf0a4d2b (patch) | |
tree | b95e6a1f8f3352c3fe93cf405108f6f6652f3947 | |
parent | Merge pull request #2666 from emersion/swaybar-hotplug (diff) | |
download | sway-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).
-rw-r--r-- | sway/input/cursor.c | 49 | ||||
-rw-r--r-- | sway/tree/container.c | 6 |
2 files changed, 47 insertions, 8 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 | ||
934 | static 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 | |||
933 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { | 974 | static 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 | ||
941 | static void handle_touch_down(struct wl_listener *listener, void *data) { | 982 | static void handle_touch_down(struct wl_listener *listener, void *data) { |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 47687744..b8af7564 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -215,8 +215,7 @@ static struct sway_container *container_at_tabbed(struct sway_node *parent, | |||
215 | child_index = children->length - 1; | 215 | child_index = children->length - 1; |
216 | } | 216 | } |
217 | struct sway_container *child = children->items[child_index]; | 217 | struct sway_container *child = children->items[child_index]; |
218 | struct sway_node *node = seat_get_focus_inactive(seat, &child->node); | 218 | return child; |
219 | return node->sway_container; | ||
220 | } | 219 | } |
221 | 220 | ||
222 | // Surfaces | 221 | // Surfaces |
@@ -243,8 +242,7 @@ static struct sway_container *container_at_stacked(struct sway_node *parent, | |||
243 | int child_index = (ly - box.y) / title_height; | 242 | int child_index = (ly - box.y) / title_height; |
244 | if (child_index < children->length) { | 243 | if (child_index < children->length) { |
245 | struct sway_container *child = children->items[child_index]; | 244 | struct sway_container *child = children->items[child_index]; |
246 | struct sway_node *node = seat_get_focus_inactive(seat, &child->node); | 245 | return child; |
247 | return node->sway_container; | ||
248 | } | 246 | } |
249 | 247 | ||
250 | // Surfaces | 248 | // Surfaces |