From ce3be7ca1b811b30f707791eedfe1199b1594e90 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 15 Jul 2017 23:15:29 -0400 Subject: [PATCH] object: Add support for signal forwarding The CAPI signal system already has this mechanism. --- lib/gears/object.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/gears/object.lua b/lib/gears/object.lua index 53935dda..4fe1d22b 100644 --- a/lib/gears/object.lua +++ b/lib/gears/object.lua @@ -56,6 +56,11 @@ function object:connect_signal(name, func) sig.strong[func] = true end +-- Register a global signal receiver. +function object:_connect_everything(callback) + table.insert(self._global_receivers, callback) +end + local function make_the_gc_obey(func) if _VERSION <= "Lua 5.1" then -- Lua 5.1 only has the behaviour we want if a userdata is used as the @@ -120,6 +125,9 @@ function object:emit_signal(name, ...) for func in pairs(sig.weak) do func(self, ...) end + for _, func in ipairs(self._global_receivers) do + func(name, self, ...) + end end local function get_miss(self, key) @@ -188,6 +196,8 @@ local function new(args) ret._signals = {} + ret._global_receivers = {} + local mt = {} -- Look for methods in another table