Version: sway version 1.1-rc1-25-g799f5a2c (Jun 5 2019, branch 'master')
I have my laptop connected to an external monitor, so my laptop lid is closed most of the time.
After booting the laptop and starting sway, i have to manually open the lid then close it in order for it to detect that my laptop lid is closed.
I have the following bindswitch commands configured:
bindswitch lid:on exec swaymsg output eDP-1 disable
bindswitch lid:off exec swaymsg output eDP-1 enable
Im assuming this is not actually a bug, and should be an enhancement request.
AFAIR evdev does not issue an event if the lid is not moved, sway can not detect the state of the lid in this case. I might be wrong though, I did not recheck.
I assumed it would be something like that. I guess i could write a script that checks this everytime sway starts, but it would be nice if it was possible for sway to do this check automatically itself.
For now i have resolved the issue by adding the following line to my sway config:
exec_always cat /proc/acpi/button/lid/LID/state | awk '{print $2}' | grep -q 'closed' && swaymsg output eDP-1 disable
According to the libinput API, libinput does send an event on initialization if the switch is on (in this case, the lid is closed), but not the inverse.
The issue here is actually that sway does not consider itself to be in an active state until the device initialization is complete. This is causing the exec to be deferred, which is not currently handled for bindings. I think the best solution is to add deferred handling for bindings. I'll take a look into making a PR for that.
Also, the exec swaymsg is not needed. The following should work on startup right now:
bindswitch lid:on output eDP-1 disable
Most helpful comment
For now i have resolved the issue by adding the following line to my sway config: