Difference between revisions of "Xmonad/Basic Desktop Environment Integration"

From HaskellWiki
Jump to navigation Jump to search
(copy the bare xmonad configuration for freedesktop.org application and session registration from the Gnome integration document, since it's not particularly Gnome-related.)
 
Line 103: Line 103:
 
logHook desktopConfig
 
logHook desktopConfig
 
</haskell>
 
</haskell>
  +
  +
=Adding Xmonad to the display manager (GUI login)=
  +
If you install xmonad using a distribution package, it will usually register a number of xmonad session types (typically bare xmonad and xmonad with Gnome). If you install via darcs or cabal-install, you will probably need to create an xmonad session definition by hand.
  +
  +
These files are examples, but likely to be directly usable.
  +
  +
For xmonad to start automatically on login you need an <code>applications/xmonad.desktop</code> file on your system. If your distro doesn't provide it, create the following file:
  +
<pre>
  +
$ cat /usr/share/applications/xmonad.desktop
  +
[Desktop Entry]
  +
Type=Application
  +
Encoding=UTF-8
  +
Name=Xmonad
  +
Exec=xmonad
  +
NoDisplay=true
  +
X-GNOME-WMName=Xmonad
  +
X-GNOME-Autostart-Phase=WindowManager
  +
X-GNOME-Provides=windowmanager
  +
X-GNOME-Autostart-Notify=false
  +
</pre>
  +
(The X-GNOME entries do not cause GNOME to be invoked, but do allow it to be used *with* GNOME in the future if you so choose.)
  +
Alternatively, you can create the above as <code>~/.local/share/applications/xmonad.desktop</code> for the current user only.
  +
  +
The above simply registers xmonad as a valid window manager; to also make an xmonad session available, you need an <code>xsessions/xmonad.desktop</code> file. To start a minimal xmonad session from gdm (see notes* below to run more than just xmonad on login), create the following file:
  +
<pre>
  +
$ cat /usr/share/xsessions/xmonad.desktop
  +
[Desktop Entry]
  +
Encoding=UTF-8
  +
Name=XMonad
  +
Comment=Lightweight tiling window manager
  +
Exec=xmonad
  +
Icon=xmonad.png
  +
Type=XSession
  +
</pre>
  +
  +
Your display manager must also be able to find the xmonad executable. If you are not using your distro package manager to install xmonad, for best results configure your build to install xmonad to a location in the system environment like /usr/local/bin/.
  +
  +
<nowiki>*NOTE:</nowiki> Using an <code>xsessions/xmonad.desktop</code> file that runs a custom script <code>xmonad.start</code> instead of just plain xmonad is also how to add other startup actions to the gdm xmonad.desktop startup, such as starting gnome daemons, apps, etc. See
  +
[http://arjuna.deltoso.net/articoli/my-configuration-of-xmonad-window-manager-with-xmobar-and-trayer/en arjuna's blog] for more details. (simono says: Creating <code>/usr/share/xsessions/xmonad.desktop</code> and <code>/usr/local/bin/xmonad.start</code> files is the preferred method for configuring an alternative window manager. The applications/xmonad.desktop file is still required.) However, see the xsession section below to continue using the classic ~/.xsession method to run a custom session.

Latest revision as of 18:11, 18 March 2013

Using Desktop Environment Config Modules

The following modules from xmonad-contrib make it easy to start with good basic defaults to work within the given desktop environment (DE). Make sure both the xmonad and xmonad-contrib packages are installed and of the same version, then import the appropriate Config module and begin with one of the example configs below.

The desktop configs enable communication between xmonad and pagers, taskbars, status bars, tray apps, etc. through extended window manager hints (EWMH's). They also set a prettier root window mouse cursor, bind the default key for gap toggling, and rebind run and logout keys to sensible desktop environment defaults.

You will still need to set up your session management and tell your DE to use xmonad as described in the DE specific documents on Xmonad, but the following will take care of getting xmonad's part of the puzzle working with a useful default configuration.

Once your DE is ready to use xmonad, placing the appropriate version below in ~/.xmonad/xmonad.hs will ensure xmonad is ready to work with the DE.

Basic desktop config examples

The core functionality used by all the specific DE configs. (Useful if you just want support for a few specific EWMH apps, or are running something other than KDE, Gnome, or xfce.)

import XMonad
import XMonad.Config.Desktop

main = xmonad desktopConfig

An xmonad.hs for xfce

import XMonad
import XMonad.Config.Xfce

main = xmonad xfceConfig

An xmonad.hs for Gnome

import XMonad
import XMonad.Config.Gnome

main = xmonad gnomeConfig

An xmonad.hs for KDE

import XMonad
import XMonad.Config.Kde

main = xmonad kdeConfig
    -- or for kde 4 (> xmonad-0.8*, darcs xmonad)
    -- xmonad kde4Config

Customizing desktop environment configs

See the documentation for the XMonad.Config.Desktop module for more details on customizing the desktop configs. However, here are examples of the most common customizations:

Modifying layouts, manageHook, or key bindings

See also Util.EZConfig for more options for modifying key bindings. To add to layouts, manageHook or key bindings use something like the following to combine your modifications with the desktop config settings:

 import XMonad
 import XMonad.Config.Desktop
 import XMonad.Layout.Tabbed
 import XMonad.Util.EZConfig (additionalKeys)

 main =
   xmonad $ desktopConfig {
     -- add manage hooks while still ignoring panels and using default manageHooks
       manageHook = myManageHook <+> manageHook desktopConfig

     -- add a fullscreen tabbed layout that does not avoid covering
     -- up desktop panels before the desktop layouts
     , layoutHook = simpleTabbed ||| layoutHook desktopConfig
     }
     -- add a screenshot key to the default desktop bindings
     `additionalKeys` [ ((mod4Mask, xK_F8), spawn "scrot") ]

To replace the desktop layouts with your own choices, but still allow toggling panel visibility, use desktopLayoutModifiers to modify your layouts:

  , layoutHook = desktopLayoutModifiers $ simpleTabbed ||| Tall 1 0.03 0.5

desktopLayoutModifiers modifies a layout to avoid covering docks, panels, etc. that set the _NET_WM_STRUT_PARTIAL property. See also XMonad.Hooks.ManageDocks.

Modifying the logHook

To add to the logHook while still sending workspace and window information to DE apps use something like:

  , logHook = myLogHook >> logHook desktopConfig

Or for more elaborate logHooks you can use do:

  , logHook = do
        dynamicLogWithPP xmobarPP
        updatePointer (Relative 0.9 0.9)
        logHook desktopConfig

Adding Xmonad to the display manager (GUI login)

If you install xmonad using a distribution package, it will usually register a number of xmonad session types (typically bare xmonad and xmonad with Gnome). If you install via darcs or cabal-install, you will probably need to create an xmonad session definition by hand.

These files are examples, but likely to be directly usable.

For xmonad to start automatically on login you need an applications/xmonad.desktop file on your system. If your distro doesn't provide it, create the following file:

$ cat /usr/share/applications/xmonad.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Xmonad
Exec=xmonad
NoDisplay=true
X-GNOME-WMName=Xmonad
X-GNOME-Autostart-Phase=WindowManager
X-GNOME-Provides=windowmanager
X-GNOME-Autostart-Notify=false

(The X-GNOME entries do not cause GNOME to be invoked, but do allow it to be used *with* GNOME in the future if you so choose.) Alternatively, you can create the above as ~/.local/share/applications/xmonad.desktop for the current user only.

The above simply registers xmonad as a valid window manager; to also make an xmonad session available, you need an xsessions/xmonad.desktop file. To start a minimal xmonad session from gdm (see notes* below to run more than just xmonad on login), create the following file:

$ cat /usr/share/xsessions/xmonad.desktop 
[Desktop Entry]
Encoding=UTF-8
Name=XMonad
Comment=Lightweight tiling window manager
Exec=xmonad
Icon=xmonad.png
Type=XSession

Your display manager must also be able to find the xmonad executable. If you are not using your distro package manager to install xmonad, for best results configure your build to install xmonad to a location in the system environment like /usr/local/bin/.

*NOTE: Using an xsessions/xmonad.desktop file that runs a custom script xmonad.start instead of just plain xmonad is also how to add other startup actions to the gdm xmonad.desktop startup, such as starting gnome daemons, apps, etc. See arjuna's blog for more details. (simono says: Creating /usr/share/xsessions/xmonad.desktop and /usr/local/bin/xmonad.start files is the preferred method for configuring an alternative window manager. The applications/xmonad.desktop file is still required.) However, see the xsession section below to continue using the classic ~/.xsession method to run a custom session.