spectrwm - tiling made simple

PackRat

Tiling window managers are pretty efficient (low resource usage etc ...) and a good way to get the most out of limited screen real estate like on a netbook or laptop. The downside of a lot of tiling window managers is that they use complex programing languages like lua (awesome), haskel (xmonad), LISP (stumpwm), or python (qtile) for configuration. If you know the programing language, or are the type that likes to learn them, you can get a lot out of those window managers - just look at some of digit's xmonad setups if you don't believe me.

For those of us that prefer simpler text files for configuration there is spectrwm which according to the authors is:

Quotespectrwm is a small dynamic tiling window manager for X11. It tries to stay out of the way so that valuable screen real estate can be used for much more important stuff. It has sane defaults and does not require one to learn a language to do any configuration. It was written by hackers for hackers and it strives to be small, compact and fast.

That also makes it an excellent tiling window manager for those that are trying one out for the first time.

It's in the repos and fairly current, but when I installed it from the repos, a file related to keybindings didn't seem to get installed. The window manager still worked, but it's really handy to have that other file so I recommend you install from git.

Get the deps (there are 2-3 small files not installed by default):

sudo apt-get build-dep spectrwm

and install suckless-tools (provides dmenu and slock if you don't have them installed)

sudo apt-get install suckless-tools

then get the sources from git (git is not installed by default in VSIDO):

git page for spectrwm

or here (towards bottom of page)

spectrwm page

this creates a <build directory>/spectrwm; for linux, change to the <build dir>/spectrwm/linux

Quotecd <build dir>/spectrwm/linux

then:

Quotemake

# followed by

sudo make install

There is a spectrwm.desktop file included with the git download you can copy over to /usr/share/xsessions.

The main configuration file and the default keybinding file are also included with the git download. The main configuration file is spectrwm.conf, the keybinding file is tagged with a language - for me it is spectrwm_us.conf.

First thing to do is edit the spectrwm.conf file. In your favorite text editor find the lines:

# program[lock] = xlock

and change it to:

program[lock] = slock

instead of slock, you can use whatever screen locking program you use, or xscreensaver, etc  ....

also find this line:

#keyboard_mapping = ~/.spectrwm_us.conf

and uncomment it

keyboard_mapping = ~/.spectrwm_us.conf  <-- also edit to reflect the language file you're using; us is the default.


this allows you to edit the default keybindings for spectrwm.

Once that is done copy spectrwm.conf and spectrwm_us.conf to /etc to provide system-wide configuration. To make your own customized configuration, copy these two files to your home directory as dotfiles

cp spectrwm.conf ~/.spectrwm.conf

and

cp spectrwm_us.conf ~/.spectrwm_us.conf  <- use the lanuguage file of choice


Should be all set to log into the default configuration for spectrwm. To customize the configuration, you'll want to be familiar with xprop and xev so you can get the window class and key codes if you need them. Read the man pages for those as well as the man page for spectrwm. The man page for spectrwm is well written and worth the read.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

PackRat

#1
To configure spectrwm, you edit the ~/.spectrwm.conf file. It's pretty self-explanatory and editing it while you also have the man page open makes configuration really simple. The configuration file lists all the default settings, if you want to make a change, uncomment the line and make the change.

A couple changes I typically make:

# workspace_limit = 22
to
workspace_limit         = 9  <-- I can think of no situation where I need 22 workspaces


# focus_mode = default
to
focus_mode              = manual  <-- the default is focus follows mouse which is sort of annoying in a tiler, manual is the familiar click-to-focus


and similar through the rest of the file.

Note that for colors, spectrwm works with rgb notation or the name so its (for black): rgb:00/00/00, or black - not #000000 or "#000000".

Spectrwm has the typical default layouts, but I make a couple changes:

# layout = ws[1]:4:0:0:0:vertical
# layout = ws[2]:0:0:0:0:horizontal
to
layout = ws[1]:0:0:0:0:horizontal
layout = ws[2]:0:1:0:0:vertical


I prefer the horizontal (bottom stack) as default so I use it on workspace 1 ( ws[1] ). That first nuber (4) is a size increment increase (-4 would decrease) for the master window, I change it to 0 so that the master window is the same size as the stack, occupying 50% of the screen. For workspace 2, I add a master window - the 1 - so that the vertical layout is now a grid:

this -

becomes -

Definitely worth reading how to code those layouts in the spectrwm man page.

Spectrwm has it's own status bar, if you can script you can output to the bar by changing the line:

# bar_action = baraction.sh     <-- note that baraction.sh is included with the git download, but gives me a syntax error
to
bar_action = some_script.sh <- may need to use full path to script.
or if you prefer to use conky:
bar_action       = conky


conky needs to be configured so that it does not output to X:

.conkyrc

out_to_console yes
out_to_x no
background no
update_interval 1
total_run_times 0
use_spacer none

TEXT
<all your conky stuff>


If you prefer a statusbar like dzen2, you can use it as well. Either run it so that it covers the spectrwm statusbar, or create a region for it (or any panel). Creating a region in spectrwm is done by editing:

# region = screen[1]:1280x1024+0+0
# region = screen[1]:1280x1024+1280+0


It's somewhat counter intuitive in that the region is the amount of screen real estate used by the open windows, not the amount you want used by the panel. My laptop resolution is 1366x768 so a region:

region  = screen[1]:1366x740+0+0

makes a working area of 1366x740 and places the upper left corner of the region at +0+0 (upper left corner of screen). Leaves a 28 pixel gap at the bottom of the screen that I ca fill with my own dzen taksbar:

 

tint2 and xfce4-panel do not work well with spectrwm.

If you want to change the default keybindings of spectrwm, make edits to the ~/.spectrwm_us.conf file, if you want to add your own, add them to the ~/.spectrwm.conf file. Just follow the example provided for firefox.

Some apps you don't want tiled - like xcalc - for that you need to define a quirk for that app using the class. Use xprop to get the class name for the app, and then define the quirk - note that the quirk reverses the order of the class name provided by xprop.

Without a quirk -



add:

quirk[XCalc:xcalc] = FLOAT + ANYWHERE

to get -



quirks are also handy if you want to have a system tray - stalonetray works pretty well with spectrwm. This quirk:

quirk[stalonetray:stalonetray] = FLOAT + ANYWHERE + NOFOCUSCYCLE + NOFOCUSONMAP + OBEYAPPFOCUSREQ

causes stalonetray to float, and removes it from the cycling order so that Alt-Tabbing does not bring it into focus:



quirks can be set up for any app - like xfce4-appliction finder if you don't want to use dmenu. Another section of the man page you'll want to read.

That pretty much covers the hilights. The configuration file is well annotated and the man page is well written. Also read through the default keybinding file to know what the basics are:

MOD+Shift+Return - starts an xterm  <- by default the Alt key is the MOD, that can be changed in the .spectrwm.conf file
MOD+q - restarts the window manager
MOD+Shift+q - exits the window manager
MOD+p - runs dmenu

and plenty more for changing workspaces, resizing the master area, toggle floating etc ...

Spectrwm is an excellent window manager, and an excellent introduction to tiling.






I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

jedi

Very nice PackRat!  That was a lot of work.  Nicely done.  Now of course I'll have to try it out!  Been back to Fluxbox since my foray into the world of awesomewm.  Actual text file configs are a very tempting reason to give it a shot...
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

VastOne

What Jedi said... nice work wolfy...  ;)
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

