systemd sleep + xrandr
Ivan Sergio Borgonovo <[email protected]>
| Newsgroups | gmane.org.user-groups.linux.svlug |
|---|---|
| Organization | http://www.WebThatWorks.it |
| Message-ID | <[email protected]> |
On 02/09/2017 08:45 PM, Akkana Peck wrote: > I wrote that script so that if I dock or undock my Lenovo X201, > it would automatically figure out whether it was docked with a > monitor connected, and display to the monitor rather than the laptop > screen. But I have yet to find a way to run anything automatically > upon resuming from suspend. Years ago, you could put wakeup scripts > in /etc/pm/sleep.d, but those aren't called reliably any more; I've > tried the systemd equivalent and several other methods I can't > remember any more, and finally gave up and just call it manually > if the screen is blank after docking or undocking. https://www.freedesktop.org/software/systemd/man/systemd-suspend.service.html BTW I did some experiment with a handmade service /etc/systemd/syste/wakemeup.service [Unit] Description=Run user script after suspend After=suspend.target hibernate.target hybrid-sleep.target graphical.target # not sure if graphical.target is a good idea, I did't do all homeworks [Service] User=[youruser] #^^^^ IMPORTANT Type=oneshot Environment=DISPLAY=:0 #^^^^ IMPORTANT ExecStart=/usr/local/bin/wakemeup StandardOutput=syslog [Install] WantedBy=suspend.target hibernate.target hybrid-sleep.target /usr/local/bin/wakemeup #!/bin/sh # ^^^^ IMPORTANT xrandr >> /tmp/gino echo $(date) >> /tmp/gino This works. It could be improved: - running as root - checking users and active display: w -oush - define a criteria about which user/display "prefer" - run xrandr -d [display] with the appropriate user -- Ivan Sergio Borgonovo http://www.webthatworks.it http://www.borgonovo.net