November 6, 2016

OpenBSD: cwm

OpenBSD comes with the nicest window manager I have ever used, cwm. It is light, of course, but in particular smartly thought. It is one of the main reasons I use OpenBSD as a desktop.

Check the latest update on github. The information here is an outdated example. In the github repository you will also find the scripts that I use on cwmrc.

My configuration file for cwm is thought to mimic eight virtual workspaces (groups):

1: mutt only
2: chat programmes
3: videos
4: net
5-8: work stuff 1-4

I like mutt on its own running in #1, and the chat programmes are chrome windows running Telegram or such. These chrome “tabs” automatically go to group 2 because WM_CLASS gets a particular name other than the default one of chrome when launched with the option --app

I have defined bindings which launch programmes and, thanks to autogroup, they automatically go to the workspaces specified above. The sticky feature forces new windows to be autogroupped to the current workspace (group), and grouponly and movetogroup allows you to select a window group while hiding windows in any other group (originally Mike Erdely’s idea, I took a lot about that idea from his page, so please refer to it for that matter).

# cwmrc configuration file
# Pau Amaro Seoane, Berlin, 02/Nov/2016

# 16/May/2017
# Changed to new syntax:
# bind-> bind-key
# group-> group-only-
# movetogroup-> window-movetogroup-

# ******************** Quick Notes ******************* #

# ================
# Quick notes
# ================

# CM-Enter spawns a new xterm
# CM-= maximizes the window vertically
# CMS-= maximizes the window horizontally
# MS-/ spawns exec menu (MS-/, then “firefox” launches Firefox)
# CM-[n] selects window group [n]
# CM-0 selects all groups
# CM-g adds currently selected window to currently selected group
# CMS-r restarts cwm (re-reading .cwmrc)
# CMS-q quits

# ******************** Windows decoration ******************* #

borderwidth 0
#color activeborder grey
#color inactiveborder black

# ******************** Virtual Desktops ******************* #

# ================
# Virtual Desktops
# ================
# There are two directives that aren’t included in the default keyboard shortcuts
# list: group-only-[n] and window-movetogroup-[n] (where [n] is the number corresponding to
# window groups 1-9).
# You can select a group and add a window to it. And you can toggle that group’s
# visibility with CM-[n].

# But, window groups get more powerful when you can select a window group while
# hiding windows in any other group.

# To do this, I added the following to my ~/.cwmrc (and typed CMS-r):

bind-key M-1 group-only-1
bind-key M-2 group-only-2
bind-key M-3 group-only-3
bind-key M-4 group-only-4
bind-key M-5 group-only-5
bind-key M-6 group-only-6
bind-key M-7 group-only-7
bind-key M-8 group-only-8
bind-key M-9 group-only-9
bind-key MS-1 window-movetogroup-1
bind-key MS-2 window-movetogroup-2
bind-key MS-3 window-movetogroup-3
bind-key MS-4 window-movetogroup-4
bind-key MS-5 window-movetogroup-5
bind-key MS-6 window-movetogroup-6
bind-key MS-7 window-movetogroup-7
bind-key MS-8 window-movetogroup-8
bind-key MS-9 window-movetogroup-9

# Now, if I type M-2, it only shows windows in window group 2.
# And, I can more easily move windows to other groups with MS-[n].
# For instance, shift+alt+2 will move the current window to group 2

# Turn on sticky-group mode, so that windows launched in current group
# stick to that group per default
sticky yes

# I am using -class “mutt” with xterm to run mutt
autogroup 1 “xterm,mutt”

# Launch web Telegram/Whatsapp/skype with
# chrome as an app, which removes
# deco and uses particular WM_CLASS
# (see bind section)
autogroup 2 “crx_clhhggbfdinjmjhajaheehoeibfljjno,Chromium-browser”
autogroup 2 “,Chromium-browser”
autogroup 2 “,Chromium-browser”
autogroup 2 “crx_bikioccmkafdpakkkcpdbppfkghcmihk,Chromium-browser”
autogroup 2 “,Chromium-browser”
# Rest of chrom tabs to Desktop#4
autogroup 4 “chromium-browser,Chromium-browser”

# Place firefox in Desktop#4
autogroup 4 “Navigator,Firefox”

# ******************** Bind definitions ******************* #

# In general, I use the win (4) key for “applications” and the alt (M) key for
# “configuration programmes”

# ******************** Configuration bindings

# Use win key and “u”, “e” to configure a US or an ES keyboard

bind-key M-u setxkbmap us
bind-key M-e setxkbmap es

# Use alt-d or alt-s to configure display (always forget if it’s _d_isplay or _s_creen)
bind-key M-d xfce4-display-settings
bind-key M-s xfce4-display-settings

# ******************** Applications bindings

# Redefine CM-Return to use some definitions of xterm
# For available fonts, check xlsfonts
# For Ubuntu fonts, install ubuntu-fonts
# If not available, use Bitstream Vera Sans Mono

bind-key CM-Return ‘xterm -fa “Ubuntu Mono” +sb -fs 17 -cc 46:48,47:48,63:48,37:48,38:48,35:48,58:48,45:48,126:48,43:48,61:48,64:48,36:48 -bg “#2f3238” -fg white’

# Define CM-r to login as root on xterm

bind-key CM-r ‘xterm -fa “Ubuntu Mono” +sb -fs 16 -cc 46:48,47:48,63:48,37:48,38:48,35:48,58:48,45:48,126:48,43:48,61:48,64:48,36:48 -bg black -fg red -title “BE CAREFUL” -e login su’

# Use win-m to launch mutt on xterm
# and use -class mutt to get an addendum
# on WM_CLASS which can be used to
# autogroup it on #1

bind-key 4-m /home/pau/bin/

#bind-key 4-m ‘xterm -fa “Bitstream Vera Sans Mono” +sb -fs 14 -cc 46:48,47:48,63:48,37:48,38:48,35:48,58:48,45:48,126:48,43:48,61:48,64:48,36:48 -bg black -fg white -class “mutt” -e “mutt”‘

# Use win-T to launch my script

bind-key 4-T ‘xterm -fa “Ubuntu Mono” +sb -fs 14 -cc 46:48,47:48,63:48,37:48,38:48,35:48,58:48,45:48,126:48,43:48,61:48,64:48,36:48 -bg black -fg white -class “mutt” -e “/home/pau/bin/”‘

# lock the screen with 4-l

bind-key 4-l slock

# Use win and t, w for web Telegram and Whatsapp. By running it with the “–app” flag
# window decoration seems to be removed but, more imporant, WM_CLASS inherits the URL
# we call, which allows us to autogroup it where we wish (in my case, Desktop#2)
bind-key 4-t “chrome –app=”
bind-key 4-w “chrome –app=”
# To obtain signal’s app ID, go to chrome://extensions, signal, Details: Create shortcut
# This will create a shortcut link in your Desktop folder. Use less to get the
# ID. It is the string after “StartupWMClass”, last line
bind-key 4-s “chrome –app-id=bikioccmkafdpakkkcpdbppfkghcmihk”
bind-key 4-S “chrome –app=”

# Use win-x for a screenshooter
bind-key 4-x xfce4-screenshooter

# Use CTRL+ALT+l to switch on LVDS1 with xrandr,
# switch off VGA1, and re-run feh for background
bind-key CM-l /home/pau/bin/

# Use CTRL+ALT+v to switch on VGA1 with xrandr,
# switch off LVDS1, and re-run feh for background
bind-key CM-v /home/pau/bin/

# Get battery life with xmessage
bind-key 4-b /home/pau/bin/

# Time with xmessage as well
bind-key 4-h /home/pau/bin/