From 8fbc3f08a50d97a5b88c00ef13e168ef1e69e0b2 Mon Sep 17 00:00:00 2001 From: Alexander Grothe Date: Mon, 24 Sep 2018 22:56:36 +0200 Subject: [PATCH] Fix detect-second-display.service --- Manual.org | 7 ++++++- .../systemd/user/detect-second-display.service.j2 | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Manual.org b/Manual.org index 733e735..4885293 100644 --- a/Manual.org +++ b/Manual.org @@ -4353,7 +4353,12 @@ Description=Detect second DISPLAY using xrandr [Service] Type=oneshot -ExecStart=/bin/bash -c 'export DISPLAY=$DISPLAY.1; xrandr -q | grep "connected" && echo "DISPLAY=$DISPLAY" > ~/.second_display || rm -f ~/.second_display' +ExecStart=/bin/bash -c '\ + source <(systemctl --user show-environment); \ + SECOND_DISPLAY="$${DISPLAY%\.[0-9]*}.1"; \ + xrandr -d "$SECOND_DISPLAY" -q | grep "connected" && \ + { [ $DISPLAY == $SECOND_DISPLAY ] && echo "DISPLAY=$${DISPLAY%\.[0-9]*}.0 > ~/.second_display || echo "DISPLAY=$SECOND_DISPLAY" > ~/.second_display; \ + } || rm -f ~/.second_display' [Install] WantedBy=yavdr-desktop.target diff --git a/roles/yavdr-desktop/templates/systemd/user/detect-second-display.service.j2 b/roles/yavdr-desktop/templates/systemd/user/detect-second-display.service.j2 index 55f5fbe..50596ac 100644 --- a/roles/yavdr-desktop/templates/systemd/user/detect-second-display.service.j2 +++ b/roles/yavdr-desktop/templates/systemd/user/detect-second-display.service.j2 @@ -3,7 +3,12 @@ Description=Detect second DISPLAY using xrandr [Service] Type=oneshot -ExecStart=/bin/bash -c 'export DISPLAY=$DISPLAY.1; xrandr -q | grep "connected" && echo "DISPLAY=$DISPLAY" > ~/.second_display || rm -f ~/.second_display' +ExecStart=/bin/bash -c '\ + source <(systemctl --user show-environment); \ + SECOND_DISPLAY="$${DISPLAY%\.[0-9]*}.1"; \ + xrandr -d "$SECOND_DISPLAY" -q | grep "connected" && \ + { [ $DISPLAY == $SECOND_DISPLAY ] && echo "DISPLAY=$${DISPLAY%\.[0-9]*}.0 > ~/.second_display || echo "DISPLAY=$SECOND_DISPLAY" > ~/.second_display; \ + } || rm -f ~/.second_display' [Install] WantedBy=yavdr-desktop.target