awesome - Arch Linux 中文维基

跳至內容

# awesome

出自 Arch Linux 中文维基

這篇文章或章節的翻譯質量不佳。

原因：最後更新 2015（在 Talk:Awesome# 中討論）

本文或本節內容已經過時。

原因： 請提供模板的第一個位置參數以概括原因。 (在Talk:Awesome討論)

來自awesome網站：

Awesome 是 X Window 下可高度定製的新一代窗口管理器。運行快捷、擴展性強，遵循GPLv2發布。

Awesome主要面向高級用戶、開發者和那些希望完美控制自己電腦的圖形界面的人。

本文主要內容為安裝、使用、配置和自定義 awesome 窗口管理器。

## 安裝

安裝位於官方軟體倉庫的軟體包 awesome包。

如果你對不穩定的預覽版本有興趣，可以從 AUR 安裝 awesome-gitAUR。但是請注意，這是一個不穩定的開發版，配置文件會有語法差異。

## 使用Awesome

### 不使用登錄管理器

不使用登錄管理器來運行 awesome，只要添加 `exec awesome`到你的啟動腳本（比如 ~/.xinitrc）。 詳情參閱xinitrc

你也可以甚至不用登錄直接使用預置用戶啟動Awesome，請參考Start X at login

### 使用登錄管理器

要想用登錄管理器啟動awesome，看這裡.

#### GDM, LightDM 以及其他使用 /usr/share/xsessions/ 的管理器

Awesome 會自動地為這些登錄管理器安裝一份配置文件，不需要做其他的事就能在登錄時選擇啟動Awesome。

#### KDM

以root身份創建:

    /usr/share/apps/kdm/sessions/awesome.desktop

    [Desktop Entry]
    Name=Awesome
    Comment=Tiling Window Manager
    Type=Application
    Exec=/usr/bin/awesome
    TryExec=/usr/bin/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的例子可以在下面這些站點找到：

- http://git.sysphere.org/awesome-configs/tree/ - Adrian C 的 Awesome 3.4 配置文件。 (anrxc)
- https://pastebin.com/f6e4b064e - Darthlukan 的 Awesome 3.4 配置文件.
- https://web.archive.org/web/20120509022348/http://www.calmar.ws/dotfiles/dotfiledir/dot_awesomerc.lua
- https://web.archive.org/web/20081012025713/http://oxmoz.no-ip.org/awesome/rc.lua
- https://www.ugolnik.info/downloads/awesome/rc.lua (screen) - 帶有小型標題欄和狀態欄的Awesome3配置文件。
- https://github.com/kakos/wolgri.config/blob/master/.config/awesome/rc.lua
- https://github.com/nblock/config/blob/b89ff1d1badfc6ba4675d779a4e6cc26708a85b3/config/awesome/rc.lua
- https://github.com/setkeh/Awesome-3.5 - Setkeh 的 Awesome 3.5 配置文件.
- http://awesome.naquadah.org/wiki/User_Configuration_Files - Collection of user configurations on the awesome homepage.

### 調試 rc.lua

#### 使用 Xephyr

用這種方式可以在不破壞現有桌面的情況下對 rc.lua 進行測試。首先把 rc.lua 複製到一個新文件 rc.lua.new，接著進行修改。然後在 Xephyr 中運行新的 rc.lua （Xephyr 允許你在 XWindow 中植入一個新的 XWindow）。 你可以這樣測試你的新 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。

#### 使用 awmtt

awmttAUR (Awesome WM Testing Tool) 是一個基於 Xephyr 的易於使用的腳本。默認情況下，它會測試 `~/.config/awesome/rc.lua.test` 。如果該文件不存在，它會測試當前使用的 rc.lua 。也可以指定要測試的配置文件所在路徑：

    $ awmtt start -C ~/.config/awesome/rc.lua.new

當測試完成後，使用以下命令關閉窗口:

    $ awmtt stop

或者通過以下命令立即查看變化:

    $ awmtt restart

### 改變鍵盤布局

如果需要使用不同的鍵盤布局 [qwerty -> dvorak] 有兩種方法。

- 第一種就是按照 Awesome Wiki 這裡所說的更改 Awesome 的配置
- 第二種就是在 xorg settings 改變鍵盤布局

## 主題

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` 中自己設置了。這允許你給每個主題配一個牆紙。

#### version >= 3.5

3.5 版本的 Awesome 不再提供 awsetbg 命令，但有了一個名為 gears 的模塊。你可以在 `theme.lua` 通過以下代碼設置你的牆紙。

    theme.wallpaper = "~/.config/awesome/themes/awesome-wallpaper.png"

為了加載你的牆紙，請確保你的 `rc.lua` 含有以下代碼:

    beautiful.init("~/.config/awesome/themes/default/theme.lua")
    for s = 1, screen.count() do
    	gears.wallpaper.maximized(beautiful.wallpaper, s, true)
    end

#### 隨機牆紙

請把以下代碼加入你的 `rc.lua`(for awesome >= 3.5):

    -- configuration - edit to your liking
    wp_index = 1
    wp_timeout  = 10
    wp_path = "/path/to/wallpapers/"
    wp_files = { "01.jpg", "02.jpg", "03.jpg" }

    -- setup the timer
    wp_timer = timer { timeout = wp_timeout }
    wp_timer:connect_signal("timeout", function()

      -- set wallpaper to current index for all screens
      for s = 1, screen.count() do
        gears.wallpaper.maximized(wp_path .. wp_files[wp_index], s, true)
      end

      -- stop the timer (we don't need multiple instances running at the same time)
      wp_timer:stop()

      -- get next random index
      wp_index = math.random( 1, #wp_files)

      --restart the timer
      wp_timer.timeout = wp_timeout
      wp_timer:start()
    end)

    -- initial start when rc.lua is first run
    wp_timer:start()

如果想從指定目錄中自動抓取圖片，把以下代碼加入你的 `rc.lua`(for awesome >= 3.5 ):

    -- {{{ Function definitions

    -- scan directory, and optionally filter outputs
    function scandir(directory, filter)
        local i, t, popen = 0, {}, io.popen
        if not filter then
            filter = function(s) return true end
        end
        print(filter)
        for filename in popen('ls -a "'..directory..'"'):lines() do
            if filter(filename) then
                i = i + 1
                t[i] = filename
            end
        end
        return t
    end

    -- }}}

    -- configuration - edit to your liking
    wp_index = 1
    wp_timeout  = 10
    wp_path = "/path/to/wallpapers/"
    wp_filter = function(s) return string.match(s,"%.png$") or string.match(s,"%.jpg$") end
    wp_files = scandir(wp_path, wp_filter)

    -- setup the timer
    wp_timer = timer { timeout = wp_timeout }
    wp_timer:connect_signal("timeout", function()

      -- set wallpaper to current index for all screens
      for s = 1, screen.count() do
        gears.wallpaper.maximized(wp_path .. wp_files[wp_index], s, true)
      end

      -- stop the timer (we don't need multiple instances running at the same time)
      wp_timer:stop()

      -- get next random index
      wp_index = math.random( 1, #wp_files)

      --restart the timer
      wp_timer.timeout = wp_timeout
      wp_timer:start()
    end)

    -- initial start when rc.lua is first run
    wp_timer:start()

想要隨機切換牆紙，只需要注釋掉 `wallpaper_cmd` 那一行, 然後把以下代碼添加到你的 `.xinitrc` 中(for awesome <= 3.4 ):

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

## 小技巧

如果你有自己的小技巧想與大家分享，請隨意添加。

### 使用awesome作為GNOME的窗口管理器

GNOME有「開包即用」的優勢，你可以在使用GNOME的同時改用awesome作為窗口管理器。如果你在用GNOME 3的話，你可以安裝awesome-gnomeAUR包，然後在用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的有Vicious，Obvious 和 Bashets。如果你選擇使用vicious，你也應該看看 vicious的文檔。

### Transparency

本文或本節內容已經過時。

原因： Awesome 3.5 has come and add_signal API has changed to connect_signal (在Talk:Awesome討論)

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

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-gitAUR，然後在你的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

注意：

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`

注意：

As of Java 1.7 and Awesome 3.5 (as installed by the awesome-git package) the fixes described above may cause undesirable behaviour related to menus not receiving proper focus. Awesome is now, apparently, a reparenting window manager as of this commit.

If you are experiencing problems having applied the 'wmname' and '_JAVA_AWT_WM_NONREPARENTING' fixes against a recent Java and Awesome, try removing both fixes.

### 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 will not be needing anymore (e.g Bluetooth Manager, Login Sounds, etc).

If you would 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 wa not 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)))
    -- }}}

### 菜單欄中的應用程式目錄

[community] 中的 Awesome 軟體包含有 menubar （默認情況下，按下 modkey+p 會在屏幕上方打開一個類似於 dmenu 的應用程式菜單）。但是，它僅搜索位於 `/usr/share/applications` 及 `/usr/local/share/applications` 目錄下的 .desktop 文件 （後者很可能在大多數 Arch 用戶的系統中都不存在）。為了改變這一情況，可以把下面這行代碼加入到你的 `rc.lua` （最好能把它加到 "Menubar configuration" 那一部分中）

    app_folders = { "/usr/share/applications/", "~/.local/share/applications/" }

注意：每次 Awesime 啟動都會重新讀取 `.desktop` 文件，因此文件過多會拖慢 Awesome 的啟動速度。如果你更喜歡使用其他方式來運行程序，可以通過在 `rc.lua` 移除 `local menubar = require("menubar")` 及其它涉及到 `menubar` 的變量來禁用菜單欄。

