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

From HaskellWiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 
 
{{xmonad}}
 
{{xmonad}}
 
[[Category:XMonad]]
 
[[Category:XMonad]]
   
=Introduction==
+
=Introduction=
  +
  +
This is an updated and hopefully less confusing version of my original blog post located here: [http://ivanmiljenovic.wordpress.com/2008/01/20/xmonad/ X<math>^2</math>Monad]
  +
  +
''Why use Xfce with XMonad?''
  +
  +
Whilst XMonad is a truly excellent Window Manager, alone it doesn't offer the full convenience of an entire Desktop Environment, such as the provided menus, all-in-one configuration settings, consistent dialogs, etc. Out of the three main DEs available in Unix-like Operating Systems - Gnome, KDE and Xfce - the latter is often touted as the most "nimble" of the lot. In my own opinion, it is simpler to use than KDE but with more configuration options (and a saner environment) than Gnome.
  +
  +
= Configuring XMonad to work with Xfce =
  +
  +
This guide assumes that you're using at least version 4.4 of Xfce, and have both XMonad and XMonad-Contrib 0.7 installed. First we need to configure Xfce to play nicely, before adding in XMonad.
  +
  +
==Xfce Settings==
  +
  +
We're going to utilise Xfce's Session Manager to make sure that xfwm4 (Xfce's default WM) is no longer started. Preferably, it'd be nice if we could have XMonad started this way as well (or even set in a configuration option like with Gnome or KDE), but the former isn't possible until XMonad supports the required Session Management Protocol and the latter isn't possible in Xfce at all.
  +
  +
===Backing up your settings===
  +
  +
If you're already using Xfce, you may wish to first backup your ~/.config directory. Whilst Xfce isn't the only application/library/etc. to utilise the ~/.config directory to store it's settings, it does so in a few different sub-directories (i.e. in some cases specific applications have their own settings directory), it's easier to backup the whole thing.
  +
  +
Note that as far as I know, it isn't possible to have for the same user both a standard Xfce login and an XMonad Xfce login. Whilst you can have different sessions to determine whether you use XMonad or not, there are some settings - such as the panel layout - that aren't saved on a per-session basis.
  +
  +
===Start a new session===
  +
  +
For backup purposes in case something goes wrong with your XMonad settings, it is recommended to create a new Xfce session. To do so, open the "Sessions and Startup" option dialog either from the "Settings" section of the Xfce menu, or in Xfce's Settings Manager (xfce-setting-show). Enable the the session chooser and automatic saving of sessions, then logout and log back in again. When the session chooser appears, choose to create a new session.
  +
  +
A word of warning: I found that the session chooser kept crashing Xfce on a freshly installed Xfce-4.4.2. If this happens to you, delete the ~/.config/xfce-session directory.
  +
  +
===Setting up Xfce===
  +
  +
Open up the Xfce settings manager. There, you can customise Xfce to your hearts content. Note that the following settings dialogs won't be applicable once we start XMonad:
  +
* Window Manager
  +
* Window Manager Tweaks
  +
* Workspaces and Margins
  +
The last option isn't required, as Xfce will happily use XMonad's workspaces.
  +
  +
These options are recommended:
  +
* Under "Desktop", let Xfce manage the desktop, but under Behaviour set the Desktop Icons to "None". This way, Xfce will control your wallpaper, etc., allowing you to have random lists, different wallpapers for different screens for multi-head setups, etc.
  +
* The Keyboard settings can be used to set keyboard shortcuts for those multimedia keys (e.g. XF86AudioMute) found on many keyboards, since these types of keys are currently difficult to create shortcuts for in XMonad. Simply setup the various keyevents to these keybindinds for use with xmodmap in ~/.Xmodmap and Xfce will read these on start.
  +
* Mouse: if you don't have or want to use a mouse, there's a limited type of mouse emulation available where you can use the Numpad arrow keys to move the cursor.
  +
* For "Preferred Applications", set whichever terminal emulator you plan to use. I find that Xfce's own Terminal application to work quite nicely with XMonad and to resize rather well.
  +
  +
If you so wish, you can now disable the session chooser, though I suggest you leave it enabled until you've successfully managed to login to your Xfce/XMonad environment several times.
  +
  +
===Xfce's Panels===
  +
  +
If you so wish you can now customize the panels and the plugins on them. This can be safely left to later, however. With XMonad, I typically only have one panel rather than the default two. In terms of panel plugins, I've removed the Task List, but kept the pager: with the EWMH settings in XMonad, Xfce's pager acts as a mini-preview of your various layouts!
  +
  +
==XMonad Hacking==
  +
  +
It's now time to customise XMonad. You have a wide variety of Layouts, Hooks, etc. to experiment with. Here are some basic changes that you ''should'' make:
  +
  +
* Replace the old gaps setup with ManageDocks (especially since Gaps are deprecated in the current darcs version of XMonad and won't be present from 0.8 onwards). This also involves changing the keybinding to hide/show panels.
  +
* Use the EWMH hooks so that Xfce can obtain Workspace information from XMonad and vice versa. This lets the Pager plugin to the panel act as a mini workspace-previewer, and let you choose which workspace to view by clicking on the pager. Note that by using this, the pager will also automatically add/remove workspaces based upon how many workspaces XMonad has.
  +
* Use ''mod4'' (aka the "Windows" key) as the modifier key. Many applications - including Xfce - use the Alt key for keybindings themselve (e.g. Xfce uses Alt-F2 to show its run dialog).
  +
* With keybindings, ''xfce4-session-logout'' to exit for the Mod-Shift-q keybinding, rather than just exiting XMonad (which will leave Xfce still running).
  +
* Use Xfce's Terminal as the terminal program.
  +
  +
Here is a minimal ~/.xmonad/xmonad.hs that demonstrates how to do this. Note that it is expected that you copy and edit the sample configuration file to get the remaining keybindings present, or else use something like the EZConfig extension in the Contrib library to selectively add/edit/remove keybindings from the default list. As it stands, this configuration file ''isn't'' sufficient, as it doesn't list all the keybindings and in fact won't compile due to the "..." present in the keybinding list.
  +
  +
<haskell>
  +
import XMonad
  +
import qualified Data.Map as M
  +
import XMonad.Hooks.ManageDocks
  +
import XMonad.Hooks.EwmhDesktops
  +
  +
myTerminal = "Terminal"
  +
  +
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
  +
[
  +
...
  +
, ((modMask, xK_b), sendMessage ToggleStruts)
  +
...
  +
, ((modMask .|. shiftMask, xK_q), spawn "xfce4-session-logout")
  +
...
  +
]
  +
  +
main = xmonad defaultConfig
  +
{ manageHook = manageDocks <+> manageHook defaultConfig
  +
, logHook = ewmhDesktopsLogHook
  +
, layoutHook = ewmhDesktopsLayout $ avoidStruts $ layoutHook defaultConfig
  +
, modMask = mod4Mask
  +
, keys = myKeys
  +
}
  +
</haskell>
  +
  +
If you so wish, you can also use ''xfrun4'' or ''xfce4-appfinder'' as the program launchers for the Mod-p and Mod-Shift-p keybindings instead of the default dmenu and gmrun.
  +
  +
You may wish to run ghci or something on your ~/.xmonad/xmonad.hs configuration file to make sure it's correct before moving on to the next section.
  +
  +
=Get XMonad Going!=
  +
  +
It's now time to ditch Xfce's default Window Manager xfwm4 and replace it with something better (i.e. XMonad). To do so, it's probably easiest to run xfrun4 with Xfce's default key combination Alt-F2 and enter the following:
  +
<code>
  +
killall xfwm4 && xmonad
  +
</code>
   
 
[[Image:Xmonad-screen-comp-xfce.jpg|200px|A screenshot of xmonad cooperating with gnome|center]]
 
[[Image:Xmonad-screen-comp-xfce.jpg|200px|A screenshot of xmonad cooperating with gnome|center]]

Revision as of 11:01, 3 May 2008

Xmonad-logo-small.png

XMonad

Introduction

This is an updated and hopefully less confusing version of my original blog post located here: XMonad

Why use Xfce with XMonad?

Whilst XMonad is a truly excellent Window Manager, alone it doesn't offer the full convenience of an entire Desktop Environment, such as the provided menus, all-in-one configuration settings, consistent dialogs, etc. Out of the three main DEs available in Unix-like Operating Systems - Gnome, KDE and Xfce - the latter is often touted as the most "nimble" of the lot. In my own opinion, it is simpler to use than KDE but with more configuration options (and a saner environment) than Gnome.

Configuring XMonad to work with Xfce

This guide assumes that you're using at least version 4.4 of Xfce, and have both XMonad and XMonad-Contrib 0.7 installed. First we need to configure Xfce to play nicely, before adding in XMonad.

Xfce Settings

We're going to utilise Xfce's Session Manager to make sure that xfwm4 (Xfce's default WM) is no longer started. Preferably, it'd be nice if we could have XMonad started this way as well (or even set in a configuration option like with Gnome or KDE), but the former isn't possible until XMonad supports the required Session Management Protocol and the latter isn't possible in Xfce at all.

Backing up your settings

If you're already using Xfce, you may wish to first backup your ~/.config directory. Whilst Xfce isn't the only application/library/etc. to utilise the ~/.config directory to store it's settings, it does so in a few different sub-directories (i.e. in some cases specific applications have their own settings directory), it's easier to backup the whole thing.

Note that as far as I know, it isn't possible to have for the same user both a standard Xfce login and an XMonad Xfce login. Whilst you can have different sessions to determine whether you use XMonad or not, there are some settings - such as the panel layout - that aren't saved on a per-session basis.

Start a new session

For backup purposes in case something goes wrong with your XMonad settings, it is recommended to create a new Xfce session. To do so, open the "Sessions and Startup" option dialog either from the "Settings" section of the Xfce menu, or in Xfce's Settings Manager (xfce-setting-show). Enable the the session chooser and automatic saving of sessions, then logout and log back in again. When the session chooser appears, choose to create a new session.

A word of warning: I found that the session chooser kept crashing Xfce on a freshly installed Xfce-4.4.2. If this happens to you, delete the ~/.config/xfce-session directory.

Setting up Xfce

Open up the Xfce settings manager. There, you can customise Xfce to your hearts content. Note that the following settings dialogs won't be applicable once we start XMonad:

  • Window Manager
  • Window Manager Tweaks
  • Workspaces and Margins

The last option isn't required, as Xfce will happily use XMonad's workspaces.

These options are recommended:

  • Under "Desktop", let Xfce manage the desktop, but under Behaviour set the Desktop Icons to "None". This way, Xfce will control your wallpaper, etc., allowing you to have random lists, different wallpapers for different screens for multi-head setups, etc.
  • The Keyboard settings can be used to set keyboard shortcuts for those multimedia keys (e.g. XF86AudioMute) found on many keyboards, since these types of keys are currently difficult to create shortcuts for in XMonad. Simply setup the various keyevents to these keybindinds for use with xmodmap in ~/.Xmodmap and Xfce will read these on start.
  • Mouse: if you don't have or want to use a mouse, there's a limited type of mouse emulation available where you can use the Numpad arrow keys to move the cursor.
  • For "Preferred Applications", set whichever terminal emulator you plan to use. I find that Xfce's own Terminal application to work quite nicely with XMonad and to resize rather well.

If you so wish, you can now disable the session chooser, though I suggest you leave it enabled until you've successfully managed to login to your Xfce/XMonad environment several times.

Xfce's Panels

If you so wish you can now customize the panels and the plugins on them. This can be safely left to later, however. With XMonad, I typically only have one panel rather than the default two. In terms of panel plugins, I've removed the Task List, but kept the pager: with the EWMH settings in XMonad, Xfce's pager acts as a mini-preview of your various layouts!

XMonad Hacking

It's now time to customise XMonad. You have a wide variety of Layouts, Hooks, etc. to experiment with. Here are some basic changes that you should make:

  • Replace the old gaps setup with ManageDocks (especially since Gaps are deprecated in the current darcs version of XMonad and won't be present from 0.8 onwards). This also involves changing the keybinding to hide/show panels.
  • Use the EWMH hooks so that Xfce can obtain Workspace information from XMonad and vice versa. This lets the Pager plugin to the panel act as a mini workspace-previewer, and let you choose which workspace to view by clicking on the pager. Note that by using this, the pager will also automatically add/remove workspaces based upon how many workspaces XMonad has.
  • Use mod4 (aka the "Windows" key) as the modifier key. Many applications - including Xfce - use the Alt key for keybindings themselve (e.g. Xfce uses Alt-F2 to show its run dialog).
  • With keybindings, xfce4-session-logout to exit for the Mod-Shift-q keybinding, rather than just exiting XMonad (which will leave Xfce still running).
  • Use Xfce's Terminal as the terminal program.

Here is a minimal ~/.xmonad/xmonad.hs that demonstrates how to do this. Note that it is expected that you copy and edit the sample configuration file to get the remaining keybindings present, or else use something like the EZConfig extension in the Contrib library to selectively add/edit/remove keybindings from the default list. As it stands, this configuration file isn't sufficient, as it doesn't list all the keybindings and in fact won't compile due to the "..." present in the keybinding list.

import XMonad
import qualified Data.Map as M
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops

myTerminal = "Terminal"

myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
    [
    ...
    , ((modMask, xK_b), sendMessage ToggleStruts)
    ...
    , ((modMask .|. shiftMask, xK_q), spawn "xfce4-session-logout")
    ...
    ]

main = xmonad defaultConfig
              { manageHook = manageDocks <+> manageHook defaultConfig
              , logHook    = ewmhDesktopsLogHook
              , layoutHook = ewmhDesktopsLayout $ avoidStruts $ layoutHook defaultConfig
              , modMask    = mod4Mask
              , keys       = myKeys
              }

If you so wish, you can also use xfrun4 or xfce4-appfinder as the program launchers for the Mod-p and Mod-Shift-p keybindings instead of the default dmenu and gmrun.

You may wish to run ghci or something on your ~/.xmonad/xmonad.hs configuration file to make sure it's correct before moving on to the next section.

Get XMonad Going!

It's now time to ditch Xfce's default Window Manager xfwm4 and replace it with something better (i.e. XMonad). To do so, it's probably easiest to run xfrun4 with Xfce's default key combination Alt-F2 and enter the following: killall xfwm4 && xmonad

A screenshot of xmonad cooperating with gnome