swaybar: separate adjacent borders

This commit decouples the surface height from the usable height, making it
possible to draw a separator between the workspace/mode and window borders
on top (for bottom bars) or bottom (for top bars). The workspace and mode
borders also get separated.

This behavior is consistent with i3bar.
This commit is contained in:
Konstantin Pospelov 2025-03-29 22:48:46 +01:00
parent 7e7994dbb2
commit 381c01a622
5 changed files with 85 additions and 67 deletions

View file

@ -458,10 +458,10 @@ static void reload_sni(struct swaybar_sni *sni, char *icon_theme,
}
uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
struct swaybar_sni *sni) {
uint32_t height = output->height * output->scale;
uint32_t height, struct swaybar_sni *sni) {
uint32_t scaled_height = height * output->scale;
int padding = output->bar->config->tray_padding;
int target_size = height - 2*padding;
int target_size = scaled_height - 2*padding;
if (target_size != sni->target_size && sni_ready(sni)) {
// check if another icon should be loaded
if (target_size < sni->min_size || target_size > sni->max_size) {
@ -508,7 +508,7 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
int size = descaled_icon_size + 2 * descaled_padding;
*x -= size;
int icon_y = floor((output->height - size) / 2.0);
int icon_y = floor((height - size) / 2.0);
cairo_operator_t op = cairo_get_operator(cairo);
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
@ -532,11 +532,11 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
hotspot->x = *x;
hotspot->y = 0;
hotspot->width = size;
hotspot->height = output->height;
hotspot->height = height;
hotspot->callback = icon_hotspot_callback;
hotspot->destroy = free;
hotspot->data = strdup(sni->watcher_id);
wl_list_insert(&output->hotspots, &hotspot->link);
return output->height;
return height;
}

View file

@ -116,7 +116,8 @@ static int cmp_output(const void *item, const void *cmp_to) {
return strcmp(item, output->name);
}
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output,
double *x, uint32_t height) {
struct swaybar_config *config = output->bar->config;
if (config->tray_outputs) {
if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) {
@ -124,14 +125,14 @@ uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
}
} // else display on all
if ((int)(output->height * output->scale) <= 2 * config->tray_padding) {
if ((int)(height * output->scale) <= 2 * config->tray_padding) {
return (2 * config->tray_padding + 1) / output->scale;
}
uint32_t max_height = 0;
struct swaybar_tray *tray = output->bar->tray;
for (int i = 0; i < tray->items->length; ++i) {
uint32_t h = render_sni(cairo, output, x, tray->items->items[i]);
uint32_t h = render_sni(cairo, output, x, height, tray->items->items[i]);
if (h > max_height) {
max_height = h;
}