xhotplug

Run arbirary commands in response to newly connected X11 displays
git clone git://git.danielmoch.com/xhotplug.git
Log | Files | Refs | README | LICENSE

xhotplug.1 (2501B)


      1 .\" See LICENSE file for copyright and license details
      2 .Dd 2020-07-05
      3 .Dt XHOTPLUG 1
      4 .Os
      5 .Sh NAME
      6 .Nm xhotplug
      7 .Nd X11 monitor attach/detach event responder
      8 .Sh SYNOPSIS
      9 .Nm
     10 .Op Fl hv
     11 .Ar script
     12 .Sh DESCRIPTION
     13 .Nm
     14 is a simple tool designed to respond to X11 monitor attach/detach
     15 events.
     16 It can be used on systems without udev to, for example, dynamically
     17 reconfigure monitors via
     18 .Xr xrandr 1 .
     19 .Pp
     20 Upon invocation,
     21 .Nm
     22 reads the required
     23 .Ar script
     24 argument and checks that the file pointed to by it can be executed.
     25 The file pointed to by
     26 .Ar script
     27 is considered not to be executable if one of the following conditions
     28 is met:
     29 .Pp
     30 .Bl -bullet -compact
     31 .It
     32 The file for directory containing
     33 .Ar script
     34 does not exist or cannot be read.
     35 .It
     36 The file is world-writeable.
     37 .It
     38 The file is not owned by the current user or the superuser.
     39 .It
     40 The file's executable bit is not set.
     41 .El
     42 .Pp
     43 If the above checks pass,
     44 .Nm
     45 waits for monitor attach/detach events, calling
     46 .Ar script
     47 whenever one is received.
     48 .Sh OPTIONS
     49 .Bl -tag -width Ds
     50 .It Fl h
     51 Print usage and exit.
     52 .It Fl v
     53 Print version and exit.
     54 .El
     55 .Sh EXAMPLES
     56 There are several ways to make use of xhotplug.
     57 The easiest is to add the following line to
     58 .Pa $HOME/.xession
     59 (or
     60 .Pa $HOME/.xinitrc
     61 if you use xinit):
     62 .Pp
     63 .Dl xhotplug script &
     64 .Pp
     65 Many desktop environments provide a way to add startup programs,
     66 although they probably also detect new displays on their own.
     67 .Pp
     68 The script called by
     69 .Nm
     70 must be able to determine which monitors are currently connected and respond accordingly.
     71 The below script does this, using
     72 .Xr xrandr 1
     73 to configure the screen:
     74 .Pp
     75 .Bd -literal -offset indent -compact
     76 #!/bin/sh
     77 
     78 expected="eDP-1 DP-1-3"
     79 
     80 for mon in $expected
     81 do
     82 	if xrandr -q | grep $mon | grep ' connected' >/dev/null 2>&1
     83 	then
     84 		connected="$connected $mon"
     85 	else
     86 		disconnected="$disconnected $mon"
     87 	fi
     88 done
     89 
     90 cmd="xrandr --dpi eDP-1"
     91 
     92 for mon in $connected
     93 do
     94 	if [ "$mon" = "eDP-1" ]
     95 	then
     96 		cmd="$cmd --output eDP-1 --auto --primary"
     97 	elif [ "$mon" = "DP-1-3" ]
     98 	then
     99 		cmd="$cmd --output DP-1-3 --auto --right-of eDP-1 --scale 2x2"
    100 	fi
    101 done
    102 
    103 for mon in $disconnected
    104 do
    105 	cmd="$cmd --output $mon --off"
    106 done
    107 
    108 echo "my-screen.local: Running cmd $cmd" >> "$HOME/var/log/my"
    109 $cmd
    110 .Eb
    111 .Sh EXIT STATUS
    112 .Ex -std
    113 .Sh SEE ALSO
    114 .Xr xrandr 1
    115 .Sh HISTORY
    116 .Nm
    117 is based on a
    118 .Lk https://gist.github.com/mafrasi2/4ee01e0ba4dad20cf7a80ae463f32fca "Gist by GitHub user mafrasi2" .
    119 .Sh AUTHORS
    120 .Nm
    121 was written by
    122 .An Daniel Moch Aq Mt daniel@danielmoch.com .