### 應用菜單

如果想要在點擊Awesome圖標，或者在桌面空白處右鍵點擊時，看到較傳統模式的應用菜單，可以參照Xdg-menu#Awesome的說明。但應用菜單不會在安裝或卸載程序時進行更新。所以，確保運行類似如下的命令，更新應用菜單：

     xdg_menu --format awesome --root-menu /etc/xdg/menus/arch-applications.menu >~/.config/awesome/archmenu.lua

### 標題欄

你可以很容易地在配置文件中rule把 `titlebars_enabled` 設置為 true 來啟用標題欄。

       { rule_any = {type = { "normal", "dialog" }
         }, properties = { titlebars_enabled = true }
       },

如果想要切換標題欄的顯示與否，可以把以下代碼加入配置文件中鍵位綁定部份的`clientkeys`部份中間位置（因為這段代碼是以逗號結尾，請不要放在`clientkeys`的最後），然後通過按 `modkey + Ctrl + t` 來切換。

       -- working toggle titlebar
       awful.key({ modkey, "Control" }, "t", function (c) awful.titlebar.toggle(c)         end,
                 {description = "Show/Hide Titlebars", group="client"}),

如果想默認情況下隱藏標題欄，僅需要在配置文件中標題欄創建後（即 在 awful.titlebar(c) : setup { 對應的右括號前）加入以下代碼

    awful.titlebar.hide(c)

此代碼會覆蓋掉前面rule中的配置

### Start xor jump

There is an extension called Run or raise, which makes it possible to configure a key to start a program if no instance exists, else jump to it. This is very useful for some programs: browsers, irc clients, music players, etc. The instructions are very well laid out at http://awesome.naquadah.org/wiki/Run_or_raise, the modular approach is advisable.

### Battery notification

If you want to add a simple battery notification you can add following lines to your rc.lua. These lines originate from a blogpost. Note that you need naughty for the notifications (installed by default in version 3.5).

    rc.lua

    -- battery warning
    local function trim(s)
      return s:find'^%s*$' and '' or s:match'^%s*(.*%S)'
    end

    local function bat_notification()
      local f_capacity = assert(io.open("/sys/class/power_supply/BAT0/capacity", "r"))
      local f_status = assert(io.open("/sys/class/power_supply/BAT0/status", "r"))
      local bat_capacity = tonumber(f_capacity:read("*all"))
      local bat_status = trim(f_status:read("*all"))

      if (bat_capacity <= 10 and bat_status == "Discharging") then
        naughty.notify({ title      = "Battery Warning"
          , text       = "Battery low! " .. bat_capacity .."%" .. " left!"
          , fg="#ffffff"
          , bg="#C91C1C"
          , timeout    = 15
          , position   = "bottom_right"
        })
      end
    end

    battimer = timer({timeout = 60})
    battimer:connect_signal("timeout", bat_notification)
    battimer:start()

    -- end here for battery warning

## 故障排除

本文或本節需要翻譯。要貢獻翻譯，請訪問簡體中文翻譯團隊。

附註： 請提供模板的第一個位置參數以更詳細的指示。（在 Talk:Awesome# 中討論）

### 滑鼠光標丟失

If you are able to login into awesome, the mouse cursor vanishes while mouse actions are still working, you can try this:

    gsettings set org.gnome.settings-daemon.plugins.cursor active false

### 灰色的Java圖形用戶界面

Some Java Applications may render just grey, empty windows. This is related to nonreparenting.

A fix might be uncommenting the last line in /etc/profile.d/jre.sh or set this manually.

    export _JAVA_AWT_WM_NONREPARENTING=1

other Methods could be found here: http://awesome.naquadah.org/wiki/Problems_with_Java

### LibreOffice

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

### Mod4 鍵

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.

注意：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 us redirect Luakit output to a temporary file:

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

## 額外連結

- http://awesome.naquadah.org/wiki/FAQ - FAQ
- https://www.lua.org/pil/ - Lua編程指南（第一版）
- http://awesome.naquadah.org/ - awesome 官方網站
- http://awesome.naquadah.org/wiki/Main_Page - awesome 維基
- https://web.archive.org/web/20111222025635/http://www.penguinsightings.org/desktop/awesome/ - 一條評論
- https://web.archive.org/web/20120427051008/http://compsoc.tardis.ed.ac.uk/wiki/AwesomeWM_guide - Awesome 指南
- https://bbs.archlinux.org/viewtopic.php?id=88926 - 分享你的awesome！

分類：​

- 動態窗口管理器
- 使用「模板:過時」標記的頁面或章節

隱藏分類：​

- 使用「模板:糟糕的翻譯」標記的頁面或章節
- 使用「模板:Translateme」標記的頁面或章節

awesome
新增話題