From a64479037f297a50de258588f2b5adfba4444db7 Mon Sep 17 00:00:00 2001 From: Simon Long Date: Mon, 13 May 2024 07:43:07 +0100 Subject: [PATCH] Make magnifier increment a theme parameter --- docs/labwc-theme.5.scd | 4 ++++ include/theme.h | 1 + src/common/scene-helpers.c | 14 ++++++++------ src/theme.c | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/labwc-theme.5.scd b/docs/labwc-theme.5.scd index 7d54d23d..0d089da0 100644 --- a/docs/labwc-theme.5.scd +++ b/docs/labwc-theme.5.scd @@ -296,6 +296,10 @@ elements are not listed here, but are supported. is the default at boot; can be modified at run-time in a keyboard or mouse binding by calling 'ZoomIn' or 'ZoomOut'. Default is x2. +*magnifier.increment* + Step by which magnification changes on each call to 'ZoomIn' or + 'ZoomOut'. Default is 0.2. + *magnifier.filter* Set to 1 to apply a bilinear filter to the magnified image. Set to 0 to use nearest-neighbour. Default is 1 - bilinear filtered. diff --git a/include/theme.h b/include/theme.h index e1e884a2..a567ba03 100644 --- a/include/theme.h +++ b/include/theme.h @@ -147,6 +147,7 @@ struct theme { float mag_border_color[4]; int mag_border_width; int mag_filter; + float mag_increment; }; struct server; diff --git a/src/common/scene-helpers.c b/src/common/scene-helpers.c index d5336afd..ef430561 100644 --- a/src/common/scene-helpers.c +++ b/src/common/scene-helpers.c @@ -14,7 +14,7 @@ #include "common/macros.h" static bool magnify_on; -static double mag_scale = 0.0; +static double mag_scale = 0.0, mag_increment = 0.0; struct wlr_surface * lab_wlr_surface_from_node(struct wlr_scene_node *node) @@ -103,6 +103,9 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box if (mag_scale == 0.0) { mag_scale = theme->mag_scale; } + if (mag_increment == 0.0) { + mag_increment = theme->mag_increment; + } if (fullscreen) { // The lines below were the first attempt at enabling fullscreen (with no @@ -304,17 +307,16 @@ magnify_toggle(void) void magnify_set_scale(enum magnify_dir dir) { -#define MAG_INCREMENT 0.2 if (dir == MAGNIFY_INCREASE) { if (magnify_on) { - mag_scale += MAG_INCREMENT; + mag_scale += mag_increment; } else { magnify_on = true; - mag_scale = 1.0 + MAG_INCREMENT; + mag_scale = 1.0 + mag_increment; } } else { - if (magnify_on && mag_scale > 1.0 + MAG_INCREMENT) { - mag_scale -= MAG_INCREMENT; + if (magnify_on && mag_scale > 1.0 + mag_increment) { + mag_scale -= mag_increment; } else { magnify_on = false; } diff --git a/src/theme.c b/src/theme.c index 71d35a9e..eb1399d6 100644 --- a/src/theme.c +++ b/src/theme.c @@ -579,6 +579,7 @@ theme_builtin(struct theme *theme, struct server *server) parse_hexstr("#ff0000", theme->mag_border_color); theme->mag_border_width = 1; theme->mag_filter = true; + theme->mag_increment = 0.2; } static void @@ -853,6 +854,9 @@ entry(struct theme *theme, const char *key, const char *value) if (match_glob(key, "magnifier.filter")) { theme->mag_filter = atoi(value); } + if (match_glob(key, "magnifier.increment")) { + theme->mag_increment = atof(value); + } } static void