From d2ca1732f1c6905d7acabfac99c82dffaec91efb Mon Sep 17 00:00:00 2001 From: DanyLE Date: Sat, 5 Jul 2025 19:58:24 +0200 Subject: [PATCH] refactor: add shell version to command line option --- meson.build | 1 + src/shell.c | 56 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index dd1016b..89f3a1f 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ add_project_arguments( '-Wno-pedantic', '-Werror=implicit-function-declaration', '-Werror=return-type', + '-D__SHELL_VERSION__="@0@"'.format(meson.project_version()) ], language: 'c') diff --git a/src/shell.c b/src/shell.c index 1b3a929..8a49205 100644 --- a/src/shell.c +++ b/src/shell.c @@ -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); 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); g_object_unref(file); } else { 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); g_free(css_resource); } g_free(css_file); gtk_style_context_add_provider_for_display( - gdk_display_get_default(), - GTK_STYLE_PROVIDER(priv->css_provider), - GTK_STYLE_PROVIDER_PRIORITY_USER); + gdk_display_get_default(), + GTK_STYLE_PROVIDER(priv->css_provider), + GTK_STYLE_PROVIDER_PRIORITY_USER); } void diya_shell_reload(DiyaShell *self) @@ -423,6 +423,21 @@ static void diya_shell_class_init(DiyaShellClass *class) 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) { DiyaShellPrivate *priv = diya_shell_get_instance_private(shell); @@ -437,10 +452,25 @@ int diya_shell_run(DiyaShell *shell, int argc, char **argv) */ // 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_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); g_object_unref(app); 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); - GAppLaunchContext* context = g_app_launch_context_new(); - if(priv->theme) + GAppLaunchContext *context = g_app_launch_context_new(); + if (priv->theme) { g_app_launch_context_setenv(context, "GTK_THEME", priv->theme); } g_app_info_launch(app, NULL, context, &error); - g_object_unref (context); - if(error) + g_object_unref(context); + if (error) { g_critical("Unable to launch application: %s", error->message); g_error_free(error);