#4
Thanks.

Should point out that the spectrwm bar does not support xft fonts, use xfontsel to find a font you like if you don't want terminus. It doesn't support colored output from conky, so keep your conkyrc simple.

VSIDO, spectrwm, urxvt, htop -



One popular feature is to have an application open on a certain workspace; this is also done with a quirk - by changing the default to this:

quirk[Gimp:gimp] = FULLSCREEN + WS[3]

gimp will open fullscreen on workspace 3.

Spectrwm also has an autorun section in the .spectrwm.conf:

# Launch applications in a workspace of choice
# autorun = ws[1]:xterm
# autorun = ws[2]:xombrero http://www.openbsd.org


add some apps here to start them when logging into spectrwm:

autorun = ws[4]:xchat
autorun = ws[1]:stalonetray -c ~/.stalonetray-spectrwm


starts xchat on workspace 4, and stalonetray in workspace 1

One limit of spectrwm is that the system tray isn't sticky across workspaces (neither are panels like tint2) so it is only visible on workspace 1 (only visible on the workspace it starts on). The xchat icon should blink when a message is recieved, and stalonetray will adhere to the quirks defined in the previous post.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

PackRat

#5
Slight update for mouse bindings and xft fonts -

I always thought that the mouse bindings in spectrwm were hard coded, but that is apparently not the case (as of 10 months ago anyway)

