From ae2638b238dc92b7eb2dedd32353cc7c25ab6420 Mon Sep 17 00:00:00 2001 From: Simon Long Date: Wed, 15 May 2024 22:50:45 +0100 Subject: [PATCH] Make initial scaling a float; prevent divide by zero --- docs/labwc-config.5.scd | 2 +- docs/rc.xml.all | 2 +- include/config/rcxml.h | 2 +- src/config/rcxml.c | 4 ++-- src/magnifier.c | 3 +++ 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index b98cd35f..6b92c6ee 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -932,7 +932,7 @@ situation. ** 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. + or mouse binding by calling 'ZoomIn' or 'ZoomOut'. Default is x2.0. ** Step by which magnification changes on each call to 'ZoomIn' or diff --git a/docs/rc.xml.all b/docs/rc.xml.all index 518db8a6..654f7d7b 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -603,7 +603,7 @@ 400 400 - 2 + 2.0 0.2 true diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 15878842..80916ea1 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -144,7 +144,7 @@ struct rcxml { /* Magnifier */ int mag_width; int mag_height; - int mag_scale; + float mag_scale; float mag_increment; bool mag_filter; }; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index c23027b7..c7bdaabc 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -1041,7 +1041,7 @@ entry(xmlNode *node, char *nodename, char *content) } else if (!strcasecmp(nodename, "height.magnifier")) { rc.mag_height = atoi(content); } else if (!strcasecmp(nodename, "initScale.magnifier")) { - rc.mag_scale = atoi(content); + set_float(content, &rc.mag_scale); } else if (!strcasecmp(nodename, "increment.magnifier")) { set_float(content, &rc.mag_increment); } else if (!strcasecmp(nodename, "useFilter.magnifier")) { @@ -1255,7 +1255,7 @@ rcxml_init(void) rc.mag_width = 400; rc.mag_height = 400; - rc.mag_scale = 2; + rc.mag_scale = 2.0; rc.mag_increment = 0.2; rc.mag_filter = true; } diff --git a/src/magnifier.c b/src/magnifier.c index 603f2952..4c2097b7 100644 --- a/src/magnifier.c +++ b/src/magnifier.c @@ -60,6 +60,9 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box if (mag_scale == 0.0) { mag_scale = rc.mag_scale; } + if (mag_scale == 0.0) { + mag_scale = 1.0; + } if (fullscreen) { width = output_buffer->width;