diff options
author | emersion <contact@emersion.fr> | 2018-10-25 18:32:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 18:32:09 +0200 |
commit | 6b59533646ea50e843f594ba041109873e0db16b (patch) | |
tree | 5b088b441106cf669162c7793b2ef876ea30c864 | |
parent | Merge pull request #2975 from RyanDwyer/deny-commands-when-no-outputs (diff) | |
parent | swaybar: when scrolling, check that there are workspaces to scroll on (diff) | |
download | sway-6b59533646ea50e843f594ba041109873e0db16b.tar.gz sway-6b59533646ea50e843f594ba041109873e0db16b.tar.zst sway-6b59533646ea50e843f594ba041109873e0db16b.zip |
Merge pull request #2973 from ianyfan/swaybar
swaybar: fix scrolling behaviour
-rw-r--r-- | swaybar/input.c | 70 | ||||
-rw-r--r-- | swaybar/ipc.c | 2 | ||||
-rw-r--r-- | swaybar/render.c | 2 |
3 files changed, 32 insertions, 42 deletions
diff --git a/swaybar/input.c b/swaybar/input.c index d0191f51..263d0253 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, | |||
152 | 152 | ||
153 | // If there is a button press binding, execute it, skip default behavior, | 153 | // If there is a button press binding, execute it, skip default behavior, |
154 | // and check button release bindings | 154 | // and check button release bindings |
155 | if (check_bindings(bar, wl_axis_to_x11_button(axis, value), | 155 | enum x11_button button = wl_axis_to_x11_button(axis, value); |
156 | WL_POINTER_BUTTON_STATE_PRESSED)) { | 156 | if (check_bindings(bar, button, WL_POINTER_BUTTON_STATE_PRESSED)) { |
157 | check_bindings(bar, wl_axis_to_x11_button(axis, value), | 157 | check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); |
158 | WL_POINTER_BUTTON_STATE_RELEASED); | ||
159 | return; | 158 | return; |
160 | } | 159 | } |
161 | 160 | ||
@@ -168,68 +167,59 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | |||
168 | && x < hotspot->x + hotspot->width | 167 | && x < hotspot->x + hotspot->width |
169 | && y < hotspot->y + hotspot->height) { | 168 | && y < hotspot->y + hotspot->height) { |
170 | if (HOTSPOT_IGNORE == hotspot->callback( | 169 | if (HOTSPOT_IGNORE == hotspot->callback( |
171 | output, pointer->x, pointer->y, | 170 | output, pointer->x, pointer->y, button, hotspot->data)) { |
172 | wl_axis_to_x11_button(axis, value), hotspot->data)) { | ||
173 | return; | 171 | return; |
174 | } | 172 | } |
175 | } | 173 | } |
176 | } | 174 | } |
177 | 175 | ||
176 | struct swaybar_config *config = bar->config; | ||
178 | double amt = wl_fixed_to_double(value); | 177 | double amt = wl_fixed_to_double(value); |
179 | if (amt == 0.0) { | 178 | if (amt == 0.0 || !config->workspace_buttons) { |
179 | check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); | ||
180 | return; | 180 | return; |
181 | } | 181 | } |
182 | 182 | ||
183 | // last doesn't actually need initialization, | 183 | if (!sway_assert(!wl_list_empty(&output->workspaces), "axis with no workspaces")) { |
184 | // but gcc (7.3.1) is too dumb to figure it out | 184 | return; |
185 | struct swaybar_workspace *first = NULL; | 185 | } |
186 | struct swaybar_workspace *active = NULL; | ||
187 | struct swaybar_workspace *last = NULL; | ||
188 | 186 | ||
189 | struct swaybar_workspace *iter; | 187 | struct swaybar_workspace *first = |
190 | wl_list_for_each(iter, &output->workspaces, link) { | 188 | wl_container_of(output->workspaces.next, first, link); |
191 | if (!first) { | 189 | struct swaybar_workspace *last = |
192 | first = iter; | 190 | wl_container_of(output->workspaces.prev, last, link); |
193 | } | ||
194 | 191 | ||
195 | if (iter->visible) { | 192 | struct swaybar_workspace *active; |
196 | active = iter; | 193 | wl_list_for_each(active, &output->workspaces, link) { |
194 | if (active->visible) { | ||
195 | break; | ||
197 | } | 196 | } |
198 | |||
199 | last = iter; | ||
200 | } | 197 | } |
201 | 198 | if (!sway_assert(active->visible, "axis with null workspace")) { | |
202 | if (!sway_assert(active, "axis with null workspace")) { | ||
203 | return; | 199 | return; |
204 | } | 200 | } |
205 | 201 | ||
206 | struct swaybar_workspace *new; | 202 | struct swaybar_workspace *new; |
207 | 203 | if (amt < 0.0) { | |
208 | if (amt > 0.0) { | ||
209 | if (active == first) { | 204 | if (active == first) { |
210 | if (!bar->config->wrap_scroll) { | 205 | new = config->wrap_scroll ? last : NULL; |
211 | return; | 206 | } else { |
212 | } | 207 | new = wl_container_of(active->link.prev, new, link); |
213 | new = last; | ||
214 | } | 208 | } |
215 | |||
216 | new = wl_container_of(active->link.prev, new, link); | ||
217 | } else { | 209 | } else { |
218 | if (active == last) { | 210 | if (active == last) { |
219 | if (!bar->config->wrap_scroll) { | 211 | new = config->wrap_scroll ? first : NULL; |
220 | return; | 212 | } else { |
221 | } | 213 | new = wl_container_of(active->link.next, new, link); |
222 | new = first; | ||
223 | } | 214 | } |
224 | |||
225 | new = wl_container_of(active->link.next, new, link); | ||
226 | } | 215 | } |
227 | 216 | ||
228 | ipc_send_workspace_command(bar, new->name); | 217 | if (new) { |
218 | ipc_send_workspace_command(bar, new->name); | ||
219 | } | ||
229 | 220 | ||
230 | // Check button release bindings | 221 | // Check button release bindings |
231 | check_bindings(bar, wl_axis_to_x11_button(axis, value), | 222 | check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); |
232 | WL_POINTER_BUTTON_STATE_RELEASED); | ||
233 | } | 223 | } |
234 | 224 | ||
235 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | 225 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { |
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) { | |||
307 | if (ws->urgent) { | 307 | if (ws->urgent) { |
308 | bar->visible_by_urgency = true; | 308 | bar->visible_by_urgency = true; |
309 | } | 309 | } |
310 | wl_list_insert(&output->workspaces, &ws->link); | 310 | wl_list_insert(output->workspaces.prev, &ws->link); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | } | 313 | } |
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) { | |||
466 | x = 0; | 466 | x = 0; |
467 | if (config->workspace_buttons) { | 467 | if (config->workspace_buttons) { |
468 | struct swaybar_workspace *ws; | 468 | struct swaybar_workspace *ws; |
469 | wl_list_for_each_reverse(ws, &output->workspaces, link) { | 469 | wl_list_for_each(ws, &output->workspaces, link) { |
470 | uint32_t h = render_workspace_button(cairo, output, ws, &x); | 470 | uint32_t h = render_workspace_button(cairo, output, ws, &x); |
471 | max_height = h > max_height ? h : max_height; | 471 | max_height = h > max_height ? h : max_height; |
472 | } | 472 | } |