stuff
This commit is contained in:
70
src/main.rs
70
src/main.rs
@ -1,11 +1,11 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use eyre::{bail, eyre};
|
||||
use niri_ipc::WorkspaceReferenceArg;
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
|
||||
mod hyprland;
|
||||
mod niri;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Opt {
|
||||
#[clap(subcommand)]
|
||||
@ -58,8 +58,8 @@ fn main() -> eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
match &*WM {
|
||||
WindowManager::Niri => handle_niri(opt.command)?,
|
||||
WindowManager::Hyprland => handle_hyprland(opt.command)?,
|
||||
WindowManager::Niri => niri::handle(opt.command)?,
|
||||
WindowManager::Hyprland => hyprland::handle(opt.command)?,
|
||||
_ => eyre::bail!("Window manager not supported"),
|
||||
}
|
||||
|
||||
@ -71,63 +71,3 @@ struct Workspace {
|
||||
monitor: i32,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
fn handle_niri(command: Command) -> eyre::Result<()> {
|
||||
let socket = niri_ipc::Socket::connect()?;
|
||||
|
||||
match command {
|
||||
Command::Workspaces {} => {
|
||||
let reply = socket
|
||||
.send(niri_ipc::Request::Workspaces)?
|
||||
.map_err(|e| eyre!("niri error: {e}"))?;
|
||||
|
||||
let niri_ipc::Response::Workspaces(workspaces) = reply else {
|
||||
bail!("Wrong response from niri: {reply:?}");
|
||||
};
|
||||
|
||||
let workspaces = workspaces
|
||||
.into_iter()
|
||||
.map(|ws| {
|
||||
let workspace = Workspace {
|
||||
monitor: 0,
|
||||
active: ws.is_active,
|
||||
};
|
||||
(ws.idx, workspace)
|
||||
})
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
println!("{}", serde_json::to_string(&workspaces)?);
|
||||
}
|
||||
|
||||
Command::SwitchWorkspace { to } => {
|
||||
let _reply = socket
|
||||
.send(niri_ipc::Request::Action(
|
||||
niri_ipc::Action::FocusWorkspace {
|
||||
reference: WorkspaceReferenceArg::Index(to),
|
||||
},
|
||||
))?
|
||||
.map_err(|e| eyre!("niri error: {e}"))?;
|
||||
}
|
||||
Command::KeyboardLayout { next: _ } => todo!(),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_hyprland(command: Command) -> eyre::Result<()> {
|
||||
match command {
|
||||
Command::Workspaces {} => {
|
||||
std::process::Command::new("eww-workspaces")
|
||||
.status()
|
||||
.map_err(|e| eyre!("unga bunga: {e}"))?;
|
||||
}
|
||||
Command::SwitchWorkspace { .. } => {
|
||||
bail!("not supported on Hyprland");
|
||||
}
|
||||
Command::KeyboardLayout { .. } => {
|
||||
bail!("not supported on Hyprland");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user