refactor: add shell version to command line option

This commit is contained in:
DanyLE
2025-07-05 19:58:24 +02:00
parent 2a88d12bfa
commit d2ca1732f1
2 changed files with 44 additions and 13 deletions

View File

@ -12,6 +12,7 @@ add_project_arguments(
'-Wno-pedantic', '-Wno-pedantic',
'-Werror=implicit-function-declaration', '-Werror=implicit-function-declaration',
'-Werror=return-type', '-Werror=return-type',
'-D__SHELL_VERSION__="@0@"'.format(meson.project_version())
], ],
language: 'c') language: 'c')

View File

@ -98,22 +98,22 @@ static void diya_shell_reload_theme(DiyaShell *shell)
g_debug("diya_shell_reload_theme: Looking for css file: %s", css_file); g_debug("diya_shell_reload_theme: Looking for css file: %s", css_file);
if (g_file_test(css_file, G_FILE_TEST_EXISTS)) if (g_file_test(css_file, G_FILE_TEST_EXISTS))
{ {
GFile* file = g_file_new_for_path(css_file); GFile *file = g_file_new_for_path(css_file);
gtk_css_provider_load_from_file(priv->css_provider, file); gtk_css_provider_load_from_file(priv->css_provider, file);
g_object_unref(file); g_object_unref(file);
} }
else else
{ {
g_warning("diya_shell_reload_theme: Unable to load CSS from file: %s. Fallback to default theme", css_file); g_warning("diya_shell_reload_theme: Unable to load CSS from file: %s. Fallback to default theme", css_file);
gchar* css_resource = g_strconcat("/dev/iohub/diya/shell/css/", priv->name, ".css", NULL); gchar *css_resource = g_strconcat("/dev/iohub/diya/shell/css/", priv->name, ".css", NULL);
gtk_css_provider_load_from_resource(priv->css_provider, css_resource); gtk_css_provider_load_from_resource(priv->css_provider, css_resource);
g_free(css_resource); g_free(css_resource);
} }
g_free(css_file); g_free(css_file);
gtk_style_context_add_provider_for_display( gtk_style_context_add_provider_for_display(
gdk_display_get_default(), gdk_display_get_default(),
GTK_STYLE_PROVIDER(priv->css_provider), GTK_STYLE_PROVIDER(priv->css_provider),
GTK_STYLE_PROVIDER_PRIORITY_USER); GTK_STYLE_PROVIDER_PRIORITY_USER);
} }
void diya_shell_reload(DiyaShell *self) void diya_shell_reload(DiyaShell *self)
@ -423,6 +423,21 @@ static void diya_shell_class_init(DiyaShellClass *class)
G_TYPE_UINT); G_TYPE_UINT);
} }
static int diya_shell_handle_local_options(GApplication *application, GVariantDict *options, gpointer user_data)
{
(void) application;
(void) user_data;
#ifdef __SHELL_VERSION__
guint32 count;
if (g_variant_dict_lookup(options, "version", "b", &count))
{
g_print("Shell version: %s\n", __SHELL_VERSION__);
return EXIT_SUCCESS;
}
#endif
return -1;
}
int diya_shell_run(DiyaShell *shell, int argc, char **argv) int diya_shell_run(DiyaShell *shell, int argc, char **argv)
{ {
DiyaShellPrivate *priv = diya_shell_get_instance_private(shell); DiyaShellPrivate *priv = diya_shell_get_instance_private(shell);
@ -437,10 +452,25 @@ int diya_shell_run(DiyaShell *shell, int argc, char **argv)
*/ */
// keymap dir // keymap dir
gchar* path = g_strconcat(g_get_user_config_dir(), "/diya/xkb/", NULL); gchar *path = g_strconcat(g_get_user_config_dir(), "/diya/xkb/", NULL);
g_mkdir_with_parents((const gchar *)path, 0755); g_mkdir_with_parents((const gchar *)path, 0755);
g_free(path); g_free(path);
const GOptionEntry cmd_params[] =
{
#ifdef __SHELL_VERSION__
{
.long_name = "version",
.short_name = 'v',
.flags = G_OPTION_FLAG_NONE,
.arg = G_OPTION_ARG_NONE,
.arg_data = NULL,
.description = "Show version information",
.arg_description = NULL,
},
#endif
{NULL}};
g_application_add_main_option_entries(G_APPLICATION(app), cmd_params);
g_signal_connect(app, "handle-local-options", G_CALLBACK(diya_shell_handle_local_options), shell);
int status = g_application_run(G_APPLICATION(app), argc, argv); int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app); g_object_unref(app);
return status; return status;
@ -517,18 +547,18 @@ void diya_shell_unwatch_file(DiyaShell *self, const gchar *file)
} }
} }
void diya_shell_launch(DiyaShell* self, GAppInfo* app) void diya_shell_launch(DiyaShell *self, GAppInfo *app)
{ {
GError* error = NULL; GError *error = NULL;
DiyaShellPrivate *priv = diya_shell_get_instance_private(self); DiyaShellPrivate *priv = diya_shell_get_instance_private(self);
GAppLaunchContext* context = g_app_launch_context_new(); GAppLaunchContext *context = g_app_launch_context_new();
if(priv->theme) if (priv->theme)
{ {
g_app_launch_context_setenv(context, "GTK_THEME", priv->theme); g_app_launch_context_setenv(context, "GTK_THEME", priv->theme);
} }
g_app_info_launch(app, NULL, context, &error); g_app_info_launch(app, NULL, context, &error);
g_object_unref (context); g_object_unref(context);
if(error) if (error)
{ {
g_critical("Unable to launch application: %s", error->message); g_critical("Unable to launch application: %s", error->message);
g_error_free(error); g_error_free(error);