# Xmonad (日本語)

xmonad は、Xのタイル型ウィンドウマネージャです。画面を分割し、重なり合わないようにウィンドウを配置することで、画面を最大限に活用することができます。ウィンドウマネージャの機能はキーボードから利用することができます。（マウスはオプションです。）

xmonadは Haskell で実装されており、設定や拡張もHaskellで書かれています。レイアウトやキーバインド、その他の設定はユーザーが設定ファイルに書き込むことで変更できます。

レイアウトは動的に適用され、各ワークスペース上で異なるレイアウトを使用することができます。Xinerama は完全にサポートされ、ウィンドウを複数のモニタで並べて表示することができます。

詳細は、xmonadのウェブサイトをご覧ください。 http://xmonad.org/

## インストール

xmonad と xmonad-contrib は公式リポジトリから利用可能です。 A build for the current development snapshot (darcs) is in the AUR. The following instructions are for xmonad-darcs, the development snapshot.

### 開発版 (xmonad-darcs)

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

- xmonad-darcs -- The core window manager
- xmonad-contrib-darcs -- Contributed extensions providing custom layouts, configurations, etc.

## 設定

### Xmonadの起動

Xmonadを自動起動するには、起動スクリプトに`xmonad`コマンドを追加します。(例えば、startxを使う場合 `~/.xinitrc`、xdmログインマネージャを使う場合 `~/.xsession`) GDMやKDMを使う場合は、新しいセッションファイルを作成し、セッションメニューからxmonadを選択します。

Note: デフォルトではマウスカーソルはxです。left_ptrに設定するには起動スクリプトに以下を追加します(例 `~/.xinitrc`):

    xsetroot -cursor_name left_ptr

また、標準ではUSキーボードレイアウトなので、必要に応じて変更します。例えば日本語キーボードレイアウトは`~/.xinitrc`に以下を追加します。キーボードレイアウトの設定についてはここを参照してください。:

     setxkbmap -layout jp

例 `~/.xinitrc`:

     # set the cursor
     xsetroot -cursor_name left_ptr
     # set Japanese keyboard layout
     setxkbmap -layout jp
     # start xmonad
     exec xmonad

もし、起動しない場合はホームディレクトリに`.xmonad`ディレクトリがあるか確認してください。もしない場合は作成します。

     mkdir ~/.xmonad

詳細については、xinitrcを参照してください。

### Xmonadの設定

Xmonadユーザーは`~/.xmonad/xmonad.hs`を追加、修正することでXmonadをカスタマイズすることができます。再コンパイルは`Mod+q`でその場で自動的にされます。

ディレクトリ`~/.xmonad`がない場合は`xmonad --recompile`を実行してディレクトリを作成します。

Xmonadのデフォルトの設定は非常に優秀で、`xmonad.hs`なしで実行することができます。そのため、`xmonad --recompile`を実行したあとでも`~/.xmonad/xmonad.hs`は多分無いでしょう。あなたがそれをカスタマイズしたいのならば、ファイルを作成しそれを編集していきましょう。

Xmonadの設定ファイルはHaskellで書かれているため、設定の調整が難しい時期があるかもしれません。設定例や詳細は以下のページを参照して下さい。

- xmonad wiki
- xmonad config archive
- xmonad FAQ
- Arch Linux forum thread

最善の方法は組み込みの関数defaultConfigを使用し、必要なところを`~/.xmonad/xmonad.hs`で変更やカスタマイズをすることです。

これは、次のように`xmonad.hs`を書くことによって達成されます。

     import XMonad

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

これはデフォルトの設定に端末とボーダーの設定を上書きします。(その他の設定はdefaultConfig関数から継承されます。)

より複雑になるにつれ、それぞれ別の関数で設定しメイン関数内でそれらの関数を呼び出したほうが便利です。これは、大規模なカスタマイズをするときに保守を簡易にします

上記の簡単な`xmonad.hs`は次のように書くことができます。

     import XMonad

     main = do
       xmonad $ defaultConfig
         { terminal    = myTerminal
         , modMask     = myModMask
         , borderWidth = myBorderWidth
         }

     myTerminal    = "urxvt"
     myModMask     = mod4Mask -- Win key or Super_L
     myBorderWidth = 3

また、Haskellではimportが最初になる限り、関数や{}内の順序は重要ではありません。

以下はこの設定ファイルの一部です。これは一般的な機能の一例です。

     {
       terminal           = myTerminal,
       focusFollowsMouse  = myFocusFollowsMouse,
       borderWidth        = myBorderWidth,
       modMask            = myModMask,
       -- numlockMask deprecated in 0.9.1
       -- numlockMask        = myNumlockMask,
       workspaces         = myWorkspaces,
       normalBorderColor  = myNormalBorderColor,
       focusedBorderColor = myFocusedBorderColor,
       -- key bindings
       keys               = myKeys,
       mouseBindings      = myMouseBindings,
       -- hooks, layouts
       layoutHook         = myLayout,
       manageHook         = myManageHook,
       handleEventHook    = myEventHook,
       logHook            = myLogHook,
       startupHook        = myStartupHook
     }

