diff options
author | 2016-07-14 18:57:37 -0400 | |
---|---|---|
committer | 2016-07-14 18:57:37 -0400 | |
commit | 6abbe04e7590f3bfba13351eb87ada70ac3d506e (patch) | |
tree | f7c64d6e9d082bd080960c42e21e54edf01839de /swaybar/bar.c | |
parent | Merge pull request #726 from Hummer12007/hwc (diff) | |
parent | Send command to sway to change workspace when workspace button is clicked (diff) | |
download | sway-6abbe04e7590f3bfba13351eb87ada70ac3d506e.tar.gz sway-6abbe04e7590f3bfba13351eb87ada70ac3d506e.tar.zst sway-6abbe04e7590f3bfba13351eb87ada70ac3d506e.zip |
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) { | |||
58 | return output; | 58 | return output; |
59 | } | 59 | } |
60 | 60 | ||
61 | static 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); | ||
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 | } | ||
90 | } | ||
91 | |||
61 | void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | 92 | void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { |
62 | /* initialize bar with default values */ | 93 | /* initialize bar with default values */ |
63 | bar_init(bar); | 94 | bar_init(bar); |
@@ -92,6 +123,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | |||
92 | /* set font */ | 123 | /* set font */ |
93 | bar_output->window->font = bar->config->font; | 124 | bar_output->window->font = bar->config->font; |
94 | 125 | ||
126 | /* set font */ | ||
127 | bar_output->window->pointer_input.notify = mouse_button_notify; | ||
128 | |||
95 | /* set window height */ | 129 | /* set window height */ |
96 | set_window_height(bar_output->window, bar->config->height); | 130 | set_window_height(bar_output->window, bar->config->height); |
97 | } | 131 | } |