refactor: reorganize theme manager, allow set default theme + default virtual keyboard layout via envar
This commit is contained in:
parent
224252807a
commit
7dab18e121
15
README.md
15
README.md
@ -1,3 +1,18 @@
|
||||
# diya-shell
|
||||
|
||||
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`
|
@ -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);
|
||||
|
48
src/shell.c
48
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);
|
||||
}
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <gtk/gtk.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())
|
||||
G_DECLARE_DERIVABLE_TYPE(DiyaShell, diya_shell, DIYA, SHELL, DiyaObject)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user