Session
X apps, environment variables for apps, programs to start with the session, and portals for screen sharing and file pickers.
All of these build on your first config. Paste them in the order below: the environment has to be set before the programs that need it start.
X apps
Hazel has no X support of its own. xwayland-satellite runs X apps as normal Wayland windows. Install it, then:
local x_display = ":12"
if not wm.is_reload then spawn("xwayland-satellite", { x_display }) end
spawn_env.DISPLAY = x_display- Everything started with
spawnfrom here on getsDISPLAY, and so does everything started from those, like apps you run in the terminal. - Pick another number if
:12is in use, for example by a second Hazel. - Apps that systemd or D-Bus start don't see
spawn_env. On a tty, also callwm:import_environment({ DISPLAY = x_display }). Leave it out while nested, because it changes the environment of the session around Hazel. - X windows arrive through
new_windowlike any other, so the rest of your config treats them the same.
Environment for apps
Variables that make toolkits pick Wayland, and anything else every app should see.
spawn_env.QT_QPA_PLATFORM = "wayland;xcb"
spawn_env.SDL_VIDEODRIVER = "wayland,x11"
spawn_env.ELECTRON_OZONE_PLATFORM_HINT = "auto"
spawn_env._JAVA_AWT_WM_NONREPARENTING = "1"Programs started by systemd or D-Bus, rather than by Hazel, don't see spawn_env. See below for what they get.
What systemd and D-Bus see
Portals, notification daemons and other services are started by systemd or D-Bus. On a tty, once Hazel is ready for apps, it sets these for both, so those services find it:
WAYLAND_DISPLAYXDG_CURRENT_DESKTOP, which ishazelunless it was already set when Hazel startedXDG_SESSION_TYPE=wayland
On quit it unsets them in systemd and empties them in D-Bus, which can't unset a variable. A failure is logged and Hazel carries on. Nested, it sets nothing.
For other variables services need, use wm:import_environment.
Autostart
Programs started once per session. Saving the config doesn't start them again.
local autostart = {
{ "swaybg", "-c", "#2e3440" },
{ "nm-applet", "--indicator" },
{ "wl-paste", "--watch", "cliphist", "store" },
{ "/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1" },
}
if not wm.is_reload then
for _, command in ipairs(autostart) do
spawn(command[1], { table.unpack(command, 2) })
end
end- A program that isn't installed is logged, and the rest still start.
- Programs Hazel started get SIGTERM when it quits.
- For a program that should restart when it crashes, a systemd user service is the better fit.
Portals
Screen sharing, screenshots in Flatpak apps, and file pickers go through xdg-desktop-portal. It reads XDG_CURRENT_DESKTOP, which is hazel, and looks for ~/.config/xdg-desktop-portal/hazel-portals.conf:
[preferred]
default=gtk
org.freedesktop.impl.portal.ScreenCast=wlr
org.freedesktop.impl.portal.Screenshot=wlrInstall xdg-desktop-portal, xdg-desktop-portal-gtk and xdg-desktop-portal-wlr. The wlr portal captures the screen the same way grim does. When you share a screen it asks which output with a chooser of its own. See man xdg-desktop-portal-wlr to set one, such as slurp.
All of them
local x_display = ":12"
if not wm.is_reload then spawn("xwayland-satellite", { x_display }) end
spawn_env.DISPLAY = x_display
spawn_env.QT_QPA_PLATFORM = "wayland;xcb"
spawn_env.SDL_VIDEODRIVER = "wayland,x11"
spawn_env.ELECTRON_OZONE_PLATFORM_HINT = "auto"
spawn_env._JAVA_AWT_WM_NONREPARENTING = "1"
local autostart = {
{ "swaybg", "-c", "#2e3440" },
{ "nm-applet", "--indicator" },
{ "wl-paste", "--watch", "cliphist", "store" },
{ "/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1" },
}
if not wm.is_reload then
for _, command in ipairs(autostart) do
spawn(command[1], { table.unpack(command, 2) })
end
end