Merge pull request #2658 from psychon/delayed_call_run_now

Add and use gears.timer.run_delayed_calls_now()
This commit is contained in:
mergify[bot] 2019-02-17 19:25:04 +00:00 committed by GitHub
commit fd38e2fb5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 71 additions and 64 deletions

View File

@ -227,12 +227,17 @@ function timer.weak_start_new(timeout, callback)
end end
local delayed_calls = {} local delayed_calls = {}
capi.awesome.connect_signal("refresh", function()
--- Run all pending delayed calls now. This function should best not be used at
-- all, because it means that less batching happens and the delayed calls run
-- prematurely.
-- @function gears.timer.run_delayed_calls_now
function timer.run_delayed_calls_now()
for _, callback in ipairs(delayed_calls) do for _, callback in ipairs(delayed_calls) do
protected_call(unpack(callback)) protected_call(unpack(callback))
end end
delayed_calls = {} delayed_calls = {}
end) end
--- Call the given function at the end of the current main loop iteration --- Call the given function at the end of the current main loop iteration
-- @tparam function callback The function that should be called -- @tparam function callback The function that should be called
@ -243,6 +248,8 @@ function timer.delayed_call(callback, ...)
table.insert(delayed_calls, { callback, ... }) table.insert(delayed_calls, { callback, ... })
end end
capi.awesome.connect_signal("refresh", timer.run_delayed_calls_now)
function timer.mt.__call(_, ...) function timer.mt.__call(_, ...)
return timer.new(...) return timer.new(...)
end end

View File

@ -32,7 +32,7 @@ local p = awful.popup { --DOC_HIDE
placement = awful.placement.centered, --DOC_HIDE placement = awful.placement.centered, --DOC_HIDE
} --DOC_HIDE } --DOC_HIDE
p:_apply_size_now() --DOC_HIDE p:_apply_size_now() --DOC_HIDE
awesome.emit_signal("refresh") --DOC_HIDE require("gears.timer").run_delayed_calls_now() --DOC_HIDE
p._drawable._do_redraw() --DOC_HIDE p._drawable._do_redraw() --DOC_HIDE
--DOC_HIDE Necessary as the widgets are drawn later --DOC_HIDE Necessary as the widgets are drawn later

View File

@ -111,7 +111,7 @@ local p10 = awful.popup {
shape = gears.shape.infobubble, shape = gears.shape.infobubble,
} }
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
p10:bind_to_widget(mytextclock) p10:bind_to_widget(mytextclock)
-- The titlebar -- The titlebar

View File

@ -13,7 +13,7 @@ local args = loadfile(file_path)() or {}
-- Emulate the event loop for 5 iterations -- Emulate the event loop for 5 iterations
for _ = 1, 5 do for _ = 1, 5 do
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
-- Draw the result -- Draw the result
@ -172,7 +172,7 @@ end
-- Emulate the event loop for another 5 iterations -- Emulate the event loop for another 5 iterations
for _ = 1, 5 do for _ = 1, 5 do
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
for _, d in ipairs(drawin.get()) do for _, d in ipairs(drawin.get()) do

View File

