Add "enable_find" option (default: true)

This commit is contained in:
David Kosorin 2024-10-19 18:53:30 +02:00
parent 41c46af7f7
commit 626bd1818b
No known key found for this signature in database
2 changed files with 31 additions and 18 deletions

View File

@ -22,6 +22,7 @@ local hotkeys_popup = {
-- see `awful.hotkeys_popup.widget.show_help` for more information -- see `awful.hotkeys_popup.widget.show_help` for more information
-- @tparam[opt] client c The hostkeys for the client "c". -- @tparam[opt] client c The hostkeys for the client "c".
-- @tparam[opt] screen s The screen. -- @tparam[opt] screen s The screen.
-- @tparam[opt=true] boolean show_args.enable_find Enable find.
-- @tparam[opt=true] boolean show_args.show_awesome_keys Show AwesomeWM hotkeys. -- @tparam[opt=true] boolean show_args.show_awesome_keys Show AwesomeWM hotkeys.
-- When set to `false` only app-specific hotkeys will be shown. -- When set to `false` only app-specific hotkeys will be shown.
-- @staticfct awful.hotkeys_popup.show_help -- @staticfct awful.hotkeys_popup.show_help

View File

@ -682,7 +682,7 @@ function widget.new(args)
) )
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 = wibox_height - group_label_height - find_data.height local max_height_px = wibox_height - group_label_height - find_data.container_height
local joined_descriptions = "" local joined_descriptions = ""
for i, key in ipairs(keys) do for i, key in ipairs(keys) do
@ -818,21 +818,27 @@ function widget.new(args)
return pages return pages
end end
function widget_instance:_create_find_data() function widget_instance:_create_find_data(enable_find)
local margin = self.find_margin local data = {
local textbox = wibox.widget.textbox() enabled = enable_find,
local container = wibox.container.margin(textbox, margin, margin, margin, margin) textbox = wibox.widget.textbox(),
local height = beautiful.get_font_height(self.find_font) + 2 * margin
return {
textbox = textbox,
container = container,
height = height,
groups = {}, groups = {},
last_query = "", last_query = "",
} }
if enable_find then
local margin = self.find_margin
data.container = wibox.container.margin(data.textbox, margin, margin, margin, margin)
data.container_height = beautiful.get_font_height(self.find_font) + 2 * margin
else
data.container = wibox.widget.empty
data.container_height = 0
end end
function widget_instance:_create_wibox(s, available_groups, show_awesome_keys) return data
end
function widget_instance:_create_wibox(s, available_groups, show_awesome_keys, enable_find)
s = get_screen(s) s = get_screen(s)
local wa = s.workarea local wa = s.workarea
local wibox_height = (self.height < wa.height) and self.height or local wibox_height = (self.height < wa.height) and self.height or
@ -840,7 +846,7 @@ function widget.new(args)
local wibox_width = (self.width < wa.width) and self.width or local wibox_width = (self.width < wa.width) and self.width or
(wa.width - self.border_width * 2) (wa.width - self.border_width * 2)
local find_data = self:_create_find_data() local find_data = self:_create_find_data(enable_find)
local pages = self:_create_pages(s, available_groups, show_awesome_keys, wibox_width, wibox_height, find_data) local pages = self:_create_pages(s, available_groups, show_awesome_keys, wibox_width, wibox_height, find_data)
@ -920,10 +926,10 @@ function widget.new(args)
keypressed_callback = function(_, key) keypressed_callback = function(_, key)
if key == "Prior" then if key == "Prior" then
w_self:page_prev() w_self:page_prev()
return true
elseif key == "Next" then elseif key == "Next" then
w_self:page_next() w_self:page_next()
return true elseif not w_self.find_data.enabled then
w_self:hide()
end end
end, end,
} }
@ -934,6 +940,10 @@ function widget.new(args)
w_self.popup.visible = false w_self.popup.visible = false
end end
function widget_obj.find(w_self, input) function widget_obj.find(w_self, input)
if not w_self.find_data.enabled then
return
end
local keywords = {} local keywords = {}
for keyword in string.gmatch(input or "", "([^%s]+)") do for keyword in string.gmatch(input or "", "([^%s]+)") do
keyword = string.lower(keyword) keyword = string.lower(keyword)
@ -972,6 +982,7 @@ function widget.new(args)
-- @method show_help -- @method show_help
function widget_instance:show_help(c, s, show_args) function widget_instance:show_help(c, s, show_args)
show_args = show_args or {} show_args = show_args or {}
local enable_find = show_args.enable_find ~= false
local show_awesome_keys = show_args.show_awesome_keys ~= false local show_awesome_keys = show_args.show_awesome_keys ~= false
self:_import_awful_keys() self:_import_awful_keys()
@ -1001,14 +1012,14 @@ function widget.new(args)
if not need_match then table.insert(available_groups, group) end if not need_match then table.insert(available_groups, group) end
end end
local joined_groups = join_plus_sort(available_groups)..tostring(show_awesome_keys) local cache_key = join_plus_sort(available_groups)..tostring(show_awesome_keys)..tostring(enable_find)
if not self._cached_wiboxes[s] then if not self._cached_wiboxes[s] then
self._cached_wiboxes[s] = {} self._cached_wiboxes[s] = {}
end end
if not self._cached_wiboxes[s][joined_groups] then if not self._cached_wiboxes[s][cache_key] then
self._cached_wiboxes[s][joined_groups] = self:_create_wibox(s, available_groups, show_awesome_keys) self._cached_wiboxes[s][cache_key] = self:_create_wibox(s, available_groups, show_awesome_keys, enable_find)
end end
local help_wibox = self._cached_wiboxes[s][joined_groups] local help_wibox = self._cached_wiboxes[s][cache_key]
help_wibox:show() help_wibox:show()
end end
@ -1059,6 +1070,7 @@ end
-- @tparam[opt] client c Client. -- @tparam[opt] client c Client.
-- @tparam[opt] screen s Screen. -- @tparam[opt] screen s Screen.
-- @tparam[opt] table args Additional arguments. -- @tparam[opt] table args Additional arguments.
-- @tparam[opt=true] boolean args.enable_find Enable find.
-- @tparam[opt=true] boolean args.show_awesome_keys Show AwesomeWM hotkeys. -- @tparam[opt=true] boolean args.show_awesome_keys Show AwesomeWM hotkeys.
-- When set to `false` only app-specific hotkeys will be shown. -- When set to `false` only app-specific hotkeys will be shown.
-- @noreturn -- @noreturn