summaryrefslogtreecommitdiffstats
path: root/meta-xilinx-core/recipes-graphics/xorg-xserver/xserver-xorg/monitor-hotplug.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta-xilinx-core/recipes-graphics/xorg-xserver/xserver-xorg/monitor-hotplug.sh')
-rwxr-xr-xmeta-xilinx-core/recipes-graphics/xorg-xserver/xserver-xorg/monitor-hotplug.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/meta-xilinx-core/recipes-graphics/xorg-xserver/xserver-xorg/monitor-hotplug.sh b/meta-xilinx-core/recipes-graphics/xorg-xserver/xserver-xorg/monitor-hotplug.sh
new file mode 100755
index 00000000..bceb5607
--- /dev/null
+++ b/meta-xilinx-core/recipes-graphics/xorg-xserver/xserver-xorg/monitor-hotplug.sh
@@ -0,0 +1,65 @@
1#! /bin/sh
2
3# Copyright (C) 2018 Xilinx, Inc. All rights reserved.
4# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23
24# Adapt this script to your needs.
25
26DEVICES=$(find /sys/class/drm/*/status)
27
28# inspired by /etc/acpd/lid.sh and the function it sources.
29
30# Read first X display number from the list.
31displaynum=`ls /tmp/.X11-unix/* | sed s#/tmp/.X11-unix/X## | head -n 1`
32displaynum=${displaynum%% *}
33
34display=":$displaynum.0"
35export DISPLAY=":$displaynum.0"
36
37# from https://wiki.archlinux.org/index.php/Acpid#Laptop_Monitor_Power_Off
38
39# Clear XAUTHORITY by default in case X session is not using display manager.
40unset XAUTHORITY
41
42# Detect X session command line started for the display $displaynum and extract
43# -auth argument if any.
44ps -eo args | grep -e "Xorg\W*:$displaynum" | grep -e -auth | while read -r line
45do
46 if [[ "${line%% *}" == *Xorg ]]; then
47 export XAUTHORITY=`echo $line | sed -n 's/.*-auth //; s/ -[^ ].*//; p'`
48 break
49 fi
50done
51
52for i in /sys/class/drm/*/*/status ;
53do
54 status=$(cat $i);
55 connector=${i%/status*};
56 connector=${connector#*-};
57 if [ "$status" == "disconnected" ]; then
58 xset dpms force off
59 elif [ "$status" == "connected" ]; then
60 xset dpms force on
61 if [ "$(xrandr | grep '\*')" = "" ]; then
62 xrandr --output $connector --auto
63 fi
64 fi
65done