awesome (简体中文)

From ArchWiki
Jump to: navigation, search

Tango-preferences-desktop-locale.png 本页面或部分需要翻译,部分内容可能已经与英文文章脱节。如果您希望贡献翻译,请访问简体中文翻译组
附注: please use the first argument of the template to provide more detailed indications.
Tango-preferences-desktop-locale.png
翻译状态: 本文是英文页面 Awesome翻译,最后翻译时间:2012-11-25,点击这里可以查看翻译后英文页面的改动。
摘要
关于安装、使用、配置和自定义 awesome 窗口管理器的指南。

来自awesome网站:

Awesome 是 XWindows 下可高度定制的新一代窗口管理器。运行快捷、扩展性强,遵循GPLv2发布。

Awesome主要面向高级用户、开发者和那些希望完美控制自己电脑的图形界面的人。

Contents

安装

安装位于官方软件仓库的软件包 awesome

如果你对不稳定的预览版本有兴趣,可以从 AUR 安装 awesome-git。但是请注意,这是一个不稳定的开发版,配置文件会有语法差异。

使用Awesome

不使用登陆管理器

不使用登录管理器来运行 awesome,只要添加 exec awesome到你的启动脚本(比如 ~/.xinitrc)。 详情参阅xinitrc

你也可以甚至不用登陆直接使用预置用户启动Awesome,请参考Start X at Login

使用登陆管理器

要想用登陆管理器启动awesome,看这里.

配置

Awesome默认的配置已经很不错了,不过你迟早会想要做一些修改的。配置文件是一个lua脚本:~/.config/awesome/rc.lua.

创建配置文件

创建配置文件所在的文件夹

 $ mkdir -p ~/.config/awesome/

Awesome会自动使用~/.config/awesome/rc.lua里的所有配置。这个文件并不会自动创建,所以我们先要从模板复制一个过来:

$ cp /etc/xdg/awesome/rc.lua ~/.config/awesome

配置文件的语法会随着Awesome的版本升级而变化,所以当你升级了之后遇到问题时,重复上面的步骤,或者你得手动修改配置文件。

要获得关于配置Awesome的更多信息,请看Awesome wiki的配置部分

更多的配置资源

注意: Awesome配置文件语法有时会变化,所以你可能得动手修改下载的配置文件。

一些不错的rc.lua的例子可以在下面这些站点找到:

用 Xephyr 测试 rc.lua

用这种方式可以在不破坏现有桌面的情况下对rc.lua进行测试。首先把 rc.lua 复制到一个新文件rc.lua.new,接着进行修改。然后在Xephyr中运行新的rc.lua (Xephyr允许你在XWindow中植入一个新的XWindow - screenshot)。 你可以这样测试你的新rc.lua

$ Xephyr -ac -br -noreset -screen 1152x720 :1 &
$ DISPLAY=:1.0 awesome -c ~/.config/awesome/rc.lua.new

这种方式的巨大优势在于如果你弄坏了rc.lua.new,你不至于把现有的Awesome桌面弄得一团糟(并且很可能还会把XWindow弄崩溃了,没保存的工作全部丢失………)。一旦你觉得新的配置文件不错,就用rc.lua.new代替rc.lua,然后重启Awesome。

目前(2011.07),还有一个工具awmtt可以提供上述功能。

主题

Beautiful可以让你动态地改变背景图片和颜色主题,而不需要改变rc.lua文件。

默认的主题文件是 /usr/share/awesome/themes/default。把它复制到 ~/.config/awesome/themes/default 然后修改一下 rc.lua中的theme_path。

beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")

更多细节参考这里

一些样例:themes

设置墙纸

Beautiful 可以设置墙纸,所以你就不用在.xinitrc 或者 .xsession 中自己设置了。Beautiful 允许你给每个主题配一个墙纸。如果你看一看默认的主题文件,可以找到一个 wallpaper_cmd 值。当beautiful.init("path_to_theme_file")运行的时候,给定的命令就会运行。如果不想要 Beautiful 修改你的墙纸,你可以在这里自己定义一个命令,或者把这个值注释掉。

例如,如果你想用 awsetbg 设置墙纸,你可以这样写:

theme.wallpaper_cmd = { "awsetbg -f .config/awesome/themes/awesome-wallpaper.png" }
注意: 要让Awsetbg工作,你需要有一个能设置背景图片的软件,比如"Feh"。

随机墙纸

想要随机切换墙纸,只需要注释掉 wallpaper_cmd 一行,然后使用下面的代码添加脚本到到你的 .xinitrc 文件中:

while true;
do
  awsetbg -r <path/to/the/directory/of/your/wallpapers>
  sleep 15m
done &

小技巧

如果你有自己的小技巧想与大家分享,请随意添加。

使用awesome作为GNOME的窗口管理器

