diff options
-rw-r--r-- | include/swaybar/bar.h | 1 | ||||
-rw-r--r-- | swaybar/bar.c | 89 | ||||
-rw-r--r-- | swaybar/render.c | 175 |
3 files changed, 185 insertions, 80 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 74292519..503b961c 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -58,6 +58,7 @@ struct swaybar_output { | |||
58 | bool focused; | 58 | bool focused; |
59 | 59 | ||
60 | uint32_t width, height; | 60 | uint32_t width, height; |
61 | int32_t scale; | ||
61 | struct pool_buffer buffers[2]; | 62 | struct pool_buffer buffers[2]; |
62 | struct pool_buffer *current_buffer; | 63 | struct pool_buffer *current_buffer; |
63 | }; | 64 | }; |
diff --git a/swaybar/bar.c b/swaybar/bar.c index fb417095..ea0141cc 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -69,11 +69,19 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | |||
69 | break; | 69 | break; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | int max_scale = 1; | ||
73 | struct swaybar_output *_output; | ||
74 | wl_list_for_each(_output, &bar->outputs, link) { | ||
75 | if (_output->scale > max_scale) { | ||
76 | max_scale = _output->scale; | ||
77 | } | ||
78 | } | ||
79 | wl_surface_set_buffer_scale(pointer->cursor_surface, max_scale); | ||
72 | wl_surface_attach(pointer->cursor_surface, | 80 | wl_surface_attach(pointer->cursor_surface, |
73 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | 81 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); |
74 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | 82 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, |
75 | pointer->cursor_image->hotspot_x, | 83 | pointer->cursor_image->hotspot_x / max_scale, |
76 | pointer->cursor_image->hotspot_y); | 84 | pointer->cursor_image->hotspot_y / max_scale); |
77 | wl_surface_commit(pointer->cursor_surface); | 85 | wl_surface_commit(pointer->cursor_surface); |
78 | } | 86 | } |
79 | 87 | ||
@@ -103,10 +111,12 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
103 | } | 111 | } |
104 | struct swaybar_hotspot *hotspot; | 112 | struct swaybar_hotspot *hotspot; |
105 | wl_list_for_each(hotspot, &output->hotspots, link) { | 113 | wl_list_for_each(hotspot, &output->hotspots, link) { |
106 | if (pointer->x >= hotspot->x | 114 | double x = pointer->x * output->scale; |
107 | && pointer->y >= hotspot->y | 115 | double y = pointer->y * output->scale; |
108 | && pointer->x < hotspot->x + hotspot->width | 116 | if (x >= hotspot->x |
109 | && pointer->y < hotspot->y + hotspot->height) { | 117 | && y >= hotspot->y |
118 | && x < hotspot->x + hotspot->width | ||
119 | && y < hotspot->y + hotspot->height) { | ||
110 | hotspot->callback(output, pointer->x, pointer->y, | 120 | hotspot->callback(output, pointer->x, pointer->y, |
111 | button, hotspot->data); | 121 | button, hotspot->data); |
112 | } | 122 | } |
@@ -197,12 +207,43 @@ const struct wl_seat_listener seat_listener = { | |||
197 | .name = seat_handle_name, | 207 | .name = seat_handle_name, |
198 | }; | 208 | }; |
199 | 209 | ||
210 | static void output_geometry(void *data, struct wl_output *output, int32_t x, | ||
211 | int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, | ||
212 | const char *make, const char *model, int32_t transform) { | ||
213 | // Who cares | ||
214 | } | ||
215 | |||
216 | static void output_mode(void *data, struct wl_output *output, uint32_t flags, | ||
217 | int32_t width, int32_t height, int32_t refresh) { | ||
218 | // Who cares | ||
219 | } | ||
220 | |||
221 | static void output_done(void *data, struct wl_output *output) { | ||
222 | // Who cares | ||
223 | } | ||
224 | |||
225 | static void output_scale(void *data, struct wl_output *wl_output, | ||
226 | int32_t factor) { | ||
227 | struct swaybar_output *output = data; | ||
228 | output->scale = factor; | ||
229 | if (output->surface) { | ||
230 | render_frame(output->bar, output); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | struct wl_output_listener output_listener = { | ||
235 | .geometry = output_geometry, | ||
236 | .mode = output_mode, | ||
237 | .done = output_done, | ||
238 | .scale = output_scale, | ||
239 | }; | ||
240 | |||
200 | static void handle_global(void *data, struct wl_registry *registry, | 241 | static void handle_global(void *data, struct wl_registry *registry, |
201 | uint32_t name, const char *interface, uint32_t version) { | 242 | uint32_t name, const char *interface, uint32_t version) { |
202 | struct swaybar *bar = data; | 243 | struct swaybar *bar = data; |
203 | if (strcmp(interface, wl_compositor_interface.name) == 0) { | 244 | if (strcmp(interface, wl_compositor_interface.name) == 0) { |
204 | bar->compositor = wl_registry_bind(registry, name, | 245 | bar->compositor = wl_registry_bind(registry, name, |
205 | &wl_compositor_interface, 1); | 246 | &wl_compositor_interface, 3); |
206 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | 247 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { |
207 | bar->seat = wl_registry_bind(registry, name, | 248 | bar->seat = wl_registry_bind(registry, name, |
208 | &wl_seat_interface, 1); | 249 | &wl_seat_interface, 1); |
@@ -216,7 +257,9 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
216 | calloc(1, sizeof(struct swaybar_output)); | 257 | calloc(1, sizeof(struct swaybar_output)); |
217 | output->bar = bar; | 258 | output->bar = bar; |
218 | output->output = wl_registry_bind(registry, name, | 259 | output->output = wl_registry_bind(registry, name, |
219 | &wl_output_interface, 1); | 260 | &wl_output_interface, 3); |
261 | wl_output_add_listener(output->output, &output_listener, output); | ||
262 | output->scale = 1; | ||
220 | output->index = index++; | 263 | output->index = index++; |
221 | wl_list_init(&output->workspaces); | 264 | wl_list_init(&output->workspaces); |
222 | wl_list_init(&output->hotspots); | 265 | wl_list_init(&output->hotspots); |
@@ -256,24 +299,36 @@ void bar_setup(struct swaybar *bar, | |||
256 | bar->status = status_line_init(bar->config->status_command); | 299 | bar->status = status_line_init(bar->config->status_command); |
257 | } | 300 | } |
258 | 301 | ||
259 | assert(bar->display = wl_display_connect(NULL)); | 302 | bar->display = wl_display_connect(NULL); |
303 | assert(bar->display); | ||
260 | 304 | ||
261 | struct wl_registry *registry = wl_display_get_registry(bar->display); | 305 | struct wl_registry *registry = wl_display_get_registry(bar->display); |
262 | wl_registry_add_listener(registry, ®istry_listener, bar); | 306 | wl_registry_add_listener(registry, ®istry_listener, bar); |
263 | wl_display_roundtrip(bar->display); | 307 | wl_display_roundtrip(bar->display); |
264 | assert(bar->compositor && bar->layer_shell && bar->shm); | 308 | assert(bar->compositor && bar->layer_shell && bar->shm); |
309 | wl_display_roundtrip(bar->display); | ||
310 | |||
265 | struct swaybar_pointer *pointer = &bar->pointer; | 311 | struct swaybar_pointer *pointer = &bar->pointer; |
266 | 312 | ||
267 | assert(pointer->cursor_theme = wl_cursor_theme_load(NULL, 16, bar->shm)); | 313 | int max_scale = 1; |
314 | struct swaybar_output *output; | ||
315 | wl_list_for_each(output, &bar->outputs, link) { | ||
316 | if (output->scale > max_scale) { | ||
317 | max_scale = output->scale; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | pointer->cursor_theme = wl_cursor_theme_load( | ||
322 | NULL, 24 * max_scale, bar->shm); | ||
323 | assert(pointer->cursor_theme); | ||
268 | struct wl_cursor *cursor; | 324 | struct wl_cursor *cursor; |
269 | assert(cursor = wl_cursor_theme_get_cursor( | 325 | cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); |
270 | pointer->cursor_theme, "left_ptr")); | 326 | assert(cursor); |
271 | pointer->cursor_image = cursor->images[0]; | 327 | pointer->cursor_image = cursor->images[0]; |
272 | assert(pointer->cursor_surface = | 328 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); |
273 | wl_compositor_create_surface(bar->compositor)); | 329 | assert(pointer->cursor_surface); |
274 | 330 | ||
275 | // TODO: we might not necessarily be meant to do all of the outputs | 331 | // TODO: we might not necessarily be meant to do all of the outputs |
276 | struct swaybar_output *output; | ||
277 | wl_list_for_each(output, &bar->outputs, link) { | 332 | wl_list_for_each(output, &bar->outputs, link) { |
278 | struct config_output *coutput; | 333 | struct config_output *coutput; |
279 | wl_list_for_each(coutput, &bar->config->outputs, link) { | 334 | wl_list_for_each(coutput, &bar->config->outputs, link) { |
@@ -281,8 +336,8 @@ void bar_setup(struct swaybar *bar, | |||
281 | continue; | 336 | continue; |
282 | } | 337 | } |
283 | output->name = strdup(coutput->name); | 338 | output->name = strdup(coutput->name); |
284 | assert(output->surface = wl_compositor_create_surface( | 339 | output->surface = wl_compositor_create_surface(bar->compositor); |
285 | bar->compositor)); | 340 | assert(output->surface); |
286 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | 341 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( |
287 | bar->layer_shell, output->surface, output->output, | 342 | bar->layer_shell, output->surface, output->output, |
288 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); | 343 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); |
diff --git a/swaybar/render.c b/swaybar/render.c index 6f3b0788..be58301d 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -14,55 +14,72 @@ | |||
14 | #include "swaybar/status_line.h" | 14 | #include "swaybar/status_line.h" |
15 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 15 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
16 | 16 | ||
17 | static const int ws_horizontal_padding = 5; | 17 | static const int WS_HORIZONTAL_PADDING = 5; |
18 | static const double ws_vertical_padding = 1.5; | 18 | static const double WS_VERTICAL_PADDING = 1.5; |
19 | static const double border_width = 1; | 19 | static const double BORDER_WIDTH = 1; |
20 | 20 | ||
21 | static uint32_t render_status_line_error(cairo_t *cairo, | 21 | static uint32_t render_status_line_error(cairo_t *cairo, |
22 | struct swaybar_config *config, const char *error, | 22 | struct swaybar_output *output, struct swaybar_config *config, |
23 | double *x, uint32_t width, uint32_t height) { | 23 | const char *error, double *x, uint32_t surface_height) { |
24 | if (!error) { | 24 | if (!error) { |
25 | return 0; | 25 | return 0; |
26 | } | 26 | } |
27 | |||
28 | uint32_t height = surface_height * output->scale; | ||
29 | |||
27 | cairo_set_source_u32(cairo, 0xFF0000FF); | 30 | cairo_set_source_u32(cairo, 0xFF0000FF); |
28 | static const int margin = 3; | 31 | |
32 | int margin = 3 * output->scale; | ||
33 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | ||
34 | |||
29 | int text_width, text_height; | 35 | int text_width, text_height; |
30 | get_text_size(cairo, config->font, | 36 | get_text_size(cairo, config->font, |
31 | &text_width, &text_height, 1, false, "%s", error); | 37 | &text_width, &text_height, output->scale, false, "%s", error); |
38 | |||
32 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 39 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
33 | if (height < ideal_height) { | 40 | if (height < ideal_height) { |
34 | return ideal_height; | 41 | return ideal_height / output->scale; |
35 | } | 42 | } |
36 | *x -= text_width + margin; | 43 | *x -= text_width + margin; |
44 | |||
37 | double text_y = height / 2.0 - text_height / 2.0; | 45 | double text_y = height / 2.0 - text_height / 2.0; |
38 | cairo_move_to(cairo, *x, (int)floor(text_y)); | 46 | cairo_move_to(cairo, *x, (int)floor(text_y)); |
39 | pango_printf(cairo, config->font, 1, false, "%s", error); | 47 | pango_printf(cairo, config->font, output->scale, false, "%s", error); |
40 | *x -= margin; | 48 | *x -= margin; |
41 | return ideal_height; | 49 | return ideal_height / output->scale; |
42 | } | 50 | } |
43 | 51 | ||
44 | static uint32_t render_status_line_text(cairo_t *cairo, | 52 | static uint32_t render_status_line_text(cairo_t *cairo, |
45 | struct swaybar_config *config, const char *text, | 53 | struct swaybar_output *output, struct swaybar_config *config, |
46 | bool focused, double *x, uint32_t width, uint32_t height) { | 54 | const char *text, bool focused, double *x, uint32_t surface_height) { |
47 | if (!text) { | 55 | if (!text) { |
48 | return 0; | 56 | return 0; |
49 | } | 57 | } |
58 | |||
59 | uint32_t height = surface_height * output->scale; | ||
60 | |||
50 | cairo_set_source_u32(cairo, focused ? | 61 | cairo_set_source_u32(cairo, focused ? |
51 | config->colors.focused_statusline : config->colors.statusline); | 62 | config->colors.focused_statusline : config->colors.statusline); |
52 | static const int margin = 3; | 63 | |
53 | int text_width, text_height; | 64 | int text_width, text_height; |
54 | get_text_size(cairo, config->font, &text_width, &text_height, | 65 | get_text_size(cairo, config->font, &text_width, &text_height, |
55 | 1, config->pango_markup, "%s", text); | 66 | output->scale, config->pango_markup, "%s", text); |
67 | |||
68 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | ||
69 | int margin = 3 * output->scale; | ||
70 | |||
56 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 71 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
57 | if (height < ideal_height) { | 72 | if (height < ideal_height) { |
58 | return ideal_height; | 73 | return ideal_height / output->scale; |
59 | } | 74 | } |
75 | |||
60 | *x -= text_width + margin; | 76 | *x -= text_width + margin; |
61 | double text_y = height / 2.0 - text_height / 2.0; | 77 | double text_y = height / 2.0 - text_height / 2.0; |
62 | cairo_move_to(cairo, *x, (int)floor(text_y)); | 78 | cairo_move_to(cairo, *x, (int)floor(text_y)); |
63 | pango_printf(cairo, config->font, 1, config->pango_markup, "%s", text); | 79 | pango_printf(cairo, config->font, output->scale, |
80 | config->pango_markup, "%s", text); | ||
64 | *x -= margin; | 81 | *x -= margin; |
65 | return ideal_height; | 82 | return ideal_height / output->scale; |
66 | } | 83 | } |
67 | 84 | ||
68 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | 85 | static void render_sharp_line(cairo_t *cairo, uint32_t color, |
@@ -99,23 +116,29 @@ static void block_hotspot_callback(struct swaybar_output *output, | |||
99 | static uint32_t render_status_block(cairo_t *cairo, | 116 | static uint32_t render_status_block(cairo_t *cairo, |
100 | struct swaybar_config *config, struct swaybar_output *output, | 117 | struct swaybar_config *config, struct swaybar_output *output, |
101 | struct i3bar_block *block, double *x, | 118 | struct i3bar_block *block, double *x, |
102 | uint32_t height, bool focused, bool edge) { | 119 | uint32_t surface_height, bool focused, bool edge) { |
103 | static const int margin = 3; | ||
104 | if (!block->full_text || !*block->full_text) { | 120 | if (!block->full_text || !*block->full_text) { |
105 | return 0; | 121 | return 0; |
106 | } | 122 | } |
107 | 123 | ||
124 | uint32_t height = surface_height * output->scale; | ||
125 | |||
108 | int text_width, text_height; | 126 | int text_width, text_height; |
109 | get_text_size(cairo, config->font, &text_width, &text_height, | 127 | get_text_size(cairo, config->font, &text_width, &text_height, |
110 | 1, block->markup, "%s", block->full_text); | 128 | output->scale, block->markup, "%s", block->full_text); |
129 | |||
130 | int margin = 3 * output->scale; | ||
131 | int ws_vertical_padding = WS_VERTICAL_PADDING * 2; | ||
132 | |||
111 | int width = text_width; | 133 | int width = text_width; |
112 | if (width < block->min_width) { | 134 | if (width < block->min_width) { |
113 | width = block->min_width; | 135 | width = block->min_width; |
114 | } | 136 | } |
137 | |||
115 | double block_width = width; | 138 | double block_width = width; |
116 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 139 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
117 | if (height < ideal_height) { | 140 | if (height < ideal_height) { |
118 | return ideal_height; | 141 | return ideal_height / output->scale; |
119 | } | 142 | } |
120 | 143 | ||
121 | *x -= width; | 144 | *x -= width; |
@@ -133,10 +156,10 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
133 | if (config->sep_symbol) { | 156 | if (config->sep_symbol) { |
134 | int _height; | 157 | int _height; |
135 | get_text_size(cairo, config->font, &sep_width, &_height, | 158 | get_text_size(cairo, config->font, &sep_width, &_height, |
136 | 1, false, "%s", config->sep_symbol); | 159 | output->scale, false, "%s", config->sep_symbol); |
137 | uint32_t _ideal_height = _height + ws_vertical_padding * 2; | 160 | uint32_t _ideal_height = _height + ws_vertical_padding * 2; |
138 | if (height < _ideal_height) { | 161 | if ((uint32_t)_height < _ideal_height / output->scale) { |
139 | return _height; | 162 | return _height / output->scale; |
140 | } | 163 | } |
141 | if (sep_width > block->separator_block_width) { | 164 | if (sep_width > block->separator_block_width) { |
142 | block->separator_block_width = sep_width + margin * 2; | 165 | block->separator_block_width = sep_width + margin * 2; |
@@ -160,22 +183,26 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
160 | double pos = *x; | 183 | double pos = *x; |
161 | if (block->background) { | 184 | if (block->background) { |
162 | cairo_set_source_u32(cairo, block->background); | 185 | cairo_set_source_u32(cairo, block->background); |
163 | cairo_rectangle(cairo, pos - 0.5, 1, block_width, height); | 186 | cairo_rectangle(cairo, pos - 0.5 * output->scale, |
187 | output->scale, block_width, height); | ||
164 | cairo_fill(cairo); | 188 | cairo_fill(cairo); |
165 | } | 189 | } |
166 | 190 | ||
167 | if (block->border && block->border_top > 0) { | 191 | if (block->border && block->border_top > 0) { |
168 | render_sharp_line(cairo, block->border, | 192 | render_sharp_line(cairo, block->border, |
169 | pos - 0.5, 1, block_width, block->border_top); | 193 | pos - 0.5 * output->scale, output->scale, |
194 | block_width, block->border_top); | ||
170 | } | 195 | } |
171 | if (block->border && block->border_bottom > 0) { | 196 | if (block->border && block->border_bottom > 0) { |
172 | render_sharp_line(cairo, block->border, | 197 | render_sharp_line(cairo, block->border, |
173 | pos - 0.5, height - 1 - block->border_bottom, | 198 | pos - 0.5 * output->scale, |
199 | height - output->scale - block->border_bottom, | ||
174 | block_width, block->border_bottom); | 200 | block_width, block->border_bottom); |
175 | } | 201 | } |
176 | if (block->border != 0 && block->border_left > 0) { | 202 | if (block->border != 0 && block->border_left > 0) { |
177 | render_sharp_line(cairo, block->border, | 203 | render_sharp_line(cairo, block->border, |
178 | pos - 0.5, 1, block->border_left, height); | 204 | pos - 0.5 * output->scale, output->scale, |
205 | block->border_left, height); | ||
179 | pos += block->border_left + margin; | 206 | pos += block->border_left + margin; |
180 | } | 207 | } |
181 | 208 | ||
@@ -190,13 +217,15 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
190 | cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); | 217 | cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); |
191 | uint32_t color = block->color ? *block->color : config->colors.statusline; | 218 | uint32_t color = block->color ? *block->color : config->colors.statusline; |
192 | cairo_set_source_u32(cairo, color); | 219 | cairo_set_source_u32(cairo, color); |
193 | pango_printf(cairo, config->font, 1, block->markup, "%s", block->full_text); | 220 | pango_printf(cairo, config->font, output->scale, |
221 | block->markup, "%s", block->full_text); | ||
194 | pos += width; | 222 | pos += width; |
195 | 223 | ||
196 | if (block->border && block->border_right > 0) { | 224 | if (block->border && block->border_right > 0) { |
197 | pos += margin; | 225 | pos += margin; |
198 | render_sharp_line(cairo, block->border, | 226 | render_sharp_line(cairo, block->border, |
199 | pos - 0.5, 1, block->border_right, height); | 227 | pos - 0.5 * output->scale, output->scale, |
228 | block->border_right, height); | ||
200 | pos += block->border_right; | 229 | pos += block->border_right; |
201 | } | 230 | } |
202 | 231 | ||
@@ -209,7 +238,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
209 | if (config->sep_symbol) { | 238 | if (config->sep_symbol) { |
210 | offset = pos + (block->separator_block_width - sep_width) / 2; | 239 | offset = pos + (block->separator_block_width - sep_width) / 2; |
211 | cairo_move_to(cairo, offset, margin); | 240 | cairo_move_to(cairo, offset, margin); |
212 | pango_printf(cairo, config->font, 1, false, | 241 | pango_printf(cairo, config->font, output->scale, false, |
213 | "%s", config->sep_symbol); | 242 | "%s", config->sep_symbol); |
214 | } else { | 243 | } else { |
215 | cairo_set_line_width(cairo, 1); | 244 | cairo_set_line_width(cairo, 1); |
@@ -220,19 +249,19 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
220 | cairo_stroke(cairo); | 249 | cairo_stroke(cairo); |
221 | } | 250 | } |
222 | } | 251 | } |
223 | return ideal_height; | 252 | return ideal_height / output->scale; |
224 | } | 253 | } |
225 | 254 | ||
226 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 255 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
227 | struct swaybar_config *config, struct swaybar_output *output, | 256 | struct swaybar_config *config, struct swaybar_output *output, |
228 | struct status_line *status, bool focused, | 257 | struct status_line *status, bool focused, |
229 | double *x, uint32_t width, uint32_t height) { | 258 | double *x, uint32_t surface_height) { |
230 | uint32_t max_height = 0; | 259 | uint32_t max_height = 0; |
231 | bool edge = true; | 260 | bool edge = true; |
232 | struct i3bar_block *block; | 261 | struct i3bar_block *block; |
233 | wl_list_for_each(block, &status->blocks, link) { | 262 | wl_list_for_each(block, &status->blocks, link) { |
234 | uint32_t h = render_status_block(cairo, config, output, | 263 | uint32_t h = render_status_block(cairo, config, output, |
235 | block, x, height, focused, edge); | 264 | block, x, surface_height, focused, edge); |
236 | max_height = h > max_height ? h : max_height; | 265 | max_height = h > max_height ? h : max_height; |
237 | edge = false; | 266 | edge = false; |
238 | } | 267 | } |
@@ -242,17 +271,17 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo, | |||
242 | static uint32_t render_status_line(cairo_t *cairo, | 271 | static uint32_t render_status_line(cairo_t *cairo, |
243 | struct swaybar_config *config, struct swaybar_output *output, | 272 | struct swaybar_config *config, struct swaybar_output *output, |
244 | struct status_line *status, bool focused, | 273 | struct status_line *status, bool focused, |
245 | double *x, uint32_t width, uint32_t height) { | 274 | double *x, uint32_t surface_height) { |
246 | switch (status->protocol) { | 275 | switch (status->protocol) { |
247 | case PROTOCOL_ERROR: | 276 | case PROTOCOL_ERROR: |
248 | return render_status_line_error(cairo, | 277 | return render_status_line_error(cairo, output, config, |
249 | config, status->text, x, width, height); | 278 | status->text, x, surface_height); |
250 | case PROTOCOL_TEXT: | 279 | case PROTOCOL_TEXT: |
251 | return render_status_line_text(cairo, | 280 | return render_status_line_text(cairo, output, config, |
252 | config, status->text, focused, x, width, height); | 281 | status->text, focused, x, surface_height); |
253 | case PROTOCOL_I3BAR: | 282 | case PROTOCOL_I3BAR: |
254 | return render_status_line_i3bar(cairo, config, output, status, | 283 | return render_status_line_i3bar(cairo, config, output, |
255 | focused, x, width, height); | 284 | status, focused, x, surface_height); |
256 | case PROTOCOL_UNDEF: | 285 | case PROTOCOL_UNDEF: |
257 | return 0; | 286 | return 0; |
258 | } | 287 | } |
@@ -260,15 +289,23 @@ static uint32_t render_status_line(cairo_t *cairo, | |||
260 | } | 289 | } |
261 | 290 | ||
262 | static uint32_t render_binding_mode_indicator(cairo_t *cairo, | 291 | static uint32_t render_binding_mode_indicator(cairo_t *cairo, |
263 | struct swaybar_config *config, const char *mode, double x, | 292 | struct swaybar_output *output, struct swaybar_config *config, |
264 | uint32_t height) { | 293 | const char *mode, double x, uint32_t surface_height) { |
294 | |||
295 | uint32_t height = surface_height * output->scale; | ||
296 | |||
265 | int text_width, text_height; | 297 | int text_width, text_height; |
266 | get_text_size(cairo, config->font, &text_width, &text_height, | 298 | get_text_size(cairo, config->font, &text_width, &text_height, |
267 | 1, true, "%s", mode); | 299 | output->scale, true, "%s", mode); |
300 | |||
301 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | ||
302 | int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; | ||
303 | int border_width = BORDER_WIDTH * output->scale; | ||
304 | |||
268 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 | 305 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 |
269 | + border_width * 2; | 306 | + border_width * 2; |
270 | if (height < ideal_height) { | 307 | if (height < ideal_height) { |
271 | return ideal_height; | 308 | return ideal_height / output->scale; |
272 | } | 309 | } |
273 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; | 310 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
274 | 311 | ||
@@ -289,8 +326,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
289 | double text_y = height / 2.0 - text_height / 2.0; | 326 | double text_y = height / 2.0 - text_height / 2.0; |
290 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); | 327 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); |
291 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); | 328 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); |
292 | pango_printf(cairo, config->font, 1, true, "%s", mode); | 329 | pango_printf(cairo, config->font, output->scale, true, "%s", mode); |
293 | return ideal_height; | 330 | return ideal_height / output->scale; |
294 | } | 331 | } |
295 | 332 | ||
296 | static const char *strip_workspace_number(const char *ws_name) { | 333 | static const char *strip_workspace_number(const char *ws_name) { |
@@ -313,7 +350,7 @@ static void workspace_hotspot_callback(struct swaybar_output *output, | |||
313 | 350 | ||
314 | static uint32_t render_workspace_button(cairo_t *cairo, | 351 | static uint32_t render_workspace_button(cairo_t *cairo, |
315 | struct swaybar_output *output, struct swaybar_config *config, | 352 | struct swaybar_output *output, struct swaybar_config *config, |
316 | struct swaybar_workspace *ws, double *x, uint32_t height) { | 353 | struct swaybar_workspace *ws, double *x, uint32_t surface_height) { |
317 | const char *name = ws->name; | 354 | const char *name = ws->name; |
318 | if (config->strip_workspace_numbers) { | 355 | if (config->strip_workspace_numbers) { |
319 | name = strip_workspace_number(ws->name); | 356 | name = strip_workspace_number(ws->name); |
@@ -330,14 +367,22 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
330 | box_colors = config->colors.inactive_workspace; | 367 | box_colors = config->colors.inactive_workspace; |
331 | } | 368 | } |
332 | 369 | ||
370 | uint32_t height = surface_height * output->scale; | ||
371 | |||
333 | int text_width, text_height; | 372 | int text_width, text_height; |
334 | get_text_size(cairo, config->font, &text_width, &text_height, | 373 | get_text_size(cairo, config->font, &text_width, &text_height, |
335 | 1, true, "%s", name); | 374 | output->scale, true, "%s", name); |
375 | |||
376 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | ||
377 | int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; | ||
378 | int border_width = BORDER_WIDTH * output->scale; | ||
379 | |||
336 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height | 380 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height |
337 | + border_width * 2; | 381 | + border_width * 2; |
338 | if (height < ideal_height) { | 382 | if (height < ideal_height) { |
339 | return ideal_height; | 383 | return ideal_height / output->scale; |
340 | } | 384 | } |
385 | |||
341 | uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2; | 386 | uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2; |
342 | 387 | ||
343 | cairo_set_source_u32(cairo, box_colors.background); | 388 | cairo_set_source_u32(cairo, box_colors.background); |
@@ -357,7 +402,7 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
357 | double text_y = height / 2.0 - text_height / 2.0; | 402 | double text_y = height / 2.0 - text_height / 2.0; |
358 | cairo_set_source_u32(cairo, box_colors.text); | 403 | cairo_set_source_u32(cairo, box_colors.text); |
359 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); | 404 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); |
360 | pango_printf(cairo, config->font, 1, true, "%s", name); | 405 | pango_printf(cairo, config->font, output->scale, true, "%s", name); |
361 | 406 | ||
362 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); | 407 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); |
363 | hotspot->x = *x; | 408 | hotspot->x = *x; |
@@ -370,7 +415,7 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
370 | wl_list_insert(&output->hotspots, &hotspot->link); | 415 | wl_list_insert(&output->hotspots, &hotspot->link); |
371 | 416 | ||
372 | *x += width; | 417 | *x += width; |
373 | return height; | 418 | return height / output->scale; |
374 | } | 419 | } |
375 | 420 | ||
376 | static uint32_t render_to_cairo(cairo_t *cairo, | 421 | static uint32_t render_to_cairo(cairo_t *cairo, |
@@ -394,7 +439,13 @@ static uint32_t render_to_cairo(cairo_t *cairo, | |||
394 | * height is too tall, the render function should adapt its drawing to | 439 | * height is too tall, the render function should adapt its drawing to |
395 | * utilize the available space. | 440 | * utilize the available space. |
396 | */ | 441 | */ |
397 | double x = 0; | 442 | double x = output->width * output->scale; |
443 | if (bar->status) { | ||
444 | uint32_t h = render_status_line(cairo, config, output, | ||
445 | bar->status, output->focused, &x, output->height); | ||
446 | max_height = h > max_height ? h : max_height; | ||
447 | } | ||
448 | x = 0; | ||
398 | if (config->workspace_buttons) { | 449 | if (config->workspace_buttons) { |
399 | struct swaybar_workspace *ws; | 450 | struct swaybar_workspace *ws; |
400 | wl_list_for_each_reverse(ws, &output->workspaces, link) { | 451 | wl_list_for_each_reverse(ws, &output->workspaces, link) { |
@@ -404,14 +455,8 @@ static uint32_t render_to_cairo(cairo_t *cairo, | |||
404 | } | 455 | } |
405 | } | 456 | } |
406 | if (config->binding_mode_indicator && config->mode) { | 457 | if (config->binding_mode_indicator && config->mode) { |
407 | uint32_t h = render_binding_mode_indicator( | 458 | uint32_t h = render_binding_mode_indicator(cairo, |
408 | cairo, config, config->mode, x, output->height); | 459 | output, config, config->mode, x, output->height); |
409 | max_height = h > max_height ? h : max_height; | ||
410 | } | ||
411 | x = output->width; | ||
412 | if (bar->status) { | ||
413 | uint32_t h = render_status_line(cairo, config, output, bar->status, | ||
414 | output->focused, &x, output->width, output->height); | ||
415 | max_height = h > max_height ? h : max_height; | 460 | max_height = h > max_height ? h : max_height; |
416 | } | 461 | } |
417 | 462 | ||
@@ -451,7 +496,9 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) { | |||
451 | } else { | 496 | } else { |
452 | // Replay recording into shm and send it off | 497 | // Replay recording into shm and send it off |
453 | output->current_buffer = get_next_buffer(bar->shm, | 498 | output->current_buffer = get_next_buffer(bar->shm, |
454 | output->buffers, output->width, output->height); | 499 | output->buffers, |
500 | output->width * output->scale, | ||
501 | output->height * output->scale); | ||
455 | cairo_t *shm = output->current_buffer->cairo; | 502 | cairo_t *shm = output->current_buffer->cairo; |
456 | 503 | ||
457 | cairo_save(shm); | 504 | cairo_save(shm); |
@@ -462,9 +509,11 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) { | |||
462 | cairo_set_source_surface(shm, recorder, 0.0, 0.0); | 509 | cairo_set_source_surface(shm, recorder, 0.0, 0.0); |
463 | cairo_paint(shm); | 510 | cairo_paint(shm); |
464 | 511 | ||
512 | wl_surface_set_buffer_scale(output->surface, output->scale); | ||
465 | wl_surface_attach(output->surface, | 513 | wl_surface_attach(output->surface, |
466 | output->current_buffer->buffer, 0, 0); | 514 | output->current_buffer->buffer, 0, 0); |
467 | wl_surface_damage(output->surface, 0, 0, output->width, output->height); | 515 | wl_surface_damage(output->surface, 0, 0, |
516 | output->width, output->height); | ||
468 | wl_surface_commit(output->surface); | 517 | wl_surface_commit(output->surface); |
469 | wl_display_roundtrip(bar->display); | 518 | wl_display_roundtrip(bar->display); |
470 | } | 519 | } |