mod clients;
mod color;
mod color_management;
mod config;
mod control_center;
mod damage_tracking;
mod duration;
mod generate;
mod idle;
mod input;
mod json;
mod log;
mod pid;
mod quit;
mod randr;
mod reexec;
mod run_privileged;
mod run_tagged;
pub mod screenshot;
mod seat_test;
mod set_log_level;
mod tree;
mod unlock;
mod version;
mod xwayland;
use {
crate::{
cli::{
clients::ClientsArgs, color_management::ColorManagementArgs, config::ConfigArgs,
damage_tracking::DamageTrackingArgs, idle::IdleCmd, input::InputArgs,
json::VERBOSE_JSON, randr::RandrArgs, reexec::ReexecArgs, run_tagged::RunTaggedArgs,
tree::TreeArgs, xwayland::XwaylandArgs,
},
compositor::{LogLevel, start_compositor},
format::{Format, ref_formats},
portal,
pr_caps::drop_all_pr_caps,
},
clap::{Args, Parser, Subcommand, ValueEnum, ValueHint, builder::PossibleValue},
clap_complete::Shell,
std::sync::atomic::Ordering::Relaxed,
};
#[derive(Parser, Debug)]
struct Jay {
#[clap(flatten)]
global: GlobalArgs,
#[clap(subcommand)]
command: Cmd,
}
#[derive(Args, Debug)]
pub struct GlobalArgs {
#[clap(value_enum, long, default_value_t)]
pub log_level: LogLevel,
#[clap(long)]
pub json: bool,
#[clap(long)]
pub all_json_fields: bool,
}
#[derive(Subcommand, Debug)]
pub enum Cmd {
Run(RunArgs),
Config(ConfigArgs),
GenerateCompletion(GenerateArgs),
Log(LogArgs),
SetLogLevel(SetLogArgs),
Quit,
Unlock,
Screenshot(ScreenshotArgs),
Idle(IdleArgs),
RunPrivileged(RunPrivilegedArgs),
RunTagged(RunTaggedArgs),
SeatTest(SeatTestArgs),
Portal,
Randr(RandrArgs),
Input(InputArgs),
#[clap(hide = true)]
DamageTracking(DamageTrackingArgs),
Xwayland(XwaylandArgs),
ColorManagement(ColorManagementArgs),
#[clap(hide = true)]
Reexec(ReexecArgs),
Clients(ClientsArgs),
Tree(TreeArgs),
ControlCenter,
Version,
Pid,
#[cfg(feature = "it")]
RunTests,
}
#[derive(Args, Debug)]
pub struct IdleArgs {
#[clap(subcommand)]
pub command: Option<IdleCmd>,
}
#[derive(Args, Debug)]
pub struct RunPrivilegedArgs {
#[clap(required = true, trailing_var_arg = true, value_hint = ValueHint::CommandWithArguments)]
pub program: Vec<String>,
}
#[derive(ValueEnum, Debug, Copy, Clone, Hash, Default, PartialEq)]
pub enum ScreenshotFormat {
#[default]
Png,
Qoi,
}
#[derive(Args, Debug)]
pub struct ScreenshotArgs {
#[clap(value_enum, long, default_value_t)]
pub format: ScreenshotFormat,
#[clap(value_hint = ValueHint::FilePath)]
pub filename: Option<String>,
}
#[derive(Args, Debug, Default)]
pub struct RunArgs {
#[clap(value_enum, use_value_delimiter = true, long)]
pub backends: Vec<CliBackend>,
}
#[derive(Args, Debug)]
pub struct LogArgs {
#[clap(long)]
path: bool,
#[clap(long, short)]
follow: bool,
#[clap(long, short = 'e')]
pager_end: bool,
}
#[derive(Args, Debug)]
pub struct SetLogArgs {
#[clap(value_enum)]
level: LogLevel,
}
#[derive(Args, Debug)]
pub struct SeatTestArgs {
#[clap(long, short = 'a')]
all: bool,
seat: Option<String>,
}
#[derive(ValueEnum, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub enum CliBackend {
X11,
Metal,
Headless,
}
#[derive(Args, Debug)]
pub struct GenerateArgs {
#[clap(value_enum)]
shell: Shell,
}
impl ValueEnum for &'static Format {
fn value_variants<'a>() -> &'a [Self] {
ref_formats()
}
fn to_possible_value(&self) -> Option<PossibleValue> {
Some(PossibleValue::new(self.name))
}
}
pub fn main() {
let cli = Jay::parse();
if not_matches!(cli.command, Cmd::Run(_)) {
drop_all_pr_caps();
}
if cli.global.all_json_fields {
VERBOSE_JSON.store(true, Relaxed);
}
match cli.command {
Cmd::Run(a) => start_compositor(cli.global, a),
Cmd::GenerateCompletion(g) => generate::main(g),
Cmd::Log(a) => log::main(cli.global, a),
Cmd::Quit => quit::main(cli.global),
Cmd::SetLogLevel(a) => set_log_level::main(cli.global, a),
Cmd::Screenshot(a) => screenshot::main(cli.global, a),
Cmd::Idle(a) => idle::main(cli.global, a),
Cmd::Unlock => unlock::main(cli.global),
Cmd::RunPrivileged(a) => run_privileged::main(cli.global, a),
Cmd::RunTagged(a) => run_tagged::main(cli.global, a),
Cmd::SeatTest(a) => seat_test::main(cli.global, a),
Cmd::Portal => portal::run_freestanding(cli.global),
Cmd::Randr(a) => randr::main(cli.global, a),
Cmd::Input(a) => input::main(cli.global, a),
Cmd::DamageTracking(a) => damage_tracking::main(cli.global, a),
Cmd::Xwayland(a) => xwayland::main(cli.global, a),
Cmd::ColorManagement(a) => color_management::main(cli.global, a),
Cmd::Clients(a) => clients::main(cli.global, a),
Cmd::Tree(a) => tree::main(cli.global, a),
Cmd::Version => version::main(cli.global),
Cmd::Pid => pid::main(cli.global),
#[cfg(feature = "it")]
Cmd::RunTests => crate::it::run_tests(),
Cmd::Reexec(a) => reexec::main(cli.global, a),
Cmd::ControlCenter => control_center::main(cli.global),
Cmd::Config(a) => config::main(cli.global, a),
}
}