aboutsummaryrefslogtreecommitdiffstats
path: root/bin/setup_screens
diff options
context:
space:
mode:
authorDavid Runge <david.runge@native-instruments.de>2018-11-24 14:19:45 +0100
committerDavid Runge <david.runge@native-instruments.de>2018-11-24 14:19:45 +0100
commitf4fec3ab8e56e82bf7904c3c19876e2f4e13667d (patch)
tree23a4dd266333fc6cfeb5ee05c6000ced30724098 /bin/setup_screens
parent31895b1b525ab673becdb10c7a421f71510f6354 (diff)
parentde1f86528b58faa0844f24b9edb63e5837dd7444 (diff)
downloaddotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.tar.gz
dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.tar.bz2
dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.tar.xz
dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.zip
Merge branch 'master' of git.sleepmap.de:config/dotfiles
* 'master' of git.sleepmap.de:config/dotfiles: (36 commits) .config/packages-community.txt: Adding pd-lua. .config/systemd/user/mpd@.service: Adding local override for mpd@ user service. Raising LimitRTPrio to 75, as some threads in mpd apparently require it. .config/jack/*: Changing all configurations for jack@ user service (as its layout has changed). .gitignore: Removing ignore of .config/systemd (time to add some local overrides). .config/packages-aur.txt: Removing ssr (now in [community]). .config/systemd/user/jack@.service: Adding a local jack@ user service, so no package is required. .config/packages-community.txt: Adding dragonfly-reverb, libmusicxml, ssr and wolf-shaper. .ncmpcpp/config: Switching to local visualizer fifo. Using visualizer_type ellipse. .zsh.after/aliases.zsh: Removing useless pacsearch overloading. bin/setup_screens: Fixing and simplifying various things with the help of shellcheck. Using a separate get_display function to retrieve DISPLAY. bin/xorg_autolock: Properly quoting variables. Abstracting lock_cmd. bin/xorg_lock: Properly quote variables. Rename variables for better readibility. .xprofile: Repaired with the help of shellcheck. .config/packages-community.txt: Adding marsyas. .config/packages-aur.txt: Removing gmsynth.lv2 (now in community). Adding librenms and patroneo-git. .config/packages-community.txt: Adding ams-lv2, beatslash-lv2, gmsynth.lv2, lib32-fluidsynth, lsp-plugins, lvtk, stk and removing ssmtp. bin/cs: Fixing script according to shellcheck. .config/packages-community.txt: Adding nextcloud-app-spreed. .vim/addons-settings.vim: Adding supercollider settings for split in tmux. .config/linuxsampler.org/Qsampler.conf: Remove, because it makes no sense in repo. ...
Diffstat (limited to 'bin/setup_screens')
-rwxr-xr-xbin/setup_screens66
1 files changed, 36 insertions, 30 deletions
diff --git a/bin/setup_screens b/bin/setup_screens
index 1a84bba..7cd0b17 100755
--- a/bin/setup_screens
+++ b/bin/setup_screens
@@ -2,23 +2,29 @@
# Script to setup screens on login and lid-switch-action
# Uses autorandr to determine which screens are connected and which to setup.
#
-# Per default a configuration named "internal" will be used, if the computer is
+# Per default a configuration named "default" will be used, if the computer is
# a laptop and not docked.
# A configuration named "docked-closed" will be used during login, when the lid
# is closed and docked.
-# A configuration named "docked-open" will be used during login, when the lid
+# A configuration named "docked-all" will be used during login, when the lid
# is open and docked.
set -e -u
lid_state=""
-docking_state=""
fingerprint=""
action=""
x_user=""
+display=""
current_user=""
path=""
+# get DISPLAY number
+get_display()
+{
+ display=$(pgrep -a Xorg|cut -d':' -f2| cut -d' ' -f1)
+}
+
# get current user running X
get_x_user()
{
@@ -41,15 +47,17 @@ get_path()
function get_lid_state()
{
if [ -r "/proc/acpi/button/lid/LID/state" ]; then
- lid_state="$(cat /proc/acpi/button/lid/LID/state|awk '{print $2}')"
+ lid_state="$(awk '{print $2}' /proc/acpi/button/lid/LID/state)"
fi
}
# Get current docking state ("true" or "false")
-function get_docking_state()
+function is_docked()
{
- if [ -x "/usr/bin/busctl" ]; then
- docking_state="$(busctl introspect org.freedesktop.login1 /org/freedesktop/login1|grep "\.Docked"|awk '{print $4}')"
+ if command -v busctl > /dev/null; then
+ busctl introspect org.freedesktop.login1 /org/freedesktop/login1| grep -E '^.Docked'| awk '{print $4}'
+ else
+ echo false
fi
}
@@ -63,8 +71,8 @@ function get_setup_fingerprint()
function get_configuration_fingerprint()
{
local fingerprint=""
- if [ -r $HOME/.config/autorandr/$1/setup ]; then
- fingerprint="$(md5sum $HOME/.config/autorandr/$1/setup| cut -d ' ' -f 1)"
+ if [ -r "$HOME/.config/autorandr/$1/setup" ]; then
+ fingerprint="$(md5sum "$HOME/.config/autorandr/$1/setup"| cut -d ' ' -f 1)"
fi
echo "$fingerprint"
}
@@ -73,19 +81,19 @@ function set_configuration()
{
local state=0
# if the computer is docked
- if [ "$docking_state" = "true" ]; then
+ if is_docked ; then
# if there's a lid-switch action
if [ -n "$action" ]; then
case "$action" in
"open")
- if [ $(get_configuration_fingerprint "docked-open") == "$fingerprint" ]; then
- echo "Loading docked-open."
+ if [ "$(get_configuration_fingerprint 'docked-all')" == "$fingerprint" ]; then
+ echo "Loading docked-all."
state=1
- autorandr -l docked-open
+ autorandr -l docked-all
fi
;;
"close")
- if [ $(get_configuration_fingerprint "docked-closed") == "$fingerprint" ]; then
+ if [ "$(get_configuration_fingerprint 'docked-closed')" == "$fingerprint" ]; then
echo "Loading docked-closed."
state=1
autorandr -l docked-closed
@@ -96,10 +104,10 @@ function set_configuration()
# check the lid state
case "$lid_state" in
"open")
- if [[ $(get_configuration_fingerprint "docked-open") == "$fingerprint" ]]; then
- echo "Loading docked-open."
+ if [[ $(get_configuration_fingerprint "docked-all") == "$fingerprint" ]]; then
+ echo "Loading docked-all."
state=1
- autorandr -l docked-open
+ autorandr -l docked-all
fi
;;
"closed")
@@ -125,11 +133,11 @@ function set_configuration()
fi
fi
fi
- # if the screen still has not been setup, try using internal
+ # if the screen still has not been setup, try using default
if [ $state -ne 1 ]; then
- if [[ $(get_configuration_fingerprint "internal") == "$fingerprint" ]]; then
- echo "Loading internal."
- autorandr -l internal
+ if [[ $(get_configuration_fingerprint "default") == "$fingerprint" ]]; then
+ echo "Loading default."
+ autorandr -l default
fi
fi
}
@@ -147,27 +155,25 @@ fi
logger "Calling 'setup_screens'"
get_x_user
+get_display
get_current_user
get_path
# Export Xorg DISPLAY and XAUTHORITY
-export DISPLAY=$(ls /tmp/.X*|grep "lock"|cut -d '.' -f2| cut -d '-' -f1|sed -e 's/X/:/')
-export XAUTHORITY="$(eval echo ~$x_user/.Xauthority)"
+export DISPLAY=":$display"
+export XAUTHORITY="/home/$x_user/.Xauthority"
# if the script caller is the current X user or root (and lightdm is the current X user)
-if [ "$current_user" = "$x_user" ] || [ $current_user = "root" -a $x_user = "lightdm" ]; then
+if [ "$current_user" == "$x_user" ]; then
get_lid_state
- get_docking_state
get_setup_fingerprint
set_configuration
-else
- if [ $current_user = "root" ]; then
+elif [ "$current_user" == "root" ]; then
logger "Running $path as user $x_user now."
- runuser -l $x_user -c $path
- else
+ runuser -l "$x_user" -c "$path"
+else
echo "$current_user is not currently running X and is not allowed to let the current X user run this script."
exit 1
- fi
fi
exit 0