GNOME有“开包即用”的优势,你可以在使用GNOME的同时改用awesome作为窗口管理器。如果你在用GNOME 3的话,你可以安装awesome-gnome包,然后在用GDM登陆的时候选择"Awesome GNOME"。更多详细内容请参考awesome wiki

像compiz那样的平铺桌面效果

Revelation可以显示所有你开启的客户端;左键点击客户端会跳到该客户端所在的第一个标签并聚焦于该客户端。按下回车键会跳到当前聚焦的客户端,按下ESc键退出。更多内容请参考[1]

在awesome 3中显示/隐藏wibox

要使用Modkey-b来在当前屏幕上隐藏/显示默认的状态栏 (Awesome 2.3中的默认行为),把下面代码加入rc.lua里的globalkeys变量:

awful.key({ modkey }, "b", function ()
    mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible
end),

截图

在awesome中想要通过PrtScn按键来截图就必须借助其他截图工具. Arch软件仓库中,Scrot是个很简单就可以实现这些功能的截图工具.

只需要输入:

# pacman -S scrot

如果optional dependencies中可选的包觉得有用,也可以安装.

下一步,就是需要获得PrtScr按键的按键名, 如果不确定是什么,一般就是 "Print"了.

终端里面输入命令:

# xev

然后按键盘上的PrtScr按键, 将会输出类似下面的结果:

 KeyPress event ....
     root 0x25c, subw 0x0, ...
     state 0x0, keycode 107 (keysym 0xff61, Print), same_screen YES,
     ....

我们判断没错,键名就是 "Print".

接下来继续配置awesome!

在配置文件中的全局数组(任意地方)中输入并保存:

Lua 代码:

 awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/screenshots/ 2>/dev/null'") end),

这里的 ~/screenshots/ 可以改成你截图想要保存的地方.

动态标签

Eminent是一个小型的lua库,扩展了awful并提供了简单快速的wmii一样的动态标签功能。跟shifty不同, eminent无意提供全面详尽的标签系统,而是试图让动态标签越简单越好。实际上除了导入eminent库,你不用在rc.lua里改任何东西,eminent会把所有的事情帮你搞定。

Shifty是实现了动态标签的一个Awesome 3的扩展。它也实现了一个配置系统来让你设置几个变量和键位绑定就完全掌控你的桌面!

Space Invaders

Space Invaders是一个用来展现Awesome Lua API无限能力的演示。

请注意它从3.4-rc1版以后就没有被包括进Awesome包里了。

Naughty弹窗提醒

请查看Awesome维基上的naughty页面.

弹出菜单项

这是一份 awesome3 的默认简单菜单项, 看起来要自定义也十分容易. 然而,如果你在用awesome的 2.x 版本, 那么请看awful.menu.

如果你想要配置 freedesktop.org 的菜单项,就到 awesome-freedesktop .

一个 awesome3 的菜单配置示例:

