Tested on OpenBSD 6.3 and ThinkPad X1C5

Dock laptop with xrandr(1), xinput(1), xrdb(1), and sysctl(8)

TL;DR: Check out my dock and undock.

Screens

Toggle displays with xrandr(1). For example, only laptop’s display (eDP-1) is on, then an external one (HDMI-1), then both side by side:

$ xrandr --output eDP-1 --auto --output HDMI-1 --off
$ xrandr --output HDMI-1 --auto --output eDP-1 --off
$ xrandr --output HDMI-1 --auto --output eDP-1 --auto --right-of HDMI-1
$

Mouse, track point, and touchpad

List all connected devices with xinput(1):

$ xinput
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ /dev/wsmouse0                             id=7    [slave  pointer  (2)]
⎜   ↳ /dev/wsmouse                              id=8    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ /dev/wskbd                                id=6    [slave  keyboard (3)]
$

In this example, /dev/wsmouse0 is a built-in touchpad and /dev/wsmouse is an external mouse. Reverse scrolling (swap 4 and 5, 6 and 7) for the touchpad and slow down the mouse.

$ xinput set-button-map /dev/wsmouse0 1 2 3 5 4 7 6
$ xinput set-prop /dev/wsmouse 'Device Accel Constant Deceleration' 5
$

For devices (e.g. trackballs) with two buttons: enable Middle Button Emulation and then press two buttons at the same time to emulate the middle button.

$ xinput set-prop /dev/wsmouse 'WS Pointer Middle Button Emulation' 1
$

For devices (e.g. mices) with three or more buttons: Enable Wheel Emulation, then hold the middle button (2) and move the mouse up and down to scroll. Adjust Inertia and Timeout if needed.

$ xinput set-prop /dev/wsmouse 'WS Pointer Wheel Emulation'         1
$ xinput set-prop /dev/wsmouse 'WS Pointer Wheel Emulation Button'  2
$ xinput set-prop /dev/wsmouse 'WS Pointer Wheel Emulation Inertia' 3
$ xinput set-prop /dev/wsmouse 'WS Pointer Wheel Emulation Timeout' 500
$

Install unclutter:

# pkg_add unclutter
quirks-3.16 signed on 2018-10-12T15:26:25Z
unclutter-8p1: ok
#

…then add this line to ~/.xsession to hide X pointer when it has not moved for a few seconds:

unclutter -root -idle 2 -noevents &

See also my .xsession.

Fonts

Toggle DPI for all X programs (including Firefox) and fonts for xterm(1). On high DPI screens, use large TrueType fonts:

Xft.dpi: 133
XTerm*font:
XTerm*faceName: DejaVu Sans Mono:size=12

On low DPI screens, use bitmap ones:

Xft.dpi: 92
XTerm*font: -misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1
XTerm*faceName:

To apply these settings use xrdb(1) (don’t forget to restart X programs after that):

$ xrdb .Xdefaults
$ echo 'Xft.dpi: 92' | xrdb -merge
$

Here is my .Xdefaults.

Lid

Define an action on laptop’s lid closing. Do nothing (0), suspend (1), or hibernate (2):

# sysctl machdep.lidaction=0
machdep.lidaction: 2 -> 0
# sysctl machdep.lidaction=1
machdep.lidaction: 0 -> 1
# sysctl machdep.lidaction=2
machdep.lidaction: 1 -> 2
#