The bind[] option in spectrwm has been coded now to accept mouse pointer options -

spectrwm git version bind options for pointer

By default, spectrwm uses the familiar ALT+MOUSE to move and resize, now that can be changed along with other key bindings. For example, I change the default modifier from Mod1 (ALT) to Mod4 (WIN) - so Mod4+Mouse had to be used to move/resize floating windows. Now I can change that back to Mod1+Mouse and be consistent across window managers.

Fonts:

xft fonts can be used now. Find the appropriate lines in ~/.spectrwm.conf and edit to look similar to:

# bar_font      = -*-terminus-medium-r-normal-*-12-120-*-*-*-*-*-*                                < - comment out default
bar_font      = Blockzone:style=regular:size=11:antialias=true:hintstyle=slight                         < - syntax for xft font

spectrwm with BlockStone font for all you DOS fans -

I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

a

A lot of good tips, tried it out but the thing that keeps me from using Spectrwm is I can't get a bar to show me if there are any apps running on that workspace , the bar at the top could have 4 workspaces with an app open on one and I wouldn't know which. I dont use the default bar as I wanted one with clickable workspaces.
Here is my bar conf at the moment. (uses dzen2)
#!/bin/sh

#FG='#ffffff'
BG='#404040'
Time(){
date=$(date "+%a %b %d %I:%M")
echo -n "$date"
return
}

while true ; do
    echo "^fg(white)  ^ca(1,xdotool key super+1)1^ca() | ^ca(1,xdotool key super+2)Web^ca() | ^ca(1,xdotool key super+3)3^ca() | ^ca(1,xdotool key super+4)4^ca() | ^ca(1,xdotool key super+5)5^ca() |     ^fg(green) $(Time)" | dzen2 -p -w 1150 -bg $BG
    sleep 5
done

PackRat

You do need to script your own bar - or patch spectrwm - if you want that type of functionality.

I was looking through the Arch Wiki at some of the bars their users have created for snapwm, monsterwm etc ... If you can code, maybe one of those than can be ported to spectrwm.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

PackRat

Current configuration -



.spectrwm.conf

# PLEASE READ THE MAN PAGE BEFORE EDITING THIS FILE!
# http://opensource.conformal.com/cgi-bin/man-cgi?spectrwm
# NOTE: all rgb color values in this file are in hex! see XQueryColor for examples

workspace_limit = 9
focus_mode = manual
# focus_close = previous
# focus_close_wrap = 1
# focus_default = last
# spawn_position = next
# workspace_clamp = 1
# warp_focus = 1
# warp_pointer = 1

# Window Decoration
border_width = 2
color_focus = rgb:85/81/6F
color_focus_maximized = rgb:85/81/6F
color_unfocus = rgb:42/42/42
color_unfocus_maximized = rgb:42/42/42
region_padding = 3
tile_gap = 3

# Region containment
# Distance window must be dragged/resized beyond the region edge before it is
# allowed outside the region.
# boundary_width = 50