myawesomemenu = {
   { "lock", "xscreensaver-command -activate" },
   { "manual", terminal .. " -e man awesome" },
   { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
   { "restart", awesome.restart },
   { "quit", awesome.quit }
}

mycommons = {
   { "pidgin", "pidgin" },
   { "OpenOffice", "soffice-dev" },
   { "Graphic", "gimp" }
}

mymainmenu = awful.menu.new({ items = { 
                                        { "terminal", terminal },
                                        { "icecat", "icecat" },
                                        { "Editor", "gvim" },
                                        { "File Manager", "pcmanfm" },
                                        { "VirtualBox", "VirtualBox" },
                                        { "Common App", mycommons, beautiful.awesome_icon },
                                        { "awesome", myawesomemenu, beautiful.awesome_icon }
                                       }
                             })

Awesome的更多插件

Awesome中的插件是一些你可以加入插件栏 (状态栏和标题栏) 的东西,它们提供了关于你的系统的各种信息,并让你很方便地直接在窗口管理器上就看到这些信息。这些插件很简易而且有很强的灵活性。 -- 来自 Awesome Wiki: Widgets

有一个被广泛使用的插件库叫Wicked (只与3.4版以前的Awesome兼容),它提供了更多插件,比如MPD插件,CPU使用情况,内存使用情况等。要更详细的了解参见 Wicked

Awesome 3.4中用来代替Wicked的有ViciousObviousBashets。如果你选择使用vicious,你也应该看看 vicious的文档

Transparency

Awesome has support for true transparency through xcompmgr. Note that you'll probably want the git version of xcompmgr, which is available in AUR.

Add this to your ~/.xinitrc:

xcompmgr &

See man xcompmgr or xcompmgr for more options.

In awesome 3.4, window transparency can be set dynamically using signals. For example, your rc.lua could contain the following:

client.add_signal("focus", function(c)
                              c.border_color = beautiful.border_focus
                              c.opacity = 1
                           end)
client.add_signal("unfocus", function(c)
                                c.border_color = beautiful.border_normal
                                c.opacity = 0.7
                             end)

If you got error messages about add_signal, using connect_signal insteaded.

Note that if you are using conky, you must set it to create its own window instead of using the desktop. To do so, edit ~/.conkyrc to contain:

own_window yes
own_window_transparent yes
own_window_type desktop

Otherwise strange behavior may be observed, such as all windows becoming fully transparent. Note also that since conky will be creating a transparent window on your desktop, any actions defined in awesome's rc.lua for the desktop will not work where conky is.

As of Awesome 3.1, there is built-in pseudo-transparency for wiboxes. To enable it, append 2 hexadecimal digits to the colors in your theme file (~/.config/awesome/themes/default, which is usually a copy of /usr/share/awesome/themes/default), like shown here:

bg_normal = #000000AA

where "AA" is the transparency value.

To change transparency for the actual selected window by pressing Modkey + PageUp/PageDown you can also use tansset-df available through the community package repository and the following modification to your rc.lua:

globalkeys = awful.util.table.join(
    -- your keybindings
    [...]
    awful.key({ modkey }, "Next", function (c)
        awful.util.spawn("transset-df --actual --inc 0.1")
    end),
    awful.key({ modkey }, "Prior", function (c)
        awful.util.spawn("transset-df --actual --dec 0.1")
    end),
    -- Your other key bindings
    [...]
)

ImageMagick

如果你用ImageMagick的display命令来设置你的墙纸,可能会遇到xcompmgr效果不好的问题。请注意awsetbg可能会用display如果它没有其他选项。安装habak,feh,hsetroot或者其他的包应该会解决这个问题。 (grep -A 1 wpsetters /usr/bin/awsetbg 来看你有哪些选项)

自动运行程序

参见 Awesome维基上的自动运行.

Awesome不会运行那些被Freedesktop如GNOME或KDE设置为自动运行的程序。不过Awesome提供了一些运行程序的函数 (除了Lua标准库里的函数 os.execute)。要运行跟GNOME或KDE里一样自动运行的程序,你可以从 AUR 安装 dex-git,然后在你的rc.lua里加入:

os.execute"dex -a -e Awesome"

如果你只想列出一些程序来在让Awesome启动时运行,你可以创建一个你需要启动命令的列表然后循环启动:

do
  local cmds = 
  { 
    "swiftfox",
    "mutt",
    "consonance",
    "linux-fetion",
    "weechat-curses",
    --and so on...
  }

  for _,i in pairs(cmds) do
    awful.util.spawn(i)
  end
end

(你也可以调用 os.execute 加上命令名,在结尾加上 '&',但最好还是调用 spawn 函数来运行)

如要程序仅在当前没有运行情况下运行,你可以只在 pgrep 找不到跟它一样名字的进程的时候运行它。

function run_once(prg)
  awful.util.spawn_with_shell("pgrep -u $USER -x " .. prg .. " || (" .. prg .. ")")
end

所以,举个例子,要在当前 parcellite 没有运行的情况下运行 parcellite:

run_once("parcellite")

使用 awesome-client 给文本插件传递信息

只需要创建一个新的插件,就可以很容易的传递信息。

 mywidget = widget({ type = "textbox", name = "mywidget" })
 mywidget.text = "initial text"

使用 awesome-client 从外部更新“initial text":

 
 echo -e 'mywidget.text = "new text"' | awesome-client

不要忘记把插件增加到 wibox.

使用其他任务栏

如果你喜欢 awesome 既轻量又强大的功能,但又不喜欢默认那个任务栏的外观, 你可以安装其他的.比如 xfce4-panel:

sudo pacman -S xfce4-panel

当然,你可能有更好的选择.然后要把它添加到配置文件 rc.lua 的自动启动部分(该如何写请看wiki吧).你可以注释掉配置文件中给每个桌面创建 wiboxes 的那部分(开头是"mywibox[s] = awful.wibox({ position = "top", screen = s })"),因为已经不需要了. 检查配置文件没有错误之后就可以执行命令生效:

awesome -k rc.lua

另外你还需要改变"modkey+R"的快捷键绑定, 比如用Xfrun4, bashrun等,来替代awesome自带的启动器. 请看这个Openbox文章中的启动器部分作为参考. 别忘了添加

      properties = { floating = true } },
    { rule = { instance = "$yourapplicationlauncher" },

到你 rc.lua 配置文件中

Fix Java (GUI appears gray only)

Guide taken from [2].

  1. Install wmname from community
  2. Run the following command or add it to your .xinitrc:
    wmname LG3D
Note:

If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in /etc/profile.d/openjdk6.sh

If you use a non-reparenting window manager and Java 7, you should uncomment the corresponding line in /etc/profile.d/jre.sh

Prevent Nautilus from displaying the desktop (Gnome3)

Run dconf-editor. Navigate to org->gnome->desktop->background and uncheck "draw-background" as well as "show-desktop-icons" for good measure. That's it!

Another option is moving /usr/bin/nautilus to a new location and replacing it with a script that runs 'nautilus --no-desktop' passing any arguments it receives along.

#!/bin/sh
/usr/bin/nautilus-real --no-desktop $@

Transitioning away from Gnome3

Run 'gnome-session-properties' and remove programs that you won't be needing anymore (e.g Bluetooth Manager, Login Sounds, etc).

If you'd like to get rid of GDM, make sure that your rc.conf DAEMONS list includes "dbus" (and "cupsd" if you have a printer). It's advisable to get a different login manager (like SLiM), but you can do things manually if you wish. That entails setting up your .xinitrc properly and installing something like devmon (AUR).

If you wan't to keep a few convenient systray applets and your GTK theme, append this to your rc.lua;

function start_daemon(dae)
	daeCheck = os.execute("ps -eF | grep -v grep | grep -w " .. dae)
	if (daeCheck ~= 0) then
		os.execute(dae .. " &")
	end
end

procs = {"gnome-settings-daemon", "nm-applet", "kupfer", "gnome-sound-applet", "gnome-power-manager"}
for k = 1, #procs do
	start_daemon(procs[k])
end

Prevent the mouse scroll wheel from changing tags

In your rc.lua, change the Mouse Bindings section to the following;

-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
    awful.button({ }, 3, function () mymainmenu:toggle() end)))
