1From a9aadf9c310805dd43866c494b01ce891158eedd Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Thu, 2 Jun 2022 19:00:40 +0800 4Subject: [PATCH 68/79] desktop-shell: Support setting panel scale in 5 weston.ini 6 7Tested with: 8[shell] 9panel-scale=2 10 11Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 12--- 13 clients/desktop-shell.c | 41 ++++++++++++++++++++++++++--------------- 14 1 file changed, 26 insertions(+), 15 deletions(-) 15 16diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c 17index 6cf21da..a81eb0a 100644 18--- a/clients/desktop-shell.c 19+++ b/clients/desktop-shell.c 20@@ -109,6 +109,7 @@ struct panel { 21 enum weston_desktop_shell_panel_position panel_position; 22 enum clock_format clock_format; 23 uint32_t color; 24+ double scale; 25 }; 26 27 struct background { 28@@ -242,17 +243,18 @@ panel_launcher_redraw_handler(struct widget *widget, void *data) 29 { 30 struct panel_launcher *launcher = data; 31 struct rectangle allocation; 32+ double scale = launcher->panel->scale; 33 cairo_t *cr; 34 35 cr = widget_cairo_create(launcher->panel->widget); 36 37 widget_get_allocation(widget, &allocation); 38 allocation.x += allocation.width / 2 - 39- cairo_image_surface_get_width(launcher->icon) / 2; 40+ cairo_image_surface_get_width(launcher->icon) * scale / 2; 41 if (allocation.width > allocation.height) 42 allocation.x += allocation.width / 2 - allocation.height / 2; 43 allocation.y += allocation.height / 2 - 44- cairo_image_surface_get_height(launcher->icon) / 2; 45+ cairo_image_surface_get_height(launcher->icon) * scale / 2; 46 if (allocation.height > allocation.width) 47 allocation.y += allocation.height / 2 - allocation.width / 2; 48 if (launcher->pressed) { 49@@ -260,14 +262,15 @@ panel_launcher_redraw_handler(struct widget *widget, void *data) 50 allocation.y++; 51 } 52 53+ cairo_scale(cr, scale, scale); 54 cairo_set_source_surface(cr, launcher->icon, 55- allocation.x, allocation.y); 56+ allocation.x / scale, allocation.y / scale); 57 cairo_paint(cr); 58 59 if (launcher->focused) { 60 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); 61 cairo_mask_surface(cr, launcher->icon, 62- allocation.x, allocation.y); 63+ allocation.x / scale, allocation.y / scale); 64 } 65 66 cairo_destroy(cr); 67@@ -394,6 +397,8 @@ panel_clock_redraw_handler(struct widget *widget, void *data) 68 time_t rawtime; 69 struct tm * timeinfo; 70 char string[128]; 71+ double scale = clock->panel->scale; 72+ int spacing = DEFAULT_SPACING * scale; 73 74 time(&rawtime); 75 timeinfo = localtime(&rawtime); 76@@ -404,11 +409,11 @@ panel_clock_redraw_handler(struct widget *widget, void *data) 77 return; 78 79 cr = widget_cairo_create(clock->panel->widget); 80- cairo_set_font_size(cr, 14); 81+ cairo_set_font_size(cr, 14 * scale); 82 cairo_text_extents(cr, string, &extents); 83 if (allocation.x > 0) 84 allocation.x += 85- allocation.width - DEFAULT_SPACING * 1.5 - extents.width; 86+ allocation.width - spacing * 1.5 - extents.width; 87 else 88 allocation.x += 89 allocation.width / 2 - extents.width / 2; 90@@ -499,8 +504,10 @@ panel_resize_handler(struct widget *widget, 91 int w = height > width ? width : height; 92 int h = w; 93 int horizontal = panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP || panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM; 94- int first_pad_h = horizontal ? 0 : DEFAULT_SPACING / 2; 95- int first_pad_w = horizontal ? DEFAULT_SPACING / 2 : 0; 96+ double scale = panel->scale; 97+ int spacing = DEFAULT_SPACING * scale; 98+ int first_pad_h = horizontal ? 0 : spacing / 2; 99+ int first_pad_w = horizontal ? spacing / 2 : 0; 100 101 wl_list_for_each(launcher, &panel->launcher_list, link) { 102 widget_set_allocation(launcher->widget, x, y, 103@@ -513,14 +520,14 @@ panel_resize_handler(struct widget *widget, 104 } 105 106 if (panel->clock_format == CLOCK_FORMAT_SECONDS) 107- w = 170; 108+ w = 170 * scale; 109 else /* CLOCK_FORMAT_MINUTES and 24H versions */ 110- w = 150; 111+ w = 150 * scale; 112 113 if (horizontal) 114 x = width - w; 115 else 116- y = height - (h = DEFAULT_SPACING * 3); 117+ y = height - (h = spacing * 3); 118 119 if (panel->clock) 120 widget_set_allocation(panel->clock->widget, 121@@ -552,21 +559,21 @@ panel_configure(void *data, 122 switch (desktop->panel_position) { 123 case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: 124 case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: 125- height = 32; 126+ height = 32 * panel->scale; 127 break; 128 case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: 129 case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: 130 switch (desktop->clock_format) { 131 case CLOCK_FORMAT_NONE: 132- width = 32; 133+ width = 32 * panel->scale; 134 break; 135 case CLOCK_FORMAT_MINUTES: 136 case CLOCK_FORMAT_MINUTES_24H: 137 case CLOCK_FORMAT_SECONDS_24H: 138- width = 150; 139+ width = 150 * panel->scale; 140 break; 141 case CLOCK_FORMAT_SECONDS: 142- width = 170; 143+ width = 170 * panel->scale; 144 break; 145 } 146 break; 147@@ -636,6 +643,10 @@ panel_create(struct desktop *desktop, struct output *output) 148 s = weston_config_get_section(desktop->config, "shell", NULL, NULL); 149 weston_config_section_get_color(s, "panel-color", 150 &panel->color, 0xaa000000); 151+ weston_config_section_get_double(s, "panel-scale", 152+ &panel->scale, 1.0f); 153+ if (!panel->scale) 154+ panel->scale = 1.0f; 155 156 panel_add_launchers(panel, desktop); 157 158-- 1592.20.1 160 161