Xmonad/Using xmonad in KDE

From HaskellWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Xmonad-logo-small.png

XMonad

Here's how to configure Xmonad to work with KDE.

Screen-sjanssen-kde-kicker.png

Motivation

You've heard about the wonders of Xmonad, and you want to try it out. But you're a KDE user, and you want to stay with KDE because of:

  • Ability to browse all programs and utilities with desktop bar (kicker).
  • Easy integration of Xmonad on a system using kdm for logins.
  • Easier system monitoring on laptops with the KDE networking widget.
  • Best environment for running GUI applications developed with Qt.
  • Consistent user interface and shared system services for the vast collection of KDE applications.
  • You're just used to it.

Then this page is for you.

Related reading

Read the GNOME/xmonad page, really. Much of what is written there also applies to KDE and is not repeated here.

But if all you want is to get started quickly with Xmonad in KDE, read on.

Versions

The following instructions are optimized and tested (so far) for xmonad 0.7 with KDE 3.5 and KDE 4.1

Before you begin

Make sure that xmonad and xmonad-contrib are installed. On most systems, you can just install the packages using KPackage, or your favorite package manager. For a list of systems with pre-built xmonad binaries, see the ports and distributions list. Or you can build xmonad from source.

Make sure that KDE is not configured for multiple desktops. To configure that, open the KDE Control Center, select Desktop > Multiple desktops, and set the number of desktops to 1.

Read the guided tour of xmonad, so that you'll know what to do once xmonad starts up. (Ignore the "Starting xmonad" section, though. These instructions replace that for KDE.) The xmonad man page has a nice summary of the default key bindings for xmonad.

Sample xmonad configuration for KDE

As usual, place xmonad configuration in ~/.xmonad/xmonad.hs.

The following sample configuration sets up xmonad to cooperate with the KDE desktop and panel; for more details about how this works, see the Gnome page.

This configuration also does the following:

  • uses the Windows key instead of the Alt key as "mod" for xmonad (freeing up Alt for common emacs-style key bindings in applications)
  • causes certain applications to launch as floating windows
  • automatically sends certain applications to a specific desktop when they launch.

Using Config.Kde

For xmonad-0.8 and greater, you can use the XMonad.Config.Kde module to start with good base defaults for xmonad in KDE (Note: KDE4 users should replace kdeConfig with kde4Config in the following example. The Config.Kde module is found in the XMonadContrib repository, not in the xmonad repository. ) This base config

  • deals with docks and taskbars
  • sets the default terminal to konsole
  • sets mod-p to run popup
  • sets mod-shift-q to logout properly.
import XMonad
import XMonad.Config.Kde
import qualified XMonad.StackSet as W -- to shift and float windows

main = xmonad $ kdeConfig

 { modMask = mod4Mask -- use the Windows button as mod
 , manageHook = manageHook kdeConfig <+> myManageHook
 }
 where
   myManageHook = composeAll . concat $
     [ [ className   =? c --> doFloat           | c <- myFloats]
     , [ title       =? t --> doFloat           | t <- myOtherFloats]
     , [ className   =? c --> doF (W.shift "2") | c <- webApps]
     , [ className   =? c --> doF (W.shift "3") | c <- ircApps]
     ]
   myFloats      = ["MPlayer", "Gimp"]
   myOtherFloats = ["alsamixer"]
   webApps       = ["Firefox-bin", "Opera"] -- open on desktop 2
   ircApps       = ["Ksirc"]                -- open on desktop 3

xmonad-0.7 and earlier

import XMonad
import XMonad.Hooks.ManageDocks 
import XMonad.Hooks.EwmhDesktops
import qualified XMonad.StackSet as W

main = xmonad $ defaultConfig 

 { manageHook            = manageHook defaultConfig <+> myManageHook
 , logHook               = ewmhDesktopsLogHook
 , layoutHook            = avoidStruts $ layoutHook defaultConfig
 , modMask               = mod4Mask -- use the Windows button as mod
 }
 where
   myManageHook = composeAll . concat $
     [ [manageDocks]
     , [ className   =? c --> doFloat           | c <- myFloats]
     , [ title       =? t --> doFloat           | t <- myOtherFloats]
     , [ className   =? c --> doF (W.shift "2") | c <- webApps]
     , [ className   =? c --> doF (W.shift "3") | c <- ircApps]
     ]
   myFloats      = ["MPlayer", "Gimp"]
   myOtherFloats = ["alsamixer"]
   webApps       = ["Firefox-bin", "Opera"] -- open on desktop 2
   ircApps       = ["Ksirc"]                -- open on desktop 3

Note: To get the class name or title of an application for use in the above:

  1. Open the application.
  2. Enter the command xprop | grep WM_CLASS in a terminal window on the same desktop.
  3. Click on the application window.
  4. Read the class name in the terminal window. The class name is the second of the two quoted strings displayed, usually capitalized.
 (Use the command xprop | grep WM_NAME to get the title property.)

Thanks to everyone on #xmonad, especially sjanssen, for all the help in putting together this sample xmonad configuration for KDE.

For more tips on xonfiguring your xmonad, see: XMonad FAQ's, XMonad Configuration Tips.

Make xmonad your window manager in KDE

Create the directory ~/.kde/env if it does not already exist. (For KDE 4 use ~/.kde4/env) Create a file there called set_window_manager.sh containing only the following line of text:

KDEWM=/path/to/xmonad

where "/path/to/xmonad" is the path to the xmonad binary on your system. For example, on Debian systems this is /usr/bin/xmonad. If you compiled xmonad from source, it may be something like /home/$USER/bin/xmonad.

You may also have to use chmod to ensure that set_window_manager.sh is executable.

Restart your KDE session

Now end your current KDE session and start a new one. Welcome to xmonad with KDE!

Tips and issues

  • As in Gnome, it is very important not to use the xmonad mod-shift-q key to exit your session. Use the KDE menu or panel applet. This is dealt with in Config.Kde. It's ok to mod-shift-q to logout when using Config.Kde binding for mod-shift-q.

To do: In the sample configuration, show how to bind mod-shift-Q to the command dcop kdesktop default logout to end the KDE session via a dialog, or to the command dcop ksmserver default logout 0 -1 -1 to end the KDE session directly. Then remove the above bullet.