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 | 97 | ||||
-rw-r--r-- | swaybar/tray/tray.c | 8 |
5 files changed, 93 insertions, 55 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 8e7a542e..bc5c28b4 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 9fe4ee9c..993c8228 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -35,7 +35,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, | |||
35 | cairo_set_source_u32(cairo, 0xFF0000FF); | 35 | cairo_set_source_u32(cairo, 0xFF0000FF); |
36 | 36 | ||
37 | int margin = 3 * output->scale; | 37 | int margin = 3 * output->scale; |
38 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 38 | double ws_vertical_padding = |
39 | output->bar->config->status_padding * output->scale; | ||
39 | 40 | ||
40 | char *font = output->bar->config->font; | 41 | char *font = output->bar->config->font; |
41 | int text_width, text_height; | 42 | int text_width, text_height; |
@@ -71,7 +72,7 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
71 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 72 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, |
72 | output->scale, config->pango_markup, "%s", text); | 73 | output->scale, config->pango_markup, "%s", text); |
73 | 74 | ||
74 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 75 | double ws_vertical_padding = config->status_padding * output->scale; |
75 | int margin = 3 * output->scale; | 76 | int margin = 3 * output->scale; |
76 | 77 | ||
77 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 78 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
@@ -90,13 +91,24 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
90 | return output->height; | 91 | return output->height; |
91 | } | 92 | } |
92 | 93 | ||
93 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | 94 | static void render_sharp_rectangle(cairo_t *cairo, uint32_t color, |
94 | double x, double y, double width, double height) { | 95 | double x, double y, double width, double height) { |
96 | cairo_save(cairo); | ||
95 | cairo_set_source_u32(cairo, color); | 97 | cairo_set_source_u32(cairo, color); |
98 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); | ||
99 | cairo_rectangle(cairo, x, y, width, height); | ||
100 | cairo_fill(cairo); | ||
101 | cairo_restore(cairo); | ||
102 | } | ||
103 | |||
104 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | ||
105 | double x, double y, double width, double height) { | ||
96 | if (width > 1 && height > 1) { | 106 | if (width > 1 && height > 1) { |
97 | cairo_rectangle(cairo, x, y, width, height); | 107 | render_sharp_rectangle(cairo, color, x, y, width, height); |
98 | cairo_fill(cairo); | ||
99 | } else { | 108 | } else { |
109 | cairo_save(cairo); | ||
110 | cairo_set_source_u32(cairo, color); | ||
111 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); | ||
100 | if (width == 1) { | 112 | if (width == 1) { |
101 | x += 0.5; | 113 | x += 0.5; |
102 | height += y; | 114 | height += y; |
@@ -111,6 +123,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, | |||
111 | cairo_set_line_width(cairo, 1.0); | 123 | cairo_set_line_width(cairo, 1.0); |
112 | cairo_line_to(cairo, width, height); | 124 | cairo_line_to(cairo, width, height); |
113 | cairo_stroke(cairo); | 125 | cairo_stroke(cairo); |
126 | cairo_restore(cairo); | ||
114 | } | 127 | } |
115 | } | 128 | } |
116 | 129 | ||
@@ -141,7 +154,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
141 | output->scale, block->markup, "%s", block->full_text); | 154 | output->scale, block->markup, "%s", block->full_text); |
142 | 155 | ||
143 | int margin = 3 * output->scale; | 156 | int margin = 3 * output->scale; |
144 | int ws_vertical_padding = WS_VERTICAL_PADDING * 2; | 157 | double ws_vertical_padding = config->status_padding * output->scale; |
145 | 158 | ||
146 | int width = text_width; | 159 | int width = text_width; |
147 | if (width < block->min_width) { | 160 | if (width < block->min_width) { |
@@ -157,12 +170,12 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
157 | 170 | ||
158 | *x -= width; | 171 | *x -= width; |
159 | if ((block->border || block->urgent) && block->border_left > 0) { | 172 | if ((block->border || block->urgent) && block->border_left > 0) { |
160 | *x -= (block->border_left + margin); | 173 | *x -= (block->border_left * output->scale + margin); |
161 | block_width += block->border_left + margin; | 174 | block_width += block->border_left * output->scale + margin; |
162 | } | 175 | } |
163 | if ((block->border || block->urgent) && block->border_right > 0) { | 176 | if ((block->border || block->urgent) && block->border_right > 0) { |
164 | *x -= (block->border_right + margin); | 177 | *x -= (block->border_right * output->scale + margin); |
165 | block_width += block->border_right + margin; | 178 | block_width += block->border_right * output->scale + margin; |
166 | } | 179 | } |
167 | 180 | ||
168 | int sep_width, sep_height; | 181 | int sep_width, sep_height; |
@@ -181,8 +194,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
181 | } | 194 | } |
182 | } | 195 | } |
183 | *x -= sep_block_width; | 196 | *x -= sep_block_width; |
184 | } else { | 197 | } else if (config->status_edge_padding) { |
185 | *x -= margin; | 198 | *x -= config->status_edge_padding * output->scale; |
186 | } | 199 | } |
187 | 200 | ||
188 | uint32_t height = output->height * output->scale; | 201 | uint32_t height = output->height * output->scale; |
@@ -199,48 +212,41 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
199 | wl_list_insert(&output->hotspots, &hotspot->link); | 212 | wl_list_insert(&output->hotspots, &hotspot->link); |
200 | } | 213 | } |
201 | 214 | ||
202 | double pos = *x; | 215 | double x_pos = *x; |
216 | double y_pos = ws_vertical_padding; | ||
217 | double render_height = height - ws_vertical_padding * 2; | ||
203 | 218 | ||
204 | uint32_t bg_color = block->urgent | 219 | uint32_t bg_color = block->urgent |
205 | ? config->colors.urgent_workspace.background : block->background; | 220 | ? config->colors.urgent_workspace.background : block->background; |
206 | if (bg_color) { | 221 | if (bg_color) { |
207 | cairo_set_source_u32(cairo, bg_color); | 222 | render_sharp_rectangle(cairo, bg_color, x_pos, y_pos, |
208 | cairo_rectangle(cairo, pos - 0.5 * output->scale, | 223 | block_width, render_height); |
209 | output->scale, width, height); | ||
210 | cairo_fill(cairo); | ||
211 | } | 224 | } |
212 | 225 | ||
213 | uint32_t border_color = block->urgent | 226 | uint32_t border_color = block->urgent |
214 | ? config->colors.urgent_workspace.border : block->border; | 227 | ? config->colors.urgent_workspace.border : block->border; |
215 | if (border_color && block->border_top > 0) { | 228 | if (border_color && block->border_top > 0) { |
216 | render_sharp_line(cairo, border_color, | 229 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
217 | pos - 0.5 * output->scale, output->scale, | 230 | block_width, block->border_top * output->scale); |
218 | text_width, block->border_top); | ||
219 | } | 231 | } |
220 | if (border_color && block->border_bottom > 0) { | 232 | if (border_color && block->border_bottom > 0) { |
221 | render_sharp_line(cairo, border_color, | 233 | render_sharp_line(cairo, border_color, x_pos, |
222 | pos - 0.5 * output->scale, | 234 | y_pos + render_height - block->border_bottom * output->scale, |
223 | height - output->scale - block->border_bottom, | 235 | block_width, block->border_bottom * output->scale); |
224 | text_width, block->border_bottom); | ||
225 | } | ||
226 | if (border_color != 0 && block->border_left > 0) { | ||
227 | render_sharp_line(cairo, border_color, | ||
228 | pos - 0.5 * output->scale, output->scale, | ||
229 | block->border_left, height); | ||
230 | } | 236 | } |
231 | if (border_color != 0 && block->border_right > 0) { | 237 | if (border_color && block->border_left > 0) { |
232 | render_sharp_line(cairo, border_color, | 238 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
233 | pos - 0.5 * output->scale + text_width, output->scale, | 239 | block->border_left * output->scale, render_height); |
234 | block->border_right, height); | 240 | x_pos += block->border_left * output->scale + margin; |
235 | } | 241 | } |
236 | 242 | ||
237 | double offset = 0; | 243 | double offset = 0; |
238 | if (strncmp(block->align, "left", 5) == 0) { | 244 | if (strncmp(block->align, "left", 5) == 0) { |
239 | offset = pos; | 245 | offset = x_pos; |
240 | } else if (strncmp(block->align, "right", 5) == 0) { | 246 | } else if (strncmp(block->align, "right", 5) == 0) { |
241 | offset = pos + width - text_width; | 247 | offset = x_pos + width - text_width; |
242 | } else if (strncmp(block->align, "center", 6) == 0) { | 248 | } else if (strncmp(block->align, "center", 6) == 0) { |
243 | offset = pos + (width - text_width) / 2; | 249 | offset = x_pos + (width - text_width) / 2; |
244 | } | 250 | } |
245 | cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); | 251 | cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); |
246 | uint32_t color = block->color ? *block->color : config->colors.statusline; | 252 | uint32_t color = block->color ? *block->color : config->colors.statusline; |
@@ -248,14 +254,13 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
248 | cairo_set_source_u32(cairo, color); | 254 | cairo_set_source_u32(cairo, color); |
249 | pango_printf(cairo, config->font, output->scale, | 255 | pango_printf(cairo, config->font, output->scale, |
250 | block->markup, "%s", block->full_text); | 256 | block->markup, "%s", block->full_text); |
251 | pos += width; | 257 | x_pos += width; |
252 | 258 | ||
253 | if (block->border && block->border_right > 0) { | 259 | if (block->border && block->border_right > 0) { |
254 | pos += margin; | 260 | x_pos += margin; |
255 | render_sharp_line(cairo, block->border, | 261 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
256 | pos - 0.5 * output->scale, output->scale, | 262 | block->border_right * output->scale, render_height); |
257 | block->border_right, height); | 263 | x_pos += block->border_right * output->scale; |
258 | pos += block->border_right; | ||
259 | } | 264 | } |
260 | 265 | ||
261 | if (!edge && block->separator) { | 266 | if (!edge && block->separator) { |
@@ -265,14 +270,14 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
265 | cairo_set_source_u32(cairo, config->colors.separator); | 270 | cairo_set_source_u32(cairo, config->colors.separator); |
266 | } | 271 | } |
267 | if (config->sep_symbol) { | 272 | if (config->sep_symbol) { |
268 | offset = pos + (sep_block_width - sep_width) / 2; | 273 | offset = x_pos + (sep_block_width - sep_width) / 2; |
269 | cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0); | 274 | cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0); |
270 | pango_printf(cairo, config->font, output->scale, false, | 275 | pango_printf(cairo, config->font, output->scale, false, |
271 | "%s", config->sep_symbol); | 276 | "%s", config->sep_symbol); |
272 | } else { | 277 | } else { |
273 | cairo_set_line_width(cairo, 1); | 278 | cairo_set_line_width(cairo, 1); |
274 | cairo_move_to(cairo, pos + sep_block_width / 2, margin); | 279 | cairo_move_to(cairo, x_pos + sep_block_width / 2, margin); |
275 | cairo_line_to(cairo, pos + sep_block_width / 2, height - margin); | 280 | cairo_line_to(cairo, x_pos + sep_block_width / 2, height - margin); |
276 | cairo_stroke(cairo); | 281 | cairo_stroke(cairo); |
277 | } | 282 | } |
278 | } | 283 | } |
@@ -282,7 +287,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
282 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 287 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
283 | struct swaybar_output *output, double *x) { | 288 | struct swaybar_output *output, double *x) { |
284 | uint32_t max_height = 0; | 289 | uint32_t max_height = 0; |
285 | bool edge = true; | 290 | bool edge = *x == output->width * output->scale; |
286 | struct i3bar_block *block; | 291 | struct i3bar_block *block; |
287 | wl_list_for_each(block, &output->bar->status->blocks, link) { | 292 | wl_list_for_each(block, &output->bar->status->blocks, link) { |
288 | uint32_t h = render_status_block(cairo, output, block, x, edge); | 293 | uint32_t h = render_status_block(cairo, output, block, x, edge); |
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 |