summaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar David Eklov <david.eklov@gmail.com>2016-07-11 00:11:38 -0500
committerLibravatar David Eklov <david.eklov@gmail.com>2016-07-14 17:18:01 -0500
commita0c8799c8008da4eccde3ae4bd5865b5c4422058 (patch)
treee6830dc3459a1570b900c21c6208b93efb2027d8 /swaybar/bar.c
parentUse int instead of wl_fixed_t for mouse coordinates (diff)
downloadsway-a0c8799c8008da4eccde3ae4bd5865b5c4422058.tar.gz
sway-a0c8799c8008da4eccde3ae4bd5865b5c4422058.tar.zst
sway-a0c8799c8008da4eccde3ae4bd5865b5c4422058.zip
Compute what workspace button is clicked
This commit does not do anything with this information other than logging it.
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index ed18b5e6..4f8063ac 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -58,8 +58,35 @@ struct output *new_output(const char *name) {
58 return output; 58 return output;
59} 59}
60 60
61static void mouse_button_notify(struct window *window, wl_fixed_t x, wl_fixed_t y, uint32_t button) { 61static void mouse_button_notify(struct window *window, int x, int y, uint32_t button) {
62 sway_log(L_DEBUG, "Mouse button %d clicked at %d %d\n", button, x, y); 62 sway_log(L_DEBUG, "Mouse button %d clicked at %d %d\n", button, x, y);
63
64 struct output *clicked_output = NULL;
65 for (int i = 0; i < swaybar.outputs->length; i++) {
66 struct output *output = swaybar.outputs->items[i];
67 if (window == output->window) {
68 clicked_output = output;
69 break;
70 }
71 }
72
73 if (!sway_assert(clicked_output != NULL, "Got pointer event for non-existing output")) {
74 return;
75 }
76
77 double button_x = 0.5;
78 for (int i = 0; i < clicked_output->workspaces->length; i++) {
79 struct workspace *workspace = clicked_output->workspaces->items[i];
80 int button_width, button_height;
81
82 workspace_button_size(window, workspace->name, &button_width, &button_height);
83
84 button_x += button_width;
85 if (x <= button_x) {
86 ipc_send_workspace_command(workspace->name);
87 break;
88 }
89 }
63} 90}
64 91
65void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { 92void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {