这是默认的 Awesome wm 配置中用于创建顶部栏的代码:
awful.screen.connect_for_each_screen(function(s)
-- Wallpaper
set_wallpaper(s)
-- Each screen has its own tag table.
awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
-- Create a promptbox for each screen
s.mypromptbox = awful.widget.prompt()
-- Create an imagebox widget which will contain an icon indicating which layout we're using.
-- We need one layoutbox per screen.
s.mylayoutbox = awful.widget.layoutbox(s)
s.mylayoutbox:buttons(gears.table.join(
awful.button({ }, 1, function () awful.layout.inc( 1) end),
awful.button({ }, 3, function () awful.layout.inc(-1) end),
awful.button({ }, 4, function () awful.layout.inc( 1) end),
awful.button({ }, 5, function () awful.layout.inc(-1) end)))
-- Create a taglist widget
s.mytaglist = awful.widget.taglist {
screen = s,
filter = awful.widget.taglist.filter.all,
buttons = taglist_buttons
}
-- Create a tasklist widget
s.mytasklist = awful.widget.tasklist {
screen = s,
filter = awful.widget.tasklist.filter.currenttags,
buttons = tasklist_buttons
}
-- Create the wibox
s.mywibox = awful.wibar({ position = "top", screen = s })
-- Add widgets to the wibox
s.mywibox:setup {
layout = wibox.layout.align.horizontal,
{ -- Left widgets
layout = wibox.layout.fixed.horizontal,
mylauncher,
s.mytaglist,
s.mypromptbox,
},
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
mykeyboardlayout,
wibox.widget.systray(),
mytextclock,
s.mylayoutbox,
},
}
end)
我试图将与标签管理和导航相关的代码分离到一个单独的模块中。正如您所看到的,栏的设置是在对 的调用中完成的wibar:setup
,它将各种小部件的描述作为参数。
如何将标签相关代码与该模板分开?这就是我到目前为止所做的:
function pkg.SetTags(lst)
pkg.taglist = lst
keys = {}
for i,c in ipairs(tagList) do
keys = gears.table.join(keys,
-- View tag only.
awful.key(
{ modkey }, c,
viewTagHook(i)
),
-- Toggle tag display.
awful.key(
{ modkey, "Control" }, c,
viewToggleHook(i)
),
-- Move client to tag.
awful.key(
{ modkey, "Shift" }, c,
moveClientHook(i)
),
-- Toggle tag on focused client.
awful.key(
{ modkey, "Control", "Shift" }, c,
viewClienHook(i)
)
)
end
end