summaryrefslogblamecommitdiff
path: root/drafts/2021-09-26-forget-autorandr-automate-display-switching-with-devd-on-freebsd.php
blob: 8ae50f71884aec86c574a7f8d45c19135b03ec29 (plain) (tree)








































                                                                                                                                                                                                                                                                                                                                                                                                                                  
<?php
$title = "Forget autorandr, Automate Display Switching with devd(8) on FreeBSD";
if (isset($early) && $early) {
	return;
}
include($_SERVER['DOCUMENT_ROOT'] . '/includes/head.php');
?>

<p class="description">
	<a href="https://github.com/phillipberndt/autorandr"><code>autorandr</code></a> and <a href="https://github.com/libthinkpad/dockd"><code>dockd</code></a> have been around for a while. Both let you automatically switch to or from external displays when your laptop is plugged into a hub or hooked up to a docking station. But those are largely Linux- and Thinkpad-centric solutions. Let's do it the FreeBSD way.
</p>

<p>
	Here are my requirements. I have an E-series Dell laptop with a docking station. My docking station is hooked up to one large Dell monitor. When the laptop is attached to the docking station, I want...
</p>

<ol>
	<li>The laptop to use the larger, external monitor exclusively (no mirroring)</li>
	<li>The default sound device to switch to the external monitor's speakers</li>
	<li>Disable automatic locking via <code>xautolock(1)</code></li>
	<li>Disable suspend on lid close</li>
</ol>

<p>When the laptop is removed from the docking station, I want...</p>

<ol>
	<li>The laptop to switch to its internal display</li>
	<li>The default sound device to switch back to the internal laptop speakers</li>
	<li>Automatic locking to re-enable</li>
	<li>Suspend on lid close to re-enable</li>
</ol>

<p>To do this we'll need the following:</p>

<ol>
	<li><code>devd(8)</code> for launching userland applications when kernel events occur</li>
	<li><code>xrandr(1)</code> for switching displays</li>
	<li><code>xautolock(1)</code> for automatic locking</li>
	<li><code>sysctl(8)</code> for changing hardware knobs</li>
	<li>Some core utilities and a tiny shell script to bring it all together</li>
</ol>