diff options
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 31 |
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, bar->pointer.y = wl_fixed_to_int(surface_y); } +static bool check_bindings(struct swaybar *bar, uint32_t x11_button, + uint32_t state) { + bool released = state == WL_POINTER_BUTTON_STATE_RELEASED; + for (int i = 0; i < bar->config->bindings->length; i++) { + struct swaybar_binding *binding = bar->config->bindings->items[i]; + if (binding->button == x11_button && binding->release == released) { + ipc_execute_binding(bar, binding); + return true; + } + } + return false; +} + static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { struct swaybar *bar = data; @@ -152,6 +165,11 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (!sway_assert(output, "button with no active output")) { return; } + + if (check_bindings(bar, wl_button_to_x11_button(button), state)) { + return; + } + if (state != WL_POINTER_BUTTON_STATE_PRESSED) { return; } @@ -180,6 +198,15 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, return; } + // If there is a button press binding, execute it, skip default behavior, + // and check button release bindings + if (check_bindings(bar, wl_axis_to_x11_button(axis, value), + WL_POINTER_BUTTON_STATE_PRESSED)) { + check_bindings(bar, wl_axis_to_x11_button(axis, value), + WL_POINTER_BUTTON_STATE_RELEASED); + return; + } + struct swaybar_hotspot *hotspot; wl_list_for_each(hotspot, &output->hotspots, link) { double x = pointer->x * output->scale; @@ -247,6 +274,10 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, } ipc_send_workspace_command(bar, new->name); + + // Check button release bindings + check_bindings(bar, wl_axis_to_x11_button(axis, value), + WL_POINTER_BUTTON_STATE_RELEASED); } static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { |