74 lines
1.4 KiB
Rust
74 lines
1.4 KiB
Rust
use clap::{Parser, Subcommand};
|
|
use once_cell::sync::Lazy;
|
|
use serde::Serialize;
|
|
use std::env;
|
|
|
|
mod hyprland;
|
|
mod niri;
|
|
|
|
#[derive(Parser)]
|
|
struct Opt {
|
|
#[clap(subcommand)]
|
|
command: Command,
|
|
}
|
|
|
|
#[derive(Clone, Subcommand)]
|
|
enum Command {
|
|
/// Get the list of workspaces
|
|
Workspaces {},
|
|
|
|
KeyboardLayout {
|
|
/// Switch to the next keyboard layout
|
|
#[clap(long)]
|
|
next: bool,
|
|
},
|
|
|
|
SwitchWorkspace {
|
|
to: u8,
|
|
},
|
|
}
|
|
|
|
enum WindowManager {
|
|
Hyprland,
|
|
Niri,
|
|
Unknown,
|
|
}
|
|
|
|
static WM: Lazy<WindowManager> = Lazy::new(|| {
|
|
let session_type = env::var("XDG_SESSION_TYPE").ok();
|
|
|
|
if session_type.as_deref() != Some("wayland") {
|
|
return WindowManager::Unknown;
|
|
}
|
|
|
|
// might be relevant at some point
|
|
// let _session_desktop = env::var("XDG_SESSION_DESKTOP").ok();
|
|
|
|
let current_desktop = env::var("XDG_CURRENT_DESKTOP").ok();
|
|
|
|
match current_desktop.as_deref() {
|
|
Some("niri") => WindowManager::Niri,
|
|
Some("Hyprland") => WindowManager::Hyprland,
|
|
_ => WindowManager::Unknown,
|
|
}
|
|
});
|
|
|
|
fn main() -> eyre::Result<()> {
|
|
let opt = Opt::parse();
|
|
color_eyre::install()?;
|
|
|
|
match &*WM {
|
|
WindowManager::Niri => niri::handle(opt.command)?,
|
|
WindowManager::Hyprland => hyprland::handle(opt.command)?,
|
|
_ => eyre::bail!("Window manager not supported"),
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
struct Workspace {
|
|
monitor: i32,
|
|
active: bool,
|
|
}
|