HYL_OK3568_LINUX/buildroot/package/weston/0070-desktop-shell-Support-clock-without-date.patch
2025-05-10 21:49:39 +08:00

176 lines
4.7 KiB
Diff

From 51d94d3310b0ced9a57b99ba7f2d64f114413f1f Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Wed, 15 Jun 2022 11:02:44 +0800
Subject: [PATCH 70/92] desktop-shell: Support clock without date
Tested with:
[shell]
clock-with-date=false
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
clients/desktop-shell.c | 73 ++++++++++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 23 deletions(-)
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 2a1e70e..0ce571a 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -76,6 +76,7 @@ struct desktop {
int want_panel;
enum weston_desktop_shell_panel_position panel_position;
enum clock_format clock_format;
+ bool clock_with_date;
struct window *grab_window;
struct widget *grab_widget;
@@ -109,6 +110,7 @@ struct panel {
int painted;
enum weston_desktop_shell_panel_position panel_position;
enum clock_format clock_format;
+ bool clock_with_date;
uint32_t color;
double scale;
};
@@ -157,7 +159,7 @@ struct panel_clock {
struct widget *widget;
struct panel *panel;
struct toytimer timer;
- char *format_string;
+ char format_string[128];
time_t refresh_timer;
};
@@ -170,6 +172,36 @@ struct unlock_dialog {
struct desktop *desktop;
};
+static int
+clock_get_preferred_width(enum clock_format clock_format, bool with_date)
+{
+ int width;
+
+ switch (clock_format) {
+ case CLOCK_FORMAT_NONE:
+ return 0;
+ case CLOCK_FORMAT_MINUTES:
+ width = 160;
+ break;
+ case CLOCK_FORMAT_MINUTES_24H:
+ width = 130;
+ break;
+ case CLOCK_FORMAT_SECONDS:
+ width = 180;
+ break;
+ case CLOCK_FORMAT_SECONDS_24H:
+ width = 160;
+ break;
+ default:
+ assert(!"not reached");
+ }
+
+ if (!with_date)
+ width -= 80;
+
+ return width;
+}
+
static void
panel_add_launchers(struct panel *panel, struct desktop *desktop);
@@ -413,7 +445,7 @@ panel_clock_redraw_handler(struct widget *widget, void *data)
cairo_text_extents(cr, string, &extents);
if (allocation.x > 0)
allocation.x +=
- allocation.width - spacing * 1.5 - extents.width;
+ allocation.width - spacing - extents.width;
else
allocation.x +=
allocation.width / 2 - extents.width / 2;
@@ -464,21 +496,24 @@ panel_add_clock(struct panel *panel)
clock->panel = panel;
panel->clock = clock;
+ if (panel->clock_with_date)
+ strcpy(clock->format_string, "%a %b %d, ");
+
switch (panel->clock_format) {
case CLOCK_FORMAT_MINUTES:
- clock->format_string = "%a %b %d, %I:%M %p";
+ strcat(clock->format_string, "%I:%M %p");
clock->refresh_timer = 60;
break;
case CLOCK_FORMAT_SECONDS:
- clock->format_string = "%a %b %d, %I:%M:%S %p";
+ strcat(clock->format_string, "%I:%M:%S %p");
clock->refresh_timer = 1;
break;
case CLOCK_FORMAT_MINUTES_24H:
- clock->format_string = "%a %b %d, %H:%M";
+ strcat(clock->format_string, "%H:%M");
clock->refresh_timer = 60;
break;
case CLOCK_FORMAT_SECONDS_24H:
- clock->format_string = "%a %b %d, %H:%M:%S";
+ strcat(clock->format_string, "%H:%M:%S");
clock->refresh_timer = 1;
break;
case CLOCK_FORMAT_NONE:
@@ -519,10 +554,8 @@ panel_resize_handler(struct widget *widget,
first_pad_h = first_pad_w = 0;
}
- if (panel->clock_format == CLOCK_FORMAT_SECONDS)
- w = 170 * scale;
- else /* CLOCK_FORMAT_MINUTES and 24H versions */
- w = 150 * scale;
+ w = clock_get_preferred_width(panel->clock_format,
+ panel->clock_with_date) * scale;
if (horizontal)
x = width - w;
@@ -563,19 +596,9 @@ panel_configure(void *data,
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 * panel->scale;
- break;
- case CLOCK_FORMAT_MINUTES:
- case CLOCK_FORMAT_MINUTES_24H:
- case CLOCK_FORMAT_SECONDS_24H:
- width = 150 * panel->scale;
- break;
- case CLOCK_FORMAT_SECONDS:
- width = 170 * panel->scale;
- break;
- }
+ width = clock_get_preferred_width(desktop->clock_format,
+ desktop->clock_with_date);
+ width = MAX(32, width) * panel->scale;
break;
}
window_schedule_resize(panel->window, width, height);
@@ -637,6 +660,7 @@ panel_create(struct desktop *desktop, struct output *output)
panel->panel_position = desktop->panel_position;
panel->clock_format = desktop->clock_format;
+ panel->clock_with_date = desktop->clock_with_date;
if (panel->clock_format != CLOCK_FORMAT_NONE)
panel_add_clock(panel);
@@ -1522,6 +1546,9 @@ parse_clock_format(struct desktop *desktop, struct weston_config_section *s)
else
desktop->clock_format = DEFAULT_CLOCK_FORMAT;
free(clock_format);
+
+ weston_config_section_get_bool(s, "clock-with-date",
+ &desktop->clock_with_date, true);
}
int main(int argc, char *argv[])
--
2.20.1