enkore / j4-dmenu-desktop

A fast desktop menu
GNU General Public License v3.0
672 stars 70 forks source link

Append arguments to .desktop Exec #168

Open Slider-Whistle opened 1 month ago

Slider-Whistle commented 1 month ago

Hi, say I've got the following .desktop file: (I don't actually load my Doom through Steam, but it naturally applies to other use-cases)

[Desktop Entry]
Name=Doom
Comment=Play this game on Steam
Exec=steam -applaunch 2280
Icon=steam_icon_2280
Terminal=false
Type=Application
Categories=Game;

When I enter the text Doom -warp e1m1, I think it would be nice if j4-dmenu-desktop treated the Exec line as though it looked like this: (In case you're unfamiliar, this argument makes Doom skip the title screen and start the player in a given level)

Exec=steam -applaunch 2280 -warp e1m1

What do you think, might be pretty cool?

meator commented 1 month ago

This mechanism (or a very similar one) is already implemented in j4-dmenu-desktop. j4-dmenu-desktop handles arguments for desktop files whose Exec fields includes the %f, %F, %u or %U field codes (as the XDG specification mandates). j4-dmenu-desktop's implementation isn't exactly to the spec, it just replaces the field code with arguments given to Dmenu by the user. This means that with the following slightly modified desktop file:

[Desktop Entry]
Name=Doom
Comment=Play this game on Steam
Exec=steam -applaunch 2280 %F
Icon=steam_icon_2280
Terminal=false
Type=Application
Categories=Game;

You can achieve what you want. Note that the whole name of the desktop app has to be provided. This works as expected in the default mode, but if you use something like --display-binary, Doom entry will become Doom (steam), so you'll have to type Doom (steam) -warp e1m1 (tab completion of Dmenu will help you).

This feature has been in j4-dmenu-desktop for a long time (I have verified it works on version r2.18).

The second easiest solution is to make a custom desktop file:

[Desktop Entry]
Name=Doom skip
Comment=Play this modified game on Steam
Exec=steam -applaunch 2280 -warp e1m1
Icon=steam_icon_2280
Terminal=false
Type=Application
Categories=Game;

I believe this is the best solution if you want to launch the program with this set of flags often and if you don't want to retype -warp e1m1 every time you want to execute Doom.

You can put these custom desktop files in ~/.local/share/applications/ (or wherever in your $XDG_DATA_HOME or $XDG_DATA_DIRS) instead of system directories if you don't want to mess with system directories.

Specifying arguments currently works only for desktop files with % field codes mentioned above. This means that it won't work with the desktop file you have provided in the issue. I don't think that adding support for supplying arguments to any desktop app is a critical feature. I have outlined two alternative functional ways to solve the problem above, so it is possible to achieve what you want without changing j4-dmenu-desktop. Because of this, I don't think that I'll be working on implementing this feature in the near future. This doesn't mean that it will never get implemented, if any other useful use cases come up or if more people will request this feature or react to this issue, I might reconsider. Also, this mechanism is already implemented for % field codes, so it shouldn't be that hard to change the code to add support for it for all desktop apps.

Because of this issue, I have looked deeper into the argument handling mechanism and "accidentally" found a bug: #169. It is not thankfully present in any released version of j4-dmenu-desktop, but I was planning to release version r3.1 soon, which would have included this bug if I hadn't found it. So thanks for that.

Slider-Whistle commented 1 month ago

On Wed, 10 Jul 2024 12:09:41 -0700 meator @.***> wrote:

%f, %F, %u or %U field codes

Whoops! It's been so long since I've dealt with .desktop files that I forgot those existed. Yeah that's plenty for me, I wouldn't encourage you adding anything outside of spec when the feature is basically already there. I do think it's kind of weird how there isn't always an implied one at the end of an Exec line, but that's something I'd take up more with XDG I guess. Thanks for the heads up, and I'm glad I could accidentally be some help.