diff options
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 669cb11a..d407db4f 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -156,31 +156,56 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | |||
156 | if (!sway_assert(output, "axis with no active output")) { | 156 | if (!sway_assert(output, "axis with no active output")) { |
157 | return; | 157 | return; |
158 | } | 158 | } |
159 | |||
159 | double amt = wl_fixed_to_double(value); | 160 | double amt = wl_fixed_to_double(value); |
160 | if (!bar->config->wrap_scroll) { | 161 | if (amt == 0.0) { |
161 | int i = 0; | 162 | return; |
162 | struct swaybar_workspace *ws = NULL; | 163 | } |
163 | wl_list_for_each(ws, &output->workspaces, link) { | 164 | |
164 | if (ws->focused) { | 165 | struct swaybar_workspace *first = NULL; |
165 | break; | 166 | struct swaybar_workspace *active = NULL; |
166 | } | 167 | struct swaybar_workspace *last; |
167 | ++i; | 168 | |
169 | struct swaybar_workspace *iter; | ||
170 | wl_list_for_each(iter, &output->workspaces, link) { | ||
171 | if (!first) { | ||
172 | first = iter; | ||
168 | } | 173 | } |
169 | int len = wl_list_length(&output->workspaces); | 174 | |
170 | if (!sway_assert(i != len, "axis with null workspace")) { | 175 | if (iter->visible) { |
171 | return; | 176 | active = iter; |
172 | } | 177 | } |
173 | if (i == 0 && amt > 0) { | 178 | |
174 | return; // Do not wrap | 179 | last = iter; |
180 | } | ||
181 | |||
182 | if (!sway_assert(active, "axis with null workspace")) { | ||
183 | return; | ||
184 | } | ||
185 | |||
186 | struct swaybar_workspace *new; | ||
187 | |||
188 | if (amt > 0.0) { | ||
189 | if (active == first) { | ||
190 | if (!bar->config->wrap_scroll) { | ||
191 | return; | ||
192 | } | ||
193 | new = last; | ||
175 | } | 194 | } |
176 | if (i == len - 1 && amt < 0) { | 195 | |
177 | return; // Do not wrap | 196 | new = wl_container_of(active->link.prev, new, link); |
197 | } else { | ||
198 | if (active == last) { | ||
199 | if (!bar->config->wrap_scroll) { | ||
200 | return; | ||
201 | } | ||
202 | new = first; | ||
178 | } | 203 | } |
204 | |||
205 | new = wl_container_of(active->link.next, new, link); | ||
179 | } | 206 | } |
180 | 207 | ||
181 | const char *workspace_name = | 208 | ipc_send_workspace_command(bar, new->name); |
182 | amt < 0 ? "prev_on_output" : "next_on_output"; | ||
183 | ipc_send_workspace_command(bar, workspace_name); | ||
184 | } | 209 | } |
185 | 210 | ||
186 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { | 211 | static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { |