refactor: reorganize theme manager, allow set default theme + default virtual keyboard layout via envar

This commit is contained in:
DL 2025-06-16 11:47:51 +02:00
parent 224252807a
commit 7dab18e121
4 changed files with 64 additions and 6 deletions

View File

@ -1,3 +1,18 @@
# diya-shell # diya-shell
Wayland shell for diyac wayland compositor 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`

View File

@ -241,7 +241,7 @@ static void add_new_monitor(DiyaLoginShell *self, GdkMonitor *monitor, gint posi
gtk_box_set_spacing(GTK_BOX(box), 10); gtk_box_set_spacing(GTK_BOX(box), 10);
self->revealer = gtk_revealer_new(); 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_child(GTK_REVEALER(self->revealer), self->vkb_widget);
gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), false); 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); gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer),GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);

View File

@ -5,7 +5,7 @@
#include "input.h" #include "input.h"
#include "files-monior.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 enum
{ {
@ -13,6 +13,7 @@ enum
PROP_SHELL_WAYLAND, PROP_SHELL_WAYLAND,
PROP_SHELL_APP, PROP_SHELL_APP,
PROP_SHELL_NAME, PROP_SHELL_NAME,
PROP_SHELL_THEME,
N_PROPERTIES N_PROPERTIES
}; };
@ -28,6 +29,7 @@ typedef struct _DiyaShellPrivate
GtkCssProvider *css_provider; GtkCssProvider *css_provider;
DiyaInput *input; DiyaInput *input;
DiyaFilesMonitor *files_watchdog; DiyaFilesMonitor *files_watchdog;
gchar *theme;
} DiyaShellPrivate; } DiyaShellPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(DiyaShell, diya_shell, DIYA_TYPE_OBJECT); 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); g_free(priv->name);
priv->name = NULL; priv->name = NULL;
} }
if(priv->theme)
{
g_free(priv->theme);
priv->name = NULL;
}
if (priv->css_provider) if (priv->css_provider)
{ {
g_object_unref(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; GError *err = NULL;
GBytes *bytes = 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 on_diya_shell_theme_file_changed(GFileMonitor *monitor, GFile *file, GFile *other, GFileMonitorEvent evtype, gpointer user_data)
{ {
(void)monitor; (void)monitor;
DiyaShell *shell = user_data; DiyaShell *shell = user_data;
char *fpath = g_file_get_path(file); char *fpath = g_file_get_path(file);
char *opath = NULL; char *opath = NULL;
g_debug("%s event %x", fpath, evtype);
if (other) if (other)
{ {
opath = g_file_get_path(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_MOVED_OUT:
//case G_FILE_MONITOR_EVENT_CHANGED: //case G_FILE_MONITOR_EVENT_CHANGED:
//case G_FILE_MONITOR_EVENT_CREATED: //case G_FILE_MONITOR_EVENT_CREATED:
diya_shell_reload(shell); diya_shell_reload_theme(shell);
break; break;
default: default:
g_debug("%s event %x", fpath, evtype);
break; break;
} }
if (opath) if (opath)
@ -163,10 +175,19 @@ static void on_gtk_app_startup(GtkApplication *app, void *data)
DiyaShellPrivate *priv = diya_shell_get_instance_private(shell); DiyaShellPrivate *priv = diya_shell_get_instance_private(shell);
priv->wayland = diya_wayland_new(DIYA_SHELL(shell)); priv->wayland = diya_wayland_new(DIYA_SHELL(shell));
DiyaShellClass *class = DIYA_SHELL_GET_CLASS(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); 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); diya_shell_watch_file(shell, css_file, G_CALLBACK(on_diya_shell_theme_file_changed), (gpointer)shell);
g_free(css_file); g_free(css_file);
diya_shell_reload(shell); diya_shell_reload(shell);
if (class->startup_handle) if (class->startup_handle)
{ {
class->startup_handle(shell); 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)); priv->name = g_strdup(g_value_get_string(value));
init_gtk_application(self); init_gtk_application(self);
break; 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: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break; break;
@ -258,6 +293,9 @@ static void diya_shell_get_property(GObject *object, guint property_id, GValue *
case PROP_SHELL_NAME: case PROP_SHELL_NAME:
g_value_set_string(value, priv->name); g_value_set_string(value, priv->name);
break; break;
case PROP_SHELL_THEME:
g_value_set_string(value, priv->theme);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break; break;
@ -274,6 +312,7 @@ static void diya_shell_init(DiyaShell *self)
priv->css_provider = NULL; priv->css_provider = NULL;
priv->input = NULL; priv->input = NULL;
priv->files_watchdog = NULL; priv->files_watchdog = NULL;
priv->theme = NULL;
} }
DiyaWayland *diya_shell_get_wayland(DiyaShell *shell) 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_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_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_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); g_object_class_install_properties(gobject_class, N_PROPERTIES, shell_properties);
} }

View File

@ -5,6 +5,9 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "base.h" #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()) #define DIYA_TYPE_SHELL (diya_shell_get_type())
G_DECLARE_DERIVABLE_TYPE(DiyaShell, diya_shell, DIYA, SHELL, DiyaObject) G_DECLARE_DERIVABLE_TYPE(DiyaShell, diya_shell, DIYA, SHELL, DiyaObject)