J'ai les files suivants dans /etc/acpi/events
et /etc/udev/rules.d
.
/etc/acpi/events/lidclose
# Pass all events to our one handler script event=button/lid action=/etc/acpi/monitors.sh
/etc/udev/rules.d/80-monitor.rules
# change monitor settings when monitor is plugged in or o$ ACTION=="change", SUBSYSTEM=="drm", HOTPLUG=="1", RUN+="/etc/acpi/monitors.sh"
Maintenant, le (exécutable et possédé par la racine) /etc/acpi/monitors.sh
#!/bin/sh # default monitor is LVDS1 STATE=internal INTERNAL=LVDS1 EXTERNAL=HDMI3 # functions to switch from LVDS1 to VGA and vice versa function internal { echo "Switching to internal" xrandr --output $EXTERNAL --off --output $INTERNAL --auto STATE=internal } function external { echo "Switching to external" xrandr --output $EXTERNAL --auto --output $INTERNAL --off STATE=external } function both { echo "Switching to both" xrandr --output $EXTERNAL --auto --right-of $INTERNAL --output $INTERNAL --auto --primary STATE=both } # functions to check if VGA is connected and in use function externalConnected { ! xrandr | grep "^$EXTERNAL" | grep disconnected >/dev/null } function lidOpen { ! cat /proc/acpi/button/lid/LID/state | grep closed >/dev/null } # actual script if ! [ $STATE == "both" ] && externalConnected && lidOpen then both fi if ! [ $STATE == "external" ] && externalConnected && ! lidOpen then external fi if ! [ $STATE == "internal" ] && ! externalConnected && lidOpen then internal fi
Maintenant, j'ai testé le script à la fois en tant que root et en tant qu'user, et cela a fonctionné comme un charme. J'ai aussi mis une sortie de test via echo bla > /home/me/test
, et quand il est appelé par udev
et acpid
il a généré la sortie, donc il est exécuté. La seule chose est que rien ne se passe avec xrandr
.
Qu'est-ce qui me manque? Comment puis-je save la sortie du script pour find des erreurs?
Avec l'aide des gars qui ont commenté ma question, j'ai compris ce qui n'allait pas et je l'ai corrigé dans le script.
Voici maintenant les routines mises à jour comment get la commutation d'écran automatique avec votre ordinateur portable pour fonctionner. Vous avez besoin d'acpid, kms et udev.
Créez les règles suivantes pour acpi et udev
/ etc / acpi / events / lidclose
# Pass all events to our one handler script event=button/lid action=/etc/acpi/monitors.sh
/etc/udev/rules.d/80-monitor.rules
# change monitor settings when monitor is plugged in or o$ ACTION=="change", SUBSYSTEM=="drm", HOTPLUG=="1", RUN+="/etc/acpi/monitors.sh"
Créez maintenant /etc/acpi/monitors.sh
#!/bin/sh # specify the monitors to use INTERNAL=LVDS1 EXTERNAL=HDMI3 USERNAME=oli # set some variables needed to control the x server export XAUTHORITY=/home/$USERNAME/.Xauthority export DISPLAY=:0 # functions to switch from internal screen to external screen and vice versa or to use both screens together function internal { echo "Switching to internal" >> /var/log/monitors.log xrandr --verbose --output $EXTERNAL --off --output $INTERNAL --auto >> /var/log/monitors.log 2>&1 } function external { echo "Switching to external" >> /var/log/monitors.log xrandr --verbose --output $EXTERNAL --auto --output $INTERNAL --off >> /var/log/monitors.log 2>&1 } function both { echo "Switching to both" >> /var/log/monitors.log xrandr --verbose --output $EXTERNAL --auto --right-of $INTERNAL --output $INTERNAL --auto --primary >> /var/log/monitors.log 2>&1 } # functions to check if external monitor is connected and in use function externalConnected { ! xrandr | grep "^$EXTERNAL" | grep disconnected >/dev/null } function lidOpen { ! cat /proc/acpi/button/lid/LID/state | grep closed >/dev/null } # actual script if externalConnected && lidOpen then both fi if externalConnected && ! lidOpen then external fi if ! externalConnected && lidOpen then internal fi
Et j'espère que ça va marcher.