fix(awful: hotkeys_popup): don't show group label if group itself is empty

1) factor out grouplabel-related logic into _create_group_columns() method
2) check the number of keys in group before calling that method
This commit is contained in:
actionless 2019-01-01 21:30:33 +01:00
parent 74410e9490
commit beb54c7d5f
1 changed files with 96 additions and 90 deletions

View File

@ -310,26 +310,12 @@ function widget.new(args)
return margin
end
function widget_instance:_create_wibox(s, available_groups, show_awesome_keys)
s = get_screen(s)
local wa = s.workarea
local height = (self.height < wa.height) and self.height or
(wa.height - self.border_width * 2)
local width = (self.width < wa.width) and self.width or
(wa.width - self.border_width * 2)
-- arrange hotkey groups into columns
function widget_instance:_create_group_columns(column_layouts, group, keys, s, wibox_height)
local line_height = beautiful.get_font_height(self.font)
local group_label_height = line_height + self.group_margin
-- -1 for possible pagination:
local max_height_px = height - group_label_height
local column_layouts = {}
for _, group in ipairs(available_groups) do
local keys = gtable.join(
show_awesome_keys and self._cached_awful_keys[group] or nil,
self._additional_hotkeys[group]
)
local max_height_px = wibox_height - group_label_height
local joined_descriptions = ""
for i, key in ipairs(keys) do
joined_descriptions = joined_descriptions .. key.description .. (i~=#keys and "\n" or "")
@ -411,8 +397,28 @@ function widget.new(args)
end
end
function widget_instance:_create_wibox(s, available_groups, show_awesome_keys)
s = get_screen(s)
local wa = s.workarea
local wibox_height = (self.height < wa.height) and self.height or
(wa.height - self.border_width * 2)
local wibox_width = (self.width < wa.width) and self.width or
(wa.width - self.border_width * 2)
-- arrange hotkey groups into columns
local column_layouts = {}
for _, group in ipairs(available_groups) do
local keys = gtable.join(
show_awesome_keys and self._cached_awful_keys[group] or nil,
self._additional_hotkeys[group]
)
if #keys > 0 then
self:_create_group_columns(column_layouts, group, keys, s, wibox_height)
end
end
-- arrange columns into pages
local available_width_px = width
local available_width_px = wibox_width
local pages = {}
local columns = wibox.layout.fixed.horizontal()
local previous_page_last_layout
@ -423,7 +429,7 @@ function widget.new(args)
)
table.insert(pages, columns)
columns = wibox.layout.fixed.horizontal()
available_width_px = width - item.max_width
available_width_px = wibox_width - item.max_width
item.layout:insert(
1, self:_group_label("PgUp - Prev Page", self.label_bg)
)
@ -452,10 +458,10 @@ function widget.new(args)
wibox = mywibox,
}
mywibox:geometry({
x = wa.x + math.floor((wa.width - width - self.border_width*2) / 2),
y = wa.y + math.floor((wa.height - height - self.border_width*2) / 2),
width = width,
height = height,
x = wa.x + math.floor((wa.width - wibox_width - self.border_width*2) / 2),
y = wa.y + math.floor((wa.height - wibox_height - self.border_width*2) / 2),
width = wibox_width,
height = wibox_height,
})
mywibox:set_widget(pages[1])
mywibox:buttons(gtable.join(