また、最初にxmonadに付属の最新の設定例`/usr/share/xmonad-VERSION/man/xmonad.hs`をコピーすることを検討して下さい。

### Xmonadの終了

`Mod+Shift+q` でxmonadを終了させることができます。 `Mod` はデフォルトでは `Alt` になっています。

## Tips and tricks

The keyboard-centered operation in Xmonad can be further supported with a keyboard shortcut for X-Selection-Paste.

### 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
- gmrun
- Unclutter - a small utility to hide the mouse pointer
- XMonad-log-applet - a GNOME applet for the gnome-panel (the package is in the Official repositories)

### Increase the number of workspaces

By default, xmonad uses 9 workspaces. You can increase this to 14 by extending the following line like this:

    xmonad.hs

    -- (i, k) <- zip (XMonad.workspaces conf) [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9]
    (i, k) <- zip (XMonad.workspaces conf) [xK_grave, xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0, xK_minus, xK_equal, xK_BackSpace]

### 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 $ layoutHook defaultConfig
         , 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 packages are xmonad-contrib and xmobar from the official repositories, or you can use xmobar-git from the AUR instead of the official xmobar package.

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

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

#### Option 1: Quick, less flexible

Note: There is also dzen2 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 configuration that includes all of the options described in the xmonad:Option2: More configurable choice.

    main = xmonad =<< xmobar defaultConfig { modMask = mod4Mask {- or any other configurations here ... -}}

#### 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 is being written to the bar
- The key binding to toggle the gap for the bar

The following is an example of how to use it:

    ~/.xmonad/xmonad.hs

    -- Imports.
    import XMonad
    import XMonad.Hooks.DynamicLog

    -- The main function.
    main = xmonad =<< statusBar myBar myPP toggleStrutsKey myConfig

    -- Command to launch the bar.
    myBar = "xmobar"

    -- Custom PP, configure it as you like. It determines what is being written to the bar.
    myPP = xmobarPP { ppCurrent = xmobarColor "#429942" "" . wrap "<" ">" }

    -- Key binding to toggle the gap for the bar.
    toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)

    -- Main configuration, override the defaults to your liking.
    myConfig = defaultConfig { modMask = mod4Mask }

#### Verify XMobar Config

The template and default xmobarrc contains this.

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

    ~/.xmobarrc

    Config { ...
           , commands = [ Run StdinReader .... ]
             ...
           , template = " %StdinReader% ... "
           }

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

### Controlling xmonad with external scripts

There are at least two ways to do this.

Firstly, you can use the following xmonad extension, XMonad.Hooks.ServerMode.

Secondly, you can simulate keypress events using xdotool or similar programs. See this Ubuntu forums thread. The following command would simulate the keypress `Super+n`:

    xdotool key Super+n

### Launching another window manager within xmonad

If you are using xmonad-darcs, as of January of 2011, you can restart to another window manager from within xmonad. You just need to write a small script, and add stuff to your `~/.xmonad/xmonad.hs`. Here is the script.

    ~/bin/obtoxmd

    #!/bin/sh
    openbox
    xmonad

And here are the modifications you need to add to your `~/.xmonad/xmonad.hs`:

    ~/.xmonad/xmonad.hs

    import XMonad
    --You need to add this import
    import XMonad.Util.Replace

    main do
        -- And this "replace"
        replace
        xmonad $ defaultConfig
        {
        --Add the usual here
        }

You also need to add the following key binding:

    ~/xmonad/xmonad.hs

    --Add a keybinding as follows:
    ((modm .|. shiftMask, xK_o     ), restart "/home/abijr/bin/obtoxmd" True)

Just remember to add a comma before or after and change the path to your actual script path. Now just `Mod+q` (restart xmonad to refresh the config), and then hit `Mod+Shift+o` and you should have Openbox running with the same windows open as in xmonad. To return to xmonad you should just exit Openbox. Here is a link to adamvo's `~/.xmonad/xmonad.hs` which uses this setup Adamvo's xmonad.hs

### Example configurations

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

- brisbin33 :: simple, useful, readable :: config screenshot
- jelly :: Configuration with prompt, different layouts, twinview with xmobar :: xmonad.hs
- MrElendig :: Simple configuration, with xmobar :: xmonad.hs, .xmobarrc, screenshot.
- thayer :: A minimal mouse-friendly config ideal for netbooks :: configs screenshot
- vicfryzel :: Beautiful and usable xmonad configuration, along with xmobar configuration, xinitrc, dmenu, and other scripts that make xmonad more usable. :: git repository, screenshot.
- vogt :: Check out adamvo's config and many others in the official Xmonad/Config archive

## トラブルシューティング

### GNOME 3 and xmonad

With the release of GNOME 3, some additional steps are necessary to make GNOME play nicely with xmonad.

Either install xmonad-gnome3 from the AUR, or, manually:

Add an xmonad session file for use by gnome-session (`/usr/share/gnome-session/sessions/xmonad.session`):

    [GNOME Session]
    Name=Xmonad session
    RequiredComponents=gnome-panel;gnome-settings-daemon;
    RequiredProviders=windowmanager;notifications;
    DefaultProvider-windowmanager=xmonad
    DefaultProvider-notifications=notification-daemon

