diff --git a/api/lua/pinnacle/output.lua b/api/lua/pinnacle/output.lua index 6e802b8..2e58cf6 100644 --- a/api/lua/pinnacle/output.lua +++ b/api/lua/pinnacle/output.lua @@ -164,6 +164,10 @@ function output.connect_for_all(callback) }) end +local signal_name_to_SignalName = { + connect = "OutputConnect", +} + ---@class OutputSignal ---@field connect fun(output: OutputHandle)? @@ -174,12 +178,10 @@ function output.connect_signal(signals) local handles = require("pinnacle.signal").handles.new({}) for signal, callback in pairs(signals) do - if signal == "connect" then - require("pinnacle.signal").add_callback("OutputConnect", callback) - ---@diagnostic disable-next-line: invisible - local handle = require("pinnacle.signal").handle.new("OutputConnect", callback) - handles[signal] = handle - end + require("pinnacle.signal").add_callback(signal_name_to_SignalName[signal], callback) + ---@diagnostic disable-next-line: invisible + local handle = require("pinnacle.signal").handle.new(signal_name_to_SignalName[signal], callback) + handles[signal] = handle end return handles diff --git a/api/lua/pinnacle/signal.lua b/api/lua/pinnacle/signal.lua index c876ae1..e0985cb 100644 --- a/api/lua/pinnacle/signal.lua +++ b/api/lua/pinnacle/signal.lua @@ -70,7 +70,7 @@ local signals = { WindowPointerEnter = { ---@type H2Stream? sender = nil, - ---@type (fun(output: OutputHandle))[] + ---@type (fun(window: WindowHandle))[] callbacks = {}, ---@type fun(response: table) on_response = nil, @@ -78,7 +78,7 @@ local signals = { WindowPointerLeave = { ---@type H2Stream? sender = nil, - ---@type (fun(output: OutputHandle))[] + ---@type (fun(window: WindowHandle))[] callbacks = {}, ---@type fun(response: table) on_response = nil, @@ -104,6 +104,24 @@ signals.Layout.on_response = function(response) end end +signals.WindowPointerEnter.on_response = function(response) + ---@diagnostic disable-next-line: invisible + local window_handle = require("pinnacle.window").handle.new(response.window_id) + + for _, callback in ipairs(signals.WindowPointerEnter.callbacks) do + callback(window_handle) + end +end + +signals.WindowPointerLeave.on_response = function(response) + ---@diagnostic disable-next-line: invisible + local window_handle = require("pinnacle.window").handle.new(response.window_id) + + for _, callback in ipairs(signals.WindowPointerLeave.callbacks) do + callback(window_handle) + end +end + ----------------------------------------------------------------------------- ---@class SignalHandleModule diff --git a/api/lua/pinnacle/tag.lua b/api/lua/pinnacle/tag.lua index 7e2fbd7..fb4efbd 100644 --- a/api/lua/pinnacle/tag.lua +++ b/api/lua/pinnacle/tag.lua @@ -319,6 +319,10 @@ function tag.new_layout_cycler(layouts) } end +local signal_name_to_SignalName = { + layout = "Layout", +} + ---@class TagSignal ---@field layout fun(tag: TagHandle, windows: WindowHandle[])? @@ -329,12 +333,10 @@ function tag.connect_signal(signals) local handles = require("pinnacle.signal").handles.new({}) for signal, callback in pairs(signals) do - if signal == "layout" then - require("pinnacle.signal").add_callback("Layout", callback) - ---@diagnostic disable-next-line: invisible - local handle = require("pinnacle.signal").handle.new("Layout", callback) - handles[signal] = handle - end + require("pinnacle.signal").add_callback(signal_name_to_SignalName[signal], callback) + ---@diagnostic disable-next-line: invisible + local handle = require("pinnacle.signal").handle.new(signal_name_to_SignalName[signal], callback) + handles[signal] = handle end return handles diff --git a/api/lua/pinnacle/window.lua b/api/lua/pinnacle/window.lua index 7a7668c..266cf78 100644 --- a/api/lua/pinnacle/window.lua +++ b/api/lua/pinnacle/window.lua @@ -311,6 +311,33 @@ function window.add_window_rule(rule) })) end +local signal_name_to_SignalName = { + pointer_enter = "WindowPointerEnter", + pointer_leave = "WindowPointerLeave", +} + +---@class WindowSignal +---@field pointer_enter fun(window: WindowHandle)? +---@field pointer_leave fun(window: WindowHandle)? + +---@param signals WindowSignal +---@return SignalHandles +function window.connect_signal(signals) + ---@diagnostic disable-next-line: invisible + local handles = require("pinnacle.signal").handles.new({}) + + for signal, callback in pairs(signals) do + require("pinnacle.signal").add_callback(signal_name_to_SignalName[signal], callback) + ---@diagnostic disable-next-line: invisible + local handle = require("pinnacle.signal").handle.new(signal_name_to_SignalName[signal], callback) + handles[signal] = handle + end + + return handles +end + +------------------------------------------------------------------------ + ---Send a close request to this window. --- ---### Example diff --git a/src/api/signal.rs b/src/api/signal.rs index 0bfeaaa..46beaf8 100644 --- a/src/api/signal.rs +++ b/src/api/signal.rs @@ -22,6 +22,15 @@ pub struct SignalState { SignalData>, } +impl SignalState { + pub fn clear(&mut self) { + self.output_connect.disconnect(); + self.layout.disconnect(); + self.window_pointer_enter.disconnect(); + self.window_pointer_leave.disconnect(); + } +} + #[derive(Debug, Default)] #[allow(private_bounds)] pub struct SignalData> { diff --git a/src/config.rs b/src/config.rs index 99a6a7d..e3b1ce3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -265,6 +265,8 @@ impl State { self.config.clear(&self.loop_handle); + self.signal_state.clear(); + // Because the grpc server is implemented to only start once, // any updates to `socket_dir` won't be applied until restart. if self.grpc_server_join_handle.is_none() {