From 7dab18e121060743fcbebeeaa17248db24d3d991 Mon Sep 17 00:00:00 2001 From: Dany LE Date: Mon, 16 Jun 2025 11:47:51 +0200 Subject: [PATCH] refactor: reorganize theme manager, allow set default theme + default virtual keyboard layout via envar --- README.md | 17 ++++++++++++++++- src/login-shell.c | 2 +- src/shell.c | 48 +++++++++++++++++++++++++++++++++++++++++++---- src/shell.h | 3 +++ 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2945fe6..61693aa 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # diya-shell -Wayland shell for diyac wayland compositor \ No newline at end of file +Wayland shell for diyac wayland compositor + +# Environment variables + +## Theme + +Default theme can be set using the envar `DIYA_DEFAULT_THEME`, this will cause the shell searching for CSS file theme in +`/home/$USER/.config/diya/themes/`: + +* diya-shell: will looking for file: `dev.iohub.diya.session-shell.css` +* diya-login-shell: will looking for file: `dev.iohub.diya.login-shell.css` + +# Virtual keyboard layout + +Default virtual keyboard keymap can be set via the `DIYA_VKB_KEYMAP` environment variable. When created virtual keyboard, +the shell will search for keymap file in: `/home/$USER/.config/diya/xkb/${DIYA_VKB_KEYMAP}.keymap` \ No newline at end of file diff --git a/src/login-shell.c b/src/login-shell.c index c8a162d..9670345 100644 --- a/src/login-shell.c +++ b/src/login-shell.c @@ -241,7 +241,7 @@ static void add_new_monitor(DiyaLoginShell *self, GdkMonitor *monitor, gint posi gtk_box_set_spacing(GTK_BOX(box), 10); self->revealer = gtk_revealer_new(); - self->vkb_widget = diya_virtual_keyboard_widget_new(diya_shell_get_virtual_keyboard(DIYA_SHELL(self), "fr")); + self->vkb_widget = diya_virtual_keyboard_widget_new(diya_shell_get_virtual_keyboard(DIYA_SHELL(self), g_getenv(DIYA_ENV_VKB_KEYMAP))); gtk_revealer_set_child(GTK_REVEALER(self->revealer), self->vkb_widget); gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), false); gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer),GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP); diff --git a/src/shell.c b/src/shell.c index 152a784..53d4a83 100644 --- a/src/shell.c +++ b/src/shell.c @@ -5,7 +5,7 @@ #include "input.h" #include "files-monior.h" -#define diya_shell_config_css_file(priv) (g_strconcat(g_get_user_config_dir(), "/diya/themes/", priv->name, ".css", NULL)) +#define diya_shell_config_css_file(priv) (g_strconcat(g_get_user_config_dir(), "/diya/themes/", priv->theme?priv->theme:"default", "/", priv->name, ".css", NULL)) enum { @@ -13,6 +13,7 @@ enum PROP_SHELL_WAYLAND, PROP_SHELL_APP, PROP_SHELL_NAME, + PROP_SHELL_THEME, N_PROPERTIES }; @@ -28,6 +29,7 @@ typedef struct _DiyaShellPrivate GtkCssProvider *css_provider; DiyaInput *input; DiyaFilesMonitor *files_watchdog; + gchar *theme; } DiyaShellPrivate; G_DEFINE_TYPE_WITH_PRIVATE(DiyaShell, diya_shell, DIYA_TYPE_OBJECT); @@ -46,6 +48,11 @@ static void diya_shell_dispose(GObject *object) g_free(priv->name); priv->name = NULL; } + if(priv->theme) + { + g_free(priv->theme); + priv->name = NULL; + } if (priv->css_provider) { g_object_unref(priv->css_provider); @@ -67,7 +74,7 @@ static void diya_shell_dispose(GObject *object) } } -static void diya_shell_reload(DiyaShell *shell) +static void diya_shell_reload_theme(DiyaShell *shell) { GError *err = NULL; GBytes *bytes = NULL; @@ -124,12 +131,18 @@ static void diya_shell_reload(DiyaShell *shell) } } +void diya_shell_reload(DiyaShell* self) +{ + diya_shell_reload_theme(self); +} + void on_diya_shell_theme_file_changed(GFileMonitor *monitor, GFile *file, GFile *other, GFileMonitorEvent evtype, gpointer user_data) { (void)monitor; DiyaShell *shell = user_data; char *fpath = g_file_get_path(file); char *opath = NULL; + g_debug("%s event %x", fpath, evtype); if (other) { opath = g_file_get_path(other); @@ -143,10 +156,9 @@ void on_diya_shell_theme_file_changed(GFileMonitor *monitor, GFile *file, GFile case G_FILE_MONITOR_EVENT_MOVED_OUT: //case G_FILE_MONITOR_EVENT_CHANGED: //case G_FILE_MONITOR_EVENT_CREATED: - diya_shell_reload(shell); + diya_shell_reload_theme(shell); break; default: - g_debug("%s event %x", fpath, evtype); break; } if (opath) @@ -163,10 +175,19 @@ static void on_gtk_app_startup(GtkApplication *app, void *data) DiyaShellPrivate *priv = diya_shell_get_instance_private(shell); priv->wayland = diya_wayland_new(DIYA_SHELL(shell)); DiyaShellClass *class = DIYA_SHELL_GET_CLASS(shell); + + // read envar + const char* default_theme = g_getenv(DIYA_ENV_THEME); + if(default_theme) + { + priv->theme = g_strdup(default_theme); + } + gchar *css_file = diya_shell_config_css_file(priv); diya_shell_watch_file(shell, css_file, G_CALLBACK(on_diya_shell_theme_file_changed), (gpointer)shell); g_free(css_file); diya_shell_reload(shell); + if (class->startup_handle) { class->startup_handle(shell); @@ -237,6 +258,20 @@ static void diya_shell_set_property(GObject *object, guint property_id, const GV priv->name = g_strdup(g_value_get_string(value)); init_gtk_application(self); break; + case PROP_SHELL_THEME: + { + const gchar* theme = g_value_get_string(value); + if(!priv->theme || !g_str_equal(priv->theme, theme)) + { + if(priv->theme) + { + g_free(priv->theme); + } + priv->theme = g_strdup(theme); + diya_shell_reload_theme(self); + } + break; + } default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; @@ -258,6 +293,9 @@ static void diya_shell_get_property(GObject *object, guint property_id, GValue * case PROP_SHELL_NAME: g_value_set_string(value, priv->name); break; + case PROP_SHELL_THEME: + g_value_set_string(value, priv->theme); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; @@ -274,6 +312,7 @@ static void diya_shell_init(DiyaShell *self) priv->css_provider = NULL; priv->input = NULL; priv->files_watchdog = NULL; + priv->theme = NULL; } DiyaWayland *diya_shell_get_wayland(DiyaShell *shell) @@ -321,6 +360,7 @@ static void diya_shell_class_init(DiyaShellClass *class) shell_properties[PROP_SHELL_WAYLAND] = g_param_spec_pointer("wayland", NULL, "Shell wayland", G_PARAM_READABLE); // shell_properties[PROP_SHELL_NAME] = g_param_spec_string("name", NULL, "Shell name", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); shell_properties[PROP_SHELL_APP] = g_param_spec_pointer("application", NULL, "Shell application", G_PARAM_READABLE); + shell_properties[PROP_SHELL_THEME] = g_param_spec_string("theme", NULL, "Shell theme", NULL, G_PARAM_READWRITE); g_object_class_install_properties(gobject_class, N_PROPERTIES, shell_properties); } diff --git a/src/shell.h b/src/shell.h index a9d4b45..8521790 100644 --- a/src/shell.h +++ b/src/shell.h @@ -5,6 +5,9 @@ #include #include "base.h" +#define DIYA_ENV_THEME "DIYA_DEFAULT_THEME" +#define DIYA_ENV_VKB_KEYMAP "DIYA_VKB_KEYMAP" + #define DIYA_TYPE_SHELL (diya_shell_get_type()) G_DECLARE_DERIVABLE_TYPE(DiyaShell, diya_shell, DIYA, SHELL, DiyaObject)