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

From HaskellWiki
Jump to navigation Jump to search
m (Added Config.Xfce references)
m (Fix broken anchor link)
Line 58: Line 58:
 
==XMonad Hacking==
 
==XMonad Hacking==
   
[[# Using XMonad.Config.Xfce |see also Config.Xfce]]
+
[[#Using_XMonad.Config.Xfce|see also, Config.Xfce]]
   
 
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:
 
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:

Revision as of 00:41, 12 September 2008

Xmonad-logo-small.png

XMonad

Introduction

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

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!

Ensure XMonad gets started

Because XMonad doesn't support the session protocol and Xfce is missing an option to specify which Window Manager to use, we must ensure that XMonad is started each time we log in. WARNING!!! Make sure you don't log out and back in again after setting this and before you reach the stage where we kill xfwm4, or else you will have two different Window Managers fighting each other!!! Run Xfce's Autostarted Applications manager (either under the Settings section in the Xfce menu or run xfce4-autostart-editor). There, add a new autostarted application with the command being simply xmonad (this of course assumes XMonad is in your path... otherwise, specify the full path to the binary) with whatever name you want. Ensure that the new autostarted application entry you just created is ticked.

To repeat the warning: After creating this, don't exit Xfce until you've finished configuring XMonad and have killed xfwm4!!!

XMonad Hacking

see also, Config.Xfce

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.

Using XMonad.Config.Xfce

with xmonad-contrib-0.8 or greater

Use the following in your ~/.xmonad/xmonad.hs to implement all the suggestions made above. This is a compilable configuration giving you all the basics.

import XMonad
import XMonad.Config.Xfce

main = xmonad xfceConfig

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

If all went well, you'll now find yourself in XMonad!

That's all folks!

Congratulations, you have now successfully configured XMonad and Xfce so that XMonad acts as Xfce's Window Manager! Sample screenshots to come.