summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2014-08-22 11:53:46 +0200
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2014-08-22 11:53:46 +0200
commitf0167e83c71879ec2e64c389e59819c9ff8d170a (patch)
treec75095e6b2e5cf961c61361110c784cc3f7509c6
downloaddisplay_autoset-f0167e83c71879ec2e64c389e59819c9ff8d170a.tar.xz
Initial commit
-rwxr-xr-xautodetect.sh38
-rwxr-xr-xhandlers/acpi_event_handler.sh4
-rwxr-xr-xhandlers/udev_event_handler.sh2
-rwxr-xr-xother_vesrions/autodetect_2_displays.sh38
-rw-r--r--rules/20-display-autoset.rules1
-rw-r--r--rules/INSTALL6
-rw-r--r--rules/display-autoset2
7 files changed, 91 insertions, 0 deletions
diff --git a/autodetect.sh b/autodetect.sh
new file mode 100755
index 0000000..495f9c3
--- /dev/null
+++ b/autodetect.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+#Set this values on new system!
+##########################################
+eDP1_PATH="/sys/class/drm/card0-eDP-1"
+DP1_PATH="/sys/class/drm/card0-DP-1"
+HDMI_PATH="/sys/class/drm/card0-HDMI-A-1"
+eDP1_NAME="eDP1"
+DP1_NAME="DP1"
+HDMI_NAME="HDMI1"
+##########################################
+
+eDP1_STATUS=$(cat "$eDP1_PATH/status")
+DP1_STATUS=$(cat "$DP1_PATH/status")
+HDMI_STATUS=$(cat "$HDMI_PATH/status")
+
+XRANDR_OUT=$(xrandr -q)
+eDP1_MAX=$(echo "$XRANDR_OUT" | grep -A 1 $eDP1_NAME | tail -n1 | awk '{ print $1 }')
+HDMI_MAX=$(echo "$XRANDR_OUT" | grep -A 1 $HDMI_NAME | tail -n1 | awk '{ print $1 }')
+DP1_MAX=$(echo "$XRANDR_OUT" | grep -A 1 $DP1_NAME | tail -n1 | awk '{ print $1 }')
+
+function handle_non_exist_mode {
+ xrandr --dpi 96 --output $2 --mode $4 --output $1 --mode $3 --left-of $2
+}
+
+if [[ ($HDMI_STATUS == "connected") && ($eDP1_STATUS == "connected") && ($DP1_STATUS == "disconnected") ]]; then
+ handle_non_exist_mode $HDMI_NAME $eDP1_NAME $HDMI_MAX $eDP1_MAX
+
+elif [[ ($HDMI_STATUS == "disconnected") && ($eDP1_STATUS == "connected") && ($DP1_STATUS == "connected") ]]; then
+ handle_non_exist_mode $DP1_NAME $eDP1_NAME $DP1_MAX $eDP1_MAX
+
+elif [[ ($HDMI_STATUS == "connected") && ($eDP1_STATUS == "connected") && ($DP1_STATUS == "connected") ]]; then
+ xrandr --dpi 96 --output $eDP1_NAME --mode $eDP1_MAX --output $HDMI_NAME --mode $HDMI_MAX --left-of $eDP1_NAME --output $DP1_NAME --mode $DP1_MAX --left-of $HDMI_NAME
+
+elif [[ ($HDMI_STATUS == "disconnected") && ($eDP1_STATUS == "connected") && ($DP1_STATUS == "disconnected") ]]; then
+ ~/bin/dnote.sh
+
+fi
diff --git a/handlers/acpi_event_handler.sh b/handlers/acpi_event_handler.sh
new file mode 100755
index 0000000..21ba395
--- /dev/null
+++ b/handlers/acpi_event_handler.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+#~/bin/displays/autodetect.sh
+su -c "DISPLAY=:0.0 arandr" robin;
diff --git a/handlers/udev_event_handler.sh b/handlers/udev_event_handler.sh
new file mode 100755
index 0000000..8b7541e
--- /dev/null
+++ b/handlers/udev_event_handler.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+su -c "DISPLAY=:0.0 ~/bin/displays/autodetect.sh" robin;
diff --git a/other_vesrions/autodetect_2_displays.sh b/other_vesrions/autodetect_2_displays.sh
new file mode 100755
index 0000000..2f5def5
--- /dev/null
+++ b/other_vesrions/autodetect_2_displays.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+#Set this values on new system!
+##########################################
+LVDS_PATH="/sys/class/drm/card0-eDP-1"
+#VGA_PATH="/sys/class/drm/card0-VGA-1"
+HDMI_PATH="/sys/class/drm/card0-HDMI-A-1"
+LVDS_NAME="LVDS1"
+VGA_NAME="VGA1"
+HDMI_NAME="HDMI1"
+##########################################
+
+LVDS_STATUS=$(cat "$LVDS_PATH/status")
+VGA_STATUS=$(cat "$VGA_PATH/status")
+HDMI_STATUS=$(cat "$HDMI_PATH/status")
+
+XRANDR_OUT=$(xrandr -q)
+LVDS_MAX=$(echo "$XRANDR_OUT" | grep -A 1 $LVDS_NAME | tail -n1 | awk '{ print $1 }')
+HDMI_MAX=$(echo "$XRANDR_OUT" | grep -A 1 $HDMI_NAME | tail -n1 | awk '{ print $1 }')
+VGA_MAX=$(echo "$XRANDR_OUT" | grep -A 1 $VGA_NAME | tail -n1 | awk '{ print $1 }')
+
+function handle_non_exist_mode {
+ xrandr --dpi 96 --output $2 --mode $4 --output $1 --mode $3 --left-of $2
+}
+
+if [[ ($HDMI_STATUS == "connected") && ($VGA_STATUS == "connected") ]]; then
+ ~/bin/d2ext.sh || ~/bin/dnone.sh ; ~/bin/d2ext.sh || handle_non_exist_mode $VGA_NAME $HDMI_NAME $VGA_MAX $HDMI_MAX
+
+elif [[ ($HDMI_STATUS == "connected") && ($VGA_STATUS == "disconnected") ]]; then
+ ~/bin/dboth.sh || ~/bin/dnone.sh ; ~/bin/dboth.sh || handle_non_exist_mode $HDMI_NAME $LVDS_NAME $HDMI_MAX $LVDS_MAX
+
+elif [[ ($HDMI_STATUS == "disconnected") && ($VGA_STATUS == "connected") ]]; then
+ ~/bin/dvgaboth.sh || ~/bin/dnone.sh ; ~/bin/dvgaboth.sh || handle_non_exist_mode $VGA_NAME $LVDS_NAME $VGA_MAX $LVDS_MAX
+
+else
+ ~/bin/dnote.sh || ~/bin/dnone.sh ; ~/bin/dnote.sh
+fi
+
diff --git a/rules/20-display-autoset.rules b/rules/20-display-autoset.rules
new file mode 100644
index 0000000..75dbd90
--- /dev/null
+++ b/rules/20-display-autoset.rules
@@ -0,0 +1 @@
+KERNEL=="card0", PROGRAM="/home/robin/bin/displays/udev_event_handler.sh"
diff --git a/rules/INSTALL b/rules/INSTALL
new file mode 100644
index 0000000..5b5071f
--- /dev/null
+++ b/rules/INSTALL
@@ -0,0 +1,6 @@
+root@robin-note:~# cat /etc/udev/rules.d/20-display-autoset.rules
+KERNEL=="card0", PROGRAM="/home/robin/bin/displays/udev_event_handler.sh"
+
+root@robin-note:~# cat /etc/acpi/events/display-autoset
+event=video/switchmode VMOD 00000080 00000000
+action=/home/robin/bin/displays/acpi_event_handler.sh
diff --git a/rules/display-autoset b/rules/display-autoset
new file mode 100644
index 0000000..58748eb
--- /dev/null
+++ b/rules/display-autoset
@@ -0,0 +1,2 @@
+event=video/switchmode VMOD 00000080 00000000
+action=/home/robin/bin/displays/acpi_event_handler.sh