mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-26 21:58:10 +01:00
Add window pointer enter and leave signals
This commit is contained in:
parent
6b2b7066ac
commit
d76777a633
6 changed files with 74 additions and 14 deletions
|
@ -164,6 +164,10 @@ function output.connect_for_all(callback)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local signal_name_to_SignalName = {
|
||||||
|
connect = "OutputConnect",
|
||||||
|
}
|
||||||
|
|
||||||
---@class OutputSignal
|
---@class OutputSignal
|
||||||
---@field connect fun(output: OutputHandle)?
|
---@field connect fun(output: OutputHandle)?
|
||||||
|
|
||||||
|
@ -174,12 +178,10 @@ function output.connect_signal(signals)
|
||||||
local handles = require("pinnacle.signal").handles.new({})
|
local handles = require("pinnacle.signal").handles.new({})
|
||||||
|
|
||||||
for signal, callback in pairs(signals) do
|
for signal, callback in pairs(signals) do
|
||||||
if signal == "connect" then
|
require("pinnacle.signal").add_callback(signal_name_to_SignalName[signal], callback)
|
||||||
require("pinnacle.signal").add_callback("OutputConnect", callback)
|
---@diagnostic disable-next-line: invisible
|
||||||
---@diagnostic disable-next-line: invisible
|
local handle = require("pinnacle.signal").handle.new(signal_name_to_SignalName[signal], callback)
|
||||||
local handle = require("pinnacle.signal").handle.new("OutputConnect", callback)
|
handles[signal] = handle
|
||||||
handles[signal] = handle
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return handles
|
return handles
|
||||||
|
|
|
@ -70,7 +70,7 @@ local signals = {
|
||||||
WindowPointerEnter = {
|
WindowPointerEnter = {
|
||||||
---@type H2Stream?
|
---@type H2Stream?
|
||||||
sender = nil,
|
sender = nil,
|
||||||
---@type (fun(output: OutputHandle))[]
|
---@type (fun(window: WindowHandle))[]
|
||||||
callbacks = {},
|
callbacks = {},
|
||||||
---@type fun(response: table)
|
---@type fun(response: table)
|
||||||
on_response = nil,
|
on_response = nil,
|
||||||
|
@ -78,7 +78,7 @@ local signals = {
|
||||||
WindowPointerLeave = {
|
WindowPointerLeave = {
|
||||||
---@type H2Stream?
|
---@type H2Stream?
|
||||||
sender = nil,
|
sender = nil,
|
||||||
---@type (fun(output: OutputHandle))[]
|
---@type (fun(window: WindowHandle))[]
|
||||||
callbacks = {},
|
callbacks = {},
|
||||||
---@type fun(response: table)
|
---@type fun(response: table)
|
||||||
on_response = nil,
|
on_response = nil,
|
||||||
|
@ -104,6 +104,24 @@ signals.Layout.on_response = function(response)
|
||||||
end
|
end
|
||||||
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
|
---@class SignalHandleModule
|
||||||
|
|
|
@ -319,6 +319,10 @@ function tag.new_layout_cycler(layouts)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local signal_name_to_SignalName = {
|
||||||
|
layout = "Layout",
|
||||||
|
}
|
||||||
|
|
||||||
---@class TagSignal
|
---@class TagSignal
|
||||||
---@field layout fun(tag: TagHandle, windows: WindowHandle[])?
|
---@field layout fun(tag: TagHandle, windows: WindowHandle[])?
|
||||||
|
|
||||||
|
@ -329,12 +333,10 @@ function tag.connect_signal(signals)
|
||||||
local handles = require("pinnacle.signal").handles.new({})
|
local handles = require("pinnacle.signal").handles.new({})
|
||||||
|
|
||||||
for signal, callback in pairs(signals) do
|
for signal, callback in pairs(signals) do
|
||||||
if signal == "layout" then
|
require("pinnacle.signal").add_callback(signal_name_to_SignalName[signal], callback)
|
||||||
require("pinnacle.signal").add_callback("Layout", callback)
|
---@diagnostic disable-next-line: invisible
|
||||||
---@diagnostic disable-next-line: invisible
|
local handle = require("pinnacle.signal").handle.new(signal_name_to_SignalName[signal], callback)
|
||||||
local handle = require("pinnacle.signal").handle.new("Layout", callback)
|
handles[signal] = handle
|
||||||
handles[signal] = handle
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return handles
|
return handles
|
||||||
|
|
|
@ -311,6 +311,33 @@ function window.add_window_rule(rule)
|
||||||
}))
|
}))
|
||||||
end
|
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.
|
---Send a close request to this window.
|
||||||
---
|
---
|
||||||
---### Example
|
---### Example
|
||||||
|
|
|
@ -22,6 +22,15 @@ pub struct SignalState {
|
||||||
SignalData<WindowPointerLeaveResponse, VecDeque<WindowPointerLeaveResponse>>,
|
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)]
|
#[derive(Debug, Default)]
|
||||||
#[allow(private_bounds)]
|
#[allow(private_bounds)]
|
||||||
pub struct SignalData<T, B: SignalBuffer<T>> {
|
pub struct SignalData<T, B: SignalBuffer<T>> {
|
||||||
|
|
|
@ -265,6 +265,8 @@ impl State {
|
||||||
|
|
||||||
self.config.clear(&self.loop_handle);
|
self.config.clear(&self.loop_handle);
|
||||||
|
|
||||||
|
self.signal_state.clear();
|
||||||
|
|
||||||
// Because the grpc server is implemented to only start once,
|
// Because the grpc server is implemented to only start once,
|
||||||
// any updates to `socket_dir` won't be applied until restart.
|
// any updates to `socket_dir` won't be applied until restart.
|
||||||
if self.grpc_server_join_handle.is_none() {
|
if self.grpc_server_join_handle.is_none() {
|
||||||
|
|
Loading…
Reference in a new issue