How to make configuration more manageable - bakkeby/dusk GitHub Wiki

The default configuration file in dusk, at nearly a thousand lines, can admittedly be hard to navigate.

This quick guide shows a basic example of how you can split the config.h file into multiple files if that is something you might prefer.

General idea

Create separate configuration files for specific areas, then include those configuration files from the main config.h file.

Approach

How to do this is entirely up to you, but one approach would be to move all arrays and lists out to separate files while keeping minor variables in config.h.

This would leave the main config file at about 85 lines and nine additional files / groups; autostart, barrules, clientrules, colors, functionalilty, keybinings, layouts and wsrules.

The resulting config.h might then look something like this (note the #include statements towards the end).

/* See LICENSE file for copyright and license details. */

/* appearance */
static const unsigned int borderpx       = 5;   /* border pixel of windows */
static const unsigned int snap           = 32;  /* snap pixel */
static const unsigned int gappih         = 5;   /* horiz inner gap between windows */
static const unsigned int gappiv         = 5;   /* vert inner gap between windows */
static const unsigned int gappoh         = 5;   /* horiz outer gap between windows and screen edge */
static const unsigned int gappov         = 5;   /* vert outer gap between windows and screen edge */
static const unsigned int gappfl         = 5;   /* gap between floating windows (when relevant) */
static const unsigned int smartgaps_fact = 0;   /* smartgaps factor when there is only one client; 0 = no gaps, 3 = 3x outer gaps */

static unsigned int attachdefault        = AttachAside; // AttachMaster, AttachAbove, AttachAside, AttachBelow, AttachBottom

static const int initshowbar             = 1;   /* 0 means no bar */

static const int bar_height              = 0;   /* 0 means derive from font, >= 1 explicit height */
static const int vertpad                 = borderpx;  /* vertical (outer) padding of bar */
static const int sidepad                 = borderpx;  /* horizontal (outer) padding of bar */

static const int iconsize                = 16;  /* icon size */
static const int iconspacing             = 5;   /* space between icon and title */

static const int scalepreview            = 4;   /* size of workspace previews compared to monitor size */

static int floatposgrid_x                = 5;   /* float grid columns */
static int floatposgrid_y                = 5;   /* float grid rows */

static const int horizpadbar             = 2;   /* horizontal (inner) padding for statusbar (increases lrpad) */
static const int vertpadbar              = 0;   /* vertical (inner) padding for statusbar (increases bh, overridden by bar_height) */

static const char slopspawnstyle[]       = "-t 0 -c 0.92,0.85,0.69,0.3 -o"; /* do NOT define -f (format) here */
static const char slopresizestyle[]      = "-t 0 -c 0.92,0.85,0.69,0.3"; /* do NOT define -f (format) here */
static const unsigned int systrayspacing = 2;   /* systray spacing */
static const char *toggle_float_pos      = "50% 50% 80% 80%"; // default floating position when triggering togglefloating
static const double defaultopacity       = 0;   /* client default opacity, e.g. 0.75. 0 means don't apply opacity */
static const double moveopacity          = 0;   /* client opacity when being moved, 0 means don't apply opacity */
static const double resizeopacity        = 0;   /* client opacity when being resized, 0 means don't apply opacity */
static const double placeopacity         = 0;   /* client opacity when being placed, 0 means don't apply opacity */

/* Indicators: see lib/bar_indicators.h for options */
static int indicators[IndicatorLast] = {
	[IndicatorFloating] = INDICATOR_NONE,
};

/* Custom indicators using status2d markup, e.g. enabled via INDICATOR_CUSTOM_3 */
static char *custom_2d_indicator_1 = "^c#00A523^^r0,h,w,2^"; // green underline
static char *custom_2d_indicator_2 = "^c#55cdfc^^r3,3,4,4^^c#E72608^^r4,4,2,2^"; // blue rectangle
static char *custom_2d_indicator_3 = "^f-10^^c#E72608^𐄛"; // example using a character as an indicator
static char *custom_2d_indicator_4 = "^c#E26F0B^^r0,h,w,1^^r0,0,1,h^^r0,0,w,1^^rw,0,1,h^"; // orange box
static char *custom_2d_indicator_5 = "^c#CB9700^^r0,h,w,1^^r0,0,w,1^"; // top and bottom lines
static char *custom_2d_indicator_6 = "^c#F0A523^^r6,2,1,-4^^r-6,2,1,-4^"; // orange vertical bars

/* The below are only used if the WorkspaceLabels functionality is enabled */
static char *occupied_workspace_label_format = "%s: %s"; /* format of a workspace label */
static char *vacant_workspace_label_format = "%s";       /* format of an empty / vacant workspace */
static int lowercase_workspace_labels = 1;               /* whether to change workspace labels to lower case */

static int flexwintitle_masterweight     = 15; // master weight compared to hidden and floating window titles
static int flexwintitle_stackweight      = 4;  // stack weight compared to hidden and floating window titles
static int flexwintitle_hiddenweight     = 0;  // hidden window title weight
static int flexwintitle_floatweight      = 0;  // floating window title weight, set to 0 to not show floating windows
static int flexwintitle_separator        = 0;  // width of client separator

static const char *fonts[]               = { "monospace:size=10" };
static const char dmenufont[]            = "monospace:size=10";

static const float mfact     = 0.50; /* factor of master area size [0.05..0.95] */
static const int nmaster     = 1;    /* number of clients in master area */
static const int nstack      = 0;    /* number of clients in primary stack area */
static const int enablegaps  = 1;    /* whether gaps are enabled by default or not */

#include "config.autostart.h"
#include "config.functionality.h"
#include "config.colors.h"
#include "config.clientrules.h"
#include "config.barrules.h"
#include "config.wsrules.h"
#include "config.layouts.h"
#include "config.keybindings.h"

In this example the config.functionality.h would only contain the functionality variable:

/* See util.h for options */
static uint64_t functionality = 0
//	|AutoReduceNmaster // automatically reduce the number of master clients if one is closed
//	|SmartGaps // enables no or increased gaps if there is only one visible window
//	|SmartGapsMonocle // enforces no gaps in monocle layout
	|Systray // enables a systray in the bar
	...

whereas config.colors.h would contain all the colour variables, the alpha arrays and the setting of all the colour schemes.

Pros

A solution like this can make it easy to get to configuration option that you change more frequently than others.

Cons

On the other hand this can make it more cumbersome to check for configuration differences when updating the window manager.

Debate

Q: Why is the configuration not divided like this in the first place?

A: It would make configuration more difficult to maintain. There would be no separation between the default and personal configuration unless there was a .def.h file for each of the ten files. Also having that would likely just make it even more confusing for the end user to navigate to the right file.


Back to Guides.

⚠️ **GitHub.com Fallback** ⚠️