# Remove window border when bar is disabled and there is only one window in workspace
# disable_border = 1

# Bar Settings
bar_enabled = 1
bar_border_width = 1
bar_border[1] = rgb:5A/5A/5A
bar_border_unfocus[1] = rgb:5A/5A/5A
bar_color[1] = rgb:36/36/36
bar_font_color[1] = rgb:D6/D6/D6
# bar_font = xos4-terminus-medium-r-normal-*-14-140-72-72-c-80-iso8859-1
# bar_font = -*-dina-medium-r-normal-*-13-100-96-96-c-80-iso8859-1
bar_font        = Blockzone:style=regular:size=11:antialias=true:hintstyle=slight
bar_action = conky
bar_justify = left
bar_format = +2<+I+4<+S+4<%a %e %b %k:%M+4<+A
# bar_format = +4<+L+4<+S+4<%A %e %B %k:%M+8<+A
# bar_at_bottom = 1
# stack_enabled = 1
# clock_enabled = 1
# clock_format = %a %b %d %R %Z %Y
# iconic_enabled = 0
# maximize_hide_bar = 0
# window_class_enabled = 0
# window_instance_enabled = 0
# window_name_enabled = 0
# verbose_layout = 1
# urgent_enabled = 1

# Dialog box size ratio when using TRANSSZ quirk; 0.3 < dialog_ratio <= 1.0
# dialog_ratio = 0.6

# Split a non-RandR dual head setup into one region per monitor
# (non-standard driver-based multihead is not seen by spectrwm)
# region = screen[1]:1600x800+0+0
# region = screen[1]:1280x1024+1280+0

# Launch applications in a workspace of choice
# autorun = ws[1]:xterm
# autorun = ws[2]:xombrero http://www.openbsd.org

# Customize workspace layout at start
layout = ws[1]:0:0:0:0:horizontal
layout = ws[2]:0:1:0:0:horizontal
layout = ws[3]:0:0:0:0:fullscreen
layout = ws[4]:0:0:0:0:vertical
layout = ws[5]:0:1:0:0:vertical_flip
layout = ws[6]:0:0:0:0:fullscreen
layout = ws[7]:0:0:0:0:fullscreen
layout = ws[8]:0:0:0:0:vertical
layout = ws[9]:0:0:0:0:horizontal

# Set workspace name at start
# name = ws[1]:IRC
# name = ws[2]:Email
# name = ws[3]:Browse
# name = ws[10]:Music

# Mod key, (Windows key is Mod4) (Apple key on OSX is Mod2)
modkey = Mod4

# This allows you to include pre-defined key bindings for your keyboard layout.
keyboard_mapping = ~/.spectrwm_us.conf

# PROGRAMS

# Validated default programs:
program[lock] = slock
program[term] = xterm
program[menu] = dmenu_run

# To disable validation of the above, free the respective binding(s):
# bind[] = MOD+Shift+Delete # disable lock
# bind[] = MOD+Shift+Return # disable term
# bind[] = MOD+p # disable menu

bind[] = MOD+Button1
bind[] = MOD+Button3
bind[] = MOD+Button2
bind[] = MOD+Shift+Button3

# Optional default programs that will only be validated if you override:
# program[screenshot_all] = screenshot.sh full # optional
# program[screenshot_wind] = screenshot.sh window # optional
# program[initscr] = initscreen.sh # optional

# EXAMPLE: Define 'firefox' action and bind to key.
# program[firefox] = firefox http://spectrwm.org/
# bind[firefox] = MOD+Shift+b

program[firefox] = firefox
bind[firefox] = XF86HomePage

program[mail] = thunderbird
bind[mail] = XF86Mail

program[fmangr] = thunar
bind[fmangr] = Menu

program[editor] = subl3
bind[editor] = MOD+Control+l

program[art] = gimp
bind[art] = MOD+Control+g

program[ssheet] = libreoffice --calc
bind[ssheet] = MOD+Control+p

