From 50066161b0c9f7c76a84af44c8f297b55e7d68a7 Mon Sep 17 00:00:00 2001 From: Simon Long Date: Wed, 15 May 2024 19:19:51 +0100 Subject: [PATCH] Move magnifier config into rc.xml --- docs/labwc-config.5.scd | 33 +++++++++++++++++++++++++++++++++ docs/labwc-theme.5.scd | 21 --------------------- docs/rc.xml.all | 19 +++++++++++++++++++ include/config/rcxml.h | 7 +++++++ include/theme.h | 5 ----- src/config/rcxml.c | 16 ++++++++++++++++ src/magnifier.c | 23 +++++++++++------------ src/theme.c | 20 -------------------- 8 files changed, 86 insertions(+), 58 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index d86634a8..b98cd35f 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -909,6 +909,39 @@ situation. option has been exposed for unusual use-cases. It is equivalent to Openbox's ``. Default is 250 ms. +## MAGNIFIER + +``` + + 400 + 400 + 2 + 0.2 + true + +``` + +** + Width of magnifier window in pixels. Default is 400. + Set to -1 to use fullscreen magnifier. + +** + Height of magnifier window in pixels. Default is 400. + Set to -1 to use fullscreen magnifier. + +** + Initial number of times by which magnified image is scaled. Value + 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. + +** + Step by which magnification changes on each call to 'ZoomIn' or + 'ZoomOut'. Default is 0.2. + +** [yes|no|default] + Whether to apply a bilinear filter to the magnified image, or + just to use nearest-neighbour. Default is true - bilinear filtered. + ## ENVIRONMENT VARIABLES *XCURSOR_THEME* and *XCURSOR_SIZE* are supported to set cursor theme diff --git a/docs/labwc-theme.5.scd b/docs/labwc-theme.5.scd index 0d089da0..7611d479 100644 --- a/docs/labwc-theme.5.scd +++ b/docs/labwc-theme.5.scd @@ -277,33 +277,12 @@ elements are not listed here, but are supported. *window.inactive.border.color*. This is obsolete, but supported for backward compatibility as some themes still contain it. -*magnifier.width* - Width of magnifier window in pixels. Default is 400. - Set to -1 to use fullscreen magnifier. - -*magnifier.height* - Height of magnifier window in pixels. Default is 400. - Set to -1 to use fullscreen magnifier. - *magnifier.border.width* Width of magnifier window border in pixels. Default is 1. *magnifier.border.color* Color of the magnfier window border. Default is #ff0000 (red). -*magnifier.init-scale* - Initial number of times by which magnified image is scaled. Value - 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. - # BUTTONS The images used for the titlebar icons are referred to as buttons. diff --git a/docs/rc.xml.all b/docs/rc.xml.all index cc507dc8..518db8a6 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -589,4 +589,23 @@ 250 + + + + 400 + 400 + 2 + 0.2 + true + + diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 210d92f2..15878842 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -140,6 +140,13 @@ struct rcxml { /* Menu */ unsigned int menu_ignore_button_release_period; + + /* Magnifier */ + int mag_width; + int mag_height; + int mag_scale; + float mag_increment; + bool mag_filter; }; extern struct rcxml rc; diff --git a/include/theme.h b/include/theme.h index a567ba03..50a69f6f 100644 --- a/include/theme.h +++ b/include/theme.h @@ -141,13 +141,8 @@ struct theme { int osd_window_switcher_item_height; /* magnifier */ - int mag_scale; - int mag_width; - int mag_height; float mag_border_color[4]; int mag_border_width; - int mag_filter; - float mag_increment; }; struct server; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 1e268f47..c23027b7 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -1036,6 +1036,16 @@ entry(xmlNode *node, char *nodename, char *content) } } else if (!strcasecmp(nodename, "ignoreButtonReleasePeriod.menu")) { rc.menu_ignore_button_release_period = atoi(content); + } else if (!strcasecmp(nodename, "width.magnifier")) { + rc.mag_width = atoi(content); + } else if (!strcasecmp(nodename, "height.magnifier")) { + rc.mag_height = atoi(content); + } else if (!strcasecmp(nodename, "initScale.magnifier")) { + rc.mag_scale = atoi(content); + } else if (!strcasecmp(nodename, "increment.magnifier")) { + set_float(content, &rc.mag_increment); + } else if (!strcasecmp(nodename, "useFilter.magnifier")) { + set_bool(content, &rc.mag_filter); } } @@ -1242,6 +1252,12 @@ rcxml_init(void) rc.workspace_config.min_nr_workspaces = 1; rc.menu_ignore_button_release_period = 250; + + rc.mag_width = 400; + rc.mag_height = 400; + rc.mag_scale = 2; + rc.mag_increment = 0.2; + rc.mag_filter = true; } static void diff --git a/src/magnifier.c b/src/magnifier.c index e0876910..603f2952 100644 --- a/src/magnifier.c +++ b/src/magnifier.c @@ -49,7 +49,7 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box wlr_output_layout_output_coords(server->output_layout, output->wlr_output, &ox, &oy); ox *= output->wlr_output->scale; oy *= output->wlr_output->scale; - if (theme->mag_width == -1 || theme->mag_height == -1) { + if (rc.mag_width == -1 || rc.mag_height == -1) { fullscreen = true; } if ((ox < 0 || oy < 0 || ox >= output_buffer->width || oy >= output_buffer->height) @@ -58,7 +58,7 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box } if (mag_scale == 0.0) { - mag_scale = theme->mag_scale; + mag_scale = rc.mag_scale; } if (fullscreen) { @@ -67,10 +67,10 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box x = 0; y = 0; } else { - width = theme->mag_width + 1; - height = theme->mag_height + 1; - x = ox - (theme->mag_width / 2.0); - y = oy - (theme->mag_height / 2.0); + width = rc.mag_width + 1; + height = rc.mag_height + 1; + x = ox - (rc.mag_width / 2.0); + y = oy - (rc.mag_height / 2.0); } double cropped_width = width; double cropped_height = height; @@ -201,7 +201,7 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box .dst_box = dst_box, .alpha = NULL, .clip = NULL, - .filter_mode = theme->mag_filter ? WLR_SCALE_FILTER_BILINEAR + .filter_mode = rc.mag_filter ? WLR_SCALE_FILTER_BILINEAR : WLR_SCALE_FILTER_NEAREST, }; wlr_render_pass_add_texture(tmp_render_pass, &opts); @@ -266,18 +266,17 @@ void magnify_set_scale(struct server *server, enum magnify_dir dir) { struct output *output = output_nearest_to_cursor(server); - struct theme *theme = server->theme; if (dir == MAGNIFY_INCREASE) { if (magnify_on) { - mag_scale += theme->mag_increment; + mag_scale += rc.mag_increment; } else { magnify_on = true; - mag_scale = 1.0 + theme->mag_increment; + mag_scale = 1.0 + rc.mag_increment; } } else { - if (magnify_on && mag_scale > 1.0 + theme->mag_increment) { - mag_scale -= theme->mag_increment; + if (magnify_on && mag_scale > 1.0 + rc.mag_increment) { + mag_scale -= rc.mag_increment; } else { magnify_on = false; } diff --git a/src/theme.c b/src/theme.c index a3a18e34..d3d2b20f 100644 --- a/src/theme.c +++ b/src/theme.c @@ -573,13 +573,8 @@ theme_builtin(struct theme *theme, struct server *server) theme->snapping_overlay_edge.border_color[0][0] = FLT_MIN; /* magnifier */ - theme->mag_scale = 2; - theme->mag_width = 400; - theme->mag_height = 400; parse_hexstr("#ff0000", theme->mag_border_color); theme->mag_border_width = 1; - theme->mag_filter = true; - theme->mag_increment = 0.2; } static void @@ -836,27 +831,12 @@ entry(struct theme *theme, const char *key, const char *value) parse_hexstrs(value, theme->snapping_overlay_edge.border_color); } - if (match_glob(key, "magnifier.init-scale")) { - theme->mag_scale = atoi(value); - } - if (match_glob(key, "magnifier.width")) { - theme->mag_width = atoi(value); - } - if (match_glob(key, "magnifier.height")) { - theme->mag_height = atoi(value); - } if (match_glob(key, "magnifier.border.width")) { theme->mag_border_width = atoi(value); } if (match_glob(key, "magnifier.border.color")) { parse_hexstr(value, theme->mag_border_color); } - if (match_glob(key, "magnifier.filter")) { - theme->mag_filter = atoi(value); - } - if (match_glob(key, "magnifier.increment")) { - set_float(value, &theme->mag_increment); - } } static void