diff --git a/lib/gears/timer.lua b/lib/gears/timer.lua index c01b49f47..430025e46 100644 --- a/lib/gears/timer.lua +++ b/lib/gears/timer.lua @@ -226,12 +226,17 @@ function timer.weak_start_new(timeout, callback) end 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 protected_call(unpack(callback)) end delayed_calls = {} -end) +end --- Call the given function at the end of the current main loop iteration -- @tparam function callback The function that should be called @@ -242,6 +247,8 @@ function timer.delayed_call(callback, ...) table.insert(delayed_calls, { callback, ... }) end +capi.awesome.connect_signal("refresh", timer.run_delayed_calls_now) + function timer.mt.__call(_, ...) return timer.new(...) end diff --git a/tests/examples/awful/popup/position2.lua b/tests/examples/awful/popup/position2.lua index 57de2deb6..2069d13e6 100644 --- a/tests/examples/awful/popup/position2.lua +++ b/tests/examples/awful/popup/position2.lua @@ -32,7 +32,7 @@ local p = awful.popup { --DOC_HIDE placement = awful.placement.centered, --DOC_HIDE } --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 --DOC_HIDE Necessary as the widgets are drawn later diff --git a/tests/examples/awful/popup/wiboxtypes.lua b/tests/examples/awful/popup/wiboxtypes.lua index 8dcbdb5ab..1a47c6273 100644 --- a/tests/examples/awful/popup/wiboxtypes.lua +++ b/tests/examples/awful/popup/wiboxtypes.lua @@ -111,7 +111,7 @@ local p10 = awful.popup { shape = gears.shape.infobubble, } -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() p10:bind_to_widget(mytextclock) -- The titlebar diff --git a/tests/examples/awful/template.lua b/tests/examples/awful/template.lua index a6a824b38..17c56935d 100644 --- a/tests/examples/awful/template.lua +++ b/tests/examples/awful/template.lua @@ -13,7 +13,7 @@ local args = loadfile(file_path)() or {} -- Emulate the event loop for 5 iterations for _ = 1, 5 do - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() end -- Draw the result @@ -172,7 +172,7 @@ end -- Emulate the event loop for another 5 iterations for _ = 1, 5 do - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() end for _, d in ipairs(drawin.get()) do diff --git a/tests/examples/awful/tooltip/align.lua b/tests/examples/awful/tooltip/align.lua index da6b5e86a..924f5f828 100644 --- a/tests/examples/awful/tooltip/align.lua +++ b/tests/examples/awful/tooltip/align.lua @@ -13,7 +13,7 @@ local wibox = require("wibox") 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 local tt = awful.tooltip { @@ -27,4 +27,4 @@ end mouse.coords{x=125, y= 35} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/align2.lua b/tests/examples/awful/tooltip/align2.lua index a0540f529..0f48694c9 100644 --- a/tests/examples/awful/tooltip/align2.lua +++ b/tests/examples/awful/tooltip/align2.lua @@ -13,7 +13,7 @@ local wibox = require("wibox") 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 local tt = awful.tooltip { @@ -27,4 +27,4 @@ end mouse.coords{x=125, y= 35} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/border_color.lua b/tests/examples/awful/tooltip/border_color.lua index 452eec13f..9bfc99c3c 100644 --- a/tests/examples/awful/tooltip/border_color.lua +++ b/tests/examples/awful/tooltip/border_color.lua @@ -8,7 +8,7 @@ local beautiful = require("beautiful") -- mouse.coords{x=50, y= 10} -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() local x_offset = 0 @@ -20,13 +20,13 @@ for _, color in ipairs{ "#ff0000", "#00ff00", "#0000ff", "#00ffff" } do border_color = color, } tt.bg = beautiful.bg_normal - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt:show() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt.wibox.x = x_offset x_offset = x_offset + 640/5 end mouse.coords{x=125, y= 0} -- mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/border_width.lua b/tests/examples/awful/tooltip/border_width.lua index 633f27f8b..4032f4297 100644 --- a/tests/examples/awful/tooltip/border_width.lua +++ b/tests/examples/awful/tooltip/border_width.lua @@ -8,7 +8,7 @@ local beautiful = require("beautiful") -- mouse.coords{x=50, y= 10} -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() local x_offset = 0 @@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do border_color = beautiful.border_color, } tt.bg = beautiful.bg_normal - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt:show() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt.wibox.x = x_offset x_offset = x_offset + 640/5 end mouse.coords{x=125, y= 0} -- mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/margins.lua b/tests/examples/awful/tooltip/margins.lua index 65fd743a6..9c5332b13 100644 --- a/tests/examples/awful/tooltip/margins.lua +++ b/tests/examples/awful/tooltip/margins.lua @@ -8,7 +8,7 @@ local beautiful = require("beautiful") -- mouse.coords{x=50, y= 10} -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() local x_offset = 0 @@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do border_color = beautiful.border_color, } tt.bg = beautiful.bg_normal - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt:show() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt.wibox.x = x_offset x_offset = x_offset + 640/5 end mouse.coords{x=125, y= 0} -- mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/margins_leftright.lua b/tests/examples/awful/tooltip/margins_leftright.lua index 21ef3aeb9..1edae3308 100644 --- a/tests/examples/awful/tooltip/margins_leftright.lua +++ b/tests/examples/awful/tooltip/margins_leftright.lua @@ -8,7 +8,7 @@ local beautiful = require("beautiful") -- mouse.coords{x=50, y= 10} -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() local x_offset = 0 @@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do border_color = beautiful.border_color, } tt.bg = beautiful.bg_normal - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt:show() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt.wibox.x = x_offset x_offset = x_offset + 640/5 end mouse.coords{x=125, y= 0} -- mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/margins_topbottom.lua b/tests/examples/awful/tooltip/margins_topbottom.lua index c815c9550..971f1ead1 100644 --- a/tests/examples/awful/tooltip/margins_topbottom.lua +++ b/tests/examples/awful/tooltip/margins_topbottom.lua @@ -8,7 +8,7 @@ local beautiful = require("beautiful") -- mouse.coords{x=50, y= 10} -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() local x_offset = 0 @@ -20,13 +20,13 @@ for _, width in ipairs{ 1,2,4,6 } do border_color = beautiful.border_color, } tt.bg = beautiful.bg_normal - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt:show() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt.wibox.x = x_offset x_offset = x_offset + 640/5 end mouse.coords{x=125, y= 0} -- mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/mode.lua b/tests/examples/awful/tooltip/mode.lua index 9102e37ad..6a135dd2c 100644 --- a/tests/examples/awful/tooltip/mode.lua +++ b/tests/examples/awful/tooltip/mode.lua @@ -11,7 +11,7 @@ mouse.coords{x=50, y= 10} 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 { text = "A tooltip!", objects = {wb}, @@ -20,4 +20,4 @@ tt.bg = beautiful.bg_normal mouse.coords{x=75, y= 35} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/mode2.lua b/tests/examples/awful/tooltip/mode2.lua index ec1736a74..acc856b04 100644 --- a/tests/examples/awful/tooltip/mode2.lua +++ b/tests/examples/awful/tooltip/mode2.lua @@ -11,7 +11,7 @@ mouse.coords{x=50, y= 10} 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 { text = "A tooltip!", objects = {wb}, @@ -21,4 +21,4 @@ tt.bg = beautiful.bg_normal mouse.coords{x=75, y= 35} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/preferred_alignment.lua b/tests/examples/awful/tooltip/preferred_alignment.lua index dca897f21..3a49eea6c 100644 --- a/tests/examples/awful/tooltip/preferred_alignment.lua +++ b/tests/examples/awful/tooltip/preferred_alignment.lua @@ -11,7 +11,7 @@ local wibox = require("wibox") 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 local tt = awful.tooltip { @@ -26,4 +26,4 @@ end mouse.coords{x=125, y= 75} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/preferred_alignment2.lua b/tests/examples/awful/tooltip/preferred_alignment2.lua index 1040c00af..a64679ed8 100644 --- a/tests/examples/awful/tooltip/preferred_alignment2.lua +++ b/tests/examples/awful/tooltip/preferred_alignment2.lua @@ -11,7 +11,7 @@ local wibox = require("wibox") 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 local tt = awful.tooltip { @@ -26,4 +26,4 @@ end mouse.coords{x=125, y= 75} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/preferred_alignment3.lua b/tests/examples/awful/tooltip/preferred_alignment3.lua index 288e963e0..36402f8b6 100644 --- a/tests/examples/awful/tooltip/preferred_alignment3.lua +++ b/tests/examples/awful/tooltip/preferred_alignment3.lua @@ -11,7 +11,7 @@ local wibox = require("wibox") 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 local tt = awful.tooltip { @@ -26,4 +26,4 @@ end mouse.coords{x=125, y= 75} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/preferred_positions.lua b/tests/examples/awful/tooltip/preferred_positions.lua index 1000d387e..91f0157da 100644 --- a/tests/examples/awful/tooltip/preferred_positions.lua +++ b/tests/examples/awful/tooltip/preferred_positions.lua @@ -11,7 +11,7 @@ local wibox = require("wibox") 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 local tt = awful.tooltip { @@ -25,4 +25,4 @@ end mouse.coords{x=125, y= 75} mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/shape.lua b/tests/examples/awful/tooltip/shape.lua index b83a3893d..2924f9c5d 100644 --- a/tests/examples/awful/tooltip/shape.lua +++ b/tests/examples/awful/tooltip/shape.lua @@ -9,7 +9,7 @@ local gears = {shape = require("gears.shape")} -- mouse.coords{x=50, y= 10} -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() local x_offset = 0 @@ -22,13 +22,13 @@ for _, shape in ipairs{ "rounded_rect", "rounded_bar", "octogon", "infobubble"} border_color = beautiful.border_color, } tt.bg = beautiful.bg_normal - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt:show() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() tt.wibox.x = x_offset x_offset = x_offset + 640/5 end mouse.coords{x=125, y= 0} -- mouse.push_history() -awesome.emit_signal("refresh") +require("gears.timer").run_delayed_calls_now() diff --git a/tests/examples/awful/tooltip/textclock.lua b/tests/examples/awful/tooltip/textclock.lua index f2fae1041..de1e275fb 100644 --- a/tests/examples/awful/tooltip/textclock.lua +++ b/tests/examples/awful/tooltip/textclock.lua @@ -15,7 +15,7 @@ local wb = awful.wibar { position = "top" } --DOC_HIDE wb:setup { layout = wibox.layout.align.horizontal, --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 { objects = { mytextclock }, @@ -24,7 +24,7 @@ awesome.emit_signal("refresh") --DOC_HIDE the hierarchy is async 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.push_history() --DOC_HIDE diff --git a/tests/examples/awful/tooltip/textclock2.lua b/tests/examples/awful/tooltip/textclock2.lua index 2ee0be3db..0a297cddc 100644 --- a/tests/examples/awful/tooltip/textclock2.lua +++ b/tests/examples/awful/tooltip/textclock2.lua @@ -15,7 +15,7 @@ local wb = awful.wibar { position = "top" } --DOC_HIDE wb:setup { layout = wibox.layout.align.horizontal, --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 { } --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") 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.push_history() --DOC_HIDE diff --git a/tests/examples/text/awful/keygrabber/alttab.lua b/tests/examples/text/awful/keygrabber/alttab.lua index 8b983c643..b72c572e8 100644 --- a/tests/examples/text/awful/keygrabber/alttab.lua +++ b/tests/examples/text/awful/keygrabber/alttab.lua @@ -24,7 +24,7 @@ local awful = {keygrabber = require("awful.keygrabber"), --DOC_HIDE } --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", "Tab")--DOC_HIDE root.fake_input("key_release", "Tab")--DOC_HIDE diff --git a/tests/examples/text/awful/keygrabber/root_keybindings.lua b/tests/examples/text/awful/keygrabber/root_keybindings.lua index 84a9e2c5f..86a090b83 100644 --- a/tests/examples/text/awful/keygrabber/root_keybindings.lua +++ b/tests/examples/text/awful/keygrabber/root_keybindings.lua @@ -27,7 +27,7 @@ awful.keygrabber { --DOC_NEWLINE -- The following will **NOT** trigger the keygrabbing because it isn't exported -- 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") assert(#keybinding_works == 0) diff --git a/tests/examples/wibox/container/defaults/template.lua b/tests/examples/wibox/container/defaults/template.lua index 5f6fffdbf..e628a982f 100644 --- a/tests/examples/wibox/container/defaults/template.lua +++ b/tests/examples/wibox/container/defaults/template.lua @@ -64,7 +64,7 @@ local container = wibox.widget { -- Emulate the event loop for 10 iterations for _ = 1, 10 do - awesome:emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() end -- Get the example fallback size (the tests can return a size if the want) diff --git a/tests/examples/wibox/layout/template.lua b/tests/examples/wibox/layout/template.lua index 2a65b3fb0..61b8a00f5 100644 --- a/tests/examples/wibox/layout/template.lua +++ b/tests/examples/wibox/layout/template.lua @@ -99,7 +99,7 @@ local widget, w, h = loadfile(file_path)(generic_widget, generic_before_after) -- Emulate the event loop for 10 iterations for _ = 1, 10 do - awesome:emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() end -- Save to the output file diff --git a/tests/examples/wibox/template.lua b/tests/examples/wibox/template.lua index 656d22e51..8fd1925de 100644 --- a/tests/examples/wibox/template.lua +++ b/tests/examples/wibox/template.lua @@ -13,7 +13,7 @@ image_type = image_type or "svg" -- Emulate the event loop for 10 iterations for _ = 1, 10 do - awesome:emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() end -- Get the example fallback size (the tests can return a size if the want) diff --git a/tests/test-benchmark.lua b/tests/test-benchmark.lua index def3c01f3..61e4c4e54 100644 --- a/tests/test-benchmark.lua +++ b/tests/test-benchmark.lua @@ -41,7 +41,7 @@ do end local function do_pending_repaint() - awesome.emit_signal("refresh") + require("gears.timer").run_delayed_calls_now() end local function create_and_draw_wibox() diff --git a/tests/test-leaks.lua b/tests/test-leaks.lua index e7aa1d34f..fa185575b 100644 --- a/tests/test-leaks.lua +++ b/tests/test-leaks.lua @@ -7,8 +7,8 @@ local create_wibox = require("_wibox_helper").create_wibox local wibox = require("wibox") local prepare_for_collect = nil -local function emit_refresh() - awesome.emit_signal("refresh") +local function run_delayed_calls() + require("gears.timer").run_delayed_calls_now() end -- Make the layoutbox in the default config GC'able @@ -18,7 +18,7 @@ for s in screen do s.mywibox = nil s.mylayoutbox = nil end -emit_refresh() +run_delayed_calls() -- Test if some objects can be garbage collected 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)) -- Some widgets do things via timer.delayed_call -prepare_for_collect = emit_refresh +prepare_for_collect = run_delayed_calls collectable(tooltip_delayed()) -prepare_for_collect = emit_refresh +prepare_for_collect = run_delayed_calls 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}) -prepare_for_collect = emit_refresh +prepare_for_collect = run_delayed_calls 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()) runner.run_steps({ function() return true end })