forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBa6baef7Anton Kesy10 months ago2623 commits

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