Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to add environment variables to every game #262

Open
Mammad900 opened this issue May 16, 2024 · 7 comments
Open

Option to add environment variables to every game #262

Mammad900 opened this issue May 16, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@Mammad900
Copy link

Mammad900 commented May 16, 2024

Is your feature request related to a problem? Please describe.
I need to add some environment variables to be able to launch my games using my dGPU:

env DRI_PRIME=1 __NV_SHOW_GRAPHICS_OSD=1 __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia <executable>

Right now I have to add these variables in every game's command, which is cumbersome. The long text also makes the executable field harder to use.

Describe the solution you'd like
An option to set some environment variables in one place that applies to every game would be appreciated.

Describe alternatives you've considered
This can be extended to adding any string to the start of the executables but I'm not sure if there's any use case for that.

Additional context
Add any other context or screenshots about the feature request here.

@Mammad900 Mammad900 added the enhancement New feature or request label May 16, 2024
@Mammad900
Copy link
Author

I have found a better alternative for GPU environment variables:
Adding these lines to the .desktop file will make the user's DE launch cartridges (and by extension any games launched from it) on the discrete graphics, no need to set environment variables in the command.

PrefersNonDefaultGPU=true
X-KDE-RunOnDiscreteGpu=true 

Copied from Steam's .desktop file

@kra-mo
Copy link
Owner

kra-mo commented Dec 5, 2024

Would adding the environment variable to Cartridges itself using something like Flatseal not be enough? I'd rather not overcomplicate the UI.

@kra-mo
Copy link
Owner

kra-mo commented Dec 5, 2024

And I suppose could add the desktop entry key, but I'm not sure if there could be any adverse side effects? If not, I'm all for it.

@Mammad900
Copy link
Author

Mammad900 commented Dec 6, 2024

Would adding the environment variable to Cartridges itself using something like Flatseal not be enough? I'd rather not overcomplicate the UI.

Didn't know/think about this. It's probably a suitable option.

As a side note (should probably be a separate issue) word wrap in the executable field of games would be a godsend. Right now I sometimes have to edit the command in a text editor or terminal and paste it in Cartridges.

And I suppose could add the desktop entry key, but I'm not sure if there could be any adverse side effects? If not, I'm all for it.

I haven't noticed any side effects myself, and I predict it's going to be fine for others too since steam does fine. But other users' mileage may vary.
Maybe you could add it in a beta/experimental release and see if it has any side effects?

@kra-mo
Copy link
Owner

kra-mo commented Dec 6, 2024

As a side note (should probably be a separate issue) word wrap in the executable field of games would be a godsend. Right now I sometimes have to edit the command in a text editor or terminal and paste it in Cartridges.

That's true yeah, I should probably make it more modular or just add the ability to open it in your preferred text editor directly.

 Maybe you could add it in a beta/experimental release and see if it has any side effects?

I don't do those, but it would be nice to collect feedback somewhere.

@michaelneverwins
Copy link

michaelneverwins commented Jan 18, 2025

Adding these lines to the .desktop file will make the user's DE launch cartridges (and by extension any games launched from it) on the discrete graphics, no need to set environment variables in the command.

Have you verified that this (specifically the "any games launched from it" part) actually works with Cartridges? It doesn't seem to be working for me.

I already know that my Linux Mint 22 system supports PrefersNonDefaultGPU=true in general, because I've seen it work. The desktop entry for SuperTuxKart, for example, has PrefersNonDefaultGPU=true. If I have my integrated graphics chip enabled and set as my default graphics device, then using that desktop entry for SuperTuxKart allows the game to use my discrete GPU, whereas simply running supertuxkart from the command line does not. (It's fairly obvious when SuperTuxKart is using my integrated graphics, because the frame rate is worse, which also makes it a good example for testing.)

However, I added PrefersNonDefaultGPU=true to my desktop entry for Cartridges (and also changed Name=Cartridges to Name=Cartridges! to be sure that I was seeing the updated entry in my menu), and if I launch Cartridges from that updated desktop entry and then launch SuperTuxKart from Cartridges, the game uses my integrated graphics. Note that I imported SuperTuxKart into Cartridges from a desktop entry, so the command it runs is gio launch /usr/share/applications/supertuxkart.desktop.* Just for good measure, I added the game again manually such that it just runs supertuxkart, and I got the same result. Meanwhile, if I put DRI_PRIME=1 at the front of the executable field in either case, the game runs on my discrete GPU.

It's hard to tell if Cartridges itself is even affected by the PrefersNonDefaultGPU=true flag, given that it doesn't really have graphics. In case it makes any difference, my Cartridges is a Flatpak user install, i.e. I installed it by running flatpak install --user flathub page.kramo.Cartridges.

And I suppose could add the desktop entry key, but I'm not sure if there could be any adverse side effects? If not, I'm all for it.

If one has both integrated graphics and a discrete GPU but the latter is the default device, then PrefersNonDefaultGPU=true can actually cause the program to run with integrated graphics. The intent of PrefersNonDefaultGPU, per the desktop entry spec, is to use the more powerful GPU — but the name of the key ("prefers non-default GPU") more accurately describes what it actually does, in my experience.**

For this reason, there's actually an open request to remove PrefersNonDefaultGPU from the desktop entry for Steam; see ValveSoftware/steam-for-linux#9940.

To the extent that PrefersNonDefaultGPU actually misbehaves, it's very much someone else's bug and arguably not your problem. Whether it might cause the wrong behavior for some users is something to consider, though. Of course, in my case (see above), I can't get it to affect how Cartridges launches games at all, but for now I'm assuming that might be my fault somehow.

Edit for clarification:
* Running gio launch /usr/share/applications/supertuxkart.desktop in a terminal seems to confirm that gio launch doesn't respect the given desktop entry's PrefersNonDefaultGPU in general, which is why it's even possible for Cartridges to be running this game with the integrated graphics. Only when I launch a game from my menu does its desktop entry's PrefersNonDefaultGPU=true seem to do anything. Running DRI_PRIME=1 gio launch /usr/share/applications/supertuxkart.desktop in a terminal does also make the game use the discrete GPU, though.
** I've also seen the same behavior with DRI_PRIME=1. I assume they basically do the same thing.

@michaelneverwins
Copy link

michaelneverwins commented Jan 18, 2025

Setting aside the specific issue DRI_PRIME and PrefersNonDefaultGPU (the latter of which, when true, actually results in DRI_PRIME=pci-0000_01_00_0 with my current system configuration), Cartridges doesn't seem to pass its own environment variables to the commands it launches in general.

I created the script ~/envtest.sh containing

#!/bin/bash
notify-send "MYTESTVAR=${MYTESTVAR}"

so that, if I run MYTESTVAR=foo ~/envtest.sh, I see the notification MYTESTVAR=foo.

Then I added an entry to Cartridges that simply runs ~/envtest.sh. Closing and re-launching Cartridges with any of

MYTESTVAR=foo flatpak run page.kramo.Cartridges
env MYTESTVAR=foo flatpak run page.kramo.Cartridges
export MYTESTVAR=foo && flatpak run page.kramo.Cartridges
flatpak run --env=MYTESTVAR=foo page.kramo.Cartridges
flatpak override --user page.kramo.Cartridges --env=MYTESTVAR=foo && flatpak run page.kramo.Cartridges

and then running the test entry just results in the notification MYTESTVAR=.

Given that Cartridges is a Flatpak thing that can launch non-Flatpak things, having Cartridges pass all environment variables it sees to the things it launches might be problematic, but I assume passing at least some environment variables along would be required for PrefersNonDefaultGPU=true to have any effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants