xhotplug.1 in xhotplug

at master

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
14is a simple tool designed to respond to X11 monitor attach/detach
15events.
16It can be used on systems without udev to, for example, dynamically
17reconfigure monitors via
18.Xr xrandr 1 .
19.Pp
20Upon invocation,
21.Nm
22reads the required
23.Ar script
24argument and checks that the file pointed to by it can be executed.
25The file pointed to by
26.Ar script
27is considered not to be executable if one of the following conditions
28is met:
29.Pp
30.Bl -bullet -compact
31.It
32The file for directory containing
33.Ar script
34does not exist or cannot be read.
35.It
36The file is world-writeable.
37.It
38The file is not owned by the current user or the superuser.
39.It
40The file's executable bit is not set.
41.El
42.Pp
43If the above checks pass,
44.Nm
45waits for monitor attach/detach events, calling
46.Ar script
47whenever one is received.
48.Sh OPTIONS
49.Bl -tag -width Ds
50.It Fl h
51Print usage and exit.
52.It Fl v
53Print version and exit.
54.El
55.Sh EXAMPLES
56There are several ways to make use of xhotplug.
57The easiest is to add the following line to
58.Pa $HOME/.xession
59(or
60.Pa $HOME/.xinitrc
61if you use xinit):
62.Pp
63.Dl xhotplug script &
64.Pp
65Many desktop environments provide a way to add startup programs,
66although they probably also detect new displays on their own.
67.Pp
68The script called by
69.Nm
70must be able to determine which monitors are currently connected and respond accordingly.
71The below script does this, using
72.Xr xrandr 1
73to configure the screen:
74.Pp
75.Bd -literal -offset indent -compact
76#!/bin/sh
77
78expected="eDP-1 DP-1-3"
79
80for mon in $expected
81do
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
88done
89
90cmd="xrandr --dpi eDP-1"
91
92for mon in $connected
93do
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
101done
102
103for mon in $disconnected
104do
105 cmd="$cmd --output $mon --off"
106done
107
108echo "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
117is based on a
118.Lk https://gist.github.com/mafrasi2/4ee01e0ba4dad20cf7a80ae463f32fca "Gist by GitHub user mafrasi2" .
119.Sh AUTHORS
120.Nm
121was written by
122.An Daniel Moch Aq Mt daniel@danielmoch.com .