Fluxbox

Although I often try different window managers, I always come back to fluxbox.
Much of it is like Blackbox. However, it has a few nice points of its own.I'm certainly no expert on its use, however, this page might save the reader a few minutes of searching their documentation.

Note that much of this article is about the older, 0.1.14 version. That is now only available from fluxbox's site in the older versions section. Open and NetBSD don't even have it available anymore, though it is still in the FreeBSD ports as of September 2006, with the current version available in ports as fluxbox-devel.

In the section on 0.1.14 I give a good deal of space to installing and using Mr. Kita's menu key patch. However, the the 0.9.x versions have this included by default. As the information might be useful to some, and also useful for those who need to know how to configure a port in FreeBSD or package in Debian, I'm leaving it up.

After installation to start it, edit your .xinitrc or .Xclients (in RH) to read

exec startfluxbox

You'll have a fluxbox directory. In most Linux distros it'll be in /usr/share/fluxbox or /usr/local/share/fluxbox.

There is an article on Fluxbox's site about installing and starting Fluxbox for the beginner that may also be useful. You'll note some differences--for instance, they suggest that .xinitrc should have the full path to the executable, but I haven't found it necessary. (I would have done it that way but didn't read the article before starting, so assumed that it would work with a simple exec startfluxbox)

As I've been using it primarily in FreeBSD, for the purposes of this article, we'll assume that you have a file in /usr/X11R6/share. In there you'll see several directories and files, such as styles, init, keys, etc. With the latest development version, it sometimes creates a $HOME/.fluxbox directory the first time you run it, otherwise you may have to create it yourself

cd
mkdir .fluxbox

In older versions it helped to copy over keys, menu and init from the share directory, but nowadays, those files will be put in your $HOME/.fluxbox directory the first time you run the program.

Ok, so first the init directory. The init file has several parameters--it starts with a style called Clean. You can change this to a different style (the majority are the same as the Blackbox styles) if you wish. Find the line that reads

session.styleFile: /usr/X11R6/share/fluxbox/styles/Clean

Change Clean to the style that you wish to have upon startup. Say you wish to start with Artwiz. You would change the above session.styleFile to

session.styleFile: /usr/X11R6/share/fluxbox/styles/Artwiz

There is now also a parameter that you can put in your .fluxbox/init directory to simply call the last background or style that you had. If you add the line

session.screen0.rootCommand:    fbsetbg -l

fluxbox will retain the last background. It also keeps the last style chosen unless you specifically choose another style in init.

A quick note on the init file--recently, I was finding that despite changing the strftimeFormat parameter to %I:%M (which should give the time in 24 hour format) it was still giving me 12 hour format. The man page (In FreeBSD) didn't give me the answer--however, there's a parameter not mentioned in that man page, clockFormat. This was set to 12. It apparently overrode the strftimeFormat parameter. Changing it to 24 fixed the problem, and I got my 24 hour format.

For editing the start menu or changing backgrounds the process is almost the same as described in my article on Blackbox.

A quick example of menus.

Open your home directory's .fluxbox/menu file. You'll see that the pattern of a menu item is

[exec] (xterm) {xterm}

The exec means you can execute the command (hrrm, that was obvious), the second item is how it will appear in the menu and the third, in curly braces (or French braces if you prefer) is the actual command. So, say you wanted to add kterm, an xterminal that can input and output Japanese. You want it to appear directly under the listing for xterm. So, under the listing for xterm add

[exec] (kterm) {kterm}

The second listing is how it will appear when you right click on the desktop (which is how one sees available menu options). So, I could write Kterm or KTERM in there--it makes no difference, it only affects what I see when right-clicking to view the menu. One can add whatever programs they wish, under the pre-existing menus and submenus.

Another file in the /usr/local/share/fluxbox directory is keys. (Note there are some changes in the 0.9.x version.) The default file looks like

Mod1 Tab :NextWindow
Mod1 Shift Tab :PrevWindow
Mod1 F1 :Workspace 1
Mod1 F2 :Workspace 2
Mod1 F3 :Workspace 3
Mod1 F4 :Workspace 4
Mod1 F5 :Workspace 5
Mod1 F6 :Workspace 6
Mod1 F7 :Workspace 7
Mod1 F8 :Workspace 8
Mod1 F9 :Workspace 9
Mod1 F10 :Workspace 10
Mod1 F11 :Workspace 11
Mod1 F12 :Workspace 12

(In the 0.1.14 version, it was Workspace1, Workspace2, etc.) Mod1 refers to the Alt key. So, as in MS Windows, you can go from window to window with the Alt + Tab. It accepts the same parameters as bbkeys (actually, I think they have a script to convert your bbkeysrc file, though I didn't use it.) So, say you want Alt+F4 to close whatever you're in, as it does in Windows, Alt+m to minimize a window and the Windows key plus x to open up an xterm.

Change the Mod1 F4 :workspace4 to read

Mod1 F4 :Close

Now we'll add the Alt+m to minimize a window

Mod1 m :ShadeWindow

You'll note, if you're familiar with Blackbox, that the syntax and commands are generally the same as bbkeys.

The ExecCommand feature is handy.

Mod4 x :ExecCommand xterm

Mod4 refers to the Windows key, that is the key on most keyboards with the MS logo. ExecCommand, curiously enough executes a command, in this
case, xterm. You can make as many of these as you want--for instance, if you wanted Alt+k to start kmail you could add

Mod1 k :ExecCommand kmail

If the Mod4 key doesn't work, it means that when you set up X you probably picked a 101 or 102 key rather than 104 key keyboard. This is easily fixed. You'll need to be root or use sudo. Open up your favorite text editor and open /etc/X11/XF86Config or xorg.conf. (Sometimes, this will be /etc/X11/XF86Config-4). In there you will find the line

Option "XkbModel" "pc101"

Change it to read

Option "XkbModel" "pc104"

If you don't have that pc101 line in there, then you have some other problem. Some distributions, for some reason, don't automagically bind Mod4 to Super_L. You can check this with
xmodmap

You should see something like
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x6d)
mod1        Alt_L (0x40),  Alt_L (0x7d),  Meta_L (0x9c)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x7f),  Hyper_L (0x80)
mod5        Mode_switch (0x5d),  ISO_Level3_Shift (0x7c)

If you don't, you can create a $HOME/.xmodmaprc file. In that file put
keycode 115 = Super_L
keycode 116 = Super_R
keycode 117 = Menu

The last line enables you to use the Windows menu key as well.

Save this file in your home directory and then add the following to your .xinitrc (above the exec startfluxbox line)
xmodmap .xmodmaprc

Sometimes, this doesn't work for me. In that case, I have to add
add Mod4 = Super_L

to my .xmodmaprc file

It is possible that some xorg upgrades might change these keybindings. I haven't verified this yet, but I think that Mod4 has become keycode 133. To check a keycode you can always run the xev program. Then, when you hit a key, it will give you the keycode. I'm not sure if this is a result of the recent upgrade to xorg-7.3 or not. At any rate, if you've been using keycode 115 and it stops working, try keycode 133 and see if it helps.

I also wound up with some other odd issues once this happened. For example, if I put xmodmap ~/.xmodmaprc in my .xinitrc, although Mod4 would work, both Control and Shift keys stopped working. However, if I started X, and THEN ran xmodmap ~/.xmodmaprc, Mod4 would work and the Control and Shift keys worked as expected.

I recently found another fix--it's probably been around for awhile. Instead of the .xmodmaprc file, one can edit /etc/X11/xorg.conf. In the keyboard section, (the section beginning InputDevice that covers the keyboard, usually with the driver kbd) one can add the following option.
Option	 "XkbOptions" "altwin:left_meta_win"

I've only tested this on one machine, but it worked like a charm, with the additional benefit that Control and Shift also worked.

