DEV Community

Maik Derstappen
Maik Derstappen

Posted on • Originally published at mrtango.planetcrazy.de on

Dynamic screen definitions in i3wm

Below we will generate a custom screens definition config file for i3 and using update-conf.py to generate the i3 config from a config.d directory.

Installing requirements

To generate a config file from a config.d, we are using the Python package update-conf.py, so lets install it.

sudo pip install update-conf.py

Enter fullscreen mode Exit fullscreen mode

Separating i3 config files

Now let's create the config.d directory and put our config files into the directory.

mkdir ~/.i3/config.d
cp ~/.i3/config ~/.i3/config.d/99-main

Enter fullscreen mode Exit fullscreen mode

For the screen definitions we want a separate config file the following:

set $mainscreen DP-1
set $sidescreen eDP-1

Enter fullscreen mode Exit fullscreen mode

Creating the gen-screen-config.sh script

This file will change if, we use a different settings of monitors or plug a monitor into a different port on the computer. To update this file we will use the following script.

#!/bin/bash

xrandr --listactivemonitors | awk '$1 ~ /^0/ {print "set $mainscreen " $4}'
xrandr --listactivemonitors | awk '$1 ~ /^1/ {print "set $sidescreen " $4}'

Enter fullscreen mode Exit fullscreen mode

Generating the screen config file for i3

You can use the script like this:

./gen-screens-conf.sh > ~/.i3/config.d/10-screens

Enter fullscreen mode Exit fullscreen mode

Generating the i3 config from config.d files

To generate the i3 config file from the config.d directory, we use the update-conf.py:

update-conf.py -f /home/maik/.i3/config

Enter fullscreen mode Exit fullscreen mode

This will concatenate all files in config.d directory into the i3 config file.

Optimizing the process

To make it easier to switch between setups, we can integrate the calls into i3 restart binding.

To not mess up the i3 config and to make sure the screens config config is generated when we regenerate the i3 config, we create enother script called refresh-screensettings.sh.

#!/bin/bash

~/.i3/scripts/gen-screens-conf.sh > ~/.i3/config.d/10-screens
update-conf.py -f ~/.i3/config

Enter fullscreen mode Exit fullscreen mode

With this script in place we can use it in the restart binding as follow:

bindsym $mod+Shift+r exec /home/john/.i3/scripts/refresh-screensettings.sh; restart

Enter fullscreen mode Exit fullscreen mode

Now, every time we change the setup, we just need to restart i3. Make sure you have set the primary screen before restarting i3. You can do that for example with the ARandR program.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more