From 33877c8f9403d33b514fc67bce3602b0e515b242 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Thu, 2 Jun 2022 19:00:40 +0800 Subject: [PATCH 68/74] desktop-shell: Support setting panel scale in weston.ini Tested with: [shell] panel-scale=2 Signed-off-by: Jeffy Chen --- clients/desktop-shell.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index 6cf21da..a81eb0a 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -109,6 +109,7 @@ struct panel { enum weston_desktop_shell_panel_position panel_position; enum clock_format clock_format; uint32_t color; + double scale; }; struct background { @@ -242,17 +243,18 @@ panel_launcher_redraw_handler(struct widget *widget, void *data) { struct panel_launcher *launcher = data; struct rectangle allocation; + double scale = launcher->panel->scale; cairo_t *cr; cr = widget_cairo_create(launcher->panel->widget); widget_get_allocation(widget, &allocation); allocation.x += allocation.width / 2 - - cairo_image_surface_get_width(launcher->icon) / 2; + cairo_image_surface_get_width(launcher->icon) * scale / 2; if (allocation.width > allocation.height) allocation.x += allocation.width / 2 - allocation.height / 2; allocation.y += allocation.height / 2 - - cairo_image_surface_get_height(launcher->icon) / 2; + cairo_image_surface_get_height(launcher->icon) * scale / 2; if (allocation.height > allocation.width) allocation.y += allocation.height / 2 - allocation.width / 2; if (launcher->pressed) { @@ -260,14 +262,15 @@ panel_launcher_redraw_handler(struct widget *widget, void *data) allocation.y++; } + cairo_scale(cr, scale, scale); cairo_set_source_surface(cr, launcher->icon, - allocation.x, allocation.y); + allocation.x / scale, allocation.y / scale); cairo_paint(cr); if (launcher->focused) { cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); cairo_mask_surface(cr, launcher->icon, - allocation.x, allocation.y); + allocation.x / scale, allocation.y / scale); } cairo_destroy(cr); @@ -394,6 +397,8 @@ panel_clock_redraw_handler(struct widget *widget, void *data) time_t rawtime; struct tm * timeinfo; char string[128]; + double scale = clock->panel->scale; + int spacing = DEFAULT_SPACING * scale; time(&rawtime); timeinfo = localtime(&rawtime); @@ -404,11 +409,11 @@ panel_clock_redraw_handler(struct widget *widget, void *data) return; cr = widget_cairo_create(clock->panel->widget); - cairo_set_font_size(cr, 14); + cairo_set_font_size(cr, 14 * scale); cairo_text_extents(cr, string, &extents); if (allocation.x > 0) allocation.x += - allocation.width - DEFAULT_SPACING * 1.5 - extents.width; + allocation.width - spacing * 1.5 - extents.width; else allocation.x += allocation.width / 2 - extents.width / 2; @@ -499,8 +504,10 @@ panel_resize_handler(struct widget *widget, int w = height > width ? width : height; int h = w; int horizontal = panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP || panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM; - int first_pad_h = horizontal ? 0 : DEFAULT_SPACING / 2; - int first_pad_w = horizontal ? DEFAULT_SPACING / 2 : 0; + double scale = panel->scale; + int spacing = DEFAULT_SPACING * scale; + int first_pad_h = horizontal ? 0 : spacing / 2; + int first_pad_w = horizontal ? spacing / 2 : 0; wl_list_for_each(launcher, &panel->launcher_list, link) { widget_set_allocation(launcher->widget, x, y, @@ -513,14 +520,14 @@ panel_resize_handler(struct widget *widget, } if (panel->clock_format == CLOCK_FORMAT_SECONDS) - w = 170; + w = 170 * scale; else /* CLOCK_FORMAT_MINUTES and 24H versions */ - w = 150; + w = 150 * scale; if (horizontal) x = width - w; else - y = height - (h = DEFAULT_SPACING * 3); + y = height - (h = spacing * 3); if (panel->clock) widget_set_allocation(panel->clock->widget, @@ -552,21 +559,21 @@ panel_configure(void *data, switch (desktop->panel_position) { case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: - height = 32; + height = 32 * panel->scale; break; case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: switch (desktop->clock_format) { case CLOCK_FORMAT_NONE: - width = 32; + width = 32 * panel->scale; break; case CLOCK_FORMAT_MINUTES: case CLOCK_FORMAT_MINUTES_24H: case CLOCK_FORMAT_SECONDS_24H: - width = 150; + width = 150 * panel->scale; break; case CLOCK_FORMAT_SECONDS: - width = 170; + width = 170 * panel->scale; break; } break; @@ -636,6 +643,10 @@ panel_create(struct desktop *desktop, struct output *output) s = weston_config_get_section(desktop->config, "shell", NULL, NULL); weston_config_section_get_color(s, "panel-color", &panel->color, 0xaa000000); + weston_config_section_get_double(s, "panel-scale", + &panel->scale, 1.0f); + if (!panel->scale) + panel->scale = 1.0f; panel_add_launchers(panel, desktop); -- 2.20.1