Xplugd Save

Monitor, keyboard, and mouse plug/unplug helper for X

Project README

xplugd - X plug daemon

Travis Status Coverity Status

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.

Open Source Agenda is not affiliated with "Xplugd" Project. README Source: troglobit/xplugd
Stars
64
Open Issues
5
Last Commit
1 year ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating