Difference between revisions of "Xmonad/Using xmonad in KDE"

From HaskellWiki
Jump to navigation Jump to search
m (add reference to install xmonad-contrib, too. flag dead KPackage link)
 
(19 intermediate revisions by 10 users not shown)
Line 4: Line 4:
 
Here's how to configure Xmonad to work with KDE.
 
Here's how to configure Xmonad to work with KDE.
   
[[Image:Screen-sjanssen-kde-kicker.png|200px|center]]
+
[[Image:Screen-sjanssen-kde-kicker.png|200px|right]]
   
 
== Motivation ==
 
== Motivation ==
Line 30: Line 30:
   
 
The following instructions are optimized and tested (so far) for
 
The following instructions are optimized and tested (so far) for
xmonad 0.7 with KDE 3.5 and KDE 4.1
+
xmonad 0.7 with KDE 3.5 and KDE 4.1.
  +
A more recent KDE 5.27 is reported to be reasonably working as specified in a later section.
  +
  +
Note that Plasma, which was introduced with KDE 4.2, is known to cause some problems with the current config; however, most other things should work as expected.
  +
  +
Be aware that <code>kdeConfig</code> is for KDE 3 and will not communicate with later versions properly because it uses the old <code>dcop</code> mechanism; KDE4 and KDE5 should use <code>kde4Config</code>, which uses <code>kdbus</code>.
   
 
== Before you begin ==
 
== Before you begin ==
Line 36: Line 41:
 
Make sure that xmonad and xmonad-contrib are installed.
 
Make sure that xmonad and xmonad-contrib are installed.
 
On most systems, you can just install the packages
 
On most systems, you can just install the packages
using [http://www.general.uwa.edu.au/u/toivo/kpackage/ KPackage](needs updating), or your favorite package manager.
+
using [http://www.general.uwa.edu.au/u/toivo/kpackage/ KPackage], or your favorite package manager.
 
For a list of systems with pre-built xmonad binaries, see
 
For a list of systems with pre-built xmonad binaries, see
 
the [http://xmonad.org/#ports ports and distributions list].
 
the [http://xmonad.org/#ports ports and distributions list].
Line 56: Line 61:
   
 
As usual, place xmonad configuration in <code>~/.xmonad/xmonad.hs</code>.
 
As usual, place xmonad configuration in <code>~/.xmonad/xmonad.hs</code>.
 
For xmonad-0.8 and greater, you can use the XMonad.Config.KDE module to start with a good working default configuration rather than manually configuring as in this example. Stand by for more details or ask for help on irc #xmonad on freenode.net.
 
   
 
The following sample configuration sets up xmonad to cooperate
 
The following sample configuration sets up xmonad to cooperate
Line 67: Line 70:
 
* causes certain applications to launch as floating windows
 
* causes certain applications to launch as floating windows
 
* automatically sends certain applications to a specific desktop when they launch.
 
* automatically sends certain applications to a specific desktop when they launch.
  +
  +
=== Using Config.Kde ===
  +
  +
For '''xmonad-0.8 and greater''', you can use the <code>XMonad.Config.Kde</code> module to start with good base defaults for xmonad in KDE (Note: KDE4/5 users with xmonad-0.9 or greater 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.
  +
  +
<haskell>
  +
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
  +
}
  +
  +
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]
  +
]
  +
where myFloats = ["MPlayer", "Gimp"]
  +
myOtherFloats = ["alsamixer"]
  +
webApps = ["Firefox-bin", "Opera"] -- open on desktop 2
  +
ircApps = ["Ksirc"] -- open on desktop 3
  +
</haskell>
  +
  +
=== xmonad-0.7 and earlier ===
   
 
<haskell>
 
<haskell>
   
 
import XMonad
 
import XMonad
import XMonad.Hooks.ManageDocks
+
import XMonad.Hooks.ManageDocks
 
import XMonad.Hooks.EwmhDesktops
 
import XMonad.Hooks.EwmhDesktops
 
import qualified XMonad.StackSet as W
 
import qualified XMonad.StackSet as W
   
main = xmonad $ defaultConfig
+
main = xmonad defaultConfig
  +
{ manageHook = manageHook defaultConfig <+> myManageHook
  +
, logHook = ewmhDesktopsLogHook
  +
, layoutHook = avoidStruts $ layoutHook defaultConfig
  +
, modMask = mod4Mask -- use the Windows button as mod
  +
}
   
  +
myManageHook = manageDocks <+> composeAll . concat $
{ manageHook = manageHook defaultConfig <+> myManageHook
 
, logHook = ewmhDesktopsLogHook
+
[ [ className =? c --> doFloat | c <- myFloats]
, 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]
 
, [ title =? t --> doFloat | t <- myOtherFloats]
 
, [ className =? c --> doF (W.shift "2") | c <- webApps]
 
, [ className =? c --> doF (W.shift "2") | c <- webApps]
 
, [ className =? c --> doF (W.shift "3") | c <- ircApps]
 
, [ className =? c --> doF (W.shift "3") | c <- ircApps]
 
]
 
]
  +
where
myFloats = ["MPlayer", "Gimp"]
 
myOtherFloats = ["alsamixer"]
+
myFloats = ["MPlayer", "Gimp"]
  +
myOtherFloats = ["alsamixer"]
webApps = ["Firefox-bin", "Opera"] -- open on desktop 2
 
ircApps = ["Ksirc"] -- open on desktop 3
+
webApps = ["Firefox-bin", "Opera"] -- open on desktop 2
  +
ircApps = ["Ksirc"] -- open on desktop 3
 
 
</haskell>
 
</haskell>
   
'''Note:''' To get the class name or title of an application for use in the above:
+
'''Note:''' To get the class name or title of an application for use in the manageHook above:
 
# Open the application.
 
# Open the application.
 
# Enter the command <code>xprop | grep WM_CLASS</code> in a terminal window on the same desktop.
 
# Enter the command <code>xprop | grep WM_CLASS</code> in a terminal window on the same desktop.
 
# Click on the application window.
 
# Click on the application window.
# Read the class name in the terminal window. The class name is the second of the two quoted strings displayed, usually capitalized.
+
# Read the class name in the terminal window. The class name is the second of the two quoted strings displayed, usually capitalized. The first one is resource, usually lower case.
   
 
(Use the command <code>xprop | grep WM_NAME</code> to get the title property.)
 
(Use the command <code>xprop | grep WM_NAME</code> to get the title property.)
Line 110: Line 143:
 
for KDE.
 
for KDE.
   
For more tips on xonfiguring your xmonad, see: [http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions XMonad FAQ's], [http://haskell.org/haskellwiki/Xmonad/General_xmonad.hs_config_tips XMonad Configuration Tips].
+
For more tips on configuring your xmonad, see: [http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions XMonad FAQ's], [http://haskell.org/haskellwiki/Xmonad/General_xmonad.hs_config_tips XMonad Configuration Tips].
   
 
== Make xmonad your window manager in KDE ==
 
== Make xmonad your window manager in KDE ==
  +
  +
=== KDE 4 ===
   
 
Create the directory <code>~/.kde/env</code> if it does not
 
Create the directory <code>~/.kde/env</code> if it does not
Line 119: Line 154:
   
 
<code>
 
<code>
KDEWM=/path/to/xmonad
+
export KDEWM=/path/to/xmonad
 
</code>
 
</code>
   
Line 129: Line 164:
 
You may also have to use <code>chmod</code> to ensure that
 
You may also have to use <code>chmod</code> to ensure that
 
<code>set_window_manager.sh</code> is executable.
 
<code>set_window_manager.sh</code> is executable.
  +
  +
=== KDE 5 ===
  +
  +
The current Plasma Workspace startup is using systemd boot by default as of release 5.25<ref>Merge request: [https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/1356 Enable systemd boot by default]</ref>.
  +
You may choose to keep the default or disable it<ref>Hasn't been tested here, but it is explained in the Arch wiki: [https://wiki.archlinux.org/title/KDE#systemd_startup KDE systemd_startup]</ref>.
  +
  +
This influences how you can replace KWin window manager with XMonad: head to the relevant section below!
  +
  +
==== systemd startup on (default) ====
  +
  +
First, you must prevent KWin to start by masking its service.
  +
  +
<syntaxhighlight lang="bash">
  +
systemctl --user mask plasma-kwin_x11.service
  +
</syntaxhighlight>
  +
  +
Then create <code>~/.config/systemd/user/plasma-xmonad.service</code> with the following contents ('''IMPORTANT''': make sure the path to xmonad binary is correct!):
  +
  +
<syntaxhighlight lang="systemd">
  +
[Install]
  +
WantedBy=plasma-workspace.target
  +
  +
[Unit]
  +
Description=Plasma XMonad Window Manager
  +
Before=plasma-workspace.target
  +
  +
[Service]
  +
ExecStart=/usr/bin/xmonad
  +
Slice=session.slice
  +
Restart=on-failure
  +
</syntaxhighlight>
  +
  +
With that you can enable the service and restart your session.
  +
  +
<syntaxhighlight lang="bash">
  +
systemctl --user enable plasma-xmonad.service
  +
</syntaxhighlight>
  +
  +
NOTE: usually <code>xmonad --restart</code> should work as intended, however there might be some corner cases where invoking <code>systemctl --user restart plasma-xmonad.service</code> might be necessary.
  +
  +
==== systemd startup off ====
  +
  +
With KDE 5 XDG directory structure is used, so the location where files are stored for modifying the KDE environment is a bit different.
  +
  +
Create a directory <code>~/.config/plasma-workspace/env</code> if it does not
  +
already exist. Create a file there called <code>set_window_manager.sh</code>
  +
in the same way as with older KDE versions.
   
 
== Restart your KDE session ==
 
== Restart your KDE session ==
Line 137: Line 219:
 
== Tips and issues ==
 
== Tips and issues ==
   
  +
* As in Gnome, it is '''very important''' not to use the xmonad <code>mod-shift-q</code> 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.'''
* As in Gnome, you currently cannot switch the focus to a window by clicking on it in the task bar. Use xmonad keys, or use the mouse on the window itself.
 
   
  +
* Since KDE4's system tray is built around Plasma, whose widgets normally live on the desktop layer, it can be difficult to customize the Plasma tray's display for Xmonad. If you use a 3rd party system tray such as Trayer while running KDE, and some or all icons are missing or appear to conflict with the Plasma tray, the conflict might be worked around by disabling the kded status notifier manager. systemsettings -> Startup and Shutdown -> Service Manager -> uncheck "Status Notifier Manager". Additionally, such tray applications might not implement all of KDE's system tray functionality.
* Also as in Gnome, it is '''very important''' not to use the xmonad <code>mod-shift-q</code> key to exit your session. Use the KDE menu or panel applet.
 
   
 
'''''To do:''' In the sample configuration, show how to bind''
 
'''''To do:''' In the sample configuration, show how to bind''
Line 146: Line 228:
 
''to end the KDE session via a dialog, or to the command''
 
''to end the KDE session via a dialog, or to the command''
 
<code>dcop ksmserver default logout 0 -1 -1</code>
 
<code>dcop ksmserver default logout 0 -1 -1</code>
''to end the KDE session directly. Then remove the above bullet.''
+
''to end the KDE session directly.''

Latest revision as of 03:32, 27 January 2024

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. A more recent KDE 5.27 is reported to be reasonably working as specified in a later section.

Note that Plasma, which was introduced with KDE 4.2, is known to cause some problems with the current config; however, most other things should work as expected.

Be aware that kdeConfig is for KDE 3 and will not communicate with later versions properly because it uses the old dcop mechanism; KDE4 and KDE5 should use kde4Config, which uses kdbus.

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/5 users with xmonad-0.9 or greater 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
    }

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]
    ]
  where 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
    }

myManageHook = manageDocks <+> 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]
     ]
  where
    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 manageHook 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. The first one is resource, usually lower case.
 (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 configuring your xmonad, see: XMonad FAQ's, XMonad Configuration Tips.

Make xmonad your window manager in KDE

KDE 4

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:

export 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.

KDE 5

The current Plasma Workspace startup is using systemd boot by default as of release 5.25[1]. You may choose to keep the default or disable it[2].

This influences how you can replace KWin window manager with XMonad: head to the relevant section below!

systemd startup on (default)

First, you must prevent KWin to start by masking its service.

systemctl --user mask plasma-kwin_x11.service

Then create ~/.config/systemd/user/plasma-xmonad.service with the following contents (IMPORTANT: make sure the path to xmonad binary is correct!):

[Install]
WantedBy=plasma-workspace.target

[Unit]
Description=Plasma XMonad Window Manager
Before=plasma-workspace.target

[Service]
ExecStart=/usr/bin/xmonad
Slice=session.slice
Restart=on-failure

With that you can enable the service and restart your session.

systemctl --user enable plasma-xmonad.service

NOTE: usually xmonad --restart should work as intended, however there might be some corner cases where invoking systemctl --user restart plasma-xmonad.service might be necessary.

systemd startup off

With KDE 5 XDG directory structure is used, so the location where files are stored for modifying the KDE environment is a bit different.

Create a directory ~/.config/plasma-workspace/env if it does not already exist. Create a file there called set_window_manager.sh in the same way as with older KDE versions.

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.
  • Since KDE4's system tray is built around Plasma, whose widgets normally live on the desktop layer, it can be difficult to customize the Plasma tray's display for Xmonad. If you use a 3rd party system tray such as Trayer while running KDE, and some or all icons are missing or appear to conflict with the Plasma tray, the conflict might be worked around by disabling the kded status notifier manager. systemsettings -> Startup and Shutdown -> Service Manager -> uncheck "Status Notifier Manager". Additionally, such tray applications might not implement all of KDE's system tray functionality.

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.

  1. Merge request: Enable systemd boot by default
  2. Hasn't been tested here, but it is explained in the Arch wiki: KDE systemd_startup