Difference between revisions of "Xmonad"

From ArchWiki
Jump to: navigation, search
m (Other Resources)
(Option 2: More configurable: Rewritten to reflect changes in 0.9)
Line 143: Line 143:
 
  modifyConfig x=x { modMask=mod4Mask, ...}
 
  modifyConfig x=x { modMask=mod4Mask, ...}
  
====Option 2: More configurable====
+
===== Option 2. More Configurable =====
Threading the handle manually also ''requires'' you to [[xmonad#Making room for conky or tray apps|make room for conky or tray apps]]. With this method you have access to xmobarPP, so you could change the formatting (ex. change colors or field separators).
+
As of xmonad(-contrib) 0.9, there is a new [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html#v%3AstatusBar statusBar] function in [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html XMonad.Hooks.DynamicLog]. It allows you to use your own configuration for:
 +
* The command used to execute the bar
 +
* The PP that determines what's being written to the bar
 +
* The keybinding to toggle the gap for the bar
  
First, we need to import three modules: IO, the DynamicLog and the Run utility. The logger is used to format and print various information about xmonad, like the workspaces, the title of the current window, the current layout and more. The two others are needed to run xmobar with a pipe and to print the output of the logger to it.
+
Following is an example of how to use it:
import IO
+
{{File|name=~/.xmonad/xmonad.hs|content=
import XMonad
+
<nowiki>
import XMonad.Hooks.DynamicLog
+
-- Imports.
  import XMonad.Util.Run
+
import XMonad
 +
import XMonad.Hooks.DynamicLog
 +
   
 +
-- The main function.
 +
main = xmonad =<< statusBar myBar myPP toggleStrutsKey myConfig
  
Now, on to the main function. There are several loggers you can use and you can also create your own. In this example, we will use xmobarPP, for details read the documentation on [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html XMonad.Hooks.DynamicLog].
+
-- Command to launch the bar.
 +
myBar = "xmobar"
  
The important thing here, is that we have to override the ppOutput, else it will just print to stdout.
+
-- Custom PP, configure it as you like. It determines what's being written to the bar.
main=do
+
myPP = xmobarPP { ppCurrent = xmobarColor "#429942" "" . wrap "<" ">" }
        xmobar <- spawnPipe "xmobar"  -- spawns xmobar and returns a handle
+
        xmonad $ defaultConfig
+
              { ...
+
              , logHook=dynamicLogWithPP $ xmobarPP { ppOutput=hPutStrLn xmobar } -- print the output of xmobarPP to the handle
+
              , ...
+
              }
+
  
=====Verify xmobar config=====
+
-- Keybinding to toggle the gap for the bar.
The template and default xmobarrcs contains this.<!-- contains what? -->
+
toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
 +
 
 +
-- Main configuration, override the defaults to your liking.
 +
myConfig = defaultConfig { modMask = mod4Mask }
 +
</nowiki>
 +
}}
 +
 
 +
 
 +
===== Verify XMobar Config =====
 +
 
 +
The template and default xmobarrcs contains this.
  
 
At last, open up <tt>~/.xmobarrc</tt> and make sure you got StdinReader in the template and run the plugin. E.g.
 
At last, open up <tt>~/.xmobarrc</tt> and make sure you got StdinReader in the template and run the plugin. E.g.
  Config { ...
+
  {{File|name=~/.xmobarrc|content=
        , commands=[ Run StdinReader .... ]  
+
<nowiki>
          ...
+
Config { ...
        , template=" %StdinReader% ... "
+
      , commands = [ Run StdinReader .... ]  
        }
+
        ...
 +
      , template = " %StdinReader% ... "
 +
      }
 +
</nowiki>
 +
}}
 
Now, all you should have to do is either to start, or restart xmonad.
 
Now, all you should have to do is either to start, or restart xmonad.
  

Revision as of 18:41, 6 November 2009

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n links end xmonad is a tiling window manager for X. Windows are arranged automatically to tile the screen without gaps or overlap, maximizing screen use. Window manager features are accessible from the keyboard: a mouse is optional.

xmonad is written, configured and extensible in Haskell. Custom layout algorithms, key bindings and other extensions may be written by the user in config files.

Layouts are applied dynamically, and different layouts may be used on each workspace. Xinerama is fully supported, allowing windows to be tiled on several physical screens.

For more information, please visit the xmonad website: http://xmonad.org/

Installation

xmonad is currently available in the community repo. A build for the current development snapshot (darcs) is in the aur. The following instructions are for xmonad-darcs, the development snapshot.

Development version (xmonad-darcs)

The xmonad-darcs development version can be installed from the AUR, with some additional dependencies in [community]. Install them in the following order:

Configuration

Starting xmonad

To start xmonad automatically, simply add the command exec xmonad to your startup script (e.g. ~/.xinitrc). GDM and KDM users can create a new session file and then select xmonad from the appropriate Session menu.

Note: by default, xmonad does not set an X cursor, therefore the "cross" cursor is usually displayed which can be confusing for new users (thinking that xmonad has not launched correctly). To set the expected left-pointer, add the following to your startup file (e.g. ~/.xinitrc):

xsetroot -cursor_name left_ptr

Example .xinitrc :

 # set the cursor
 xsetroot -cursor_name left_ptr
 # start xmonad
 exec ck-launch-session xmonad

Configuring xmonad

xmonad users can modify, override or extend the default settings with the ~/.xmonad/xmonad.hs configuration file. Recompiling is done on the fly, with the Mod+q shortcut.

If you find you do not have a directory at ~/.xmonad, run xmonad --recompile to create it.

The "default config" for xmonad is quite usuable and it is achieved by simply running without an xmonad.hs entirely. Therefore, even after you run --recompile you will most likely not have an ~/.xmonad/xmonad.hs file. If you would like to start tweaking things, simply create the file and edit it as described below.

Because the xmonad configuration file is written in Haskell, non-programmers may have a difficult time adjusting settings. For detailed HOWTO's and example configs, we refer you to the following resources:

The best approach is to only place your changes and customizations in ~/.xmonad/xmonad.hs and write it such that any unset parameters are picked up from the built-in defaultConfig.

This is achieved by writing an xmonad.hs like this:

 import XMonad
 
 main=do
   xmonad $ defaultConfig
     { terminal   ="urxvt"
     , modMask    =mod4Mask
     , borderWidth=3
     }

This simply overrides the default terminal and borderwidth while leaving all other settings as their defaults (inherited from the function defaultConfig).

As things get more complicated, it can be handy to call configuration options by function name inside the main function, and define these separately in their own sections of your xmonad.hs. This makes large customizations like your layout and manage hooks easier to visualize and maintain.

The above simple xmonad.hs could have been written like this:

 import XMonad
 
 main=do
   xmonad $ defaultConfig
     { terminal   =myTerminal
     , modMask    =myModMask
     , borderWidth=myBorderWidth
     }
 
 -- yes, these are functions; just very simple ones
 -- that accept no input and return static values
 myTerminal   ="urxvt"
 myModMask    =mod4Mask -- Win key or Super_L
 myBorderWidth=3

Also, functional order does not matter, you could have declared myTerminal and myBorderWidth above or below its use main. However, any import lines need to come first.

Exiting xmonad

To end the current xmonad session, press Mod+SHIFT+q (Mod being ALT by default).

Tips and tricks

Complementary applications

There are number of complementary utilities that work well with xmonad. The most common of these include:

  • dmenu
  • xmobar
  • Dzen
  • Conky and conky-cli
  • Unclutter - an small utility to hide the mouse pointer ( pacman -S unclutter and at 'unclutter&' to .xinitrc )

Making room for conky or tray apps

Wrap your layouts with avoidStruts from XMonad.Hooks.ManageDocks for automatic dock/panel/trayer spacing:

 import XMonad
 import XMonad.Hooks.ManageDocks
 
 main=do
   xmonad $ defaultConfig
     { ...
     , layoutHook=avoidStruts $ Tall ||| Wide ||| Full
     , manageHook=manageHook defaultConfig <+> manageDocks
     , ...
     }

If you ever want to toggle the gaps, this action can be added to your key bindings:

,((modMask x, xK_b     ), sendMessage ToggleStruts)

Using xmobar with xmonad

xmobar is a light and minimalistic text based bar, designed to work with xmonad.
To use xmobar with xmonad, you will need two packages in addition to the xmonad package, these are xmonad-contrib from [community] and xmobar or xmobar-darcs from aur.

Here we will start xmobar from within xmonad, which reloads xmobar whenever you reload xmonad.

Open up ~/.xmonad/xmonad.hs in your favorite editor, and choose one of the two following options:

Option 1: Quick, less flexible

Note: there is also a dzen which you can substitute for xmobar in either case.

Common imports:

import XMonad
import XMonad.Hooks.DynamicLog

The xmobar action starts xmobar and returns a modified config that includes all the options described in the xmonad:Option2: More configurable choice.

-- main for (>=0.9) and -darcs
main=xmonad=<< xmobar myConfig
myConfig=defaultConfig { modMask=mod4Mask, -- or any other configurations here ... }
-- main for (<=0.8.1)
main=xmobar (xmonad . modifyConfig)
modifyConfig x=x { modMask=mod4Mask, ...}
Option 2. More Configurable

As of xmonad(-contrib) 0.9, there is a new statusBar function in XMonad.Hooks.DynamicLog. It allows you to use your own configuration for:

  • The command used to execute the bar
  • The PP that determines what's being written to the bar
  • The keybinding to toggle the gap for the bar

Following is an example of how to use it: Template:File


Verify XMobar Config

The template and default xmobarrcs contains this.

At last, open up ~/.xmobarrc and make sure you got StdinReader in the template and run the plugin. E.g.

Template:File

Now, all you should have to do is either to start, or restart xmonad.

Example configurations

Below are some example configurations from fellow xmonad users. Feel free to add links to your own.

Troubleshooting

GDM can not find xmonad

You can force GDM to launch xmonad by creating the file xmonad.desktop in the /usr/share/xsessions directory and add the contents:

[Desktop Entry]
Encoding=UTF-8
Name=xmonad
Comment=This session starts xmonad
Exec=/usr/bin/xmonad
Type=Application

Now xmonad will show in your GDM session menu. Thanks to Santanu Chatterjee for the hint.

Missing xmonad-i386-linux

Xmonad should automatically create the xmonad-i386-linux file (in $HOME/.xmonad/). If this it not the case you can grab a cool looking config file from the xmonad wiki or create your own. Put the .hs and all others files in .xmonad/ and run the command from the folder:

xmonad --recompile

Now you should see the file.

Other Resources

xmonad - The official xmonad website

xmonad.hs - Original xmonad.hs

xmonad: a guided tour

dzen - General purpose messaging and notification program

dmenu - Dynamic X menu for the quick launching of programs