Awesome 3.5 - 屏幕顶部有两个面板(wiboxes)

在迁移至 Awesome 3.5.1 之前,我的屏幕顶部有两个面板(彼此叠放),底部没有面板。我在 3.5 之前使用的代码如下:

-- 创建wibox
mywibox[s] = awful.wibox({ position = "top", height = "32", screen = s })

-- 添加小部件到wibox - 顺序很重要
mywibox[s].widgets = {
    {
        {
            -- 左上角
            mylauncher,
            mytaglist[s],
            mypromptbox[s],
            -- 我的自定义小部件,分隔符等...
            layout = awful.widget.layout.horizontal.leftright
        },
        {
            -- 右上角
            mylayoutbox[s],
            mytextclock,
            -- 更多小部件,分隔符等...
            s == 1 and mysystray or nil,
            layout = awful.widget.layout.horizontal.rightleft
        },
    },
    {
        -- 下面一排(只有任务列表)
        mytasklist[s],
    },
    layout = awful.widget.layout.vertical.flex,
    height = mywibox[s].height
}

现在我很难想象如何使用 3.5 的配置来实现相同的效果。目前,我在顶部使用了一个基本的单面板(其中包含大多数小部件),底部使用了一个(包含任务列表)。下面是代码:

-- 创建wibox
mywibox[s] = awful.wibox({ position = "top", height = "18", screen = s })
mywibox2[s] = awful.wibox({ position = "bottom", height = "18", screen = s })

-- 左对齐的小部件
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(mylauncher)
left_layout:add(mytaglist[s])
left_layout:add(mypromptbox[s])
-- 我的自定义小部件,分隔符等...

-- 右对齐的小部件
local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray()) end
-- 我的自定义小部件,分隔符等...
right_layout:add(mytextclock)
right_layout:add(mylayoutbox[s])

-- 将它们组合在一起
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_right(right_layout)

local layout2 = wibox.layout.align.horizontal()
layout2:set_middle(mytasklist[s])

mywibox[s]:set_widget(layout)
mywibox2[s]:set_widget(layout2)

如果有人有想法如何编辑当前的 rc.lua 使其像旧版本一样工作,那将不胜感激。

点赞
用户934599
用户934599

我使用以下代码做了类似的事情:

wiboxes["top"]=awful.wibox({position="top",height=26})
local top_layout = wibox.layout.fixed.horizontal()
sublayout["cpu"] = wibox.layout.fixed.horizontal()
for i=2,3 do
  sublayout["cpu" .. i] = wibox.layout.fixed.horizontal()
  sublayout["cpu" .. i]:add(graphs["cpu"]..i) -- 图形表已经初始化
  sublayout["cpu" .. i]:add(textboxes["cpu"]..i) -- 文本框表已经初始化
  sublayout["cpu"]:add(sublayout["cpu"..i)
end
.....
top_layout:add(sublayout["cpu"])
.....
wiboxes["top"]:set_widget(top_layout)

使用这个代码,我可以看到两个图形和文本框,以查看每个核心的 CPU 使用情况,第一个位于顶部,第二个位于下方。它应该与标签列表或任何其他小部件一起工作。

2013-10-21 11:19:55
用户436275
用户436275

你可以尝试这样做,不知道是否完全符合你的需求(根据你的代码,32是wibox的高度):

local const = wibox.layout.constraint()
const:set_widget(layout)
const:set_strategy("exact")
const:set_height(32/2)

local l = wibox.layout.fixed.vertical()
l:add(const)
l:add(mytasklist[s])

mywibox[s]:set_widget(l)

首先创建了一个“约束”布局,确保“布局”(应显示在顶部的部件)始终具有16像素的大小。然后将该约束布局堆叠在任务列表的顶部,并在wibox中显示结果。

其中有些代码在最新版本中可能可以缩短,但我不确定3.5.1是否已经具备了这些方便的参数。

2013-10-23 20:07:08