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.

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

# ******************** 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: grouponly[n] and 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 M-1 grouponly1
bind M-2 grouponly2
bind M-3 grouponly3
bind M-4 grouponly4
bind M-5 grouponly5
bind M-6 grouponly6
bind M-7 grouponly7
bind M-8 grouponly8
bind M-9 grouponly9
bind MS-1 movetogroup1
bind MS-2 movetogroup2
bind MS-3 movetogroup3
bind MS-4 movetogroup4
bind MS-5 movetogroup5
bind MS-6 movetogroup6
bind MS-7 movetogroup7
bind MS-8 movetogroup8
bind MS-9 movetogroup9

# 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].

# 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 "web.telegram.org,chromium-browser"
autogroup 2 "web.whatsapp.com,chromium-browser"
autogroup 2 "web.skype.com__es,chromium-browser"
autogroup 2 "crx_bikioccmkafdpakkkcpdbppfkghcmihk,chromium-browser"

# Rest of chrom tabs to Desktop#4
autogroup 4 "chromium-browser,chromium-browser"

# ******************** 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 M-u setxkbmap us
bind M-e setxkbmap es

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

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

# Redefine CM-Return to use some definitions of (u)xterm
# Using the uxterm of xterm is required
# to start an X terminal just right for
# UTF-8 support.
# For available fonts, check xlsfonts

bind CM-Return 'uxterm -fa "Bitstream Vera Sans Mono" +sb -fs 12 -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'

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

bind 4-m 'uxterm -fa "Bitstream Vera Sans Mono" +sb -fs 12 -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"'

# lock the screen with 4-l

bind 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 4-t "chrome --app=https://web.telegram.org/"
bind 4-w "chrome --app=https://web.whatsapp.com/"
# 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
bind 4-s "chrome --app-id=bikioccmkafdpakkkcpdbppfkghcmihk"
bind 4-S "chrome --app=https://web.skype.com/es/"

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

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

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

# Get battery life with xmessage
bind 4-b /home/pau/bin/xmessage_apm.sh

# Time with xmessage as well
bind 4-h /home/pau/bin/xmessage_hora.sh