summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Scott Anderson <scott@anderso.nz>2018-04-22 17:13:52 +1200
committerLibravatar Scott Anderson <scott@anderso.nz>2018-04-22 17:25:15 +1200
commit4dfbc3160c937b4fcee2b27d78d7e46a48cd68e9 (patch)
treeb4444f49bb92cc257d529dae692958873c9736b0
parentMerge pull request #1838 from emersion/use-wlr-renderer-init-wl-shm (diff)
downloadsway-4dfbc3160c937b4fcee2b27d78d7e46a48cd68e9.tar.gz
sway-4dfbc3160c937b4fcee2b27d78d7e46a48cd68e9.tar.zst
sway-4dfbc3160c937b4fcee2b27d78d7e46a48cd68e9.zip
Fix swaybar axis event logic
Uses 'visible' instead of 'focused', since we may scroll on a bar which isn't the focused output. We can't use "next_on_output" or "prev_on_output" to implement this, because it only modify the focused output. So scrolling on an unfocused output will affect the incorrect one. We just use the "workspace name" command instead.
-rw-r--r--swaybar/bar.c61
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
186static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { 211static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {