aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-10-08 11:40:13 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-10-09 08:12:46 -0400
commit1c969e86f50065985ddf35b7fef62c14aa7688a5 (patch)
tree1d44b026ffb8cd67595b695ac92275ba320ee4d9 /swaybar/bar.c
parentMerge pull request #2804 from Emantor/swaynag-double-free (diff)
downloadsway-1c969e86f50065985ddf35b7fef62c14aa7688a5.tar.gz
sway-1c969e86f50065985ddf35b7fef62c14aa7688a5.tar.zst
sway-1c969e86f50065985ddf35b7fef62c14aa7688a5.zip
Implement bar bindsym
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 3990f1ca..3eeec5d4 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -144,6 +144,22 @@ 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 wlr_log(WLR_DEBUG, "Checking [%u, %d] against [%u, %d, %s]",
153 x11_button, released,
154 binding->button, binding->release, binding->command);
155 if (binding->button == x11_button && binding->release == released) {
156 ipc_execute_binding(bar, binding);
157 return true;
158 }
159 }
160 return false;
161}
162
147static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, 163static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
148 uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { 164 uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
149 struct swaybar *bar = data; 165 struct swaybar *bar = data;
@@ -152,6 +168,11 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
152 if (!sway_assert(output, "button with no active output")) { 168 if (!sway_assert(output, "button with no active output")) {
153 return; 169 return;
154 } 170 }
171
172 if (check_bindings(bar, wl_button_to_x11_button(button), state)) {
173 return;
174 }
175
155 if (state != WL_POINTER_BUTTON_STATE_PRESSED) { 176 if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
156 return; 177 return;
157 } 178 }
@@ -180,6 +201,11 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
180 return; 201 return;
181 } 202 }
182 203
204 if (check_bindings(bar, wl_axis_to_x11_button(axis, value),
205 WL_POINTER_BUTTON_STATE_PRESSED)) {
206 return;
207 }
208
183 struct swaybar_hotspot *hotspot; 209 struct swaybar_hotspot *hotspot;
184 wl_list_for_each(hotspot, &output->hotspots, link) { 210 wl_list_for_each(hotspot, &output->hotspots, link) {
185 double x = pointer->x * output->scale; 211 double x = pointer->x * output->scale;