There's other nice things you can do with the key bindings. For example, you can open up the root menu, move windows with keystrokes, etc. I have for example, in my fluxbox keys file

Mod4 j  :MoveDown 50
Mod4 k  :MoveUp  50     
Mod4 h  :MoveLeft 50
Mod4 l  :MoveRight 50

(In 0.1.14 this was BigNudgeDown, BigNudgeUp, etc) If you use vi, you'll recognize why I chose those particular letters, since they duplicate vi movement commands. You can also simply use the more prosaic Up Down Left Right with whatever Mod key you choose, and then use the arrow keys, such as

Mod4 Down :MoveDown 50

If you did that, then the Windows key and down arrow will move the window down.

The 0.9.x version has a few nice eye candy tricks. For example, if you prefer a window with no decorations, until now, you had to always do the ToggleDecor thing. There is now an additional file you can put in your $HOME/.fluxbox directory called apps. Although fluxbox-devel can do this automagically if you use the Remember item from the menu shown when you right click on a window's title bar, you can also create the file manually. Mine reads

[app] (aterm)
  [Position]    {194 50}
  [Deco]        {NONE}
[end]
[app] (xbuffy)
  [Deco]        {NONE}
[end]

This opens up an aterm window where I like it and the Deco part makes it completely borderless. In my .Xdefaults I have aterm set to be transparent with a shading of 50 so, it opens up a window just slightly darker than the background.

From 0.9.x one can also put in a keybinding to open up the RootMenu. I use

Mod1 KP_Enter :RootMenu