program[lodoc] = libreoffice --writer
bind[lodoc] = MOD+Control+o

program[volup] = amixer -q sset Master 5%+ unmute
bind[volup] = XF86AudioRaiseVolume

program[voldown] = amixer -q sset Master 5%- unmute
bind[voldown] = XF86AudioLowerVolume

program[volmute] = amixer sset Master,0 toggle
bind[volmute] = XF86AudioMute

#program[tray] = stalonetray -c /home/doug/.spectrwmtrayrc
#bind[tray] = XF86Tools

program[tmuxterm] = xterm -e tmux
bind[tmuxterm] = MOD+Shift+Return

program[Xterm] = xterm
bind[Xterm] = Mod1+F3

program[Calc] = xcalc
bind[Calc] = XF86Calculator

program[Logout] = void-logout
bind[Logout] = MOD+Shift+q

program[gtkmenu] = rofi -show
bind[gtkmenu] = Mod + d

# QUIRKS
# Default quirks, remove with: quirk[class:name] = NONE
# quirk[MPlayer:xv] = FLOAT + FULLSCREEN + FOCUSPREV
# quirk[OpenOffice.org 2.4:VCLSalFrame] = FLOAT
# quirk[OpenOffice.org 3.0:VCLSalFrame] = FLOAT
# quirk[OpenOffice.org 3.1:VCLSalFrame] = FLOAT
# quirk[Firefox-bin:firefox-bin] = TRANSSZ
# quirk[Firefox:Dialog] = FLOAT
# quirk[XTerm:xterm] = XTERM_FONTADJ
# quirk[xine:Xine Window] = FLOAT + ANYWHERE
# quirk[Xitk:Xitk Combo] = FLOAT + ANYWHERE
# quirk[xine:xine Panel] = FLOAT + ANYWHERE
# quirk[Xitk:Xine Window] = FLOAT + ANYWHERE
# quirk[xine:xine Video Fullscreen Window] = FULLSCREEN + FLOAT
# quirk[pcb:pcb] = FLOAT

quirk[Firefox:Dialog] = FLOAT
quirk[stalonetray:stalonetray] = FLOAT + ANYWHERE + NOFOCUSONMAP + MINIMALBORDER + NOFOCUSCYCLE
quirk[XCalc:xcalc] = FLOAT + ANYWHERE
quirk[Galculator:galculator] = FLOAT + ANYWHERE
quirk[Gcolor2:gcolor2] = FLOAT + ANYWHERE
quirk[Galculator:galculator] = FLOAT + ANYWHERE
#quirk[UXTerm:xterm] = FLOAT + ANYWHERE
#quirk[XTerm:xterm] = FLOAT + ANYWHERE
quirk[Thunderbird:Msgcompose] = FLOAT + ANYWHERE
quirk[Sakura:sakura] = FLOAT + ANYWHERE
quirk[Xfce4-appfinder:xfce4-appfinder] = FLOAT + ANYWHERE
quirk[Gimp:gimp] = FULLSCREEN


.conkyrc - version 1.10

conky.config = {
out_to_console = true,
out_to_x = false,
background = false,
cpu_avg_samples = 2,
net_avg_samples = 2,
no_buffers = true,
out_to_stderr = false,
update_interval = 1.0,
uppercase = false,
use_spacer = 'none',

};

conky.text = [[
Uptime:  ${uptime_short}    CPU:  ${cpu cpu0}%    ${loadavg}    Mem:  ${memperc}%    Net:  Down - ${downspeedf enp2s0} kb/s  Up - ${upspeedf enp2s0} kb/s 
]];


I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

PackRat

Using i3status for system information -



much easier to configure than conky; not as many options, but does have the basics which is all I want. Smaller memory footprint than conky.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

ozitraveller

@PackRat - Thanks for the reminder to try i3status again. I've tried it before in jessie, but had broken dependencies.

PackRat

I've been messing around with it; i3status piped to dzen2 with some clickable areas would make a nice panel for minimal wm's.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo