! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Inconsistent behavior between autostart and applications for desktop files
Status:
RESOLVED: MOVED
Product:
Xfce4-session
Component:
General

Comments

Description Tamaranch 2020-04-06 00:55:10 CEST
The percentage character ("%") is not treated the same way when appearing in a desktop file put in ~/.config/autostart or ~/.local/share/applications.
With this simple example :

[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=testcmd
Comment=
Exec=xfce4-terminal -H -x echo %%
OnlyShowIn=XFCE;
RunHook=0
StartupNotify=false
Terminal=false
Hidden=false

When this desktop file is put in ~/.local/share/applications, and "executed" by "gtk-launch testcmd", a terminal appears with "%" as content (expected behavior).
When this desktop file is put in ~/.config/autostart, and the desktop session restarted, a terminal appears with "%%" as content (unexpected behavior).

I think the good behavior is the first one, but at least, it should be the same in both cases.
Comment 1 Theo Linkspfeifer editbugs 2020-04-06 12:30:28 CEST
This is called field code expansion. See:
https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html

I assume that xfce4-session does not do this type of evaluation because it seems unnecessary for autostart launchers.
Comment 2 Tamaranch 2020-04-06 16:13:05 CEST
Yes, I know this is called "field code expansion": I read the specification. :)
That's why I said "expected behavior" in the first case ("%%" gives "%" on display), but not in the second one.

However, I'm not agree with you when you say that "this type of evaluation […] seems unnecessary for autostart launchers".
The percentage character can appear in option fields of many commands, like "top -o%MEM".
So if you have in your desktop file

Exec=xfce4-terminal -H -x top -o%MEM

or a more complex command, like

Exec=sh -c '… if [ … ]; then xfce4-terminal -H -x top -o%MEM; fi …'

the launcher will work as autostart application (when put in ~/.config/autostart), but not in an active session (when put in ~/.local/share/applications).

Furthermore, if you remove the line

OnlyShowIn=XFCE;

to use the launcher as autostart application with an other desktop environment, like gnome, it will not work, because gnome has consistent behavior between autostart and applications menu: I tested this.
Comment 3 Theo Linkspfeifer editbugs 2020-04-06 17:40:37 CEST
Would you be able to provide a patch?
Comment 4 Tamaranch 2020-04-06 18:15:01 CEST
Well, I haven't thought about it.
I would have to clone the repository, dive into the code, and see what I can do.
It is not impossible that I could provide something in the end, but I have no idea when! :D
But hey, why not: if it's not a priority, and nobody has the time to take care of it, I can try to have a look. :)
(concerning the result,I don't promise anything though)
Comment 5 Tamaranch 2020-04-10 20:26:12 CEST
Created attachment 9691 
patch for autostart applications
Comment 6 Tamaranch 2020-04-10 20:26:57 CEST
Created attachment 9692 
test file
Comment 7 Tamaranch 2020-04-10 20:28:01 CEST
Well, I think I have a patch, but with minimum work: this is essentially an adapted copy of the part called "/* expand the field codes */" in garcon/garcon-gtk/garcon-gtk-menu.c (line 383), to the function xfsm_launch_desktop_files_on_run_hook in xfce4-session/xfce4-session/xfsm-global.c

I think (not sure) that a better way to do it would be to directly use garcon, as it is done in xfce4-panel, but I feel like it's significantly more work.

I have attached the patch and a test file.
Comment 8 Theo Linkspfeifer editbugs 2020-04-13 14:22:10 CEST
Thanks for the patch. I will give it a try soon.

Maybe the code could be moved to libxfce4util/xfce-miscutils.c which contains a similar function xfce_expand_variables().
Comment 9 Tamaranch 2020-05-11 11:26:06 CEST
Created attachment 9851 
0001-Patch-for-autostart-applications.patch

Change author in case of commit.
Comment 10 Git Bot editbugs 2020-05-26 00:51:47 CEST
-- GitLab Migration Automatic Message --

This bug has been migrated to xfce.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.xfce.org/xfce/xfce4-session/-/issues/64.

Please create an account or use an existing account on one of our supported OAuth providers. 

If you want to fork to submit patches and merge requests please continue reading here: https://docs.xfce.org/contribute/dev/git/start#gitlab_forks_and_merge_requests

Also feel free to reach out to us on the mailing list https://mail.xfce.org/mailman/listinfo/xfce4-dev

Bug #16642

Reported by:
Tamaranch
Reported on: 2020-04-06
Last modified on: 2020-05-26

People

Assignee:
Xfce Bug Triage
CC List:
2 users

Version

Version:
4.14.2

Attachments

patch for autostart applications (3.56 KB, patch)
2020-04-10 20:26 CEST , Tamaranch
no flags
test file (285 bytes, application/x-desktop)
2020-04-10 20:26 CEST , Tamaranch
no flags
0001-Patch-for-autostart-applications.patch (3.56 KB, patch)
2020-05-11 11:26 CEST , Tamaranch
no flags

Additional information