summaryrefslogtreecommitdiff
path: root/core/lua/astal
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-11 23:39:47 +0000
committerAylur <[email protected]>2024-09-11 23:39:47 +0000
commite04c00ac5c7cd964879380d9e9f9f6bf8e2dfa8e (patch)
tree392f0d111dfbb48bb1c504b1dcba06ef0fd2687c /core/lua/astal
parent56aa40a8765fc3d2da61cda3775e894d8dd0c7d9 (diff)
lua: fix hook
Diffstat (limited to 'core/lua/astal')
-rw-r--r--core/lua/astal/widget.lua18
1 files changed, 10 insertions, 8 deletions
diff --git a/core/lua/astal/widget.lua b/core/lua/astal/widget.lua
index 23b045f..2383dbb 100644
--- a/core/lua/astal/widget.lua
+++ b/core/lua/astal/widget.lua
@@ -115,18 +115,20 @@ end
local function astalify(ctor)
function ctor:hook(object, signalOrCallback, callback)
- if type(object.subscribe) == "function" then
+ if GObject.Object:is_type_of(object) and type(signalOrCallback) == "string" then
+ local id = object["on_" .. signalOrCallback]:connect(function(_, ...)
+ callback(self, ...)
+ end)
+ self.on_destroy = function()
+ GObject.signal_handler_disconnect(object, id)
+ end
+ elseif type(object.subscribe) == "function" then
local unsub = object.subscribe(function(...)
signalOrCallback(self, ...)
end)
self.on_destroy = unsub
- return
- end
- local id = object["on_" .. signalOrCallback](function(_, ...)
- callback(self, ...)
- end)
- self.on_destroy = function()
- GObject.signal_handler_disconnect(object, id)
+ else
+ error("can not hook: not gobject+signal or subscribable")
end
end