forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB111f1caTahinli1 day ago3134 commits

cli.rs148 lines, 4.7 KiBHistoryRawDownload
1use std::ffi::OsString;
2use std::path::PathBuf;
3
4use clap::{Parser, Subcommand};
5use clap_complete::Shell;
6use niri_ipc::{Action, OutputAction};
7
8use crate::utils::version;
9
10#[derive(Parser)]
11#[command(author, version = version(), about, long_about = None)]
12#[command(args_conflicts_with_subcommands = true)]
13#[command(subcommand_value_name = "SUBCOMMAND")]
14#[command(subcommand_help_heading = "Subcommands")]
15pub struct Cli {
16 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
17 ///
18 /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
19 /// command line argument takes precedence.
20 #[arg(short, long)]
21 pub config: Option<PathBuf>,
22 /// Import environment globally to systemd and D-Bus, run D-Bus services.
23 ///
24 /// Set this flag in a systemd service started by your display manager, or when running
25 /// manually as your main compositor instance. Do not set when running as a nested window, or
26 /// on a TTY as your non-main compositor instance, to avoid messing up the global environment.
27 #[arg(long)]
28 pub session: bool,
29 /// Run without a display, on a single virtual 1920x1080 output.
30 ///
31 /// Clients can connect to the Wayland socket as usual, and the output can be captured with
32 /// screenshot tools, for example to test clients without showing anything on screen.
33 #[arg(long, conflicts_with = "session")]
34 pub headless: bool,
35 /// Command to run upon compositor startup.
36 #[arg(last = true)]
37 pub command: Vec<OsString>,
38
39 #[command(subcommand)]
40 pub subcommand: Option<Sub>,
41}
42
43#[derive(Subcommand)]
44pub enum Sub {
45 /// Communicate with the running niri instance.
46 Msg {
47 #[command(subcommand)]
48 msg: Msg,
49 /// Format output as JSON.
50 #[arg(short, long)]
51 json: bool,
52 /// Print the IPC request as JSON instead of sending it.
53 #[arg(long)]
54 print_request: bool,
55 },
56 /// Validate the config file.
57 Validate {
58 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
59 ///
60 /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
61 /// command line argument takes precedence.
62 #[arg(short, long)]
63 config: Option<PathBuf>,
64 },
65 /// Cause a panic to check if the backtraces are good.
66 Panic,
67 /// Generate shell completions.
68 Completions { shell: CompletionShell },
69}
70
71#[derive(Subcommand)]
72pub enum Msg {
73 /// List connected outputs.
74 Outputs,
75 /// List workspaces.
76 Workspaces,
77 /// List open windows.
78 Windows,
79 /// List open layer-shell surfaces.
80 Layers,
81 /// Get the configured keyboard layouts.
82 KeyboardLayouts,
83 /// Print information about the focused output.
84 FocusedOutput,
85 /// Print information about the focused window.
86 FocusedWindow,
87 /// Pick a window with the mouse and print information about it.
88 PickWindow,
89 /// Pick a color from the screen with the mouse.
90 PickColor,
91 /// Perform an action.
92 Action {
93 #[command(subcommand)]
94 action: Action,
95 },
96 /// Change output configuration temporarily.
97 ///
98 /// The configuration is changed temporarily and not saved into the config file. If the output
99 /// configuration subsequently changes in the config file, these temporary changes will be
100 /// forgotten.
101 Output {
102 /// Output name.
103 ///
104 /// Run `niri msg outputs` to see the output names.
105 #[arg()]
106 output: String,
107 /// Configuration to apply.
108 #[command(subcommand)]
109 action: OutputAction,
110 },
111 /// Start continuously receiving events from the compositor.
112 EventStream,
113 /// Print the version of the running niri instance.
114 Version,
115 /// Request an error from the running niri instance.
116 RequestError,
117 /// Print the overview state.
118 OverviewState,
119 /// List screencasts.
120 Casts,
121 /// Send a raw JSON request to the compositor, reading from stdin.
122 RawRequest,
123}
124
125#[derive(Clone, Debug, clap::ValueEnum)]
126pub enum CompletionShell {
127 Bash,
128 Elvish,
129 Fish,
130 PowerShell,
131 Zsh,
132 Nushell,
133}
134
135impl TryFrom<CompletionShell> for Shell {
136 type Error = &'static str;
137
138 fn try_from(shell: CompletionShell) -> Result<Self, Self::Error> {
139 match shell {
140 CompletionShell::Bash => Ok(Shell::Bash),
141 CompletionShell::Elvish => Ok(Shell::Elvish),
142 CompletionShell::Fish => Ok(Shell::Fish),
143 CompletionShell::PowerShell => Ok(Shell::PowerShell),
144 CompletionShell::Zsh => Ok(Shell::Zsh),
145 CompletionShell::Nushell => Err("Nushell should be handled separately"),
146 }
147 }
148}