refactor: add shell version to command line option
This commit is contained in:
@ -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')
|
||||
|
||||
|
50
src/shell.c
50
src/shell.c
@ -98,14 +98,14 @@ 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);
|
||||
}
|
||||
@ -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);
|
||||
|
Reference in New Issue
Block a user