From 912083774205cb193fb6d93031a30cf469d2c52f Mon Sep 17 00:00:00 2001 From: neyfag <11970-neyfag@users.noreply.gitlab.gnome.org> Date: Fri, 10 Apr 2020 20:19:05 +0200 Subject: [PATCH] patch for autostart applications --- xfce4-session/xfsm-global.c | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/xfce4-session/xfsm-global.c b/xfce4-session/xfsm-global.c index 1f8a182..4c1ad50 100644 --- a/xfce4-session/xfsm-global.c +++ b/xfce4-session/xfsm-global.c @@ -55,6 +55,10 @@ #include +#define STR_IS_EMPTY(str) ((str) == NULL || *(str) == '\0') +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif /* global variables */ gboolean verbose = FALSE; @@ -262,7 +266,16 @@ xfsm_launch_desktop_files_on_login (gboolean start_at_spi) return xfsm_launch_desktop_files_on_run_hook (start_at_spi, XFSM_RUN_HOOK_LOGIN); } +static void +xfsm_global_append_quoted (GString *string, + const gchar *unquoted) +{ + gchar *quoted; + quoted = g_shell_quote (unquoted); + g_string_append (string, quoted); + g_free (quoted); +} gint xfsm_launch_desktop_files_on_run_hook (gboolean start_at_spi, @@ -284,6 +297,11 @@ xfsm_launch_desktop_files_on_run_hook (gboolean start_at_spi, gint n, m; gchar *filename; const gchar *pattern; + GString *string = NULL; + gchar uri[PATH_MAX]; + const gchar *icon; + const gchar *name; + const gchar *p; /* pattern for only at-spi desktop files or everything */ if (start_at_spi) @@ -386,6 +404,55 @@ xfsm_launch_desktop_files_on_run_hook (gboolean start_at_spi, /* execute the item */ exec = xfce_rc_read_entry (rc, "Exec", NULL); + + /* expand the field codes */ + string = g_string_sized_new (100); + for (p = exec; *p != '\0'; ++p) + { + if (G_UNLIKELY (p[0] == '%' && p[1] != '\0')) + { + switch (*++p) + { + case 'f': case 'F': + case 'u': case 'U': + /* TODO for dnd, not a regression, xfdesktop never had this */ + break; + + case 'i': + icon = xfce_rc_read_entry (rc, "Icon", NULL); + if (!STR_IS_EMPTY (icon)) + { + g_string_append (string, "--icon "); + xfsm_global_append_quoted (string, icon); + } + break; + + case 'c': + name = xfce_rc_read_entry (rc, "Name", NULL); + if (!STR_IS_EMPTY (name)) + xfsm_global_append_quoted (string, name); + break; + + case 'k': + if (!STR_IS_EMPTY (files[n])) + { + g_snprintf(uri,PATH_MAX,"%s%s%s%s", "file://", xfce_get_homedir(), "/", files[n]); + xfsm_global_append_quoted (string, uri); + } + break; + + case '%': + g_string_append_c (string, '%'); + break; + } + } + else + { + g_string_append_c (string, *p); + } + } + exec = string->str; + if (G_LIKELY (!skip && exec != NULL)) { /* query launch parameters */ @@ -415,6 +482,7 @@ xfsm_launch_desktop_files_on_run_hook (gboolean start_at_spi, xfce_rc_close (rc); } g_strfreev (files); + g_string_free (string, TRUE); return started; } -- 2.26.0