mirror of
https://github.com/elenapan/dotfiles.git
synced 2026-01-28 19:27:13 +08:00
helpers: Add debounce function
This can be used to solve widget signals being emitted more than once (e.g. widget::layout_changed signal being emitted twice when the widget children are updated).
This commit is contained in:
parent
13a1229a97
commit
c4b58db757
1 changed files with 14 additions and 0 deletions
|
|
@ -461,4 +461,18 @@ function helpers.this_dir()
|
|||
return str:match("(.*/)")
|
||||
end
|
||||
|
||||
function helpers.debounce(func, timeout)
|
||||
local timer = nil
|
||||
return function(...)
|
||||
local args = { ... }
|
||||
if timer then
|
||||
timer:stop()
|
||||
end
|
||||
timer = gears.timer.start_new(timeout, function()
|
||||
func(unpack(args))
|
||||
return false -- Stop the timer
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return helpers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue