HandleBar: “Hacking” my way to productivity [Part 2]: Chunkwm and Application Space Assignment

Thomas Ring
Aug 24, 2017 · 6 min read

Although I originally intended for this series to be weeks apart, there has been a big change in the main window manager, mostly that it has been rewritten from kwm to chunkwm and has been relatively unstable (but mostly not available on homebrew). This means that most of the work I’ve done to date has to be rewritten for the new system, although a lot of the UI was already configured for the second article.

The changes are focused around creating a plugin architecture. I have not dabbled in writing my own plugin yet, so I can not speak to the new system yet. However, you can read all of the changes from kwm to chunkwm on the Github page.

This opportunity will give us the chance to look at the new window manager and understand it better for future configuration.

Installation

Installation via homebrew required adding the example configuration file to the new config file directory, `~/.chunkwmrc`. My first task would be to convert my previous .kwmrc configuration to the new .chunkwmrc configuration. The default configuration file, included in chunkwm, can be found here.

The new chunkwm plugin architecture requires loading of the plugins in the configuration file, which should get all the new configuration out of the way. It appears that there are currently three plugins:

  • `chunkwm-tiling`: handles all commands and having to do with tiling windows in the different modes from kwm but with more configuration.
  • `chunkwm-border`: handles bordering windows based on their state

There are also three other plugins in the plugin folder: ffm, transparency and template. These do not include README.md files for configuration because either it has not been written yet or they are internal and not for configuration from the user. ffm is listed in the main README as a plugin that is available, which suggests that transparency is either under development or a supporting file and that template is a template for future plugins.

Additionally the main README mentions khd, a separately application that allows you to tie key commands to bash commands which is very useful.

NOTE: All plugins aside from the two bulleted above will be covered in a later article.

The plugins we’ll use here are imported by default in the example configuration file:

### LINE 8 (Configure the location of the plugins)
chunkc core::plugin_dir ~/.chunkwm_plugins
### LINE 88 (Load the plugins from the configured location
#
# NOTE: specify plugins to load when chunkwm starts.
# if chunkc plugin_dir is not set, the absolutepath is necessary.
#
chunkc core::load tiling.so
chunkc core::load ffm.so
chunkc core::load border.so

After starting chunkwm with the some of the default configuration (I disabled all space, window and application specific configurations), it works just like kwm: windows resize to take up the appropriate size, although the size is not what is was before.

(Re)Configuration

Documentation for chunkwm is organized much better and is significantly easier to read. It is also similar: define global “defaults” for each configuration and then set configurations for specific spaces, applications or windows.

This reconfiguration gives me an opportunity to rewrite some of the bash scripts I had previously and replace them with one line bash commands, which, when a command runs at least one time a second, will cut down on battery, CPU and RAM usage.

Tiling

Tiling is the main feature of chunkwm and is the most obvious to configure first. Everything that could be configured in kwm can be configured in chunkwm, as well as set window_fade_inactive and a few other features having to do with fading, but they require another module named chwm-sa. I’m assuming this means that inactive windows in a BSP are eventually faded with a configured opacity, but I’ll have to try it out with new setups since my previous on did not use too many BSPs.

It is worth noting that although the ffm plugin is supposed to encapsulate all configurations having to do with following the mouse including following window focus using the mouse, all configuration for it is in the tiling plugin configuration documentation.This may mean that ffm is a “sub-plugin” of the tiling plugin.

Configuration for the tiling plugin can be read here.

Border

Another feature used very rarely by me, I’ll set this to what I had before and see if some ideas I have for the future might utilize the border more effectively.

Configuration for the border plugin can be read here.

Spaces and Window Rules

While technically these configurations fall under the tiling plugin, they are so important to my own setup because of how each desktop is treated differently for workflow that I consider it its own section. The most important part is that applications are enforced to be within certain spaces within the desktop to help with the workflow. These were very easy to set for windows and took nearly the same amount of lines.

However, spaces are missing the ability to be named and to query the name. This was incredibly important as the ubersicht widget that allows you to glance up and see how far away you were from any application was very useful to me before switching to chunkwm.

As of time of writing, I have submitted an issue ticket on Github and may have a few solutions, including a plugin.

Fixing Ubersicht Widgets

With all the configurations fixed for the time being, the widgets must be fixed since all of the commands are different and have different outputs. This will also give an opportunity to show all the new widgets and their appearance.

Some widgets have been omitted from this post until they are complete and because they have no interactions with the window manager.

Focused-Window

Previous the command for the focused window was: /usr/local/bin/kwmc query window focused name. However, now you must query the plugin through chunkwm using /usr/local/bin/chunkc tiling::query — window name. Note that I use the full path to the command since Ubersicht has a hard time identifying the correct path variable.

Before: I was assigning a command to get a state to R and calling it as a tag which had styling to show whether the window was floating or not. The cutoff text is because of the height constraint on the widget.
After: No more special indications of floating windows, just their name.

Spaces

There is not currently a way to get space information from chunkwm, I will have to look into either writing a plugin or a separate command.

Chunkwm Status

This widget was meant to be clickable to toggle kwm off and on incase applications that could not be picked up/blacklisted were going to be used. It used a simple command: /usr/local/bin/kwmc query mouse-follows-focus. While this command did not actually check if kwm was running, it did return an error if it was not running, which we could parse as “off.”

At first this seemed easy: run any command, preferably the least expensive one, and check if there is an error. If there is an error, display that it is off, otherwise display that it is on. However, after hours of fiddling with this approach I realized that there was a problem with the new printing for errors: they were being printed through stderr, not stdout, and the piping that I had used in the previous bash command was not working.

The revised command redirects the stderr command through sed, which returns zero (0) for off and one (1) for on, which is much easier to parse. Here’s the new command:

/usr/local/bin/chunkc tiling::query — desktop id 2>&1 >/dev/null | sed “s/chunkc: connection failed\!/0/”

Explained: we execute an arbitrary command and redirect it to stdout so we can pipe the results to sed. Sed searches for the error string “chunkc: connection failed!” (bash requires all “!”s in quotations marks to be escaped) and replaces it with 0. I did attempt to change the output to a 1 if chunkwm was running, but the conversion from stderr to stdout may have prevented any other output from reaching the command’s pipeline.

Final (WIP) Product

Continued Development

Chunkwm is still under development and is much more stable now then when I installed it months ago, as well as gained support from the community.

I’m planning on working on some custom plugins for chunkwm since there is no longer support for Spaces naming (see my issue ticket here) as well as improving the Ubersicht widgets. I have also gotten around to reading Getting Things Done which has helped tremendously in continued development.

)

Thomas Ring

Written by

iOS Developer and techno-fundamentalist.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade