diff options
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 30 | ||||
-rw-r--r-- | swaybar/config.c | 2 | ||||
-rw-r--r-- | swaybar/ipc.c | 11 | ||||
-rw-r--r-- | swaybar/render.c | 37 | ||||
-rw-r--r-- | swaybar/tray/tray.c | 8 |
5 files changed, 64 insertions, 24 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 7aed4dca..d36367fc 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -59,6 +59,7 @@ static void swaybar_output_free(struct swaybar_output *output) { | |||
59 | free_workspaces(&output->workspaces); | 59 | free_workspaces(&output->workspaces); |
60 | wl_list_remove(&output->link); | 60 | wl_list_remove(&output->link); |
61 | free(output->name); | 61 | free(output->name); |
62 | free(output->identifier); | ||
62 | free(output); | 63 | free(output); |
63 | } | 64 | } |
64 | 65 | ||
@@ -166,13 +167,15 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) { | |||
166 | return visible; | 167 | return visible; |
167 | } | 168 | } |
168 | 169 | ||
169 | static bool bar_uses_output(struct swaybar *bar, const char *name) { | 170 | static bool bar_uses_output(struct swaybar_output *output) { |
170 | if (bar->config->all_outputs) { | 171 | if (output->bar->config->all_outputs) { |
171 | return true; | 172 | return true; |
172 | } | 173 | } |
174 | char *identifier = output->identifier; | ||
173 | struct config_output *coutput; | 175 | struct config_output *coutput; |
174 | wl_list_for_each(coutput, &bar->config->outputs, link) { | 176 | wl_list_for_each(coutput, &output->bar->config->outputs, link) { |
175 | if (strcmp(coutput->name, name) == 0) { | 177 | if (strcmp(coutput->name, output->name) == 0 || |
178 | (identifier && strcmp(coutput->name, identifier) == 0)) { | ||
176 | return true; | 179 | return true; |
177 | } | 180 | } |
178 | } | 181 | } |
@@ -233,7 +236,7 @@ static void xdg_output_handle_done(void *data, | |||
233 | struct swaybar *bar = output->bar; | 236 | struct swaybar *bar = output->bar; |
234 | 237 | ||
235 | assert(output->name != NULL); | 238 | assert(output->name != NULL); |
236 | if (!bar_uses_output(bar, output->name)) { | 239 | if (!bar_uses_output(output)) { |
237 | swaybar_output_free(output); | 240 | swaybar_output_free(output); |
238 | return; | 241 | return; |
239 | } | 242 | } |
@@ -258,7 +261,22 @@ static void xdg_output_handle_name(void *data, | |||
258 | 261 | ||
259 | static void xdg_output_handle_description(void *data, | 262 | static void xdg_output_handle_description(void *data, |
260 | struct zxdg_output_v1 *xdg_output, const char *description) { | 263 | struct zxdg_output_v1 *xdg_output, const char *description) { |
261 | // Who cares | 264 | // wlroots currently sets the description to `make model serial (name)` |
265 | // If this changes in the future, this will need to be modified. | ||
266 | struct swaybar_output *output = data; | ||
267 | free(output->identifier); | ||
268 | output->identifier = NULL; | ||
269 | char *paren = strrchr(description, '('); | ||
270 | if (paren) { | ||
271 | size_t length = paren - description; | ||
272 | output->identifier = malloc(length); | ||
273 | if (!output->identifier) { | ||
274 | wlr_log(WLR_ERROR, "Failed to allocate output identifier"); | ||
275 | return; | ||
276 | } | ||
277 | strncpy(output->identifier, description, length); | ||
278 | output->identifier[length - 1] = '\0'; | ||
279 | } | ||
262 | } | 280 | } |
263 | 281 | ||
264 | struct zxdg_output_v1_listener xdg_output_listener = { | 282 | struct zxdg_output_v1_listener xdg_output_listener = { |
diff --git a/swaybar/config.c b/swaybar/config.c index 9cafe061..d4cc9b1a 100644 --- a/swaybar/config.c +++ b/swaybar/config.c | |||
@@ -37,6 +37,8 @@ struct swaybar_config *init_config(void) { | |||
37 | config->workspace_buttons = true; | 37 | config->workspace_buttons = true; |
38 | config->bindings = create_list(); | 38 | config->bindings = create_list(); |
39 | wl_list_init(&config->outputs); | 39 | wl_list_init(&config->outputs); |
40 | config->status_padding = 1; | ||
41 | config->status_edge_padding = 3; | ||
40 | 42 | ||
41 | /* height */ | 43 | /* height */ |
42 | config->height = 0; | 44 | config->height = 0; |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index ba53d95d..097f9161 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -157,7 +157,7 @@ static bool ipc_parse_config( | |||
157 | json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons; | 157 | json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons; |
158 | json_object *strip_workspace_numbers, *strip_workspace_name; | 158 | json_object *strip_workspace_numbers, *strip_workspace_name; |
159 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; | 159 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; |
160 | json_object *outputs, *bindings; | 160 | json_object *outputs, *bindings, *status_padding, *status_edge_padding; |
161 | json_object_object_get_ex(bar_config, "mode", &mode); | 161 | json_object_object_get_ex(bar_config, "mode", &mode); |
162 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); | 162 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); |
163 | json_object_object_get_ex(bar_config, "position", &position); | 163 | json_object_object_get_ex(bar_config, "position", &position); |
@@ -176,6 +176,9 @@ static bool ipc_parse_config( | |||
176 | json_object_object_get_ex(bar_config, "outputs", &outputs); | 176 | json_object_object_get_ex(bar_config, "outputs", &outputs); |
177 | json_object_object_get_ex(bar_config, "pango_markup", &markup); | 177 | json_object_object_get_ex(bar_config, "pango_markup", &markup); |
178 | json_object_object_get_ex(bar_config, "bindings", &bindings); | 178 | json_object_object_get_ex(bar_config, "bindings", &bindings); |
179 | json_object_object_get_ex(bar_config, "status_padding", &status_padding); | ||
180 | json_object_object_get_ex(bar_config, "status_edge_padding", | ||
181 | &status_edge_padding); | ||
179 | if (status_command) { | 182 | if (status_command) { |
180 | free(config->status_command); | 183 | free(config->status_command); |
181 | config->status_command = strdup(json_object_get_string(status_command)); | 184 | config->status_command = strdup(json_object_get_string(status_command)); |
@@ -209,6 +212,12 @@ static bool ipc_parse_config( | |||
209 | if (bar_height) { | 212 | if (bar_height) { |
210 | config->height = json_object_get_int(bar_height); | 213 | config->height = json_object_get_int(bar_height); |
211 | } | 214 | } |
215 | if (status_padding) { | ||
216 | config->status_padding = json_object_get_int(status_padding); | ||
217 | } | ||
218 | if (status_edge_padding) { | ||
219 | config->status_edge_padding = json_object_get_int(status_edge_padding); | ||
220 | } | ||
212 | if (gaps) { | 221 | if (gaps) { |
213 | json_object *top = json_object_object_get(gaps, "top"); | 222 | json_object *top = json_object_object_get(gaps, "top"); |
214 | if (top) { | 223 | if (top) { |
diff --git a/swaybar/render.c b/swaybar/render.c index 670e8e74..55f680ed 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -36,7 +36,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, | |||
36 | cairo_set_source_u32(cairo, 0xFF0000FF); | 36 | cairo_set_source_u32(cairo, 0xFF0000FF); |
37 | 37 | ||
38 | int margin = 3 * output->scale; | 38 | int margin = 3 * output->scale; |
39 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 39 | double ws_vertical_padding = |
40 | output->bar->config->status_padding * output->scale; | ||
40 | 41 | ||
41 | char *font = output->bar->config->font; | 42 | char *font = output->bar->config->font; |
42 | int text_width, text_height; | 43 | int text_width, text_height; |
@@ -45,7 +46,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, | |||
45 | 46 | ||
46 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 47 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
47 | uint32_t ideal_surface_height = ideal_height / output->scale; | 48 | uint32_t ideal_surface_height = ideal_height / output->scale; |
48 | if (output->height < ideal_surface_height) { | 49 | if (!output->bar->config->height && |
50 | output->height < ideal_surface_height) { | ||
49 | return ideal_surface_height; | 51 | return ideal_surface_height; |
50 | } | 52 | } |
51 | *x -= text_width + margin; | 53 | *x -= text_width + margin; |
@@ -72,12 +74,13 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
72 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 74 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, |
73 | output->scale, config->pango_markup, "%s", text); | 75 | output->scale, config->pango_markup, "%s", text); |
74 | 76 | ||
75 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 77 | double ws_vertical_padding = config->status_padding * output->scale; |
76 | int margin = 3 * output->scale; | 78 | int margin = 3 * output->scale; |
77 | 79 | ||
78 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 80 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
79 | uint32_t ideal_surface_height = ideal_height / output->scale; | 81 | uint32_t ideal_surface_height = ideal_height / output->scale; |
80 | if (output->height < ideal_surface_height) { | 82 | if (!output->bar->config->height && |
83 | output->height < ideal_surface_height) { | ||
81 | return ideal_surface_height; | 84 | return ideal_surface_height; |
82 | } | 85 | } |
83 | 86 | ||
@@ -154,7 +157,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
154 | output->scale, block->markup, "%s", block->full_text); | 157 | output->scale, block->markup, "%s", block->full_text); |
155 | 158 | ||
156 | int margin = 3 * output->scale; | 159 | int margin = 3 * output->scale; |
157 | double ws_vertical_padding = WS_VERTICAL_PADDING * 2 * output->scale; | 160 | double ws_vertical_padding = config->status_padding * output->scale; |
158 | 161 | ||
159 | int width = text_width; | 162 | int width = text_width; |
160 | if (width < block->min_width) { | 163 | if (width < block->min_width) { |
@@ -164,7 +167,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
164 | double block_width = width; | 167 | double block_width = width; |
165 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 168 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
166 | uint32_t ideal_surface_height = ideal_height / output->scale; | 169 | uint32_t ideal_surface_height = ideal_height / output->scale; |
167 | if (output->height < ideal_surface_height) { | 170 | if (!output->bar->config->height && |
171 | output->height < ideal_surface_height) { | ||
168 | return ideal_surface_height; | 172 | return ideal_surface_height; |
169 | } | 173 | } |
170 | 174 | ||
@@ -186,7 +190,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
186 | output->scale, false, "%s", config->sep_symbol); | 190 | output->scale, false, "%s", config->sep_symbol); |
187 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; | 191 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; |
188 | uint32_t _ideal_surface_height = _ideal_height / output->scale; | 192 | uint32_t _ideal_surface_height = _ideal_height / output->scale; |
189 | if (output->height < _ideal_surface_height) { | 193 | if (!output->bar->config->height && |
194 | output->height < _ideal_surface_height) { | ||
190 | return _ideal_surface_height; | 195 | return _ideal_surface_height; |
191 | } | 196 | } |
192 | if (sep_width > sep_block_width) { | 197 | if (sep_width > sep_block_width) { |
@@ -194,8 +199,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
194 | } | 199 | } |
195 | } | 200 | } |
196 | *x -= sep_block_width; | 201 | *x -= sep_block_width; |
197 | } else { | 202 | } else if (config->status_edge_padding) { |
198 | *x -= margin; | 203 | *x -= config->status_edge_padding * output->scale; |
199 | } | 204 | } |
200 | 205 | ||
201 | uint32_t height = output->height * output->scale; | 206 | uint32_t height = output->height * output->scale; |
@@ -213,8 +218,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
213 | } | 218 | } |
214 | 219 | ||
215 | double x_pos = *x; | 220 | double x_pos = *x; |
216 | double y_pos = WS_VERTICAL_PADDING * output->scale; | 221 | double y_pos = ws_vertical_padding; |
217 | double render_height = height - ws_vertical_padding + output->scale; | 222 | double render_height = height - ws_vertical_padding * 2; |
218 | 223 | ||
219 | uint32_t bg_color = block->urgent | 224 | uint32_t bg_color = block->urgent |
220 | ? config->colors.urgent_workspace.background : block->background; | 225 | ? config->colors.urgent_workspace.background : block->background; |
@@ -287,7 +292,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
287 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 292 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
288 | struct swaybar_output *output, double *x) { | 293 | struct swaybar_output *output, double *x) { |
289 | uint32_t max_height = 0; | 294 | uint32_t max_height = 0; |
290 | bool edge = true; | 295 | bool edge = *x == output->width * output->scale; |
291 | struct i3bar_block *block; | 296 | struct i3bar_block *block; |
292 | wl_list_for_each(block, &output->bar->status->blocks, link) { | 297 | wl_list_for_each(block, &output->bar->status->blocks, link) { |
293 | uint32_t h = render_status_block(cairo, output, block, x, edge); | 298 | uint32_t h = render_status_block(cairo, output, block, x, edge); |
@@ -333,7 +338,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
333 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 | 338 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 |
334 | + border_width * 2; | 339 | + border_width * 2; |
335 | uint32_t ideal_surface_height = ideal_height / output->scale; | 340 | uint32_t ideal_surface_height = ideal_height / output->scale; |
336 | if (output->height < ideal_surface_height) { | 341 | if (!output->bar->config->height && |
342 | output->height < ideal_surface_height) { | ||
337 | return ideal_surface_height; | 343 | return ideal_surface_height; |
338 | } | 344 | } |
339 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; | 345 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
@@ -399,7 +405,8 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
399 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height | 405 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height |
400 | + border_width * 2; | 406 | + border_width * 2; |
401 | uint32_t ideal_surface_height = ideal_height / output->scale; | 407 | uint32_t ideal_surface_height = ideal_height / output->scale; |
402 | if (output->height < ideal_surface_height) { | 408 | if (!output->bar->config->height && |
409 | output->height < ideal_surface_height) { | ||
403 | return ideal_surface_height; | 410 | return ideal_surface_height; |
404 | } | 411 | } |
405 | 412 | ||
@@ -526,7 +533,7 @@ void render_frame(struct swaybar_output *output) { | |||
526 | cairo_restore(cairo); | 533 | cairo_restore(cairo); |
527 | uint32_t height = render_to_cairo(cairo, output); | 534 | uint32_t height = render_to_cairo(cairo, output); |
528 | int config_height = output->bar->config->height; | 535 | int config_height = output->bar->config->height; |
529 | if (config_height >= 0 && height < (uint32_t)config_height) { | 536 | if (config_height > 0) { |
530 | height = config_height; | 537 | height = config_height; |
531 | } | 538 | } |
532 | if (height != output->height || output->width == 0) { | 539 | if (height != output->height || output->width == 0) { |
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index 0c3517cb..d5d0c84e 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c | |||
@@ -101,13 +101,17 @@ void tray_in(int fd, short mask, void *data) { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | static int cmp_output(const void *item, const void *cmp_to) { | 103 | static int cmp_output(const void *item, const void *cmp_to) { |
104 | return strcmp(item, cmp_to); | 104 | const struct swaybar_output *output = cmp_to; |
105 | if (output->identifier && strcmp(item, output->identifier) == 0) { | ||
106 | return 0; | ||
107 | } | ||
108 | return strcmp(item, output->name); | ||
105 | } | 109 | } |
106 | 110 | ||
107 | uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { | 111 | uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { |
108 | struct swaybar_config *config = output->bar->config; | 112 | struct swaybar_config *config = output->bar->config; |
109 | if (config->tray_outputs) { | 113 | if (config->tray_outputs) { |
110 | if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) { | 114 | if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) { |
111 | return 0; | 115 | return 0; |
112 | } | 116 | } |
113 | } // else display on all | 117 | } // else display on all |