From f6ae945187771bd826ef72a165641d33e1a60661 Mon Sep 17 00:00:00 2001 From: Christophe-Marie Duquesne Date: Sun, 10 Nov 2019 17:37:29 +0100 Subject: [PATCH] Improvement of the regex performance for lid monitoring This version of the regex avoids reading entire lines from the libinput output, and concentrates on the event field. --- contrib/etc/xdg/autostart/autorandr-lid-listener.desktop | 2 +- contrib/listen_lid.sh | 4 +++- contrib/systemd/autorandr-lid-listener.service | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop b/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop index 48c7fc8..9d16f07 100644 --- a/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop +++ b/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop @@ -2,5 +2,5 @@ Name=Autorandr Lid Listener Comment=Trigger autorandr whenever the lid state changes Type=Application -Exec=bash -c "stdbuf -oL libinput debug-events | grep --line-buffered SWITCH_TOGGLE | while read line; do autorandr --change --default default; done" +Exec=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --change --default default; done" X-GNOME-Autostart-Phase=Initialization diff --git a/contrib/listen_lid.sh b/contrib/listen_lid.sh index 8283d37..7288490 100755 --- a/contrib/listen_lid.sh +++ b/contrib/listen_lid.sh @@ -3,6 +3,8 @@ # /!\ You must be part of the input group # sudo gpasswd -a $USER input -stdbuf -oL libinput debug-events | grep --line-buffered SWITCH_TOGGLE | while read line; do +stdbuf -oL libinput debug-events | \ + egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | \ + while read line; do autorandr --change --default default done diff --git a/contrib/systemd/autorandr-lid-listener.service b/contrib/systemd/autorandr-lid-listener.service index 7e45438..a6776ee 100644 --- a/contrib/systemd/autorandr-lid-listener.service +++ b/contrib/systemd/autorandr-lid-listener.service @@ -3,7 +3,7 @@ Description=Runs autorandr whenever the lid state changes [Service] Type=simple -ExecStart=bash -c "stdbuf -oL libinput debug-events | grep --line-buffered SWITCH_TOGGLE | while read line; do autorandr --batch --change --default default; done" +ExecStart=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --batch --change --default default; done" Restart=always RestartSec=30 SyslogIdentifier=autorandr