diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-10-25 12:55:08 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-10-25 12:57:16 +0100 |
commit | c5541763c0c101944473a4cf7dd9b59e1dd04e0b (patch) | |
tree | eff4f2ca3a2a919204e623b25f782547a1c14a45 /swaybar | |
parent | swaybar: reverse order of workspaces list (diff) | |
download | sway-c5541763c0c101944473a4cf7dd9b59e1dd04e0b.tar.gz sway-c5541763c0c101944473a4cf7dd9b59e1dd04e0b.tar.zst sway-c5541763c0c101944473a4cf7dd9b59e1dd04e0b.zip |
swaybar: fix scrolling behaviour
1. wrap_scroll has been fixed
2. release bindings are checked when returning early
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/input.c | 66 |
1 files 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, | |||
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,55 @@ 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 | struct swaybar_workspace *first = |
184 | // but gcc (7.3.1) is too dumb to figure it out | 184 | wl_container_of(output->workspaces.next, first, link); |
185 | struct swaybar_workspace *first = NULL; | 185 | struct swaybar_workspace *last = |
186 | struct swaybar_workspace *active = NULL; | 186 | wl_container_of(output->workspaces.prev, last, link); |
187 | struct swaybar_workspace *last = NULL; | ||
188 | 187 | ||
189 | struct swaybar_workspace *iter; | 188 | struct swaybar_workspace *active; |
190 | wl_list_for_each(iter, &output->workspaces, link) { | 189 | wl_list_for_each(active, &output->workspaces, link) { |
191 | if (!first) { | 190 | if (active->visible) { |
192 | first = iter; | 191 | break; |
193 | } | ||
194 | |||
195 | if (iter->visible) { | ||
196 | active = iter; | ||
197 | } | 192 | } |
198 | |||
199 | last = iter; | ||
200 | } | 193 | } |
201 | 194 | if (!sway_assert(active->visible, "axis with null workspace")) { | |
202 | if (!sway_assert(active, "axis with null workspace")) { | ||
203 | return; | 195 | return; |
204 | } | 196 | } |
205 | 197 | ||
206 | struct swaybar_workspace *new; | 198 | struct swaybar_workspace *new; |
207 | |||
208 | if (amt < 0.0) { | 199 | if (amt < 0.0) { |
209 | if (active == first) { | 200 | if (active == first) { |
210 | if (!bar->config->wrap_scroll) { | 201 | new = config->wrap_scroll ? last : NULL; |
211 | return; | 202 | } else { |
212 | } | 203 | new = wl_container_of(active->link.prev, new, link); |
213 | new = last; | ||
214 | } | 204 | } |
215 | |||
216 | new = wl_container_of(active->link.prev, new, link); | ||
217 | } else { | 205 | } else { |
218 | if (active == last) { | 206 | if (active == last) { |
219 | if (!bar->config->wrap_scroll) { | 207 | new = config->wrap_scroll ? first : NULL; |
220 | return; | 208 | } else { |
221 | } | 209 | new = wl_container_of(active->link.next, new, link); |
222 | new = first; | ||
223 | } | 210 | } |
224 | |||
225 | new = wl_container_of(active->link.next, new, link); | ||
226 | } | 211 | } |
227 | 212 | ||
228 | ipc_send_workspace_command(bar, new->name); | 213 | if (new) { |
214 | ipc_send_workspace_command(bar, new->name); | ||
215 | } | ||
229 | 216 | ||
230 | // Check button release bindings | 217 | // Check button release bindings |
231 | check_bindings(bar, wl_axis_to_x11_button(axis, value), | 218 | check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); |
232 | WL_POINTER_BUTTON_STATE_RELEASED); | ||
233 | } | 219 | } |
234 | 220 | ||
235 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | 221 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { |