Skip to content

Commit

Permalink
Merge pull request codingtony#5 from lbischof/remove_ck_dep
Browse files Browse the repository at this point in the history
Remove Consolekit dependency
  • Loading branch information
codingtony committed Jan 13, 2017
2 parents 99f5274 + e58c2dd commit 4a47986
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ I was tired of having to configure manually the disposition of my monitors when

So I decided to write this script that define custom behaviour when monitor are plugged in

You might want to adapt the script to your needs ./usr/local/bin/monitor-hotplug.sh
You might want to adapt the script to your needs ./usr/local/bin/monitor-hotplug.sh

I was inspired by http://stackoverflow.com/questions/5469828/how-to-create-a-callback-for-monitor-plugged-on-an-intel-graphics

## Installation
* clone the repo
* sudo cp usr/local/bin/monitor-hotplug.sh /usr/local/bin/
* sudo cp etc/udev/rules.d/99-monitor-hotplug.rules /etc/udev/rules.d/
* sudo apt-get install consolekit
* sudo service udev restart

## Debuging
Expand All @@ -21,7 +20,7 @@ I was inspired by http://stackoverflow.com/questions/5469828/how-to-create-a-cal
* check what's happening when you plug/unplug your monitor


## License
## License

I'm not responsible of the effect of this script on your computer

Expand Down
30 changes: 12 additions & 18 deletions usr/local/bin/monitor-hotplug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,30 @@ displaynum=`ls /tmp/.X11-unix/* | sed s#/tmp/.X11-unix/X##`
display=":$displaynum.0"
export DISPLAY=":$displaynum.0"

uid=$(ck-list-sessions | awk 'BEGIN { unix_user = ""; } /^Session/ { unix_user = ""; } /unix-user =/ { gsub(/'\''/,"",$3); unix_user = $3; } /x11-display = '\'$display\''/ { print unix_user; exit (0); }')
if [ -n "$uid" ]; then
# from https://wiki.archlinux.org/index.php/Acpid#Laptop_Monitor_Power_Off
export XAUTHORITY=$(ps -C Xorg -f --no-header | sed -n 's/.*-auth //; s/ -[^ ].*//; p')
else
echo "unable to find an X session"
exit 1
fi
# from https://wiki.archlinux.org/index.php/Acpid#Laptop_Monitor_Power_Off
export XAUTHORITY=$(ps -C Xorg -f --no-header | sed -n 's/.*-auth //; s/ -[^ ].*//; p')


#this while loop declare the $HDMI1 $VGA1 $LVDS1 and others if they are plugged in
while read l
do
dir=$(dirname $l);
status=$(cat $l);
dev=$(echo $dir | cut -d\- -f 2-);
while read l
do
dir=$(dirname $l);
status=$(cat $l);
dev=$(echo $dir | cut -d\- -f 2-);

if [ $(expr match $dev "HDMI") != "0" ]
then
#REMOVE THE -X- part from HDMI-X-n
dev=HDMI${dev#HDMI-?-}
else
else
dev=$(echo $dev | tr -d '-')
fi

if [ "connected" == "$status" ]
then
then
echo $dev "connected"
declare $dev="yes";
declare $dev="yes";

fi
done <<< "$DEVICES"

Expand Down

0 comments on commit 4a47986

Please sign in to comment.