That is simply my choice. The RootMenu can be navigated with the arrow keys. There is also the handy key binding to quit, which will end the X session. (In the 0.1.14 version, the RootMenu navigation by keystrokes was only available with Mr. Kita's patch, covered in detail later in this article.)

Backgrounds

This is really pretty well covered in my blackbox article so I'll just give a quick overview here. Go to your fluxbox/styles directory. (As mentioned above, this might be in /usr/share, /usr/local/share, or /usr/X11R6/share.) Suppose you've created an image, called image.jpg. You would like to use it as your background for the style Clean. Make a directory in your .fluxbox directory, called backgrounds, and put the image.jpg file in there. Open the styles/Clean file. At the end of the file, you'll see a line like
rootCommand: bsetroot -gradient interlacedflatcrossdiagonalgradient -from rgb:4c/04/03 -to black

Add the line

rootCommand: fbsetbg -f ~/.fluxbox/backgrounds/image.jpg

(This is really only necessary if you want to associate that particular image with a particular style. You can simply set your background and use that fbsetbg -l in your .fluxbox/init and the image will remain be your background next time you start fluxbox.)

This will (and I've found no consistancy with this), sometimes automatically tile the image, sometimes stretch it, and sometimes simply center it. If your image is the same size as your screen, then you're fine. In my case, I prefer to make smaller images and tile them, so rather than the -f option, I use

rootCommand: fbsetbg -t ~/.fluxbox/backgrounds/image.jpg

This will tile the image.

If nothing happens, then it's possible that you don't have a program to properly display the image. You can check this with

fbsetbg -i

It might give you a message like

display doesn't set the wallpaper properly. Transparency for fluxbox and
apps like aterm and xchat won't work right with it. Consider installing
feh, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use
them instead.

Once it's all done, you should find, the next time you choose the style Clean, that your image.jpg is its background. If you have Eterm installed, you can use the Esetroot command. It will automatically tile images and seems to handle the widest range of files. In that case it's simply

rootCommand Esetroot ~/.fluxbox/backgrounds/image.jpg

If, for example, fbsetbg is using ImageMagik (which I had installed for other uses) while it will set a background, if I try something like

aterm -tr -sh 50

which should give me a semi-transparent aterm, I'll just get a black aterm. However, if I then install feh and again do fbsetbg -i I get the response

feh is a nice wallpapersetter. You won't have any problems.

So, if you like transparencies, use feh, eterm or the like. (To get transparent menus, one can go to the root menu, choose fluxbox menu=>Configure=>Transparency and you can choose the alpha setting for focused window, unfocused window and menu. The lower the number, the greater the transparency. Left clicking the mouse moves the number down and right clicking moves it up. 0 is full transparency.)

Icons

Some folks like icons on their desktop, regardless of Window Manager. There's a little program called Idesk that will do it. There is also Rox. I haven't used either, so I'm not really up on their use, however, they do exist.

Mr. Kita's RootMenu patch (for fluxbox 0.1.14)

For those who do use fluxbox 0.1.14 and older, ArchLinux, as well as Gentoo, have added a patch to Flux to enable the user to navigate the rootmenu with keystrokes. The development version has the patch built in (although unlike Mr. Kita's patch, you can't customize the navigation of the RootMenu, you simply use the arrow keys.)

Here are my keybindings for it.

Mod4 KP_Enter :RootMenu
Mod4 KP_1 :SelectMenuItem
Mod4 KP_2 :NextMenuItem
Mod4 KP_5 :PrevMenuItem
Mod4 KP_4 :CloseMenu
Mod4 KP_6 :OpenSubMenu

The KP_ refers to the keypad. You don't have to use the keypad keys, of course, that's my choice

The actual patch itself was written by Mr. Junichiro Kita, and he keeps it on his site.

As of November, 2003 ArchLinux has also included Mr. Kita's patch in their package build. They send the user here for details about its use.

Using the menu patch in FreeBSD

For those less-experienced with these things, here is how you can apply the patch in FreeBSD.
cd /usr/ports/x11-wm/fluxbox
make extract

Once the source is extracted.

cd work/fluxbox-0.1.14/src

Now, we get the patch.

fetch http://kitaj.no-ip.com/files/fluxbox/fluxbox-0.1.14-menukey.patch

(We're assuming you have the 0-1.14 version of fluxbox, otherwise change the version number accordingly).

patch < fluxbox-0.1.14-menukey.patch

Once the patch has been applied

cd ../../..
make install 

The above method also works with Linux. As far as I know, only Gentoo and Arch incorporate Mr. Kita's patch. However, downloading the fluxbox tarball and patching it as mentioned above should work in most Linux distributions.

The RootMenu patch in Debian

Debian can be a bit tricky if you're not familiar with its method of building source packages. Although this is covered in their faq somewhere, here is the information.
apt-get build-dep fluxbox
apt-get source fluxbox
apt-get install fakeroot
apt-get install dpkg-dev
apt-get install automake

(You may already have fakeroot and dpkg-dev installed). Although apt-get build-dep fluxbox should also install all necessary tools, I have found that I also have to get automake.

This will bring you three files (version number correct as of January 2004) fluxbox_0.1.14-2.orig.tar.gz, fluxbox_0.1.14-2.diff.gz and fluxbox_0.1.14-2.dsc. You will also have a fluxbox-0.1.14 directory.

The next step is

dpkg-source -x fluxbox_0.1.14-2.dsc

I'm assuming you have wget or something similar, if not do a quick

apt-get install wget

Now, we patch

cd fluxbox-0.1.14/src
wget kitaj.no-ip.com/files/fluxbox/fluxbox-0.1.14-menukey.patch
patch < fluxbox-0.1.14-menukey.patch

Now to build and install the package. You are in the fluxbox-0.1.14/src directory

cd ../
dpkg-buildpackage -rfakeroot -b

This will take some time. When it's done

dpkg -i ../fluxbox_0.1.14-2_i386.deb

The RootMenu navigation is one of those nice little features that, once you get used to it, you wonder how you managed without it.

Again, with 0.9.x versions, the RootMenu patch is built in, however, you have to navigate the menus with the arrow keys. (You can open up the RootMenu with any key combination that you wish to use.)

Well, that should be enough to get you started. Enjoy