Create a desktop file for GDM (`/usr/share/xsessions/xmonad-gnome-session.desktop`):

    [Desktop Entry]
    Name=Xmonad GNOME
    Comment=Tiling window manager
    TryExec=/usr/bin/gnome-session
    Exec=gnome-session --session=xmonad
    Type=XSession

Create or edit this file (`/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

Finally, install xmonad-contrib and create or edit `~/.xmonad/xmonad.hs` to have the following

    import XMonad
    import XMonad.Config.Gnome

    main = xmonad gnomeConfig

Xmonad should now appear in the list of GDM sessions and also play nicely with gnome-session itself.

#### Compositing in GNOME and Xmonad

Some applications look better (e.g. GNOME Do) when composition is enabled. This is, however not, the case in the default Xmonad window manager. To enable it add an additional .desktop file `/usr/share/xsessions/xmonad-gnome-session-composite.desktop`:

    [Desktop Entry]
    Name=Xmonad GNOME (Composite)
    Comment=Tiling window manager
    TryExec=/usr/bin/gnome-session
    Exec=/usr/sbin/gnome-xmonad-composite
    Type=XSession

And create `/usr/sbin/gnome-xmonad-composite` and `chmod +x /usr/sbin/gnome-xmonad-composite`:

    xcompmgr &
    gnome-session --session=xmonad

Now choose "Xmonad GNOME (Composite)" in the list of sessions during login. Reference `man xcompmgr` for additional "eye candy".

### GDM 2.x/KDM cannot 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.

For KDM, you will need to create the file here as `/usr/share/apps/kdm/sessions/xmonad.desktop`

Official documentation can be found here: Haskell Documentation Page

### Missing xmonad-i386-linux or xmonad-x86_64-linux

Xmonad should automatically create the `xmonad-i386-linux` file (in `~/.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 this command from the folder:

    xmonad --recompile

Now you should see the file.

Note: A reason you may get an error message saying that xmonad-x86_64-linux is missing is that xmonad-contrib is not installed.

### Problems with Java applications

The standard Java GUI toolkit has a hard-coded list of "non-reparenting" window managers. Since xmonad is not in that list, there can be some problems with running some Java applications. One of the most common problems is "gray blobs", when the Java application renders as a plain gray box instead of rendering the GUI.

There are several things that may help:

- If you are using jre7-openjdk, uncomment the line `export _JAVA_AWT_WM_NONREPARENTING=1` in `/etc/profile.d/jre.sh`. Then, source the file `/etc/profile.d/jre.sh` or log out and log back in.
- If you are using Oracle's JRE/JDK, the best solution is usually to use SetWMName. However, its effect may be nullified if one also uses XMonad.Hooks.EwmhDesktops, in which case

     >> setWMName "LG3D"

added to the LogHook may help.

For more details about the problem, refer to the xmonad FAQ.

### Empty space at the bottom of gvim or terminals

See Vim#Empty space at the bottom of gvim windows for a solution which makes the area match the background color.

For rxvt-unicode, you can use rxvt-unicode-patched.

You can also configure xmonad to respect size hints, but this will leave a gap instead. See the documentation on Xmonad.Layout.LayoutHints.

### Chromium/Chrome will not go fullscreen

If Chrome fails to go fullscreen when `F11` is pressed, you can use the XMonad.Hooks.EwmhDesktops extension found in the xmonad-contrib package. Simply add the `import` statement to your `~/.xmonad/xmonad.hs`:

    import XMonad.Hooks.EwmhDesktops

and then add `handleEventHook = fullscreenEventHook` to the appropriate place; for example:

    ...
            xmonad $ defaultConfig
                { modMask            = mod4Mask
                , handleEventHook    = fullscreenEventHook
                }
    ...

After a recompile/restart of xmonad, Chromium should now respond to `F11` (fullscreen) as expected.

### Multitouch / touchegg

Touchégg polls the window manager for the _NET_CLIENT_LIST (in order to fetch a list of windows it should listen for mouse events on.) By default, xmonad does not supply this property. To enable this, use the XMonad.Hooks.EwmhDesktops extension found in the xmonad-contrib package.

### Keybinding issues with an azerty keyboard layout

Users with a keyboard with azerty layout can run into issues with certain keybindings. Using the XMonad.Config.Azerty module will solve this.

### GNOME 3 mod4+p changes display configuration instead of launching dmenu

If you do not need the capability to switch the display-setup in the gnome-control-center, just execute

    dconf write /org/gnome/settings-daemon/plugins/xrandr/active false

as your user, to disable the xrandr plugin which grabs Super+p.

## 関連項目

- xmonad - The official xmonad website
- xmonad.hs - Template xmonad.hs
- xmonad: a guided tour
- dzen - General purpose messaging and notification program
- dmenu - Dynamic X menu for the quick launching of programs
- Comparison of Tiling Window Managers - Arch wiki article providing an overview of mainstream tiling window managers
- Share your xmonad desktop!
- xmonad hacking thread

Category:

- Tiling WMs (日本語)