Support PrefersNonDefaultGPU key in desktop files
Hi there. Version 1.4 of the Desktop Entry Specification added a new key, "PrefersNonDefaultGPU". It's an optional boolean key described as follows:
If true, the application prefers to be run on a more powerful discrete GPU if available, which we describe as “a GPU other than the default one” in this spec to avoid the need to define what a discrete GPU is and in which cases it might be considered more powerful than the default GPU. This key is only a hint and support might not be present depending on the implementation.
On systems with NVidia discrete GPUs, render offload is controlled with three different environment vars as documented here. It's probably a good idea to just set all of them when the discrete GPU is requested.
__NV_PRIME_RENDER_OFFLOAD=1for Vulkan applications to enumerate the NVidia GPU first.
__GLX_VENDOR_LIBRARY_NAME=nvidiafor GLX applications; tells GLVND to load the NVidia GLX driver.
__VK_LAYER_NV_optimus=NVIDIA_onlyensures integrated GPUs are not enumerated at all.
On systems with AMD discrete GPUs, exporting
DRI_PRIME=1 may be all that is needed, but there may be pitfalls to doing it like that.
On Xubuntu 20.04, the key currently does nothing, at least as far as I can tell since I have a laptop with Optimus. The most recent steam-launcher sets this key, and it is present in the latest Flatpak for Steam. If I start Steam from Whisker Menu and run a graphically intensive game, it chugs like it's on integrated. But if I set the requisite environment vars myself before starting Steam, the same game runs fine.
Thanks for your time.