「Xmonad」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
 
(1版 をインポートしました)
(相違点なし)

2015年1月6日 (火) 21:23時点における版

関連記事

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

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

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

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

インストール

xmonadxmonad-contrib公式リポジトリから利用可能です。最新の開発スナップショットのビルド (darcs) は AUR にあります。下のセクションは、開発スナップショット xmonad-darcsAUR の使い方です。

ノート: ArchHaskell リポジトリを使うことを選んだ場合は、xmonad の代わりに haskell-xmonad パッケージをインストールする必要があります (公式の community リポジトリにあるパッケージは依存パッケージが異なっています)。

開発版 (xmonad-darcs)

xmonad-darcs 開発版は AUR からインストールでき、公式リポジトリに多少の依存パッケージがあります。以下の順番でインストールしてください:

設定

Xmonad の起動

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

ノート: デフォルトではマウスカーソルは 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 で書かれているため、プログラマーでないとなかなか設定が難しいと思われます。設定例や詳細方法は以下のページを参照して下さい:

最善の方法は組み込みの関数 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.hs が入っており、これは xmonad.hs の最新の公式サンプルです。/usr/share/ の中にアーキテクチャとバージョン別に置かれています (例: find /usr/share -name xmonad.hs)。

Xmonad の終了

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

Tips and tricks

X-Selection-Paste

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

Also, there exists a function "pasteSelection" in XMonad.Util.Paste that can be bound to a key using a line like:

xmonad.hs
  -- X-selection-paste buffer
  , ((0, xK_Insert), pasteSelection)

Pressing the "Insert" key will now paste the mouse buffer in the active window.

Complementary applications

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

  • xmobar — A lightweight, text-based, status bar written in Haskell.
http://projects.haskell.org/xmobar/ || xmobar, xmobar-gitAUR
An applet for the GNOME, MATE or xfce panel. || xmonad-log-applet-xfce4-gitAUR, xmonad-log-applet-gnome-gitAUR

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-gitAUR 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:

Quick, less flexible

ノート: 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 ... -}}

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-darcsAUR, 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

KDE と xmonad

The xmonad wiki has instructions on how to run xmonad inside KDE

It also might be a good idea to set a global keyboard shortcut in KDE to start xmonad in case it is accidentally killed or closed.

Skype 用の IM レイアウト

In orded to create an IM layout for the newer versions of skype, the following code can be used:

xmonad.hs
myIMLayout = withIM (1%7) skype Grid
    where
      skype = And (ClassName "Skype") (Role "")

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 と xmonad

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

Either install xmonad-gnome3AUR 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.

GNOME と 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".

Xfce 4 と xmonad

Use xfceConfig instead of defaultConfig after importing XMonad.Config.Xfce in ~/.xmonad/xmonad.hs, e.g. adapting the minimal config above:

import XMonad
import XMonad.Config.Xfce
main = xmonad xfceConfig
    { terminal    = "urxvt"
    , modMask     = mod4Mask
    }

Also add an entry to Settings > Session and Startup > Application Autostart that runs xmonad --replace.

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, grab a configuration 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.

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

Java アプリケーションの問題

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:

  • For jre7-openjdk or jre8-openjdk, append 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.
  • For Oracle's JRE/JDK, use SetWMName. However, its effect may be canceled when also using XMonad.Hooks.EwmhDesktops. In this case, appending
 >> setWMName "LG3D"

to the LogHook may help.

See [1] for more information.

gvim やターミナルの底部の空きスペース

スペースを背景色と合わせる方法は Vim#gVim ウィンドウの底部の空きスペース を見て下さい。

rxvt-unicode の場合、rxvt-unicode-patchedAUR が使えます。

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 がフルスクリーンにならない

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.

Problems with focused border in VirtualBox

A known issue with Virtualbox (Ticket #6479) can cause problems with the focused window border. A solution can be found by installing a compositing manager like xcompmgr which overrides the incorrect behavior of vboxvideo.

Steam のゲーム (Half-Life, Left 4 Dead, …) と xmonad

There seems to be some trouble with Source engine based game (like Half-Life). If they don't start or get stuck with a black screen a workaround it to start them in window mode: right click on the game in your library and choose properties, click on launch options and enter: [2]

-windowed

Another solution is to float the window of the game using the manage hook. For example, the following line can be used for Half-Life:

 className =? "hl_linux" --> doFloat

参照