-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be aware of lid state #104
Comments
This change would increase the complexity from a user's perspective a lot. Currently, it's fairly easy: A set of specific monitors connected to specific physical outputs is what autorandr calls a setup. Reproduce a setup, and autorandr will reload the configuration you stored earlier for you. I'd rather not add complexity to this. (For example, valid follow up questions would be: Shouldn't we then distinguish between monitors in stand-by and powered-on monitors as well?) That being said, you can use the |
No, there isn't any ambiguous continuation for this. The laptop case is pretty straightforward: if lid is closed, internal monitor becomes useless and is expected to be unused. There may be a different approach: add a config option to mark output(s) as internal. Treat those outputs as disconnected if lid is closed. |
I think it would be very useful too |
@phillipberndt As a user, I would have expected autorandr to treat lid open/close events as a screen connect/disconnect. At least this is essentially how I think about it when I open/close the lid, since there is no way to actually disconnect it. That being said, even though I would enjoy if autorandr's behavior would match my way of thinking, it is nice to see that it also provides ways to work around such edge cases and I thank you for that. I just spent an hour figuring this out, so I figured I would share for others who bump into the same issue. Automatically switch display configuration based on lid state
#!/bin/bash
exec grep -q close /proc/acpi/button/lid/LID0/state
#!/bin/bash
exec grep -q open /proc/acpi/button/lid/LID0/state
autorandr --change Your preferred config should apply accordingly. If it does not, make sure you made both block files executables.
#!/bin/bash
/usr/bin/autorandr --batch --change --default default Create the file
And then restart acpid. The configuration switch should now happen automatically. If not, double check that |
Honestly, after going through this, I would find it easier if autorandr treated a closed lid as disconnected (what am I going to display on it when it is closed anyway?) |
Open questions:
|
|
As I wrote, I don't think this should be something that needs manual configuration. If it does then there's no real advantage over the
The profile must store whether the lid is supposed to be open or closed, for the profile to apply, doesn't it? |
Why? The profile would just lack an internal output, no EDID, no config (or off). Just like with any other disconnected outputs. |
The |
Send |
If the system reports that an output has a monitor attached and the |
By treating internal output as disconnected I meant faking it at info gathering stage. Inject xrandr data characteristic of a disconnected output if lid is closed. Everything else does not need to change in this case.
This bit is already in the code. Just fake |
For some laptops, the lid state appears to be reported in
Unfortunately, I don't know about a bulletproof approach. I would suggest using a list of common names, but make it override-able. This way we would catch 80% of the users by default, and the last 20% can fine-tune their configuration if their use-case is not covered.
What would make sense to me would be that autoxrandr would just pretend the screen is disconnected if the lid is closed. Looking at the setup files I have in my profiles, that would correspond to removing the line of the lid from the setup file when the lid is closed. |
@chmduquesne Looks like Lenovo X1 Carbon is a practical example of one of the ones that use |
Hi, I developed a branch where a closed lid is treated as if it was a disconnected output. This means, essentially, that running This is of course not backward compatible with current configurations, but I think it matches better what any user would expect. I know @phillipberndt wants to stay backward compatible, but I find it silly to make this behavior optional, because I can't think of anyone who would like to configure an output they can't see. If there is a situation justifying doing this, I am willing to modify my PR, but I am curious to read about it. I also wrote code to trigger What is your general opinion? Does it make sense to make this the default? Is it desirable to keep supporting old configs? Should the lid monitor be a systemd script, or an autostart desktop entry? |
|
Some comments about the two links you suggested:
The systemd service that I provided solves the problem and does not require the user to be in |
Thanks for implementing this, this makes the decision whether to do this way easier ;-) re 3: I'm fine with the systemd stuff as it is in the PR. Those files are in the contrib folder, and others are free to improve it later. re 2: IMHO it'd suffice to add this once someone complains. Your version should cover almost all cases. re 1: Sounds good, and having this logic outside the xrandr parser is nicer from a code perspective, too. |
re 3: If overhead of dumping and grepping through all input events is negligible, then ok. |
1 is now implemented. I elected not to implement 2, because I believe that my version covers all cases (as I mentioned in the PR, I went through the code of the graphic drivers to determine how the output names are generated for xrandr). I would prefer to add code only if we are sure that somebody needs it. I understand why 3 is controversial. I agree that there is an small overhead: libinput does indeed receive all input events. I tried to mitigate this by improving the regexp performance and only look at the relevant part of the events. All I can say is that I am already using this code on my personal laptop as well as my work laptop without noticeable impact, but that is a totally subjective remark. Alternatively, I can include code for doing this based on acpid hooks in the contrib directory. I was doing this before and it was working quite well. IMHO it's a heavier dependency, but the users may choose as they wish. @Vladimir-csp if you can come up with a better implementation, you are very welcome to do so! |
Merged as is for now, thanks for your work! (Happy to accept further PRs if you guys have good ideas for improving lid event integration.) |
Cool, thanks! As far as I am concerned, this issue can be closed, then 🙂 |
Thanks! |
In case anyone is interested, I used sudo pacman -S acpid
sudo systemctl enable --now acpid Then in systemctl start --no-block autorandr.service
|
I used NixOS own module for acpid: services.acpid = {
enable = true;
lidEventCommands = ''
#!${pkgs.bash}/bin/bash
export DISPLAY=:0
if grep -q open /proc/acpi/button/lid/LID/state; then
${pkgs.sudo}/bin/sudo -u ivan ${pkgs.autorandr}/bin/autorandr all
else
${pkgs.sudo}/bin/sudo -u ivan ${pkgs.autorandr}/bin/autorandr monitor
fi
'';
}; In plain it looks similar to this:
|
Here is a small script I created & it worked for me without issues: #!/bin/bash
# Allows to automatically disable/enable the laptop screen when the lid is opend/closed
sudo pacman -S acpid --needed --noconfirm
sudo mkdir /etc/acpi/actions
sudo tee /etc/acpi/actions/lid.sh > /dev/null <<EOT
#!/bin/bash
# Automatically enable/disable output to Laptop (LVDS1) when lid close/open event happens
export XAUTHORITY=/home/$USER/.Xauthority
export DISPLAY=":0.0"
case "$3" in
close)
logger 'LID closed'
xrandr --output LVDS1 --off
;;
open)
logger 'LID opened'
xrandr --output LVDS1 --auto
;;
*)
logger "ACPI action undefined: $3"
;;
esac
EOT
sudo tee /etc/acpi/events/lid > /dev/null <<EOT
event=button/lid LID (open|close)
action=/etc/acpi/actions/lid.sh
EOT
sudo chmod +x /etc/acpi/actions/lid.sh
# remove 'anything' event handler
sudo rm /etc/acpi/events/anything
# restart acpid
sudo systemctl stop acpid
sudo systemctl enable acpid
sudo systemctl start acpid Checked in at https://github.com/Xcalizorz/endeavouros-i3wm-setup/blob/main/custom-scripts/install-acpid-events.sh |
For what it's worth, with current autorandr the lid is handled exactly as I expect, i.e. "lid closed" means internal monitor is disconnected. However, I need to manually run |
Yes, that was implemented in #169.
For this to happen, make sure contrib/etc/xdg/autostart/autorandr-lid-listener.desktop is installed properly. Alternatively, you can run the script I suggested in #269, available in https://github.com/chmduquesne/autorandr/blob/dbus_monitor/contrib/autorandr_dbus_monitor.sh, which can replace every script that triggers autorandr. |
Thanks! Why not close this issue as fixed then? :-). |
To handle situations like laptop lid being closed or open with regards to external monitor:
Lid states can be acquired from /proc/acpi/button/lid/*/state
The text was updated successfully, but these errors were encountered: