summaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 3990f1ca..5b7fea71 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -144,6 +144,19 @@ static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
144 bar->pointer.y = wl_fixed_to_int(surface_y); 144 bar->pointer.y = wl_fixed_to_int(surface_y);
145} 145}
146 146
147static bool check_bindings(struct swaybar *bar, uint32_t x11_button,
148 uint32_t state) {
149 bool released = state == WL_POINTER_BUTTON_STATE_RELEASED;
150 for (int i = 0; i < bar->config->bindings->length; i++) {
151 struct swaybar_binding *binding = bar->config->bindings->items[i];
152 if (binding->button == x11_button && binding->release == released) {
153 ipc_execute_binding(bar, binding);
154 return true;
155 }
156 }
157 return false;
158}
159
147static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, 160static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
148 uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { 161 uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
149 struct swaybar *bar = data; 162 struct swaybar *bar = data;
@@ -152,6 +165,11 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
152 if (!sway_assert(output, "button with no active output")) { 165 if (!sway_assert(output, "button with no active output")) {
153 return; 166 return;
154 } 167 }
168
169 if (check_bindings(bar, wl_button_to_x11_button(button), state)) {
170 return;
171 }
172
155 if (state != WL_POINTER_BUTTON_STATE_PRESSED) { 173 if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
156 return; 174 return;
157 } 175 }
@@ -180,6 +198,15 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
180 return; 198 return;
181 } 199 }
182 200
201 // If there is a button press binding, execute it, skip default behavior,
202 // and check button release bindings
203 if (check_bindings(bar, wl_axis_to_x11_button(axis, value),
204 WL_POINTER_BUTTON_STATE_PRESSED)) {
205 check_bindings(bar, wl_axis_to_x11_button(axis, value),
206 WL_POINTER_BUTTON_STATE_RELEASED);
207 return;
208 }
209
183 struct swaybar_hotspot *hotspot; 210 struct swaybar_hotspot *hotspot;
184 wl_list_for_each(hotspot, &output->hotspots, link) { 211 wl_list_for_each(hotspot, &output->hotspots, link) {
185 double x = pointer->x * output->scale; 212 double x = pointer->x * output->scale;
@@ -247,6 +274,10 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
247 } 274 }
248 275
249 ipc_send_workspace_command(bar, new->name); 276 ipc_send_workspace_command(bar, new->name);
277
278 // Check button release bindings
279 check_bindings(bar, wl_axis_to_x11_button(axis, value),
280 WL_POINTER_BUTTON_STATE_RELEASED);
250} 281}
251 282
252static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { 283static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {