Merge pull request #2529 from actionless/hotkeys-popup-dont-show-empty-groups

fix(awful: hotkeys_popup): don't show group label if group itself is empty
This commit is contained in:
mergify[bot] 2019-10-12 22:14:48 +00:00 committed by GitHub
commit 344964a44a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 142 additions and 91 deletions

View File

@ -42,6 +42,7 @@ addons:
- xvfb - xvfb
- zsh - zsh
- x11-apps - x11-apps
- vim-nox
# Need xorg-macros # Need xorg-macros
- xutils-dev - xutils-dev
# lgi. # lgi.

View File

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

View File

@ -24,6 +24,8 @@ local function num_pairs(container_table)
return number_of_items return number_of_items
end end
local test_context = {}
local steps = { local steps = {
function(count) function(count)
if count <= 5 then if count <= 5 then
@ -239,11 +241,22 @@ local steps = {
elseif count == 2 then elseif count == 2 then
assert(num_pairs(cached_wiboxes) > 0) assert(num_pairs(cached_wiboxes) > 0)
assert(num_pairs(cached_wiboxes[s]) == 1) assert(num_pairs(cached_wiboxes[s]) == 1)
elseif (
test_context.hotkeys01_count_vim and
(count - test_context.hotkeys01_count_vim) == 2
) then
-- new wibox instance should be generated for including vim hotkeys:
assert(num_pairs(cached_wiboxes[s]) == 2)
end end
local hotkeys_wibox local hotkeys_wibox
local visible_hotkeys_widget
for _, widget in pairs(cached_wiboxes[s]) do for _, widget in pairs(cached_wiboxes[s]) do
hotkeys_wibox = widget.wibox hotkeys_wibox = widget.wibox
if hotkeys_wibox.visible then
visible_hotkeys_widget = widget
end
end end
if count == 2 then if count == 2 then
@ -255,8 +268,39 @@ local steps = {
elseif count == 3 then elseif count == 3 then
assert(not hotkeys_wibox.visible) assert(not hotkeys_wibox.visible)
root.fake_input("key_release", "Super_L") root.fake_input("key_release", "Super_L")
-- now let's run vim so hotkeys widget will show hotkeys for it:
test_context.hotkeys01_clients_before = #client.get()
awful.spawn("xterm -e vim")
elseif not test_context.hotkeys01_count_vim then
-- if xterm with vim got already opened:
if (
test_context.hotkeys01_clients_before and
test_context.hotkeys01_clients_before < #client.get()
) then
-- open hotkeys popup with vim hotkeys:
awful.key.execute({modkey}, "s")
test_context.hotkeys01_count_vim = count
end
elseif test_context.hotkeys01_count_vim then
if (count - test_context.hotkeys01_count_vim) == 1 then
assert(visible_hotkeys_widget ~= nil)
assert(visible_hotkeys_widget.current_page == 1)
-- Should change the page on PgDn:
root.fake_input("key_press", "Next")
elseif (count - test_context.hotkeys01_count_vim) == 2 then
assert(visible_hotkeys_widget ~= nil)
assert(visible_hotkeys_widget.current_page == 2)
root.fake_input("key_release", "Next")
-- Should disappear on anykey
root.fake_input("key_press", "Super_L")
elseif (count - test_context.hotkeys01_count_vim) == 3 then
assert(not visible_hotkeys_widget)
root.fake_input("key_release", "Super_L")
return true return true
end end
end
end, end,
} }