dwm
dwm (dynamic window manager の略) はsuckless.org による X11 向けの動的ウィンドウマネージャです。dwm は単一のバイナリであり、そのソースコードは決して 2000 SLOC を超えないように意図されています。
dwm は C 言語のソースコードを編集して、再コンパイルすることで設定されます。suckless web サイトでは、プロジェクトは経験豊かな上級者のコンピュータユーザに焦点を当てており、またおそらく冗談半分ですが、ソースコードを編集することによるカスタマイズは「そのユーザベースを小さく、エリート主義者に限定された状態を保っている」としています。
ウィンドウモデル
dwm is a dynamic window manager, as such it manages windows in tiled, monocle and floating layouts. All of the layouts can be applied dynamically, optimizing the environment for the application in use and the task performed.
Launch a few terminals with Shift+Alt+Enter and dwm will tile the windows between the master and stack. A new terminal appears on the master window. Existing windows are pushed upon a stack to the right of the screen. Alt+Enter toggles windows between master and stack.
+------+----------------------------------+--------+ | tags | title | status + +------+---------------------+------------+--------+ | | | | | | | | | | | | | master | stack | | | | | | | | | | | | | +----------------------------+---------------------+
インストール
USE フラグ
USE flags for x11-wm/dwm a dynamic window manager for X11
savedconfig
|
Use this to restore your config from /etc/portage/savedconfig ${CATEGORY}/${PN}. Make sure your USE flags allow for appropriate dependencies |
xinerama
|
Add support for querying multi-monitor screen geometry through the Xinerama API |
後で編集するために、カスタマイズされた設定ファイルを /etc/portage/savedconfig/x11-wm/dwm-6.0.h に保存するには、savedconfig
USE フラグの有効化を検討すべきです。
root #
euse --enable savedconfig
複数のモニタで使用する場合は、Xinerama を使用するかしないかにかかわらず、xinerama
USE フラグを有効化すべきです。
root #
euse --enable xinerama
Emerge
x11-wm/dwm をインストールしてください:
root #
emerge --ask x11-wm/dwm
設定
開始
dwm を開始するには、ディスプレイマネージャまたは startx コマンドを使用してください。
startx を選択した場合は、次のファイルを作成する必要があります:
~/.xinitrc
exec dbus-launch --sh-syntax --exit-with-session dwm
メインの dwm 設定ファイル (dwm.h ファイル)
先述したように、メインの dwm 設定ファイルは /etc/portage/savedconfig/x11-wm/dwm-6.0 ファイルであり、このファイルへの変更を反映させるには、変更のたびに dwm を再コンパイルする必要があります。
エディタが適切に C コードのためのシンタックスハイライトを表示できるようにするには、C ヘッダファイル名拡張子を使用するシンボリックリンクを作成してください。
root #
ln -s /etc/portage/savedconfig/x11-wm/dwm-6.0 /etc/portage/savedconfig/x11-wm/dwm-6.0.h
または、拡張子とは関係なくファイルに対して使用するシンタックスハイライトを変更する方法についての、選択したエディタのドキュメンテーションを参照してください。
再コンパイル後に新しい設定を使用するためには、すでに dwm セッションの中にいる場合は、dwm を終了 (Mod+Shift+Q) してリロードすることで、メモリ内の現在実行中のバイナリを置き換えてください。
設定ファイル (dwmrc)
Gentoo Ebuild によって提供されるデフォルトの xsession ファイル (/etc/X11/Sessions/dwm) は、システム負荷および日時か、~/.dwm/dwmrc にユーザが置いたシェルコードの結果を表示する、デフォルトのステータスボックスを提供します。ウィンドウマネージャのバー内のステータスボックスにテキストを送信するための (dwm-6.0 時点での) 現在のメカニズムは、上述のデフォルト xsession によって示される通り、'xsetroot' を使用するものです。数行のシェルコードを使用することで、このメカニズムを使用してステータスバーに任意のテキストを送信することができます (例えば CPU 温度、音楽プレイヤーの現在のトラック、未読 e メール件数、など)。
追加の機能
dmenu は X のための動的メニューで、当初は dwm のために設計されました。
インストール
Emerge
dmenu をインストールしてください:
root #
emerge --ask x11-misc/dmenu
設定
dmenu のオプションは dwm.h ファイルを使用してカスタマイズできます。例えばメニューをディスプレイの下部に表示するには:
/etc/portage/savedconfig/x11-misc/dmenu-4.9.h
static const char *dmenucmd[] = { "dmenu_run", "-b", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
使い方
デフォルトでは Alt + P キーでメニューを有効化します。
追加のステータス情報
dwm のメニューバーに追加のステータス情報を表示するには x11-apps/xsetroot を使用すべきです。これは右上隅のテキスト情報を設定します。
まず、まだインストールしていない場合は x11-apps/xsetroot をインストールしてください。
そして、dwm ステータスに現在の情報を繰り返し表示するために、スクリプトまたはサイドプログラムを使用してください。
root #
emerge --ask x11-apps/xsetroot
Conky
例えば、システムについての現在の情報を表示するために Conky を試してみてください。テキスト情報のみが dwm インスタンスへとパイプされるように、 -X
USE フラグ付きでインストールするのがよいでしょう。(考慮すべき USE フラグは "-X hddtemp iostats wifi" です。)
root #
emerge --ask app-admin/conky
~/.config/conky/conky.conf ファイルの例。設定ファイルは 2 つのセクションに分けられます: conky.config
と conky.text
です。conky.config
セクションは Conky に関連するオプションを含む一方で、conky.text
セクションは何の情報をどのように表示するかを定義します。使用中のシステム上で Conky を使用するには、システムによって異なることがあるネットワークインターフェースまたはハードドライブへのパスなど、conky.text
セクション内の設定をいくつか修正する必要があるかもしれません。
~/.config/conky/conky.conf
conky.config = {
background = no,
format_human_readable = yes,
out_to_console = yes,
temperature_unit = celsius,
total_run_times = 0,
update_interval = 1,
#use_spacer = left,
use_spacer = none,
};
conky.text = [[
M ${memperc}%/${swapperc}% | \
/sda ${diskio sda} /sdb ${diskio sdb} \
/sdc ${diskio sdc} | \
${if_existing /proc/net/route ppp0}P0 U ${upspeed ppp0} D ${downspeed ppp0} |${endif}\
${if_existing /proc/net/route eth0}E0 U ${upspeed eth0} D ${downspeed eth0} |${endif}\
${if_existing /proc/net/route wlan0}W0 U ${upspeed eth0} D ${downspeed eth0}\
${wireless_ap wlan0} ${wireless_link_qual_perc wlan0} ${endif}\
CPU ${hwmon 1 temp 1}F \
/sda ${hddtemp /dev/sda}F \
/sdb ${hddtemp /dev/sdb}F \
${time %a, %b %d %Y %H:%M (%z)}
]]
以前に Conky を使用したことがある場合、波括弧と等号を使った新しい構文に注意してください。
先述した ~/.xinitrc ファイル内の dwm コマンドの実行の前に、行を追加してください。
~/.xinitrc
conky | while read -r; do xsetroot -name "$REPLY"; done &
exec ck-launch-session dbus-launch --sh-syntax --exit-with-session dwm
カスタムスクリプト
サイドプログラムを emerge する代わりに、日付、時刻、天気、その他のシステム情報を表示する単純なループを作成することもできます。
例えば天気と日付と時刻をを表示するには、~/.scripts/ にシェルスクリプトファイルを作成してください:
~/.scripts/xsetloop.sh
#!/bin/sh
let loop=0
while true; do
if [[ $loop%300 -eq 0 ]]; then
weather="$(curl 'https://wttr.in?format=1')"
let loop=0
fi
xsetroot -name " $weather | $(date '+%b %d %a') | $(date '+%H:%M') "
let loop=$loop+1
sleep 1
done
このスクリプトは単体でループ実行されるので、~/.xinitrc ファイル内で xroot に設定するだけでよいです。
~/.xinitrc
. ~/.scripts/xsetloop.sh &
exec ck-launch-session dbus-launch --sh-syntax --exit-with-session dwm
使い方
キーと機能
すべての (デフォルトの) dwm キーバインディングは、dwm.h で定義される特定の MODKEY
とともに動作します。MODKEY
のデフォルト値は Mod1Mask
で、これは PC キーボードでは Alt のことです。この記事の以降の部分では、MODKEY
を表すために Mod を使用します。
ウィンドウを手動で移動する
ウィンドウを他のウィンドウタグに手動で移動するには、Mod キーを押しながらウィンドウ上のどこかを左クリックしてください。そして、Mod を押したまま、ウィンドウを移動させたい先のウィンドウタグをクリックしてください。
デフォルトショートカット
これらのショートカットは x11-wm/dwm のデフォルトとして使用されています。
ウィンドウ管理
- Mod+2 - ウィンドウタグ番号 2 を表示します。
- Mod+Shift+1-9 - ウィンドウにマウスをホバーさせてこのキーを押すと、ウィンドウを指定されたタグ番号に配置します。
- Mod+Shift+0 - ウィンドウにマウスをホバーさせてこのキーを押すと、ウィンドウをすべてのタグ番号に配置します。
ユーティリティ
- Mod+Shift+Enter - 端末を起動する
- Mod+Shift+C - ウィンドウを閉じる
- Mod+P - dmenu
- Mod+J または Mod+K - 別の端末に移動する。
- Mod+Enter - ウィンドウをスタックとマスタの間で入れ替える。
- Mod+Shift+Q - dwm を終了する
レイアウト変更
- Mod+F - レイアウトをフロート型に変更する。
- Mod+T - レイアウトをタイル型に変更する。
音量キー
"..." は x11-wm/dwm にファイル終端以外に含めることを意味します。
以下の行をコンフィグファイルに追加して、dwm を再 emerge してください:
/etc/portage/savedconfig/x11-wm/dwm-6.0
#include <X11/XF86keysym.h>
...
/* commands */
static const char *upvol[] = { "amixer", "set", "Master", "2+", NULL };
static const char *downvol[] = { "amixer", "set", "Master", "2-", NULL };
// for muting/unmuting //
static const char *mute[] = { "amixer", "-q", "set", "Master", "toggle", NULL };
// for pulse compatible //
static const char *upvol[] = { "amixer", "-q", "sset", "Master", "1%+", NULL };
static const char *downvol[] = { "amixer", "-q", "sset", "Master", "1%-", NULL };
static const char *mute[] = { "amixer", "-q", "-D", "pulse", "sset", "Master", "toggle", NULL };
...
static Key keys[] = {
/* modifier key function argument */
{ 0, XF86XK_AudioRaiseVolume, spawn, {.v = upvol } },
{ 0, XF86XK_AudioLowerVolume, spawn, {.v = downvol } },
{ 0, XF86XK_AudioMute, spawn, {.v = mute } },
カスタマイズ
dwm はそのソースコードを編集することでカスタマイズされます
(ユーザのヒントと小技をここに書いてください。)
パッチ
Gentoo には dwm にパッチを当てるための固有の方法があります。パッチがすでに dwm ソースとマージできる状態であれば、emerge プロセス中に呼び出すことができる eapply_user
という特別な関数があります。この関数によって、ユーザパッチをソースに適用することができるようになります。必要なパッチを以下の 2 つの場所のうちいずれかに移動してください:
- /etc/portage/patches/category/application
- ebuild リポジトリ
/etc/portage/patches/category/application 内のパッチ
まず以下のディレクトリを作成してください:
root #
mkdir -p /etc/portage/patches/x11-wm/dwm
dwm パッチを /etc/portage/patches/x11-wm/dwm/ にコピーして、各パッチの先頭に数値を付けてください (01-name_of_patch.patch のように)。また、ファイル名は .patch
または .diff
で終わる必要があります。さもないと Portage はそれを適用しないでしょう。以下の例では、larry という名前のユーザのホームディレクトリ (/home/larry) にパッチが置かれていると仮定しています。
root #
cp /home/larry/01-dwm.6.0-xft.patch /etc/portage/patches/x11-wm/dwm/
それでは dwm をインストールしてください。パッチの適用は emerge が面倒を見てくれます
root #
emerge --ask x11-wm/dwm
Portage で使用するように構成された ebuild リポジトリ内にパッチを置く
dwm パッチのための ebuild リポジトリを作成することで、それらを別のマシンと共有したり、公開したいときに、役立てることができます。
x11-wm/dwm を /var/db/repos/gentoo/ から新しい ebuild リポジトリに、あるいは適切なリポジトリがあればそちらに、コピーしてください。
files ディレクトリ内にパッチを配置してください (この例では、これらのファイルを保持するために作成されたリポジトリは "dwm_patches" と名付けられています):
root #
cp /home/larry/01-dwm-6.0-xft.diff /var/db/repos/dwm_patches/x11-wm/dwm/files/
ebuild ファイル /var/db/repos/dwm_patches/x11-wm/dwm/dwm-6.1.ebuild をテキストエディタで開き、自動適用させるために PATCHES 変数配列にパッチを列挙してください:
/var/db/repos/dwm_patches/x11-wm/dwm-6.1.ebuild
PATCHES=( "${FILESDIR}/01-dwm-6.0-xft.diff"
"${FILESDIR}/02-dwm-6.1-x11.diff"
)
emerge を実行して楽しんでください
root #
emerge --ask x11-wm/dwm
Assigning applications to window tags
A user can have their favorite applications start on a different window tag, such as starting MPlayer on window tag number five.
First, know the name of the application recorded by Xorg so dwm can be aware of this window on startup. To find this, start the target application (MPlayer in this example) and then further execute the xprop command (x11-apps/xprop). Click on the MPlayer window and xprop will report Xorg's data on the MPlayer window. Use the second window name identified on the WM_CLASS(STRING)
line. Now we have the name of the window dwm needs to be aware of.
Sometimes an application will have multiple windows of itself and will report one window with capital letters, while the second will have no capital letters. Wildcard characters are allowed within window names.
/etc/portage/savedconfig/x11-wm/dwm-6.0.h
static const Rule rules[] ={
{ "MPlayer", NULL, NULL, 1 << 4, True, 0 },
};
トラブルシューティング
Upgrading to dwm-6.0
Upgrading from dwm-5.9 to dwm-6.0 incorporated many changes making the previous config.h a likely problem for compiling dwm-6.0. Likely problems displayed might be compiler error messages "'nmaster' undeclared". To resolve, compile and install dwm-6.0 without using the custom config.h file and then find the default dwm-6.0 config.h file and diff against the old config.h file. (Or, decompress the dwm-6.0 tarball to acquire the default dwm-6.0 config.h file.)
Fix " Permission Denied"
A logind provider, like systemd or elogind, must be running in order to start a X session as non privileged user. If a logind provider is not running and the user issues startx dwm fails to start and message similar to this appears:
(EE) parse_vt_settings: Cannot open /dev/tty0 (Permission denied)
If this is the case and the system is OpenRC-based, add elogind to boot and start the service:
root #
rc-update add elogind boot
root #
/etc/init.d/elogind start
for more information, please visit Non root Xorg wiki page.
Remap mod key
If there are conflicts with the default dwm Alt conflicting with other console interface applications, use the Esc while within the console application. The Esc is an immediate usable fall back escape key. Another option, redefine the Mod key to use the keyboard Super (Windows) or other additional keys near the Space.
/etc/portage/savedconfig/x11-wm/dwm-6.0.h
#define MODKEY Mod4Mask /* Use Super Key */
To assign a second Mod key allowing a user to have a Mod key on both sides of the keyboard, mimic or copy this keys activity to another key on the keyboard. The Microsoft Menu key (or context menu key) on Microsoft keyboards is directly opposite of the Super (Windows). The x11-apps/xmodmap package is required for this. (For reference, the two key's values are: showkey 125/127
and xev 133/135
respectively - on MS NEK4000 keyboard.)
$HOME/.xinitrc
# Top of $HOME/.xinitrc file is a good place for this.
# This reassigns MS NEK4000 right Menu key to simulate DWM Mod4Key as well.
xmodmap -e "keycode 135 = Super_L" # reassign MS Menu Keypress to Super_L
xmodmap -e "remove mod1 = Super_L" # make sure X keeps it out of the mod1 group
Now, a user should have a non-conflicting and easily accessible Mod key on both sides of the keyboard!
Fix Java application misbehaving
Java-based applications are known to misbehave as Java doesn't know the WM being used. This result in GUI of specific Java applications to not work properly. To solve this we need to set the window manager name property of the root window. This can be done using the wmname tool and set it to LG3D
.
Install the tool:
root #
emerge --ask x11-misc/wmname
and set the property name:
user $
wmname LG3D
To make this setting permanent add this command to ~/.xinitrc.
It is also useful to export AWT_TOOLKIT if some Java applications are using AWT, as noted below.
Blank (grey) windows of Java applications
Java-based applications, such as Apache NetBeans, does not render properly. To mitigate this problem set the AWT_TOOLKIT variable as:
user $
AWT_TOOLKIT=MToolkit; export AWT_TOOLKIT
To make the action permanent is is required to add the command to the startup script, for example ~/.xinitrc.
Background not redrawing
Sometimes the background may not properly redraw when the current view is switched. For example, some terminal emulators such as st don't draw the entirety of their allocated window space. In these cases, X root window must have a properly defined color. This can be done with the xsetroot command. For example:
user $
xsetroot -solid black