timer: Replace `.data` by `._private`.
First step toward converting it into a normal `gears.object` to later use a base class.
This commit is contained in:
parent
3feeec3a1f
commit
e3976e0a19
|
@ -87,11 +87,11 @@ local timer = { mt = {} }
|
||||||
-- @method start
|
-- @method start
|
||||||
-- @emits start
|
-- @emits start
|
||||||
function timer:start()
|
function timer:start()
|
||||||
if self.data.source_id ~= nil then
|
if self._private.source_id ~= nil then
|
||||||
gdebug.print_error(traceback("timer already started"))
|
gdebug.print_error(traceback("timer already started"))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, self.data.timeout * 1000, function()
|
self._private.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, self._private.timeout * 1000, function()
|
||||||
protected_call(self.emit_signal, self, "timeout")
|
protected_call(self.emit_signal, self, "timeout")
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
@ -102,12 +102,12 @@ end
|
||||||
-- @method stop
|
-- @method stop
|
||||||
-- @emits stop
|
-- @emits stop
|
||||||
function timer:stop()
|
function timer:stop()
|
||||||
if self.data.source_id == nil then
|
if self._private.source_id == nil then
|
||||||
gdebug.print_error(traceback("timer not started"))
|
gdebug.print_error(traceback("timer not started"))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
glib.source_remove(self.data.source_id)
|
glib.source_remove(self._private.source_id)
|
||||||
self.data.source_id = nil
|
self._private.source_id = nil
|
||||||
self:emit_signal("stop")
|
self:emit_signal("stop")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ end
|
||||||
-- @emits start
|
-- @emits start
|
||||||
-- @emits stop
|
-- @emits stop
|
||||||
function timer:again()
|
function timer:again()
|
||||||
if self.data.source_id ~= nil then
|
if self._private.source_id ~= nil then
|
||||||
self:stop()
|
self:stop()
|
||||||
end
|
end
|
||||||
self:start()
|
self:start()
|
||||||
|
@ -137,9 +137,9 @@ end
|
||||||
local timer_instance_mt = {
|
local timer_instance_mt = {
|
||||||
__index = function(self, property)
|
__index = function(self, property)
|
||||||
if property == "timeout" then
|
if property == "timeout" then
|
||||||
return self.data.timeout
|
return self._private.timeout
|
||||||
elseif property == "started" then
|
elseif property == "started" then
|
||||||
return self.data.source_id ~= nil
|
return self._private.source_id ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return timer[property]
|
return timer[property]
|
||||||
|
@ -147,7 +147,7 @@ local timer_instance_mt = {
|
||||||
|
|
||||||
__newindex = function(self, property, value)
|
__newindex = function(self, property, value)
|
||||||
if property == "timeout" then
|
if property == "timeout" then
|
||||||
self.data.timeout = tonumber(value)
|
self._private.timeout = tonumber(value)
|
||||||
self:emit_signal("property::timeout", value)
|
self:emit_signal("property::timeout", value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -167,7 +167,27 @@ function timer.new(args)
|
||||||
args = args or {}
|
args = args or {}
|
||||||
local ret = object()
|
local ret = object()
|
||||||
|
|
||||||
ret.data = { timeout = 0 } --TODO v5 rename to ._private
|
rawset(ret, "_private", { timeout = 0 })
|
||||||
|
|
||||||
|
-- Preserve backward compatibility with Awesome 4.0-4.3 use of "data"
|
||||||
|
-- rather then "_private".
|
||||||
|
rawset(ret, "data", setmetatable({}, {
|
||||||
|
__index = function(_, key)
|
||||||
|
gdebug.deprecate(
|
||||||
|
"gears.timer.data is deprecated, use normal properties",
|
||||||
|
{deprecated_in=5}
|
||||||
|
)
|
||||||
|
return ret._private[key]
|
||||||
|
end,
|
||||||
|
__newindex = function(_, key, value)
|
||||||
|
gdebug.deprecate(
|
||||||
|
"gears.timer.data is deprecated, use normal properties",
|
||||||
|
{deprecated_in=5}
|
||||||
|
)
|
||||||
|
ret._private[key] = value
|
||||||
|
end
|
||||||
|
}))
|
||||||
|
|
||||||
setmetatable(ret, timer_instance_mt)
|
setmetatable(ret, timer_instance_mt)
|
||||||
|
|
||||||
for k, v in pairs(args) do
|
for k, v in pairs(args) do
|
||||||
|
|
Loading…
Reference in New Issue