feat: full poc

This commit is contained in:
atagen 2025-06-19 17:35:38 +10:00
parent b76036038e
commit a8847b93cf
14 changed files with 630 additions and 323 deletions

59
cli/main.rs Normal file
View file

@ -0,0 +1,59 @@
use anyhow::{Context, Result, anyhow};
use clap::{Parser, Subcommand};
use niri_tag::TagCmd;
use nix::unistd::geteuid;
use std::{io::Write, os::unix::net::UnixStream};
#[derive(Parser)]
#[command(name = "tagctl")]
#[command(about = "ipc wrapper for niri-tag")]
struct Cli {
#[command(subcommand)]
cmd: Commands,
}
#[derive(Clone, Debug, Subcommand)]
enum Commands {
Add { tag: u8 },
Remove { tag: u8 },
Toggle { tag: u8 },
Enable { tag: u8 },
Disable { tag: u8 },
ToggleWs { tag: u8 },
}
impl From<Commands> for niri_tag::TagCmd {
fn from(value: Commands) -> Self {
match value {
Commands::Add { tag } => TagCmd::Add(tag),
Commands::Remove { tag } => TagCmd::Remove(tag),
Commands::Enable { tag } => TagCmd::Enable(tag),
Commands::Disable { tag } => TagCmd::Disable(tag),
Commands::Toggle { tag } => TagCmd::Toggle(tag),
Commands::ToggleWs { tag } => TagCmd::ToggleWs(tag),
}
}
}
fn main() -> Result<()> {
let cli = Cli::parse();
use Commands::*;
println!("{:?}", cli.cmd);
match cli.cmd {
Add { tag } if tag > 0 => (),
Remove { tag } if tag > 0 => (),
Enable { tag } if tag > 0 => (),
Disable { tag } if tag > 0 => (),
Toggle { tag } if tag > 0 => (),
ToggleWs { tag } if tag > 0 => (),
_ => return Err(anyhow!("Can't change tag 0!")),
};
let cmd = TagCmd::from(cli.cmd);
let mut ipc = UnixStream::connect(format!("/run/user/{}/niri-tag.sock", geteuid()))
.context("Connecting to niri-tag ipc socket")?;
ipc.write_all(serde_json::to_string(&cmd)?.as_bytes())?;
Ok(())
}