hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
From 33877c8f9403d33b514fc67bce3602b0e515b242 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
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 <jeffy.chen@rock-chips.com>
---
 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