@ -13,7 +13,7 @@ local wibox = require("wibox")
width = 100, height = 44, x = 100, y = 10, visible = true, bg = "#00000000" width = 100, height = 44, x = 100, y = 10, visible = true, bg = "#00000000"
} }
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
for _, side in ipairs{ "top_left", "bottom_left", "top_right", "bottom_right"} do for _, side in ipairs{ "top_left", "bottom_left", "top_right", "bottom_right"} do
local tt = awful.tooltip { local tt = awful.tooltip {
@ -27,4 +27,4 @@ end
mouse.coords{x=125, y= 35} mouse.coords{x=125, y= 35}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -13,7 +13,7 @@ local wibox = require("wibox")
width = 100, height = 44, x = 100, y = 10, visible = true, bg = "#00000000" width = 100, height = 44, x = 100, y = 10, visible = true, bg = "#00000000"
} }
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
for _, side in ipairs{ "left", "right", "bottom", "top" } do for _, side in ipairs{ "left", "right", "bottom", "top" } do
local tt = awful.tooltip { local tt = awful.tooltip {
@ -27,4 +27,4 @@ end
mouse.coords{x=125, y= 35} mouse.coords{x=125, y= 35}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -8,7 +8,7 @@ local beautiful = require("beautiful")
-- mouse.coords{x=50, y= 10} -- mouse.coords{x=50, y= 10}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local x_offset = 0 local x_offset = 0
@ -20,13 +20,13 @@ for _, color in ipairs{ "#ff0000", "#00ff00", "#0000ff", "#00ffff" } do
border_color = color, border_color = color,
} }
tt.bg = beautiful.bg_normal tt.bg = beautiful.bg_normal
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt:show() tt:show()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt.wibox.x = x_offset tt.wibox.x = x_offset
x_offset = x_offset + 640/5 x_offset = x_offset + 640/5
end end
mouse.coords{x=125, y= 0} mouse.coords{x=125, y= 0}
-- mouse.push_history() -- mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -8,7 +8,7 @@ local beautiful = require("beautiful")
-- mouse.coords{x=50, y= 10} -- mouse.coords{x=50, y= 10}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local x_offset = 0 local x_offset = 0
@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do
border_color = beautiful.border_color, border_color = beautiful.border_color,
} }
tt.bg = beautiful.bg_normal tt.bg = beautiful.bg_normal
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt:show() tt:show()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt.wibox.x = x_offset tt.wibox.x = x_offset
x_offset = x_offset + 640/5 x_offset = x_offset + 640/5
end end
mouse.coords{x=125, y= 0} mouse.coords{x=125, y= 0}
-- mouse.push_history() -- mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -8,7 +8,7 @@ local beautiful = require("beautiful")
-- mouse.coords{x=50, y= 10} -- mouse.coords{x=50, y= 10}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local x_offset = 0 local x_offset = 0
@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do
border_color = beautiful.border_color, border_color = beautiful.border_color,
} }
tt.bg = beautiful.bg_normal tt.bg = beautiful.bg_normal
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt:show() tt:show()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt.wibox.x = x_offset tt.wibox.x = x_offset
x_offset = x_offset + 640/5 x_offset = x_offset + 640/5
end end
mouse.coords{x=125, y= 0} mouse.coords{x=125, y= 0}
-- mouse.push_history() -- mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -8,7 +8,7 @@ local beautiful = require("beautiful")
-- mouse.coords{x=50, y= 10} -- mouse.coords{x=50, y= 10}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local x_offset = 0 local x_offset = 0
@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do
border_color = beautiful.border_color, border_color = beautiful.border_color,
} }
tt.bg = beautiful.bg_normal tt.bg = beautiful.bg_normal
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt:show() tt:show()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt.wibox.x = x_offset tt.wibox.x = x_offset
x_offset = x_offset + 640/5 x_offset = x_offset + 640/5
end end
mouse.coords{x=125, y= 0} mouse.coords{x=125, y= 0}
-- mouse.push_history() -- mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -8,7 +8,7 @@ local beautiful = require("beautiful")
-- mouse.coords{x=50, y= 10} -- mouse.coords{x=50, y= 10}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local x_offset = 0 local x_offset = 0
@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do
border_color = beautiful.border_color, border_color = beautiful.border_color,
} }
tt.bg = beautiful.bg_normal tt.bg = beautiful.bg_normal
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt:show() tt:show()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt.wibox.x = x_offset tt.wibox.x = x_offset
x_offset = x_offset + 640/5 x_offset = x_offset + 640/5
end end
mouse.coords{x=125, y= 0} mouse.coords{x=125, y= 0}
-- mouse.push_history() -- mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -11,7 +11,7 @@ mouse.coords{x=50, y= 10}
local wb = wibox {width = 100, height = 44, x = 50, y = 25, visible = true} local wb = wibox {width = 100, height = 44, x = 50, y = 25, visible = true}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local tt = awful.tooltip { local tt = awful.tooltip {
text = "A tooltip!", text = "A tooltip!",
objects = {wb}, objects = {wb},
@ -20,4 +20,4 @@ tt.bg = beautiful.bg_normal
mouse.coords{x=75, y= 35} mouse.coords{x=75, y= 35}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -11,7 +11,7 @@ mouse.coords{x=50, y= 10}
local wb = wibox {width = 100, height = 44, x = 50, y = 25, visible = true} local wb = wibox {width = 100, height = 44, x = 50, y = 25, visible = true}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local tt = awful.tooltip { local tt = awful.tooltip {
text = "A tooltip!", text = "A tooltip!",
objects = {wb}, objects = {wb},
@ -21,4 +21,4 @@ tt.bg = beautiful.bg_normal
mouse.coords{x=75, y= 35} mouse.coords{x=75, y= 35}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -11,7 +11,7 @@ local wibox = require("wibox")
local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true} local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
for _, side in ipairs{ "left", "right", "bottom", "top" } do for _, side in ipairs{ "left", "right", "bottom", "top" } do
local tt = awful.tooltip { local tt = awful.tooltip {
@ -26,4 +26,4 @@ end
mouse.coords{x=125, y= 75} mouse.coords{x=125, y= 75}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -11,7 +11,7 @@ local wibox = require("wibox")
local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true} local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
for _, side in ipairs{ "left", "right", "bottom", "top" } do for _, side in ipairs{ "left", "right", "bottom", "top" } do
local tt = awful.tooltip { local tt = awful.tooltip {
@ -26,4 +26,4 @@ end
mouse.coords{x=125, y= 75} mouse.coords{x=125, y= 75}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -11,7 +11,7 @@ local wibox = require("wibox")
local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true} local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
for _, side in ipairs{ "left", "right", "bottom", "top" } do for _, side in ipairs{ "left", "right", "bottom", "top" } do
local tt = awful.tooltip { local tt = awful.tooltip {
@ -26,4 +26,4 @@ end
mouse.coords{x=125, y= 75} mouse.coords{x=125, y= 75}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -11,7 +11,7 @@ local wibox = require("wibox")
local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true} local wb = wibox {width = 100, height = 44, x = 100, y = 50, visible = true}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
for _, side in ipairs{ "left", "right", "bottom", "top" } do for _, side in ipairs{ "left", "right", "bottom", "top" } do
local tt = awful.tooltip { local tt = awful.tooltip {
@ -25,4 +25,4 @@ end
mouse.coords{x=125, y= 75} mouse.coords{x=125, y= 75}
mouse.push_history() mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -9,7 +9,7 @@ local gears = {shape = require("gears.shape")}
-- mouse.coords{x=50, y= 10} -- mouse.coords{x=50, y= 10}
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
local x_offset = 0 local x_offset = 0
@ -22,13 +22,13 @@ for _, shape in ipairs{ "rounded_rect", "rounded_bar", "octogon", "infobubble"}
border_color = beautiful.border_color, border_color = beautiful.border_color,
} }
tt.bg = beautiful.bg_normal tt.bg = beautiful.bg_normal
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt:show() tt:show()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
tt.wibox.x = x_offset tt.wibox.x = x_offset
x_offset = x_offset + 640/5 x_offset = x_offset + 640/5
end end
mouse.coords{x=125, y= 0} mouse.coords{x=125, y= 0}
-- mouse.push_history() -- mouse.push_history()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()

View File

@ -15,7 +15,7 @@ local wb = awful.wibar { position = "top" } --DOC_HIDE
wb:setup { layout = wibox.layout.align.horizontal, --DOC_HIDE wb:setup { layout = wibox.layout.align.horizontal, --DOC_HIDE
nil, nil, mytextclock} --DOC_HIDE nil, nil, mytextclock} --DOC_HIDE
awesome.emit_signal("refresh") --DOC_HIDE the hierarchy is async require("gears.timer").run_delayed_calls_now() --DOC_HIDE the hierarchy is async
local myclock_t = awful.tooltip { local myclock_t = awful.tooltip {
objects = { mytextclock }, objects = { mytextclock },
@ -24,7 +24,7 @@ awesome.emit_signal("refresh") --DOC_HIDE the hierarchy is async
end, end,
} }
awesome.emit_signal("refresh") --DOC_HIDE require("gears.timer").run_delayed_calls_now() --DOC_HIDE
mouse.coords{x=250, y= 10} --DOC_HIDE mouse.coords{x=250, y= 10} --DOC_HIDE
mouse.push_history() --DOC_HIDE mouse.push_history() --DOC_HIDE

View File

@ -15,7 +15,7 @@ local wb = awful.wibar { position = "top" } --DOC_HIDE
wb:setup { layout = wibox.layout.align.horizontal, --DOC_HIDE wb:setup { layout = wibox.layout.align.horizontal, --DOC_HIDE
nil, nil, mytextclock} --DOC_HIDE nil, nil, mytextclock} --DOC_HIDE
awesome.emit_signal("refresh") --DOC_HIDE the hierarchy is async require("gears.timer").run_delayed_calls_now() --DOC_HIDE the hierarchy is async
local myclock_t = awful.tooltip { } local myclock_t = awful.tooltip { }
--DOC_NEWLINE --DOC_NEWLINE
@ -25,7 +25,7 @@ awesome.emit_signal("refresh") --DOC_HIDE the hierarchy is async
myclock_t.text = os.date("Today is %A %B %d %Y\nThe time is %T") myclock_t.text = os.date("Today is %A %B %d %Y\nThe time is %T")
end) end)
awesome.emit_signal("refresh") --DOC_HIDE require("gears.timer").run_delayed_calls_now() --DOC_HIDE
mouse.coords{x=250, y= 10} --DOC_HIDE mouse.coords{x=250, y= 10} --DOC_HIDE
mouse.push_history() --DOC_HIDE mouse.push_history() --DOC_HIDE

View File

@ -24,7 +24,7 @@ local awful = {keygrabber = require("awful.keygrabber"), --DOC_HIDE
} }
--DOC_HIDE Trigger the keybinging --DOC_HIDE Trigger the keybinging
awesome.emit_signal("refresh") --DOC_HIDE `export_keybindings` is async require("gears.timer").run_delayed_calls_now() --DOC_HIDE `export_keybindings` is async
root.fake_input("key_press", "Alt_L")--DOC_HIDE root.fake_input("key_press", "Alt_L")--DOC_HIDE
root.fake_input("key_press", "Tab")--DOC_HIDE root.fake_input("key_press", "Tab")--DOC_HIDE
root.fake_input("key_release", "Tab")--DOC_HIDE root.fake_input("key_release", "Tab")--DOC_HIDE

View File

@ -27,7 +27,7 @@ awful.keygrabber {
--DOC_NEWLINE --DOC_NEWLINE
-- The following will **NOT** trigger the keygrabbing because it isn't exported -- The following will **NOT** trigger the keygrabbing because it isn't exported
-- to the root (global) keys. Adding `export_keybindings` would solve that -- to the root (global) keys. Adding `export_keybindings` would solve that
awesome.emit_signal("refresh") --DOC_HIDE `root_keybindings` is async require("gears.timer").run_delayed_calls_now() --DOC_HIDE `root_keybindings` is async
root._execute_keybinding({"Mod4", "Shift"}, "i") root._execute_keybinding({"Mod4", "Shift"}, "i")
assert(#keybinding_works == 0) assert(#keybinding_works == 0)

View File

@ -64,7 +64,7 @@ local container = wibox.widget {
-- Emulate the event loop for 10 iterations -- Emulate the event loop for 10 iterations
for _ = 1, 10 do for _ = 1, 10 do
awesome:emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
-- Get the example fallback size (the tests can return a size if the want) -- Get the example fallback size (the tests can return a size if the want)

View File

@ -99,7 +99,7 @@ local widget, w, h = loadfile(file_path)(generic_widget, generic_before_after)
-- Emulate the event loop for 10 iterations -- Emulate the event loop for 10 iterations
for _ = 1, 10 do for _ = 1, 10 do
awesome:emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
-- Save to the output file -- Save to the output file

View File

@ -13,7 +13,7 @@ image_type = image_type or "svg"
-- Emulate the event loop for 10 iterations -- Emulate the event loop for 10 iterations
for _ = 1, 10 do for _ = 1, 10 do
awesome:emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
-- Get the example fallback size (the tests can return a size if the want) -- Get the example fallback size (the tests can return a size if the want)

View File

@ -41,7 +41,7 @@ do
end end
local function do_pending_repaint() local function do_pending_repaint()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
local function create_and_draw_wibox() local function create_and_draw_wibox()

View File

@ -7,8 +7,8 @@ local create_wibox = require("_wibox_helper").create_wibox
local wibox = require("wibox") local wibox = require("wibox")
local prepare_for_collect = nil local prepare_for_collect = nil
local function emit_refresh() local function run_delayed_calls()
awesome.emit_signal("refresh") require("gears.timer").run_delayed_calls_now()
end end
-- Make the layoutbox in the default config GC'able -- Make the layoutbox in the default config GC'able
@ -18,7 +18,7 @@ for s in screen do
s.mywibox = nil s.mywibox = nil
s.mylayoutbox = nil s.mylayoutbox = nil
end end
emit_refresh() run_delayed_calls()
-- Test if some objects can be garbage collected -- Test if some objects can be garbage collected
local function collectable(a, b, c, d, e, f, g, h, last) local function collectable(a, b, c, d, e, f, g, h, last)
@ -66,19 +66,19 @@ collectable(wibox.widget.textclock())
collectable(awful.widget.layoutbox(1)) collectable(awful.widget.layoutbox(1))
-- Some widgets do things via timer.delayed_call -- Some widgets do things via timer.delayed_call
prepare_for_collect = emit_refresh prepare_for_collect = run_delayed_calls
collectable(tooltip_delayed()) collectable(tooltip_delayed())
prepare_for_collect = emit_refresh prepare_for_collect = run_delayed_calls
collectable(tooltip_now()) collectable(tooltip_now())
prepare_for_collect = emit_refresh prepare_for_collect = run_delayed_calls
collectable(awful.widget.taglist{screen=1, filter=awful.widget.taglist.filter.all}) collectable(awful.widget.taglist{screen=1, filter=awful.widget.taglist.filter.all})
prepare_for_collect = emit_refresh prepare_for_collect = run_delayed_calls
collectable(awful.widget.tasklist{screen=1, filter=awful.widget.tasklist.filter.currenttags}) collectable(awful.widget.tasklist{screen=1, filter=awful.widget.tasklist.filter.currenttags})
prepare_for_collect = emit_refresh prepare_for_collect = run_delayed_calls
collectable(create_wibox()) collectable(create_wibox())
runner.run_steps({ function() return true end }) runner.run_steps({ function() return true end })