i3 / i3lock

improved screen locker
https://i3wm.org/i3lock
BSD 3-Clause "New" or "Revised" License
921 stars 404 forks source link

Could not connect to X11 if using lxdm #180

Closed nenad closed 5 years ago

nenad commented 6 years ago

Since I moved to using lxdm I noticed my systemctl service for locking on suspend started failing with the following message:

Mar 17 17:15:34 xps betterlockscreen[10043]: No protocol specified
Mar 17 17:15:34 xps betterlockscreen[10043]: i3lock: Could not connect to X11, maybe you need to set DISPLAY?

This is how the script looks like:

[Unit]
Description=Lock screen on suspend

[Service]
User=nenad
Environment=DISPLAY=:0
Type=forking
ExecStart=/usr/bin/betterlockscreen -l

[Install]
WantedBy=suspend.target
WantedBy=sleep.target

The betterlockscreen is a very simple image manipulator which uses i3lock (https://github.com/pavanjadhaw/betterlockscreen/)

LXDM puts the .Xauthority file in /run/lxdm/$UID/.Xauthority. I symlinked it from there to ~/.Xauthority and it works now, but I'm not sure if this can be fixed in i3lock itself.

stapelberg commented 5 years ago

i3lock uses XCB, which uses libXau, which pretty much every piece of software uses for X authentication, so there shouldn’t be a difference here.

My guess is that lxdm sets the XAUTHORITY environment variable, resulting in programs picking up the correct location without needing the symlink. In your service file, try setting not only DISPLAY, but also XAUTHORITY.

nenad commented 5 years ago

Thanks for the answer! I can't test it since I've moved to using sway, but I'm pretty confident your solution will work.

alexsoul99 commented 1 year ago

I know its been a while since this issue was closed, and dont know if you would read this, but I wanted to thank you a lot, I was having the same issue and this helped me..