-- }}}

Troubleshooting

LibreOffice

If you encounter UI problems with libreoffice install libreoffice-gnome.

Mod4 key

The Mod4 is by default the Win key. If it's not mapped by default, for some reason, you can check the keycode of your Mod4 key with

$ xev

It should be 115 for the left one. Then add this to your ~/.xinitrc

xmodmap -e "keycode 115 = Super_L" -e "add mod4 = Super_L"
exec awesome

The problem in this case is that some xorg installations recognize keycode 115, but incorrectly as the 'Select' key. The above command explictly remaps keycode 115 to the correct 'Super_L' key.

Mod4 key vs. IBM ThinkPad users

IBM ThinkPads do not come equipped with a Window key (although Lenovo have changed this tradition on their ThinkPads). As of writing, the Alt key is not used in command combinations by the default rc.lua (refer to the Awesome wiki for a table of commands), which allows it be used as a replacement for the Super/Mod4/Win key. To do this, edit your rc.lua and replace:

modkey = "Mod4"

by:

modkey = "Mod1"

Note: Awesome does a have a few commands that make use of Mod4 plus a single letter. Changing Mod4 to Mod1/Alt could cause overlaps for some key combinations. The small amount of instances where this happens can be changed in the rc.lua file.

If you do not like to change the awesome standards, you might like to remap a key. For instance the caps lock key is rather useless (for me) adding the following contents to ~/.Xmodmap

clear lock 
add mod4 = Caps_Lock

and (re)load the file. This will change the caps lock key into the mod4 key and works nicely with the standard awesome settings. In addition, if needed, it provides the mod4 key to other X-programs as well.

Not confirmed, but if recent updates of xorg related packages break mentioned remapping the second line can be replaced by (tested on a DasKeyboard with no left Super key):

keysym Caps_Lock = Super_L Caps_Lock

Eclipse: cannot resize/move main window

If you get stuck and cannot move or resize the main window (using mod4 + left/right mouse button) edit the workbench.xml and set fullscreen/maximized to false (if set) and reduce the width and height to numbers smaller than your single screen desktop area.

Note: workbench.xml can be found in: <eclipse_workspace>/.metadata/.plugins/org.eclipse.ui.workbench/ and the line to edit is <window height="xx" maximized="true" width="xx" x="xx" y="xx">.

YouTube: fullscreen appears in background

[3] If YouTube videos appear underneath your web browser when in fullscreen mode, add this to your rc.lua

   { rule = { instance = "plugin-container" },
     properties = { floating = true } },

With Chromium add

   { rule = { instance = "exe" },
     properties = { floating = true } },

Starting console clients on specific tags

It does not work when the console application is invoked from a GTK terminal (e.g. LXTerminal). URxvt is known to work.

Redirecting console output to a file

Some GUI application are very verbose when launched from a terminal. As a consequence, when started from Awesome, they output everything to the TTY from where Awesome was started, which tend to get messy. To remove the garbage output, you have to redirect it. However, the awful.util.spawn function does not handle pipes and redirections very well as stated in the official FAQ.

As example, let's redirect Luakit output to a temporary file:

awful.key({ modkey, }, "w", function () awful.util.spawn_with_shell("luakit 2>>/tmp/luakit.log") end),

External Links