diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-07-14 18:57:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-14 18:57:37 -0400 |
commit | 6abbe04e7590f3bfba13351eb87ada70ac3d506e (patch) | |
tree | f7c64d6e9d082bd080960c42e21e54edf01839de /swaybar/bar.c | |
parent | 1e95191900d1f16b4d195f2d05f1eb7cb1f62ad5 (diff) | |
parent | 8a232c8cfd60c1469ceaaa911f31a6d75e8ad851 (diff) |
Merge pull request #743 from deklov/panel-as-shell-03
Set panels/backgrounds' geometries correctly and don't render them ex…
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 6d858f92..4f8063ac 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -58,6 +58,37 @@ struct output *new_output(const char *name) { return output; } +static void mouse_button_notify(struct window *window, int x, int y, uint32_t button) { + sway_log(L_DEBUG, "Mouse button %d clicked at %d %d\n", button, x, y); + + struct output *clicked_output = NULL; + for (int i = 0; i < swaybar.outputs->length; i++) { + struct output *output = swaybar.outputs->items[i]; + if (window == output->window) { + clicked_output = output; + break; + } + } + + if (!sway_assert(clicked_output != NULL, "Got pointer event for non-existing output")) { + return; + } + + double button_x = 0.5; + for (int i = 0; i < clicked_output->workspaces->length; i++) { + struct workspace *workspace = clicked_output->workspaces->items[i]; + int button_width, button_height; + + workspace_button_size(window, workspace->name, &button_width, &button_height); + + button_x += button_width; + if (x <= button_x) { + ipc_send_workspace_command(workspace->name); + break; + } + } +} + void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { /* initialize bar with default values */ bar_init(bar); @@ -92,6 +123,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { /* set font */ bar_output->window->font = bar->config->font; + /* set font */ + bar_output->window->pointer_input.notify = mouse_button_notify; + /* set window height */ set_window_height(bar_output->window, bar->config->height); } |