diff options
Diffstat (limited to 'swaybar/render.c')
-rw-r--r-- | swaybar/render.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/swaybar/render.c b/swaybar/render.c index 3d9ef66b..c2358724 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <limits.h> | 2 | #include <limits.h> |
2 | #include <stdlib.h> | 3 | #include <stdlib.h> |
3 | #include <stdint.h> | 4 | #include <stdint.h> |
@@ -8,6 +9,7 @@ | |||
8 | #include "pool-buffer.h" | 9 | #include "pool-buffer.h" |
9 | #include "swaybar/bar.h" | 10 | #include "swaybar/bar.h" |
10 | #include "swaybar/config.h" | 11 | #include "swaybar/config.h" |
12 | #include "swaybar/ipc.h" | ||
11 | #include "swaybar/render.h" | 13 | #include "swaybar/render.h" |
12 | #include "swaybar/status_line.h" | 14 | #include "swaybar/status_line.h" |
13 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 15 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
@@ -108,9 +110,14 @@ static const char *strip_workspace_number(const char *ws_name) { | |||
108 | return ws_name; | 110 | return ws_name; |
109 | } | 111 | } |
110 | 112 | ||
113 | static void workspace_hotspot_callback(struct swaybar_output *output, | ||
114 | int x, int y, uint32_t button, void *data) { | ||
115 | ipc_send_workspace_command(output->bar, (const char *)data); | ||
116 | } | ||
117 | |||
111 | static uint32_t render_workspace_button(cairo_t *cairo, | 118 | static uint32_t render_workspace_button(cairo_t *cairo, |
112 | struct swaybar_config *config, struct swaybar_workspace *ws, | 119 | struct swaybar_output *output, struct swaybar_config *config, |
113 | double *x, uint32_t height) { | 120 | struct swaybar_workspace *ws, double *x, uint32_t height) { |
114 | const char *name = ws->name; | 121 | const char *name = ws->name; |
115 | if (config->strip_workspace_numbers) { | 122 | if (config->strip_workspace_numbers) { |
116 | name = strip_workspace_number(ws->name); | 123 | name = strip_workspace_number(ws->name); |
@@ -156,8 +163,18 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
156 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); | 163 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); |
157 | pango_printf(cairo, config->font, 1, true, "%s", name); | 164 | pango_printf(cairo, config->font, 1, true, "%s", name); |
158 | 165 | ||
166 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); | ||
167 | hotspot->x = *x; | ||
168 | hotspot->y = 0; | ||
169 | hotspot->height = height; | ||
170 | hotspot->width = width; | ||
171 | hotspot->callback = workspace_hotspot_callback; | ||
172 | hotspot->destroy = free; | ||
173 | hotspot->data = strdup(name); | ||
174 | wl_list_insert(&output->hotspots, &hotspot->link); | ||
175 | |||
159 | *x += width; | 176 | *x += width; |
160 | return ideal_height; | 177 | return height; |
161 | } | 178 | } |
162 | 179 | ||
163 | static uint32_t render_to_cairo(cairo_t *cairo, | 180 | static uint32_t render_to_cairo(cairo_t *cairo, |
@@ -184,8 +201,8 @@ static uint32_t render_to_cairo(cairo_t *cairo, | |||
184 | if (config->workspace_buttons) { | 201 | if (config->workspace_buttons) { |
185 | struct swaybar_workspace *ws; | 202 | struct swaybar_workspace *ws; |
186 | wl_list_for_each_reverse(ws, &output->workspaces, link) { | 203 | wl_list_for_each_reverse(ws, &output->workspaces, link) { |
187 | uint32_t h = render_workspace_button( | 204 | uint32_t h = render_workspace_button(cairo, |
188 | cairo, config, ws, &x, output->height); | 205 | output, config, ws, &x, output->height); |
189 | max_height = h > max_height ? h : max_height; | 206 | max_height = h > max_height ? h : max_height; |
190 | } | 207 | } |
191 | } | 208 | } |
@@ -203,8 +220,16 @@ static uint32_t render_to_cairo(cairo_t *cairo, | |||
203 | return max_height > output->height ? max_height : output->height; | 220 | return max_height > output->height ? max_height : output->height; |
204 | } | 221 | } |
205 | 222 | ||
206 | void render_frame(struct swaybar *bar, | 223 | void render_frame(struct swaybar *bar, struct swaybar_output *output) { |
207 | struct swaybar_output *output) { | 224 | struct swaybar_hotspot *hotspot, *tmp; |
225 | wl_list_for_each_safe(hotspot, tmp, &output->hotspots, link) { | ||
226 | if (hotspot->destroy) { | ||
227 | hotspot->destroy(hotspot->data); | ||
228 | } | ||
229 | wl_list_remove(&hotspot->link); | ||
230 | free(hotspot); | ||
231 | } | ||
232 | |||
208 | cairo_surface_t *recorder = cairo_recording_surface_create( | 233 | cairo_surface_t *recorder = cairo_recording_surface_create( |
209 | CAIRO_CONTENT_COLOR_ALPHA, NULL); | 234 | CAIRO_CONTENT_COLOR_ALPHA, NULL); |
210 | cairo_t *cairo = cairo_create(recorder); | 235 | cairo_t *cairo = cairo_create(recorder); |