From 0b23ae5d1e5c38eb8bf3fb1bf4d8e6896f40085f Mon Sep 17 00:00:00 2001 From: Arnor Nolen Date: Mon, 17 Apr 2023 19:27:37 +0300 Subject: [PATCH 1/6] Scaling patch --- config.def.h | 2 ++ dwlb.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index 83d7481..f91787b 100644 --- a/config.def.h +++ b/config.def.h @@ -14,6 +14,8 @@ static bool status_commands = true; static bool center_title = false; // use title space as status text element static bool custom_title = false; +// scale +static uint32_t buffer_scale = 1; // font static char *fontstr = "monospace:size=16"; // tag names if ipc is disabled diff --git a/dwlb.c b/dwlb.c index 78acdb9..3785c72 100644 --- a/dwlb.c +++ b/dwlb.c @@ -190,7 +190,7 @@ static char **layouts; static uint32_t layouts_l, layouts_c; static struct fcft_font *font; -static uint32_t height, textpadding; +static uint32_t height, textpadding, buffer_scale; static bool run_display; @@ -465,6 +465,7 @@ draw_frame(Bar *bar) munmap(data, bar->bufsize); + wl_surface_set_buffer_scale(bar->wl_surface, buffer_scale); wl_surface_attach(bar->wl_surface, buffer, 0, 0); wl_surface_damage_buffer(bar->wl_surface, 0, 0, bar->width, bar->height); wl_surface_commit(bar->wl_surface); @@ -477,6 +478,9 @@ static void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h) { + w = w * buffer_scale; + h = h * buffer_scale; + zwlr_layer_surface_v1_ack_configure(surface, serial); Bar *bar = (Bar *)data; @@ -1719,10 +1723,14 @@ main(int argc, char **argv) /* Load selected font */ fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR); fcft_set_scaling_filter(FCFT_SCALING_FILTER_LANCZOS3); - if (!(font = fcft_from_name(1, (const char *[]) {fontstr}, NULL))) + + unsigned int dpi = 96 * buffer_scale; + char buf[10]; + snprintf(buf, sizeof buf, "dpi=%u", dpi); + if (!(font = fcft_from_name(1, (const char *[]) {fontstr}, buf))) DIE("Could not load font"); textpadding = font->height / 2; - height = font->height + vertical_padding * 2; + height = font->height / buffer_scale + vertical_padding * 2; /* Configure tag names */ if (ipc && tags) { From e668bfa49604af979d0d9482595c06ca080abdcd Mon Sep 17 00:00:00 2001 From: Arnor Nolen Date: Thu, 20 Apr 2023 19:15:32 +0300 Subject: [PATCH 2/6] Fixed mouse --- dwlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwlb.c b/dwlb.c index 3785c72..9dc3466 100644 --- a/dwlb.c +++ b/dwlb.c @@ -640,7 +640,7 @@ pointer_frame(void *data, struct wl_pointer *pointer) if (!active && !occupied && !urgent) continue; } - x += TEXT_WIDTH(tags[i], seat->bar->width - x, seat->bar->textpadding); + x += TEXT_WIDTH(tags[i], seat->bar->width - x, seat->bar->textpadding) / buffer_scale; } while (seat->pointer_x >= x && ++i < tags_l); if (i < tags_l) { From 5680f405db06a8a69b70d5ac6c2dd086ee30ee4a Mon Sep 17 00:00:00 2001 From: Arnor Nolen Date: Thu, 20 Apr 2023 21:29:46 +0300 Subject: [PATCH 3/6] Fixed hiding the bar --- dwlb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dwlb.c b/dwlb.c index 9dc3466..162227a 100644 --- a/dwlb.c +++ b/dwlb.c @@ -882,12 +882,12 @@ show_bar(Bar *bar) DIE("Could not create layer_surface"); zwlr_layer_surface_v1_add_listener(bar->layer_surface, &layer_surface_listener, bar); - zwlr_layer_surface_v1_set_size(bar->layer_surface, 0, bar->height); + zwlr_layer_surface_v1_set_size(bar->layer_surface, 0, bar->height / buffer_scale); zwlr_layer_surface_v1_set_anchor(bar->layer_surface, (bar->bottom ? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT); - zwlr_layer_surface_v1_set_exclusive_zone(bar->layer_surface, bar->height); + zwlr_layer_surface_v1_set_exclusive_zone(bar->layer_surface, bar->height / buffer_scale); wl_surface_commit(bar->wl_surface); bar->hidden = false; @@ -906,7 +906,7 @@ hide_bar(Bar *bar) static void setup_bar(Bar *bar) { - bar->height = height; + bar->height = height * buffer_scale; bar->textpadding = textpadding; bar->bottom = bottom; bar->hidden = hidden; From c023b4d252706089d7eeb1db6b571adcabfff8ac Mon Sep 17 00:00:00 2001 From: arnor-nolen Date: Tue, 2 May 2023 17:21:51 +0300 Subject: [PATCH 4/6] Applied buffer_scale to cursor --- dwlb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dwlb.c b/dwlb.c index 162227a..ff04523 100644 --- a/dwlb.c +++ b/dwlb.c @@ -584,9 +584,10 @@ pointer_enter(void *data, struct wl_pointer *pointer, } if (!cursor_image) { - struct wl_cursor_theme *cursor_theme = wl_cursor_theme_load(NULL, 24, shm); + struct wl_cursor_theme *cursor_theme = wl_cursor_theme_load(NULL, 24 * buffer_scale, shm); cursor_image = wl_cursor_theme_get_cursor(cursor_theme, "left_ptr")->images[0]; cursor_surface = wl_compositor_create_surface(compositor); + wl_surface_set_buffer_scale(cursor_surface, buffer_scale); wl_surface_attach(cursor_surface, wl_cursor_image_get_buffer(cursor_image), 0, 0); wl_surface_commit(cursor_surface); } From 37c7259625a33cc10534dfc81ddc6de0bb9e1a9a Mon Sep 17 00:00:00 2001 From: arnor-nolen Date: Wed, 3 May 2023 10:29:16 +0300 Subject: [PATCH 5/6] Added -scale as an option --- dwlb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dwlb.c b/dwlb.c index ff04523..d3314aa 100644 --- a/dwlb.c +++ b/dwlb.c @@ -1696,6 +1696,10 @@ main(int argc, char **argv) EDIE("strdup"); tags_l = tags_c = v; i += v; + } else if (!strcmp(argv[i], "-scale")) { + if (++i >= argc) + DIE("Option -scale requires an argument"); + buffer_scale = strtoul(argv[i], &argv[i] + strlen(argv[i]), 10); } else if (!strcmp(argv[i], "-v")) { fprintf(stderr, PROGRAM " " VERSION "\n"); return 0; From 0493b74b10a362148e972af8fa721f4bbe58b955 Mon Sep 17 00:00:00 2001 From: arnor-nolen Date: Wed, 3 May 2023 10:44:32 +0300 Subject: [PATCH 6/6] Added help and readme explanations --- README.md | 7 +++++++ dwlb.c | 1 + 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 360af71..8335cfc 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,13 @@ dwlb -status all 'text ^bg(ff0000)^lm(foot)text^bg()^lm() text' A color command with no argument reverts to the default value. `^^` represents a single `^` character. Status commands can be disabled with `-no-status-commands`. +## Scaling +If you use scaling in Wayland, you can specify `buffer_scale` through config file or by passing it as an option (only integer values): +```bash +dwlb -scale 2 +``` +This will render both surface and a cursor with 2x detail. If your monitor is set to 1.25 or 1.5 scaling, setting scale to 2 will also work as compositor will downscale the buffer properly. + ## Other Options Run `dwlb -h` for a full list of options. diff --git a/dwlb.c b/dwlb.c index d3314aa..79a84a6 100644 --- a/dwlb.c +++ b/dwlb.c @@ -93,6 +93,7 @@ " -inactive-fg-color [COLOR] specify background color of inactive tags or monitors\n" \ " -urgent-fg-color [COLOR] specify text color of urgent tags\n" \ " -urgent-bg-color [COLOR] specify background color of urgent tags\n" \ + " -scale [BUFFER_SCALE] specify buffer scale value for integer scaling\n" \ "Commands\n" \ " -status [OUTPUT] [TEXT] set status text\n" \ " -title [OUTPUT] [TEXT] set title text, if -custom-title is enabled\n" \