From c3fdabb72545302a25a915ae1f76a04cb7f61729 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Thu, 25 Oct 2018 12:23:48 +0100 Subject: [PATCH 1/3] swaybar: reverse order of workspaces list This makes it congruent with its visual appearance, making it easier to reason about. --- swaybar/input.c | 2 +- swaybar/ipc.c | 2 +- swaybar/render.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/swaybar/input.c b/swaybar/input.c index d0191f51..8e994dcf 100644 --- a/swaybar/input.c +++ b/swaybar/input.c @@ -205,7 +205,7 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, struct swaybar_workspace *new; - if (amt > 0.0) { + if (amt < 0.0) { if (active == first) { if (!bar->config->wrap_scroll) { return; diff --git a/swaybar/ipc.c b/swaybar/ipc.c index e1b30b52..706f968d 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -307,7 +307,7 @@ bool ipc_get_workspaces(struct swaybar *bar) { if (ws->urgent) { bar->visible_by_urgency = true; } - wl_list_insert(&output->workspaces, &ws->link); + wl_list_insert(output->workspaces.prev, &ws->link); } } } diff --git a/swaybar/render.c b/swaybar/render.c index 85e7542f..4ebf922e 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -466,7 +466,7 @@ static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) { x = 0; if (config->workspace_buttons) { struct swaybar_workspace *ws; - wl_list_for_each_reverse(ws, &output->workspaces, link) { + wl_list_for_each(ws, &output->workspaces, link) { uint32_t h = render_workspace_button(cairo, output, ws, &x); max_height = h > max_height ? h : max_height; } From c5541763c0c101944473a4cf7dd9b59e1dd04e0b Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Thu, 25 Oct 2018 12:55:08 +0100 Subject: [PATCH 2/3] swaybar: fix scrolling behaviour 1. wrap_scroll has been fixed 2. release bindings are checked when returning early --- swaybar/input.c | 66 +++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/swaybar/input.c b/swaybar/input.c index 8e994dcf..4aefc6d6 100644 --- a/swaybar/input.c +++ b/swaybar/input.c @@ -152,10 +152,9 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, // If there is a button press binding, execute it, skip default behavior, // and check button release bindings - if (check_bindings(bar, wl_axis_to_x11_button(axis, value), - WL_POINTER_BUTTON_STATE_PRESSED)) { - check_bindings(bar, wl_axis_to_x11_button(axis, value), - WL_POINTER_BUTTON_STATE_RELEASED); + enum x11_button button = wl_axis_to_x11_button(axis, value); + if (check_bindings(bar, button, WL_POINTER_BUTTON_STATE_PRESSED)) { + check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); return; } @@ -168,68 +167,55 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, && x < hotspot->x + hotspot->width && y < hotspot->y + hotspot->height) { if (HOTSPOT_IGNORE == hotspot->callback( - output, pointer->x, pointer->y, - wl_axis_to_x11_button(axis, value), hotspot->data)) { + output, pointer->x, pointer->y, button, hotspot->data)) { return; } } } + struct swaybar_config *config = bar->config; double amt = wl_fixed_to_double(value); - if (amt == 0.0) { + if (amt == 0.0 || !config->workspace_buttons) { + check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); return; } - // last doesn't actually need initialization, - // but gcc (7.3.1) is too dumb to figure it out - struct swaybar_workspace *first = NULL; - struct swaybar_workspace *active = NULL; - struct swaybar_workspace *last = NULL; + struct swaybar_workspace *first = + wl_container_of(output->workspaces.next, first, link); + struct swaybar_workspace *last = + wl_container_of(output->workspaces.prev, last, link); - struct swaybar_workspace *iter; - wl_list_for_each(iter, &output->workspaces, link) { - if (!first) { - first = iter; - } - - if (iter->visible) { - active = iter; + struct swaybar_workspace *active; + wl_list_for_each(active, &output->workspaces, link) { + if (active->visible) { + break; } - - last = iter; } - - if (!sway_assert(active, "axis with null workspace")) { + if (!sway_assert(active->visible, "axis with null workspace")) { return; } struct swaybar_workspace *new; - if (amt < 0.0) { if (active == first) { - if (!bar->config->wrap_scroll) { - return; - } - new = last; + new = config->wrap_scroll ? last : NULL; + } else { + new = wl_container_of(active->link.prev, new, link); } - - new = wl_container_of(active->link.prev, new, link); } else { if (active == last) { - if (!bar->config->wrap_scroll) { - return; - } - new = first; + new = config->wrap_scroll ? first : NULL; + } else { + new = wl_container_of(active->link.next, new, link); } - - new = wl_container_of(active->link.next, new, link); } - ipc_send_workspace_command(bar, new->name); + if (new) { + ipc_send_workspace_command(bar, new->name); + } // Check button release bindings - check_bindings(bar, wl_axis_to_x11_button(axis, value), - WL_POINTER_BUTTON_STATE_RELEASED); + check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); } static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { From 19421373b9837860115f1fcf70f160f9d716aee1 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Thu, 25 Oct 2018 14:07:44 +0100 Subject: [PATCH 3/3] swaybar: when scrolling, check that there are workspaces to scroll on --- swaybar/input.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swaybar/input.c b/swaybar/input.c index 4aefc6d6..263d0253 100644 --- a/swaybar/input.c +++ b/swaybar/input.c @@ -180,6 +180,10 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, return; } + if (!sway_assert(!wl_list_empty(&output->workspaces), "axis with no workspaces")) { + return; + } + struct swaybar_workspace *first = wl_container_of(output->workspaces.next, first, link); struct swaybar_workspace *last =