xplugd - X plug daemon
xplugd is a UNIX daemon that executes a script on X input and RandR
changes, i.e., when a, keyboard, mouse. or a monitor is plugged in or
unplugged. Useful in combination with lightweight setups, e.g. when
running an X window manager like Awesome, Fluxbox, or similar to
detect when docking or undocking a laptop.
Usage
xplugd [-hnpsv] [-l LEVEL] [FILE]
-h Show help text and exit
-l LEVEL Set log level: none, err, info, notice*, debug
-n Run in foreground, do not fork to background
-p Probe currently connected outputs and output EDID info.
-s Use syslog, even if running in foreground, default w/o -n
-v Show version info and exit
FILE Optional script argument, default $XDG_CONFIG_HOME/xplugrc
Fallback also checks for ~/.config/xplugrc and ~/.xplugrc
When FILE is omitted xplugd uses $XDG_CONFIG_HOME/xplugrc, if that
cannot be found ~/.config/xplugrc is tried, and finally ~/.xplugrc.
The file is called as a shell script on plug events as follows:
xplugrc TYPE DEVICE STATUS ["Optional Description"]
| | |
| | `---- connected or disconnected
| `----------- HDMI3, LVDS1, VGA1, etc.
`---------------- keyboard, pointer, display
The script may be called like this, notice how the description is not included for displays:
xplugrc display HDMI3 disconnected
xplugrc keyboard 3 connected "Topre Corporation Realforce 87"
The keyboard or pointer is always the X slave keyboard or pointer, and
the status encoding for XIStatusEnabled and XIStatusDisabled is
forwarded to the script as connected and disconnected, respectively.
If EDID data is available from a connected display, the monitor model is passed in as fourth argument ("Optional Description") to the script.
Example ~/.config/xplugrc
#!/bin/sh
LAPTOP=LVDS1
DOCK=HDMI3
DESKPOS=--left-of
PRESPOS=--right-of
if [ "$1" != "display" ]; then
case "$1,$3,$4" in
pointer,conntected,"SynPS/2 Synaptics TouchPad")
xinput set-prop $2 'Synaptics Off' 1
;;
keyboard,connected,*)
setxkbmap -option ctrl:nocaps
;;
esac
exit 0
fi
if [ "$3" = "disconnected" ]; then
xrandr --output $2 --off
exit 0
fi
if [ "$2" = "${DOCK}" ]; then
xrandr --output $2 --auto --primary ${DESKPOS} ${LAPTOP}
elif [ "$1" != "${LAPTOP}" ]; then
xrandr --output $2 --auto ${PRESPOS} ${LAPTOP} --primary
else
xrandr --auto
fi
Build & Install
To build xplugd you need the standard libraries and header files for
X11, X11 input, and Xrandr. On a Debian/Ubuntu system these files can
be installed with:
sudo apt install libx11-dev libxi-dev libxrandr-dev
Then run the configure script and make:
./configure && make
Unless building from the GIT sources, in which case ./autogen.sh first
must be called to create the configure script. With relased tarballs this
is not necessary.
To change the default installation prefix from /usr/local, use the
./configure --prefix=/some/other/path
Followed by
make all && sudo make install-strip
Origin & References
xplugd is composed from pieces of Stefan Bolte's srandrd
and Andrew Shadura's inputplug. Please report bugs and problems
to the xplugd project.
MIT/X Consortium License Copyright (C) 2012-2015 Stefan Bolte <portix@gmx.net> Copyright (C) 2013-2015 Andrew Shadura <andrewsh@debian.org> Copyright (C) 2016-2023 Joachim Wiberg <troglobit@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
