Improve switching primary and secondary display

This commit is contained in:
Alexander Grothe 2018-09-30 10:17:20 +02:00
parent cd10eb1970
commit 2d966364e5
5 changed files with 535 additions and 473 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2859,6 +2859,7 @@ exit 0
- '{{ vdr.home }}/.config/systemd/user' - '{{ vdr.home }}/.config/systemd/user'
- '{{ vdr.home }}/.config/openbox' - '{{ vdr.home }}/.config/openbox'
- '{{ vdr.home }}/.config/pulse' - '{{ vdr.home }}/.config/pulse'
- '{{ vdr.home }}/bin'
- name: expand template for .xinitrc for vdr user - name: expand template for .xinitrc for vdr user
template: template:
@ -2941,6 +2942,14 @@ exit 0
owner: '{{ vdr.user }}' owner: '{{ vdr.user }}'
group: '{{ vdr.group }}' group: '{{ vdr.group }}'
- name: create detect-second-diplay script
template:
src: templates/bin/detect-second-display.j2
dest: '{{ vdr.home }}/bin/detect-second-display'
mode: 0755
owner: '{{ vdr.user }}'
group: '{{ vdr.group }}'
- name: create openbox-second.service for the session - name: create openbox-second.service for the session
template: template:
src: templates/systemd/user/openbox-second.service.j2 src: templates/systemd/user/openbox-second.service.j2
@ -4724,13 +4733,24 @@ AllowIsolate=yes
:PROPERTIES: :PROPERTIES:
:ID: e46166b1-0550-41c6-a7ec-d7a2622f87db :ID: e46166b1-0550-41c6-a7ec-d7a2622f87db
:END: :END:
#+BEGIN_SRC shell :tangle roles/yavdr-desktop/templates/bin/detect-second-display.j2 :mkdirp yes :padline no
#!/bin/bash
source <(systemctl --user show-environment)
SECOND_DISPLAY="${DISPLAY%\.[0-9]*}.1"
if xrandr -d "$SECOND_DISPLAY" -q | grep -q "connected"; then
[ "$DISPLAY" != "$SECOND_DISPLAY" ] && d="DISPLAY=$SECOND_DISPLAY" || d="DISPLAY=$DISPLAY"
echo "$d" > ~/.second_display;
else
rm -f ~/.second_display
fi
#+END_SRC
#+BEGIN_SRC conf :tangle roles/yavdr-desktop/templates/systemd/user/detect-second-display.service.j2 :mkdirp yes :padline no #+BEGIN_SRC conf :tangle roles/yavdr-desktop/templates/systemd/user/detect-second-display.service.j2 :mkdirp yes :padline no
[Unit] [Unit]
Description=Detect second DISPLAY using xrandr Description=Detect second DISPLAY using xrandr
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'export DISPLAY=$DISPLAY.1; xrandr -q | grep "connected" && echo "DISPLAY=$DISPLAY" > ~/.second_display || rm -f ~/.second_display' ExecStart=%h/bin/detect-second-display
[Install] [Install]
WantedBy=yavdr-desktop.target WantedBy=yavdr-desktop.target

View File

@ -12,6 +12,7 @@
- '{{ vdr.home }}/.config/systemd/user' - '{{ vdr.home }}/.config/systemd/user'
- '{{ vdr.home }}/.config/openbox' - '{{ vdr.home }}/.config/openbox'
- '{{ vdr.home }}/.config/pulse' - '{{ vdr.home }}/.config/pulse'
- '{{ vdr.home }}/bin'
- name: expand template for .xinitrc for vdr user - name: expand template for .xinitrc for vdr user
template: template:
@ -94,6 +95,14 @@
owner: '{{ vdr.user }}' owner: '{{ vdr.user }}'
group: '{{ vdr.group }}' group: '{{ vdr.group }}'
- name: create detect-second-diplay script
template:
src: templates/bin/detect-second-display.j2
dest: '{{ vdr.home }}/bin/detect-second-display'
mode: 0755
owner: '{{ vdr.user }}'
group: '{{ vdr.group }}'
- name: create openbox-second.service for the session - name: create openbox-second.service for the session
template: template:
src: templates/systemd/user/openbox-second.service.j2 src: templates/systemd/user/openbox-second.service.j2

View File

@ -0,0 +1,9 @@
#!/bin/bash
source <(systemctl --user show-environment)
SECOND_DISPLAY="${DISPLAY%\.[0-9]*}.1"
if xrandr -d "$SECOND_DISPLAY" -q | grep -q "connected"; then
[ "$DISPLAY" != "$SECOND_DISPLAY" ] && d="DISPLAY=$SECOND_DISPLAY" || d="DISPLAY=$DISPLAY"
echo "$d" > ~/.second_display;
else
rm -f ~/.second_display
fi

View File

@ -3,7 +3,7 @@ Description=Detect second DISPLAY using xrandr
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'export DISPLAY=$DISPLAY.1; xrandr -q | grep "connected" && echo "DISPLAY=$DISPLAY" > ~/.second_display || rm -f ~/.second_display' ExecStart=%h/bin/detect-second-display
[Install] [Install]
WantedBy=yavdr-desktop.target WantedBy=yavdr-desktop.target