Use gmath.round

This commit is contained in:
Anton Bulakh 2021-11-23 08:45:52 +02:00
parent e963d37cc4
commit 71d08ab6ec
No known key found for this signature in database
GPG Key ID: D666799AFFD8502A
1 changed files with 2 additions and 1 deletions

View File

@ -61,6 +61,7 @@ local glib = require("lgi").GLib
local object = require("gears.object") local object = require("gears.object")
local protected_call = require("gears.protected_call") local protected_call = require("gears.protected_call")
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
local gmath = require("gears.math")
--- Timer objects. This type of object is useful when triggering events repeatedly. --- Timer objects. This type of object is useful when triggering events repeatedly.
-- The timer will emit the "timeout" signal every N seconds, N being the timeout -- The timer will emit the "timeout" signal every N seconds, N being the timeout
@ -91,7 +92,7 @@ function timer:start()
gdebug.print_error(traceback("timer already started")) gdebug.print_error(traceback("timer already started"))
return return
end end
local timeout_ms = math.floor(self.data.timeout * 1000 + 0.5) local timeout_ms = gmath.round(self.data.timeout * 1000)
self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, timeout_ms, function() self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, timeout_ms, function()
protected_call(self.emit_signal, self, "timeout") protected_call(self.emit_signal, self, "timeout")
return true return true