swayipc_types/command.rs
1#[repr(u32)]
2#[non_exhaustive]
3#[derive(Debug, PartialEq, Copy, Clone)]
4pub enum CommandType {
5 /// Runs the payload as sway commands.
6 RunCommand = 0,
7 /// Get the list of current workspaces.
8 GetWorkspaces = 1,
9 /// Subscribe the IPC connection to the events listed in the payload.
10 Subscribe = 2,
11 /// Get the list of current outputs.
12 GetOutputs = 3,
13 /// Get the node layout tree.
14 GetTree = 4,
15 /// Get the names of all the marks currently set.
16 GetMarks = 5,
17 /// Get the specified bar config or a list of bar config names.
18 GetBarConfig = 6,
19 /// Get the version of sway that owns the IPC socket.
20 GetVersion = 7,
21 /// Get the list of binding mode names.
22 GetBindingModes = 8,
23 /// Returns the config that was last loaded.
24 GetConfig = 9,
25 /// Sends a tick event with the specified payload.
26 SendTick = 10,
27 /// Replies failure object for i3 compatibility.
28 Sync = 11,
29 /// Request the current binding state, e.g. the currently active binding
30 /// mode name.
31 GetBindingState = 12,
32 /// Get the list of input devices.
33 GetInputs = 100,
34 /// Get the list of seats.
35 GetSeats = 101,
36}
37
38impl CommandType {
39 pub fn encode(self) -> Vec<u8> {
40 crate::MAGIC
41 .into_iter()
42 .chain(0_u32.to_ne_bytes())
43 .chain(u32::from(self).to_ne_bytes())
44 .collect()
45 }
46
47 pub fn encode_with<T: AsRef<[u8]>>(self, payload: T) -> Vec<u8> {
48 let payload = payload.as_ref();
49 crate::MAGIC
50 .into_iter()
51 .chain((payload.len() as u32).to_ne_bytes())
52 .chain(u32::from(self).to_ne_bytes())
53 .chain(payload.iter().cloned())
54 .collect()
55 }
56}
57
58impl From<CommandType> for u32 {
59 fn from(value: CommandType) -> Self {
60 value as u32
61 }
62}