aboutsummaryrefslogtreecommitdiff
path: root/swaybar
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c30
-rw-r--r--swaybar/config.c2
-rw-r--r--swaybar/ipc.c11
-rw-r--r--swaybar/render.c37
-rw-r--r--swaybar/tray/tray.c8
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) {
free_workspaces(&output->workspaces);
wl_list_remove(&output->link);
free(output->name);
+ free(output->identifier);
free(output);
}
@@ -166,13 +167,15 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
return visible;
}
-static bool bar_uses_output(struct swaybar *bar, const char *name) {
- if (bar->config->all_outputs) {
+static bool bar_uses_output(struct swaybar_output *output) {
+ if (output->bar->config->all_outputs) {
return true;
}
+ char *identifier = output->identifier;
struct config_output *coutput;
- wl_list_for_each(coutput, &bar->config->outputs, link) {
- if (strcmp(coutput->name, name) == 0) {
+ wl_list_for_each(coutput, &output->bar->config->outputs, link) {
+ if (strcmp(coutput->name, output->name) == 0 ||
+ (identifier && strcmp(coutput->name, identifier) == 0)) {
return true;
}
}
@@ -233,7 +236,7 @@ static void xdg_output_handle_done(void *data,
struct swaybar *bar = output->bar;
assert(output->name != NULL);
- if (!bar_uses_output(bar, output->name)) {
+ if (!bar_uses_output(output)) {
swaybar_output_free(output);
return;
}
@@ -258,7 +261,22 @@ static void xdg_output_handle_name(void *data,
static void xdg_output_handle_description(void *data,
struct zxdg_output_v1 *xdg_output, const char *description) {
- // Who cares
+ // wlroots currently sets the description to `make model serial (name)`
+ // If this changes in the future, this will need to be modified.
+ struct swaybar_output *output = data;
+ free(output->identifier);
+ output->identifier = NULL;
+ char *paren = strrchr(description, '(');
+ if (paren) {
+ size_t length = paren - description;
+ output->identifier = malloc(length);
+ if (!output->identifier) {
+ wlr_log(WLR_ERROR, "Failed to allocate output identifier");
+ return;
+ }
+ strncpy(output->identifier, description, length);
+ output->identifier[length - 1] = '\0';
+ }
}
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) {
config->workspace_buttons = true;
config->bindings = create_list();
wl_list_init(&config->outputs);
+ config->status_padding = 1;
+ config->status_edge_padding = 3;
/* height */
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(
json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons;
json_object *strip_workspace_numbers, *strip_workspace_name;
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol;
- json_object *outputs, *bindings;
+ json_object *outputs, *bindings, *status_padding, *status_edge_padding;
json_object_object_get_ex(bar_config, "mode", &mode);
json_object_object_get_ex(bar_config, "hidden_state", &hidden_state);
json_object_object_get_ex(bar_config, "position", &position);
@@ -176,6 +176,9 @@ static bool ipc_parse_config(
json_object_object_get_ex(bar_config, "outputs", &outputs);
json_object_object_get_ex(bar_config, "pango_markup", &markup);
json_object_object_get_ex(bar_config, "bindings", &bindings);
+ json_object_object_get_ex(bar_config, "status_padding", &status_padding);
+ json_object_object_get_ex(bar_config, "status_edge_padding",
+ &status_edge_padding);
if (status_command) {
free(config->status_command);
config->status_command = strdup(json_object_get_string(status_command));
@@ -209,6 +212,12 @@ static bool ipc_parse_config(
if (bar_height) {
config->height = json_object_get_int(bar_height);
}
+ if (status_padding) {
+ config->status_padding = json_object_get_int(status_padding);
+ }
+ if (status_edge_padding) {
+ config->status_edge_padding = json_object_get_int(status_edge_padding);
+ }
if (gaps) {
json_object *top = json_object_object_get(gaps, "top");
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,
cairo_set_source_u32(cairo, 0xFF0000FF);
int margin = 3 * output->scale;
- int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
+ double ws_vertical_padding =
+ output->bar->config->status_padding * output->scale;
char *font = output->bar->config->font;
int text_width, text_height;
@@ -45,7 +46,8 @@ static uint32_t render_status_line_error(cairo_t *cairo,
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
uint32_t ideal_surface_height = ideal_height / output->scale;
- if (output->height < ideal_surface_height) {
+ if (!output->bar->config->height &&
+ output->height < ideal_surface_height) {
return ideal_surface_height;
}
*x -= text_width + margin;
@@ -72,12 +74,13 @@ static uint32_t render_status_line_text(cairo_t *cairo,
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
output->scale, config->pango_markup, "%s", text);
- int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
+ double ws_vertical_padding = config->status_padding * output->scale;
int margin = 3 * output->scale;
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
uint32_t ideal_surface_height = ideal_height / output->scale;
- if (output->height < ideal_surface_height) {
+ if (!output->bar->config->height &&
+ output->height < ideal_surface_height) {
return ideal_surface_height;
}
@@ -154,7 +157,7 @@ static uint32_t render_status_block(cairo_t *cairo,
output->scale, block->markup, "%s", block->full_text);
int margin = 3 * output->scale;
- double ws_vertical_padding = WS_VERTICAL_PADDING * 2 * output->scale;
+ double ws_vertical_padding = config->status_padding * output->scale;
int width = text_width;
if (width < block->min_width) {
@@ -164,7 +167,8 @@ static uint32_t render_status_block(cairo_t *cairo,
double block_width = width;
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
uint32_t ideal_surface_height = ideal_height / output->scale;
- if (output->height < ideal_surface_height) {
+ if (!output->bar->config->height &&
+ output->height < ideal_surface_height) {
return ideal_surface_height;
}
@@ -186,7 +190,8 @@ static uint32_t render_status_block(cairo_t *cairo,
output->scale, false, "%s", config->sep_symbol);
uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
uint32_t _ideal_surface_height = _ideal_height / output->scale;
- if (output->height < _ideal_surface_height) {
+ if (!output->bar->config->height &&
+ output->height < _ideal_surface_height) {
return _ideal_surface_height;
}
if (sep_width > sep_block_width) {
@@ -194,8 +199,8 @@ static uint32_t render_status_block(cairo_t *cairo,
}
}
*x -= sep_block_width;
- } else {
- *x -= margin;
+ } else if (config->status_edge_padding) {
+ *x -= config->status_edge_padding * output->scale;
}
uint32_t height = output->height * output->scale;
@@ -213,8 +218,8 @@ static uint32_t render_status_block(cairo_t *cairo,
}
double x_pos = *x;
- double y_pos = WS_VERTICAL_PADDING * output->scale;
- double render_height = height - ws_vertical_padding + output->scale;
+ double y_pos = ws_vertical_padding;
+ double render_height = height - ws_vertical_padding * 2;
uint32_t bg_color = block->urgent
? config->colors.urgent_workspace.background : block->background;
@@ -287,7 +292,7 @@ static uint32_t render_status_block(cairo_t *cairo,
static uint32_t render_status_line_i3bar(cairo_t *cairo,
struct swaybar_output *output, double *x) {
uint32_t max_height = 0;
- bool edge = true;
+ bool edge = *x == output->width * output->scale;
struct i3bar_block *block;
wl_list_for_each(block, &output->bar->status->blocks, link) {
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,
uint32_t ideal_height = text_height + ws_vertical_padding * 2
+ border_width * 2;
uint32_t ideal_surface_height = ideal_height / output->scale;
- if (output->height < ideal_surface_height) {
+ if (!output->bar->config->height &&
+ output->height < ideal_surface_height) {
return ideal_surface_height;
}
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,
uint32_t ideal_height = ws_vertical_padding * 2 + text_height
+ border_width * 2;
uint32_t ideal_surface_height = ideal_height / output->scale;
- if (output->height < ideal_surface_height) {
+ if (!output->bar->config->height &&
+ output->height < ideal_surface_height) {
return ideal_surface_height;
}
@@ -526,7 +533,7 @@ void render_frame(struct swaybar_output *output) {
cairo_restore(cairo);
uint32_t height = render_to_cairo(cairo, output);
int config_height = output->bar->config->height;
- if (config_height >= 0 && height < (uint32_t)config_height) {
+ if (config_height > 0) {
height = config_height;
}
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) {
}
static int cmp_output(const void *item, const void *cmp_to) {
- return strcmp(item, cmp_to);
+ const struct swaybar_output *output = cmp_to;
+ if (output->identifier && strcmp(item, output->identifier) == 0) {
+ return 0;
+ }
+ return strcmp(item, output->name);
}
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
struct swaybar_config *config = output->bar->config;
if (config->tray_outputs) {
- if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) {
+ if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) {
return 0;
}
} // else display on all