2016-12-20 112 views
0

我試圖自定義我的真棒窗口管理器,將標籤號碼更改爲羅馬數字(更改1爲I,2爲II ...)。爲了實現這一點,我正在修改我的/etc/xdg/awesome/rc.lua文件,特別是{{tags}}部分。如何更改AwesomeWM標籤名稱?

我發現this blog post,他在設法編輯隨意標記名稱,看看左上角:

detail of the tag modification

我也閱讀貼在主題rc.lua file,和意識到我所要做的技術是與某些表結合使用的for循環。

這是感興趣的文件中的代碼片段:

-- {{{ Tags 
-- Define a tag table which hold all screen tags. 
tags = {} 
tagnames = { "irc", "mpd", "net", "usr", "png", "msg", } 
taglayouts = { 
     awful.layout.suit.tile.top, 
     awful.layout.suit.tile.bottom, 
     awful.layout.suit.floating, 
     awful.layout.suit.fair, 
     awful.layout.suit.floating, 
     awful.layout.suit.floating } 

for s = 1, screen.count() do 
    -- Each screen has its own tag table. 
    tags[s] = {} 
    for tagnumber = 1, 6 do 
     -- Add tags and name them. 
     tags[s][tagnumber] = tag(tagnames[tagnumber]) 
     -- Add tags to screen one by one, giving them their layouts at the same time. 
     tags[s][tagnumber].screen = s 
     awful.layout.set(taglayouts[tagnumber], tags[s][tagnumber]) 
    end 
    -- I'm sure you want to see at least one tag. 
    tags[s][1].selected = true 
end 
-- }}} 

...這是我rc.lua文件:

-- {{{ Tags 
-- Define a tag table which hold all screen tags. 
tags = {} 
tagnames = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", } 
taglayouts = { 
     awful.layout.suit.tile.top, 
     awful.layout.suit.tile.bottom, 
     awful.layout.suit.floating, 
     awful.layout.suit.fair, 
     awful.layout.suit.floating, 
     awful.layout.suit.floating } 

for s = 1, screen.count() do 
    -- Each screen has its own tag table. 
    -- tags[s] = awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8",$ 

     tags[s] = {} 

     for tagnumber = 1, 9 do 
       tags[s][tagnumber] = tag(tagnames[tagnumber]) 
       tags[s][tagnumber].screen = s 
       awful.layout.set(taglayouts[tagnumber], tags[s][tagnumber]) 
     end 

     tags[s][1].selected = true 
end 
--- }}} 

正如你可以看到,他們是相當的相同,區別在於我有九個標籤而不是六個(我根據它改變了代碼)。當我嘗試調試使用Xephyr的設置,出現在控制檯錯誤,我只能看到我的壁紙:

error while running function 
stack traceback: 
    [C]: in global 'tag' 
    /etc/xdg/awesome/rc.lua:100: in main chunk 
error: /etc/xdg/awesome/rc.lua:100: bad argument #2 to 'tag' (table expected, got string) 
error while running function 
stack traceback: 
    [C]: in global 'tag' 
    /etc/xdg/awesome/rc.lua:100: in main chunk 
error: /etc/xdg/awesome/rc.lua:100: bad argument #2 to 'tag' (table expected, got string) 
E: awesome: main:605: couldn't find any rc file 

我看不到錯誤所在,因爲我無法檢測在錯誤行tags[s][tagnumber] = tag(tagnames[tagnumber])中的任何語言違規:它只是用我的自定義名稱填充標籤數組,告訴它把它們當作標籤而不是隨機字符串。

更新:我剛剛意識到在taglayouts中有六個佈局,與原始Lua文件中的標記數量相同。我想我應該有九個標籤佈局,但我不知道應該添加哪一個。另外,我不認爲這是代碼正確編譯的重要障礙,因爲錯誤行與佈局列表沒有任何關係。

UPDATE 2:增加了三個awful.layout.suit.floatingtaglayouts。同樣的錯誤。

+0

錯誤不是語言違規。錯誤說'表預期,得到字符串',所以問題是你傳遞一個字符串,而不是一個表。我可以看到他們在你所關注的教程中做了什麼,但所有這些文件都至少有一年的歷史。查看文檔,它應該是'mytagone = tag({name =「one」})形式'' – DavisDude

+0

注意,不要編輯'/ etc/xdg/awesome/rc.lua',創建自己的' 〜/ .config/awesome/rc.lua' – Camusensei

+0

那麼我應該怎麼做我的代碼? – xvlaze

回答

2

繼另一個答案,我代替我的{}標籤與節:

-- {{{ Tags 
-- Define a tag table which hold all screen tags. 

tagnum = { "I", "II", "III", "IV", "V", "VI", "VII", 
"VIII", "IX" } 

for i = 1, 9 do 
awful.tag.add((tagnum[i]), { 
     layout = awful.layout.suit.tile, 
     master_fill_policy = "master_width_factor", 
     gap_single_client = true, 
     gap = 15, 
     screen = s, 
}) 

end 

-- }}} 

這造成我的標籤數量,他們的名字在tagnum表中定義。這隻有在你想創建相同的標籤時纔有用,但它總是比輸入i定義更加清晰。

一個更好的,更清潔的方式:

最初的解決方案是有用的,但它有一個問題:啓動AwesomeWM時,你將不會出現在定義的標籤,但在所有的人都在同時。也就是說,如果您打開一個終端,除非您之前選擇了一個帶有Mod4 + TagNum(默認配置)的標籤,否則您將在每個標籤中打開它。

爲了解決這個問題,我比較了默認配置文件和修改後的配置文件,並且我意識到它在默認配置文件中運行良好。所以我開始修改代碼以找到解決方案。總之,我發現只要對默認代碼進行最小限度的修改,就可以隨意自定義標籤名稱。這就是我的做法:

-- {{{ Tags 
tags = {} 
-- Generates tags with custom names 
for s = 1, screen.count() do 
     tags[s] = awful.tag({ "I", "II", "III", "IV", "V", "VI", "VII", "IX" }), 
end 
-- }}} 

P.S.我保留舊的解決方案,以防有人希望將代碼用於其他目的。