Add setting of border width and colour

This commit is contained in:
Simon Long 2024-05-03 11:23:00 +01:00
parent 68acb89d26
commit 05c89f18fb
4 changed files with 50 additions and 12 deletions

View file

@ -589,12 +589,18 @@
<!-- <!--
Magnifier settings Magnifier settings
'scale' sets the initial magnification factor when first booted.
'size' sets the width and height in pixels of the magnifier window. 'size' sets the width and height in pixels of the magnifier window.
'initScale' sets the initial magnification factor when first booted.
'borderColour' is an XML RGB string with a leading # which sets the
colour of the border for the magnifier window.
'borderWidth' sets the width in pixels of the border for the
magnifier window.
--> -->
<magnifier> <magnifier>
<scale>2</scale>
<size>400</size> <size>400</size>
<initScale>2</initScale>
<borderColour>#ff0000</borderColour>
<borderWidth>1</borderWidth>
</magnifier> </magnifier>
</labwc_config> </labwc_config>

View file

@ -41,6 +41,12 @@ struct usable_area_override {
struct wl_list link; /* struct rcxml.usable_area_overrides */ struct wl_list link; /* struct rcxml.usable_area_overrides */
}; };
struct rgb_colour {
int r;
int g;
int b;
};
struct rcxml { struct rcxml {
/* from command line */ /* from command line */
char *config_dir; char *config_dir;
@ -141,6 +147,8 @@ struct rcxml {
/* magnifier */ /* magnifier */
int mag_scale; int mag_scale;
int mag_size; int mag_size;
struct rgb_colour mag_border_col;
int mag_border_width;
}; };
extern struct rcxml rc; extern struct rcxml rc;

View file

@ -43,9 +43,6 @@ lab_wlr_scene_get_prev_node(struct wlr_scene_node *node)
} }
/* TODO: move to rc. (or theme?) settings */
#define magnifier_border 1 /* in pixels */
static void static void
magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box *damage) magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box *damage)
{ {
@ -152,15 +149,20 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
/* Borders */ /* Borders */
struct wlr_box border_box = { struct wlr_box border_box = {
.x = ox - (width / 2 + magnifier_border), .x = ox - (width / 2 + rc.mag_border_width),
.y = oy - (height / 2 + magnifier_border), .y = oy - (height / 2 + rc.mag_border_width),
.width = (width + magnifier_border * 2), .width = (width + rc.mag_border_width * 2),
.height = (height + magnifier_border * 2), .height = (height + rc.mag_border_width * 2),
}; };
struct wlr_render_rect_options bg_opts = { struct wlr_render_rect_options bg_opts = {
.box = border_box, .box = border_box,
/* TODO: make this a rc. setting */ /* TODO: make this a rc. setting */
.color = (struct wlr_render_color) { 1, 0, 0, 1 }, .color = (struct wlr_render_color) {
.r = rc.mag_border_col.r / 255.0,
.g = rc.mag_border_col.g / 255.0,
.b = rc.mag_border_col.b / 255.0,
.a = 1
},
.clip = NULL, .clip = NULL,
}; };
wlr_render_pass_add_rect(tmp_render_pass, &bg_opts); wlr_render_pass_add_rect(tmp_render_pass, &bg_opts);

View file

@ -746,6 +746,19 @@ set_adaptive_sync_mode(const char *str, enum adaptive_sync_mode *variable)
} }
} }
static bool parse_rgb(const char *str, int *r, int *g, int *b)
{
int rr, rg, rb;
if (!str) return false;
if (strlen(str) != 7) return false;
if (str[0] != '#') return false;
if (sscanf(str, "#%2X%2X%2X", &rr, &rg, &rb) != 3) return false;
*r = rr;
*g = rg;
*b = rb;
return true;
}
static void static void
entry(xmlNode *node, char *nodename, char *content) entry(xmlNode *node, char *nodename, char *content)
{ {
@ -1034,10 +1047,15 @@ entry(xmlNode *node, char *nodename, char *content)
} else { } else {
wlr_log(WLR_ERROR, "Missing 'button' argument for tablet button mapping"); wlr_log(WLR_ERROR, "Missing 'button' argument for tablet button mapping");
} }
} else if (!strcasecmp(nodename, "scale.magnifier")) {
rc.mag_scale = atoi(content);
} else if (!strcasecmp(nodename, "size.magnifier")) { } else if (!strcasecmp(nodename, "size.magnifier")) {
rc.mag_size = atoi(content); rc.mag_size = atoi(content);
} else if (!strcasecmp(nodename, "initScale.magnifier")) {
rc.mag_scale = atoi(content);
} else if (!strcasecmp(nodename, "borderColour.magnifier")) {
parse_rgb(content, &rc.mag_border_col.r, &rc.mag_border_col.g,
&rc.mag_border_col.b);
} else if (!strcasecmp(nodename, "borderWidth.magnifier")) {
rc.mag_border_width = atoi(content);
} }
} }
@ -1245,6 +1263,10 @@ rcxml_init(void)
rc.mag_scale = 2; rc.mag_scale = 2;
rc.mag_size = 400; rc.mag_size = 400;
rc.mag_border_col.r = 255;
rc.mag_border_col.g = 0;
rc.mag_border_col.b = 0;
rc.mag_border_width = 1;
} }
static void static void