diff options
author | 2018-10-25 18:32:09 +0200 | |
---|---|---|
committer | 2018-10-25 18:32:09 +0200 | |
commit | 6b59533646ea50e843f594ba041109873e0db16b (patch) | |
tree | 5b088b441106cf669162c7793b2ef876ea30c864 /swaybar/input.c | |
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
Diffstat (limited to 'swaybar/input.c')
-rw-r--r-- | swaybar/input.c | 70 |
1 files changed, 30 insertions, 40 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) { |