forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

cli.rs142 lines, 4.4 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 /// Command to run upon compositor startup.
30 #[arg(last = true)]
31 pub command: Vec<OsString>,
32
33 #[command(subcommand)]
34 pub subcommand: Option<Sub>,
35}
36
37#[derive(Subcommand)]
38pub enum Sub {
39 /// Communicate with the running niri instance.
40 Msg {
41 #[command(subcommand)]
42 msg: Msg,
43 /// Format output as JSON.
44 #[arg(short, long)]
45 json: bool,
46 /// Print the IPC request as JSON instead of sending it.
47 #[arg(long)]
48 print_request: bool,
49 },
50 /// Validate the config file.
51 Validate {
52 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
53 ///
54 /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
55 /// command line argument takes precedence.
56 #[arg(short, long)]
57 config: Option<PathBuf>,
58 },
59 /// Cause a panic to check if the backtraces are good.
60 Panic,
61 /// Generate shell completions.
62 Completions { shell: CompletionShell },
63}
64
65#[derive(Subcommand)]
66pub enum Msg {
67 /// List connected outputs.
68 Outputs,
69 /// List workspaces.
70 Workspaces,
71 /// List open windows.
72 Windows,
73 /// List open layer-shell surfaces.
74 Layers,
75 /// Get the configured keyboard layouts.
76 KeyboardLayouts,
77 /// Print information about the focused output.
78 FocusedOutput,
79 /// Print information about the focused window.
80 FocusedWindow,
81 /// Pick a window with the mouse and print information about it.
82 PickWindow,
83 /// Pick a color from the screen with the mouse.
84 PickColor,
85 /// Perform an action.
86 Action {
87 #[command(subcommand)]
88 action: Action,
89 },
90 /// Change output configuration temporarily.
91 ///
92 /// The configuration is changed temporarily and not saved into the config file. If the output
93 /// configuration subsequently changes in the config file, these temporary changes will be
94 /// forgotten.
95 Output {
96 /// Output name.
97 ///
98 /// Run `niri msg outputs` to see the output names.
99 #[arg()]
100 output: String,
101 /// Configuration to apply.
102 #[command(subcommand)]
103 action: OutputAction,
104 },
105 /// Start continuously receiving events from the compositor.
106 EventStream,
107 /// Print the version of the running niri instance.
108 Version,
109 /// Request an error from the running niri instance.
110 RequestError,
111 /// Print the overview state.
112 OverviewState,
113 /// List screencasts.
114 Casts,
115 /// Send a raw JSON request to the compositor, reading from stdin.
116 RawRequest,
117}
118
119#[derive(Clone, Debug, clap::ValueEnum)]
120pub enum CompletionShell {
121 Bash,
122 Elvish,
123 Fish,
124 PowerShell,
125 Zsh,
126 Nushell,
127}
128
129impl TryFrom<CompletionShell> for Shell {
130 type Error = &'static str;
131
132 fn try_from(shell: CompletionShell) -> Result<Self, Self::Error> {
133 match shell {
134 CompletionShell::Bash => Ok(Shell::Bash),
135 CompletionShell::Elvish => Ok(Shell::Elvish),
136 CompletionShell::Fish => Ok(Shell::Fish),
137 CompletionShell::PowerShell => Ok(Shell::PowerShell),
138 CompletionShell::Zsh => Ok(Shell::Zsh),
139 CompletionShell::Nushell => Err("Nushell should be handled separately"),
140 }
141 }
142}