Add window pointer enter and leave signals

This commit is contained in:
Ottatop 2024-02-21 23:56:19 -06:00
parent 6b2b7066ac
commit d76777a633
6 changed files with 74 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -22,6 +22,15 @@ pub struct SignalState {
SignalData<WindowPointerLeaveResponse, VecDeque<WindowPointerLeaveResponse>>,
}
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<T, B: SignalBuffer<T>> {

View file

@ -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() {