fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 1 | //! The control protocol. Newline-delimited JSON over a unix socket, one |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 2 | //! message per line, each carrying the protocol version `v`. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 3 | //! |
3b180fd69834 | atagen | 2026-10-17 10:40 UTC | 4 | //! Commands also have a word form, `focus left` or `spawn beer`, shared by |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 5 | //! the CLI and keybindings in the config. |
57f44a63d99f | atagen | 2026-10-16 05:34 UTC | 6 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 7 | use serde::{Deserialize, Serialize}; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 8 | use std::fmt; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 9 | use std::path::PathBuf; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 10 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 11 | pub const VERSION: u32 = 1; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 12 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 13 | /// Where the compositor serving `display` listens. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 14 | pub fn socket_path_for(display: &str) -> Option<PathBuf> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 15 | let dir = std::env::var_os("XDG_RUNTIME_DIR")?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 16 | Some(PathBuf::from(dir).join(format!("monolith-{display}.sock"))) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 17 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 18 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 19 | /// Where a client should connect. `$MONOLITH_SOCKET`, else the socket of |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 20 | /// the compositor serving `$WAYLAND_DISPLAY`. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 21 | pub fn socket_path() -> Option<PathBuf> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 22 | if let Some(p) = std::env::var_os("MONOLITH_SOCKET") { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 23 | return Some(p.into()); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 24 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 25 | socket_path_for(&std::env::var("WAYLAND_DISPLAY").ok()?) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 26 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 27 | |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 28 | pub use monolith_layout::{Axis, Dir}; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 29 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 30 | #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 31 | #[serde(rename_all = "kebab-case")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 32 | pub enum ExpandScope { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 33 | #[default] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 34 | Window, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 35 | Container, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 36 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 37 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 38 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 39 | #[serde(tag = "command", rename_all = "kebab-case", deny_unknown_fields)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 40 | pub enum Command { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 41 | Spawn { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 42 | argv: Vec<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 43 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 44 | Close, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 45 | Quit, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 46 | Reload, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 47 | Focus { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 48 | dir: Dir, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 49 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 50 | Move { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 51 | dir: Dir, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 52 | }, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 53 | MoveContainer { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 54 | dir: Dir, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 55 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 56 | Resize { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 57 | axis: Axis, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 58 | delta: f64, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 59 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 60 | Expand { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 61 | scope: ExpandScope, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 62 | }, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 63 | /// Expands every container above the focused window towards it. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 64 | Maximize, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 65 | /// Makes the next window move do the opposite of the configured default, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 66 | /// swap or merge. Again before moving cancels it. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 67 | InvertMove, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 68 | Flip, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 69 | Float, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 70 | Fullscreen, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 71 | Sticky, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 72 | View { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 73 | tag: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 74 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 75 | ToggleView { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 76 | tag: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 77 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 78 | ViewEverywhere { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 79 | tag: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 80 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 81 | /// Sends the focused window to a tag. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 82 | Tag { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 83 | tag: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 84 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 85 | ReorderTag { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 86 | tag: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 87 | index: usize, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 88 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 89 | FocusOutput { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 90 | dir: Dir, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 91 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 92 | SendToOutput { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 93 | dir: Dir, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 94 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 95 | /// Adds the focused window to a scratchpad. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 96 | Scratchpad { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 97 | name: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 98 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 99 | Summon { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 100 | name: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 101 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 102 | Dismiss { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 103 | name: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 104 | }, |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 105 | /// Switches outputs on or off, all of them without a name. |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 106 | Power { |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 107 | on: bool, |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 108 | #[serde(default)] |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 109 | output: Option<String>, |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 110 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 111 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 112 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 113 | #[derive(Debug, Clone, PartialEq, Eq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 114 | pub struct ParseError(pub String); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 115 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 116 | impl fmt::Display for ParseError { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 117 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 118 | f.write_str(&self.0) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 119 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 120 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 121 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 122 | impl std::error::Error for ParseError {} |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 123 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 124 | impl Command { |
41569aa8395f | atagen | 2026-10-19 07:35 UTC | 125 | /// Whether a bind running this still fires on a locked session, which |
41569aa8395f | atagen | 2026-10-19 07:35 UTC | 126 | /// leaves out everything that moves focus, windows or tags, and quitting. |
41569aa8395f | atagen | 2026-10-19 07:35 UTC | 127 | pub fn allowed_while_locked(&self) -> bool { |
41569aa8395f | atagen | 2026-10-19 07:35 UTC | 128 | matches!(self, Command::Spawn { .. } | Command::Reload) |
41569aa8395f | atagen | 2026-10-19 07:35 UTC | 129 | } |
41569aa8395f | atagen | 2026-10-19 07:35 UTC | 130 | |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 131 | /// Parses the word form, as in `["move-container", "left"]`. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 132 | pub fn parse<S: AsRef<str>>(words: &[S]) -> Result<Self, ParseError> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 133 | let words: Vec<&str> = words.iter().map(AsRef::as_ref).collect(); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 134 | let Some((&name, args)) = words.split_first() else { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 135 | return Err(ParseError("empty command".into())); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 136 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 137 | let err = |m: &str| ParseError(format!("{name}: {m}")); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 138 | let one = || match args { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 139 | [a] => Ok(a.to_string()), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 140 | _ => Err(err("takes exactly one argument")), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 141 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 142 | let none = |c: Command| { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 143 | if args.is_empty() { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 144 | Ok(c) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 145 | } else { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 146 | Err(err("takes no arguments")) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 147 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 148 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 149 | let dir = || -> Result<Dir, ParseError> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 150 | match one()?.as_str() { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 151 | "left" | "h" => Ok(Dir::Left), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 152 | "right" | "l" => Ok(Dir::Right), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 153 | "up" | "k" => Ok(Dir::Up), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 154 | "down" | "j" => Ok(Dir::Down), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 155 | d => Err(err(&format!("unknown direction {d}"))), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 156 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 157 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 158 | Ok(match name { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 159 | "spawn" if !args.is_empty() => Command::Spawn { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 160 | argv: args.iter().map(|a| a.to_string()).collect(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 161 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 162 | "spawn" => return Err(err("needs a program")), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 163 | "close" => none(Command::Close)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 164 | "quit" => none(Command::Quit)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 165 | "reload" => none(Command::Reload)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 166 | "flip" => none(Command::Flip)?, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 167 | "maximize" => none(Command::Maximize)?, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 168 | "invert-move" => none(Command::InvertMove)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 169 | "float" => none(Command::Float)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 170 | "fullscreen" => none(Command::Fullscreen)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 171 | "sticky" => none(Command::Sticky)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 172 | "focus" => Command::Focus { dir: dir()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 173 | "move" => Command::Move { dir: dir()? }, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 174 | "move-container" => Command::MoveContainer { dir: dir()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 175 | "focus-output" => Command::FocusOutput { dir: dir()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 176 | "send-to-output" => Command::SendToOutput { dir: dir()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 177 | "resize" => { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 178 | let [axis, delta] = args else { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 179 | return Err(err("takes an axis and a delta")); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 180 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 181 | let axis = match *axis { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 182 | "horizontal" | "h" => Axis::Horizontal, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 183 | "vertical" | "v" => Axis::Vertical, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 184 | a => return Err(err(&format!("unknown axis {a}"))), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 185 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 186 | let delta = delta |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 187 | .parse() |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 188 | .map_err(|_| err(&format!("bad delta {delta}")))?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 189 | Command::Resize { axis, delta } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 190 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 191 | "expand" => Command::Expand { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 192 | scope: match args { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 193 | [] | ["window"] => ExpandScope::Window, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 194 | ["container"] => ExpandScope::Container, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 195 | _ => return Err(err("takes window or container")), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 196 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 197 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 198 | "view" => Command::View { tag: one()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 199 | "toggle-view" => Command::ToggleView { tag: one()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 200 | "view-everywhere" => Command::ViewEverywhere { tag: one()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 201 | "tag" => Command::Tag { tag: one()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 202 | "reorder-tag" => { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 203 | let [tag, index] = args else { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 204 | return Err(err("takes a tag and an index")); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 205 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 206 | let index = index |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 207 | .parse() |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 208 | .map_err(|_| err(&format!("bad index {index}")))?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 209 | Command::ReorderTag { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 210 | tag: tag.to_string(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 211 | index, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 212 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 213 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 214 | "scratchpad" => Command::Scratchpad { name: one()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 215 | "summon" => Command::Summon { name: one()? }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 216 | "dismiss" => Command::Dismiss { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 217 | name: match args { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 218 | [] => None, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 219 | [n] => Some(n.to_string()), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 220 | _ => return Err(err("takes at most one name")), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 221 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 222 | }, |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 223 | "power" => { |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 224 | let (on, output) = match args { |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 225 | ["on"] => (true, None), |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 226 | ["off"] => (false, None), |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 227 | ["on", o] => (true, Some(o.to_string())), |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 228 | ["off", o] => (false, Some(o.to_string())), |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 229 | _ => return Err(err("takes on or off and optionally an output")), |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 230 | }; |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 231 | Command::Power { on, output } |
140b53f6ef84 | atagen | 2026-10-19 07:43 UTC | 232 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 233 | _ => return Err(ParseError(format!("unknown command {name}"))), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 234 | }) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 235 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 236 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 237 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 238 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 239 | #[serde(rename_all = "kebab-case")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 240 | pub enum Request { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 241 | Run(Command), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 242 | Get(Query), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 243 | /// Streams a `State` event after every change until the client hangs up. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 244 | Subscribe {}, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 245 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 246 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 247 | #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 248 | #[serde(rename_all = "kebab-case")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 249 | pub enum Query { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 250 | State, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 251 | Version, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 252 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 253 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 254 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 255 | pub struct Envelope<T> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 256 | pub v: u32, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 257 | #[serde(default, skip_serializing_if = "Option::is_none")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 258 | pub id: Option<u64>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 259 | #[serde(flatten)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 260 | pub body: T, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 261 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 262 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 263 | impl<T> Envelope<T> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 264 | pub fn new(id: Option<u64>, body: T) -> Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 265 | Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 266 | v: VERSION, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 267 | id, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 268 | body, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 269 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 270 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 271 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 272 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 273 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 274 | #[serde(rename_all = "kebab-case")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 275 | pub enum Reply { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 276 | Ok(Option<Answer>), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 277 | Error(String), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 278 | Event(State), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 279 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 280 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 281 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 282 | #[serde(rename_all = "kebab-case")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 283 | pub enum Answer { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 284 | State(State), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 285 | Version(String), |
ad802fd23506 | atagen | 2026-10-19 07:28 UTC | 286 | Warnings(Vec<String>), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 287 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 288 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 289 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 290 | pub struct State { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 291 | /// The next window move does the opposite of the configured default. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 292 | pub move_inverted: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 293 | pub tags: Vec<Tag>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 294 | pub outputs: Vec<Output>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 295 | pub windows: Vec<Window>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 296 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 297 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 298 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 299 | pub struct Tag { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 300 | pub name: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 301 | pub urgent: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 302 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 303 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 304 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 305 | pub struct Output { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 306 | pub name: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 307 | /// x, y, width, height in logical pixels. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 308 | pub area: [f64; 4], |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 309 | pub viewed: Vec<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 310 | pub active: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 311 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 312 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 313 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 314 | pub struct Window { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 315 | pub id: u64, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 316 | pub app_id: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 317 | pub title: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 318 | pub tag: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 319 | pub output: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 320 | pub floating: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 321 | pub fullscreen: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 322 | pub sticky: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 323 | pub scratchpad: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 324 | pub visible: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 325 | pub focused: bool, |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 326 | pub urgent: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 327 | } |