aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 22:42:59 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 22:44:08 -0400
commit2a5108a2786383cf5c3bcefd653605c916193837 (patch)
tree10b69216bee8adb69fd81ebbeb05c8a7c36c51a3 /swaybar/render.c
parentImplement scroll wheel workspace switching (diff)
downloadsway-2a5108a2786383cf5c3bcefd653605c916193837.tar.gz
sway-2a5108a2786383cf5c3bcefd653605c916193837.tar.zst
sway-2a5108a2786383cf5c3bcefd653605c916193837.zip
Implement workspace switch on click
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c39
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
113static 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
111static uint32_t render_workspace_button(cairo_t *cairo, 118static 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
163static uint32_t render_to_cairo(cairo_t *cairo, 180static 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
206void render_frame(struct swaybar *bar, 223void 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);