`DISPLAY` takes priority over `WAYLAND_DISPLAY`

I am trying to make SDL use wayland by default, but i think having xwayland enabled makes it automatically use that instead. It chooses wayland if i set set DISPLAY="" or SDL_VIDEODRIVER=wayland, but I think it should choose it by default. I think it has something to do with the DISPLAY taking priority over WAYLAND_DISPLAY, because DISPLAY=:0 while WAYLAND_DISPLAY=wayland-1. I think it should be DISPLAY=:1 and WAYLAND_DISPLAY=wayland-0.

I am using Hyprland (programs.hyprland.enable=true in configuration.nix) and SDL3. Any suggestions on how to fix? Is there like a way to make wayland take priority?

If that’s what you want, what’s wrong with just setting SDL_VIDEODRIVER=wayland in your environment?

Environment variables – Hyprland Wiki gives a good guide, whether using uswm or not, i.e. through either the env file ~/.config/uwsm/env or adding an env command in your user hyprland.conf

I have a “generic wrapper” that can be used to wrap the executables in an existing package with a custom script. For example, you could do something like this:

environment.systemPackages = [
  ...

  (let wrapper = pkgs.writeShellScript "sdl3-wayland" "SDL_VIDEODRIVER=wayland @EXECUTABLE@ $@";
  in erosanix.lib.x86_64-linux.genericBinWrapper pkgs.foobar wrapper)
];

In the example above, the files in ${pkgs.foobar}/bin get wrapped with a script which sets the SDL_VIDEODRIVER environment variable before calling the wrapped executable; The placeholder @EXECUTABLE@ gets replaced with the actual executable.

The code is here: erosanix/lib/generic-bin-wrapper.nix at c1f191c403c26011a26b225a68df50edf44d0107 · emmanuelrosa/erosanix · GitHub