diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.c | 6 | ||||
| -rw-r--r-- | src/config.h | 1 | ||||
| -rw-r--r-- | src/display.c | 9 | ||||
| -rw-r--r-- | src/util.c | 5 | ||||
| -rw-r--r-- | src/util.h | 2 | ||||
| -rw-r--r-- | src/window.c | 9 | ||||
| -rw-r--r-- | src/window.h | 1 |
7 files changed, 27 insertions, 6 deletions
diff --git a/src/config.c b/src/config.c index ce34e55..13addef 100644 --- a/src/config.c +++ b/src/config.c @@ -27,6 +27,7 @@ static const config_entry_t bar_entries[] = { { "monitor", CONFIG_STRING, NULL, offsetof(config_t, monitor) }, { "override-redirect", CONFIG_BOOL, NULL, offsetof(config_t, override_redirect) }, { "background", CONFIG_GRADIENT, NULL, offsetof(config_t, background) }, + { "scale", CONFIG_DOUBLE, NULL, offsetof(config_t, scale) }, { 0 }, }; @@ -594,7 +595,10 @@ int config_validate(config_t *config) int errors = 0; // Validate the config itself - // ... + if (config->scale < 1 && config->scale != 0) { + log_error("Bar '%s' should be at least 1", "scale"); + errors++; + } // Validate blocks for (size_t i = 0; i < config->n_blocks; i++) { diff --git a/src/config.h b/src/config.h index 297a285..dd1bf1f 100644 --- a/src/config.h +++ b/src/config.h @@ -37,6 +37,7 @@ typedef struct { gradient_t background; unsigned int width; unsigned int height; + double scale; } config_t; typedef struct { diff --git a/src/display.c b/src/display.c index 738e91e..cdde9cd 100644 --- a/src/display.c +++ b/src/display.c @@ -125,15 +125,14 @@ void display_update_scale(display_t *display) free(dpi_value); // Ignore invalid values - if (display->screen_dpi != 0) + if (display->screen_dpi != 0) { + log_debug("Received dpi value '%.2lf'", display->screen_dpi); return; + } } - // TODO: Actually use this value - // Also allow changing the screen - // display->screen_dpi = (double)display->screen_size->height * 25.4 / (double)display->screen_size->mheight; - log_debug("Fallback dpi value '%.2lf'", display->screen_dpi); + log_debug("Calculated fallback dpi value '%.2lf'", display->screen_dpi); } void display_close(display_t *display) @@ -205,6 +205,11 @@ void strfree(char **list) free(list); } +double steps(double value, int n) +{ + return floor(value * n) * (1.0 / n); +} + bool iszero(const void *ptr, size_t size) { for (size_t i = 0; i < size; i++) { @@ -85,6 +85,8 @@ void strfree(char **list); bool iszero(const void *ptr, size_t size); +double steps(double value, int n); + void render_triangle(cairo_t *cr, int x, int y, int w, int h); // Render a capsule shape. Cannot handle w < 2*r1 diff --git a/src/window.c b/src/window.c index be922a1..b71bc07 100644 --- a/src/window.c +++ b/src/window.c @@ -151,6 +151,13 @@ void window_init(window_t *window, display_t *display, config_t *config) window->cr = cairo_create(window->surface); assert(cairo_status(window->cr) == CAIRO_STATUS_SUCCESS); log_trace("Created cairo window context"); + + window->scale = config->scale > 0 + ? config->scale + : steps(window->display->screen_dpi / 96.0, 4); + + if (window->scale < 1) window->scale = 1; + log_debug("Set window scale to '%lf'", window->scale); } void window_move(window_t *window, int x, int y) @@ -203,6 +210,7 @@ static void window_reshape(window_t *window) cairo_arc(cr, window->width - radius, radius, radius, 270 * degree, 450 * degree); cairo_fill(cr); + cairo_surface_set_device_scale(surface, window->scale, window->scale); cairo_show_page(cr); cairo_destroy(cr); @@ -243,6 +251,7 @@ void window_resize(window_t *window, int width, int height) // Update cairo surface cairo_xcb_surface_set_size(window->surface, width, height); + cairo_surface_set_device_scale(window->surface, window->scale, window->scale); } void window_present(window_t *window, cairo_surface_t *surface) diff --git a/src/window.h b/src/window.h index 579a61c..a51ed79 100644 --- a/src/window.h +++ b/src/window.h @@ -17,6 +17,7 @@ typedef struct { cairo_t *cr; int x, y; int width, height; + double scale; } window_t; void window_init(window_t *window, display_t *display, config_t *config); |
