mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-04 22:16:32 +01:00
feat(wm): subscribe to notifications
A program such as a status bar has to follow the window manager, and so far it could only ask: komorebi on Windows and on macOS sends notifications for that. The daemon now keeps subscribers, each a Unix socket in its data directory that a program listens on, and after each event and each message it handles, it connects to every subscriber and writes the event or the message with the state after it. A subscriber can ask to be sent only what changed the state; a window that is shown and a new subscription are always sent, so a subscriber has the state as soon as it subscribes. A subscriber that cannot be connected to is dropped with its socket file and not tried again, and a stopping daemon closes an empty connection to each one. komorebic gains subscribe-socket and unsubscribe-socket, and komorebi-client subscribe and subscribe_with_options, which bind the socket and subscribe. The tests subscribe through real sockets against the fake desktop: a shown window is sent with the state that has it, a subscriber that filters is not sent a question that changed nothing, and one that is gone is dropped.
This commit is contained in:
1 parent
6f657e53e3
commit
e2d757bbb0
20 files changed
+1078
-25
No files matched your search
@@ -5,6 +5,10 @@
|
||||
//! is written and the answer is printed. The messages are [`komorebi_client::SocketMessage`]s,
|
||||
//! sent with [`komorebi_client::send_message`] and [`komorebi_client::send_query`].
|
||||
//!
|
||||
//! `subscribe-socket` and `unsubscribe-socket` add and remove a subscriber: a program that listens
|
||||
//! on a socket in the daemon's data directory, to which the daemon sends a notification after each
|
||||
//! event and each message it handles.
|
||||
//!
|
||||
//! The others work without the daemon: `start` runs `komorebi` in the background, `log` follows
|
||||
//! its log, `data-directory` shows where its socket is, and `completions` prints a completion
|
||||
//! script for a shell. The hidden `docgen` writes the help of every subcommand as Markdown, wrapped
|
||||
@@ -47,6 +51,18 @@ gen_enum_subcommand_args! {
|
||||
Query: StateQuery,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct SubscribeSocket {
|
||||
/// Name of the socket to send event notifications to
|
||||
socket: String,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct UnsubscribeSocket {
|
||||
/// Name of the socket to stop sending event notifications to
|
||||
socket: String,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
struct Start {
|
||||
@@ -100,6 +116,20 @@ enum SubCommand {
|
||||
/// Query the current window manager state
|
||||
#[clap(arg_required_else_help = true)]
|
||||
Query(Query),
|
||||
/// Subscribe to komorebi events using a Unix Domain Socket
|
||||
#[clap(arg_required_else_help = true)]
|
||||
SubscribeSocket(SubscribeSocket),
|
||||
/// Unsubscribe from komorebi events
|
||||
#[clap(arg_required_else_help = true)]
|
||||
UnsubscribeSocket(UnsubscribeSocket),
|
||||
// /// Subscribe to komorebi events using a Named Pipe
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// #[clap(alias = "subscribe")]
|
||||
// SubscribePipe(SubscribePipe),
|
||||
// /// Unsubscribe from komorebi events
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// #[clap(alias = "unsubscribe")]
|
||||
// UnsubscribePipe(UnsubscribePipe),
|
||||
/// Tail komorebi's process logs (cancel with Ctrl-C)
|
||||
Log,
|
||||
/// Force the retiling of all managed windows
|
||||
@@ -233,6 +263,12 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::MonitorInformation => {
|
||||
print_query(&SocketMessage::MonitorInformation);
|
||||
}
|
||||
SubCommand::SubscribeSocket(args) => {
|
||||
send_message(&SocketMessage::AddSubscriberSocket(args.socket))?;
|
||||
}
|
||||
SubCommand::UnsubscribeSocket(args) => {
|
||||
send_message(&SocketMessage::RemoveSubscriberSocket(args.socket))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user