diff options
| author | delta <darkussdelta@gmail.com> | 2025-07-04 00:38:29 +0200 |
|---|---|---|
| committer | delta <darkussdelta@gmail.com> | 2025-07-04 00:38:29 +0200 |
| commit | b3530d7c4a102935fa26498a160ee1dc6c1e9c03 (patch) | |
| tree | d7751206a694bc5de2d6b34b0c077cfcd1855798 /.config/awesome/quarrel/animation/subscribable | |
| parent | df75ec5ed5e3848c497f0439acb43ec9246ad3e7 (diff) | |
:3
Diffstat (limited to '.config/awesome/quarrel/animation/subscribable')
| -rw-r--r-- | .config/awesome/quarrel/animation/subscribable/init.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/.config/awesome/quarrel/animation/subscribable/init.lua b/.config/awesome/quarrel/animation/subscribable/init.lua new file mode 100644 index 0000000..9542704 --- /dev/null +++ b/.config/awesome/quarrel/animation/subscribable/init.lua @@ -0,0 +1,47 @@ +------------------------------------------- +-- @author https://github.com/Kasper24 +-- @copyright 2021-2025 Kasper24 +-- Adopted from rubato +------------------------------------------- +local gobject = require "gears.object" + +-- Kidna copying awesotre's stores on a surface level for added compatibility +local function subscribable(args) + local ret = gobject {} + local subscribed = {} + + -- Subscrubes a function to the object so that it's called when `fire` is + -- Calls subscribe_callback if it exists as well + function ret:subscribe(func) + local id = tostring(func):gsub("function: ", "") + subscribed[id] = func + + if self.subscribe_callback then + self.subscribe_callback(func) + end + end + + -- Unsubscribes a function and calls unsubscribe_callback if it exists + function ret:unsubscribe(func) + if not func then + subscribed = {} + else + local id = tostring(func):gsub("function: ", "") + subscribed[id] = nil + end + + if self.unsubscribe_callback then + self.unsubscribe_callback(func) + end + end + + function ret:fire(...) + for _, func in pairs(subscribed) do + func(...) + end + end + + return ret +end + +return subscribable |
