mirror of
https://github.com/labwc/labwc.git
synced 2026-04-12 08:21:13 -04:00
Move magnifier settings into theme
This commit is contained in:
parent
15f35ed2ba
commit
19a57c6ea4
5 changed files with 62 additions and 79 deletions
|
|
@ -41,12 +41,6 @@ struct usable_area_override {
|
|||
struct wl_list link; /* struct rcxml.usable_area_overrides */
|
||||
};
|
||||
|
||||
struct rgb_colour {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
};
|
||||
|
||||
struct rcxml {
|
||||
/* from command line */
|
||||
char *config_dir;
|
||||
|
|
@ -146,14 +140,6 @@ struct rcxml {
|
|||
|
||||
/* Menu */
|
||||
unsigned int menu_ignore_button_release_period;
|
||||
|
||||
/* magnifier */
|
||||
int mag_scale;
|
||||
int mag_width;
|
||||
int mag_height;
|
||||
struct rgb_colour mag_border_col;
|
||||
int mag_border_width;
|
||||
bool mag_filter;
|
||||
};
|
||||
|
||||
extern struct rcxml rc;
|
||||
|
|
|
|||
|
|
@ -139,6 +139,14 @@ struct theme {
|
|||
|
||||
/* not set in rc.xml/themerc, but derived from font & padding_height */
|
||||
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;
|
||||
};
|
||||
|
||||
struct server;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <wlr/util/log.h>
|
||||
#include "common/scene-helpers.h"
|
||||
#include "labwc.h"
|
||||
#include "theme.h"
|
||||
|
||||
#include <wlr/render/pass.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
|
|
@ -13,6 +14,7 @@
|
|||
#include "common/macros.h"
|
||||
|
||||
static bool magnify_on;
|
||||
static int mag_scale = 0;
|
||||
|
||||
struct wlr_surface *
|
||||
lab_wlr_surface_from_node(struct wlr_scene_node *node)
|
||||
|
|
@ -66,6 +68,7 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
|
|||
|
||||
/* Fetch scale-adjusted cursor coordinates */
|
||||
struct server *server = output->server;
|
||||
struct theme *theme = server->theme;
|
||||
struct wlr_cursor *cursor = server->seat.cursor;
|
||||
double ox = cursor->x;
|
||||
double oy = cursor->y;
|
||||
|
|
@ -73,10 +76,13 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
|
|||
ox *= output->wlr_output->scale;
|
||||
oy *= output->wlr_output->scale;
|
||||
|
||||
int width = rc.mag_width + 1;
|
||||
int height = rc.mag_height + 1;
|
||||
double x = ox - (rc.mag_width / 2.0);
|
||||
double y = oy - (rc.mag_height / 2.0);
|
||||
if (!mag_scale) {
|
||||
mag_scale = theme->mag_scale;
|
||||
}
|
||||
int width = theme->mag_width + 1;
|
||||
int height = theme->mag_height + 1;
|
||||
double x = ox - (theme->mag_width / 2.0);
|
||||
double y = oy - (theme->mag_height / 2.0);
|
||||
double cropped_width = width;
|
||||
double cropped_height = height;
|
||||
double dst_x = 0;
|
||||
|
|
@ -147,18 +153,18 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
|
|||
|
||||
/* Borders */
|
||||
struct wlr_box border_box = {
|
||||
.x = ox - (width / 2 + rc.mag_border_width),
|
||||
.y = oy - (height / 2 + rc.mag_border_width),
|
||||
.width = (width + rc.mag_border_width * 2),
|
||||
.height = (height + rc.mag_border_width * 2),
|
||||
.x = ox - (width / 2 + theme->mag_border_width),
|
||||
.y = oy - (height / 2 + theme->mag_border_width),
|
||||
.width = (width + theme->mag_border_width * 2),
|
||||
.height = (height + theme->mag_border_width * 2),
|
||||
};
|
||||
struct wlr_render_rect_options bg_opts = {
|
||||
.box = border_box,
|
||||
.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
|
||||
.r = theme->mag_border_color[0],
|
||||
.g = theme->mag_border_color[1],
|
||||
.b = theme->mag_border_color[2],
|
||||
.a = theme->mag_border_color[3]
|
||||
},
|
||||
.clip = NULL,
|
||||
};
|
||||
|
|
@ -172,10 +178,10 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
|
|||
opts = (struct wlr_render_texture_options) {
|
||||
.texture = tmp_texture,
|
||||
.src_box = (struct wlr_fbox) {
|
||||
.x = width * (rc.mag_scale - 1) / (2 * rc.mag_scale),
|
||||
.y = height * (rc.mag_scale - 1) / (2 * rc.mag_scale),
|
||||
.width = width / rc.mag_scale,
|
||||
.height = height / rc.mag_scale,
|
||||
.x = width * (mag_scale - 1) / (2 * mag_scale),
|
||||
.y = height * (mag_scale - 1) / (2 * mag_scale),
|
||||
.width = width / mag_scale,
|
||||
.height = height / mag_scale,
|
||||
},
|
||||
.dst_box = (struct wlr_box) {
|
||||
.x = ox - (width / 2),
|
||||
|
|
@ -185,7 +191,7 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
|
|||
},
|
||||
.alpha = NULL,
|
||||
.clip = NULL,
|
||||
.filter_mode = rc.mag_filter ? WLR_SCALE_FILTER_BILINEAR : WLR_SCALE_FILTER_NEAREST,
|
||||
.filter_mode = theme->mag_filter ? WLR_SCALE_FILTER_BILINEAR : WLR_SCALE_FILTER_NEAREST,
|
||||
};
|
||||
wlr_render_pass_add_texture(tmp_render_pass, &opts);
|
||||
if (!wlr_render_pass_submit(tmp_render_pass)) {
|
||||
|
|
@ -244,14 +250,14 @@ magnify_set_scale(enum magnify_dir dir)
|
|||
{
|
||||
if (dir == MAGNIFY_INCREASE) {
|
||||
if (magnify_on) {
|
||||
rc.mag_scale++;
|
||||
mag_scale++;
|
||||
} else {
|
||||
magnify_on = true;
|
||||
rc.mag_scale = 2;
|
||||
mag_scale = 2;
|
||||
}
|
||||
} else {
|
||||
if (magnify_on && rc.mag_scale > 2) {
|
||||
rc.mag_scale--;
|
||||
if (magnify_on && mag_scale > 2) {
|
||||
mag_scale--;
|
||||
} else {
|
||||
magnify_on = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -746,28 +746,6 @@ 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
|
||||
entry(xmlNode *node, char *nodename, char *content)
|
||||
{
|
||||
|
|
@ -1058,19 +1036,6 @@ 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, "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);
|
||||
} else if (!strcasecmp(nodename, "useFilter.magnifier")) {
|
||||
set_bool(content, &rc.mag_filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1277,15 +1242,6 @@ rcxml_init(void)
|
|||
rc.workspace_config.min_nr_workspaces = 1;
|
||||
|
||||
rc.menu_ignore_button_release_period = 250;
|
||||
|
||||
rc.mag_scale = 2;
|
||||
rc.mag_width = 400;
|
||||
rc.mag_height = 400;
|
||||
rc.mag_border_col.r = 255;
|
||||
rc.mag_border_col.g = 0;
|
||||
rc.mag_border_col.b = 0;
|
||||
rc.mag_border_width = 1;
|
||||
rc.mag_filter = true;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
27
src/theme.c
27
src/theme.c
|
|
@ -571,6 +571,14 @@ theme_builtin(struct theme *theme, struct server *server)
|
|||
memset(theme->snapping_overlay_edge.border_color, 0,
|
||||
sizeof(theme->snapping_overlay_edge.border_color));
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -826,6 +834,25 @@ entry(struct theme *theme, const char *key, const char *value)
|
|||
if (match_glob(key, "snapping.overlay.edge.border.color")) {
|
||||
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_hexstrs(value, theme->mag_border_color);
|
||||
}
|
||||
if (match_glob(key, "magnifier.filter")) {
|
||||
theme->mag_filter = atoi(value);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue