Hyprland-rs

An unoffical rust wrapper for Hyprland's IPC
Disclaimer
If something doesn't work, doesn't matter what,
make sure you are on the latest commit of Hyprland before making an issue!
Getting started!
Lets get started with Hyprland-rs!
Adding to your project
Add the code below to the dependencies section of your Cargo.toml file!
hyprland = "0.3.0"
What this crate provides
This crate provides 3 modules (+1 for shared things)
data for getting information on the compositor
event_listener which provides the EventListener struct for listening for events
dispatch for calling dispatchers and changing keywords
Example Usage
here is an example of most of the provided features being utilized
use hyprland::data::{Client, Clients, Monitors};
use hyprland::dispatch::*;
use hyprland::event_listener::EventListenerMutable as EventListener;
use hyprland::keyword::*;
use hyprland::prelude::*;
use hyprland::shared::WorkspaceType;
fn main() -> hyprland::shared::HResult<()> {
hyprland::dispatch!(Exec, "kitty")?;
Dispatch::call(DispatchType::MoveCursorToCorner(Corner::TopLeft))?;
hyprland::bind!(SUPER, Key, "i" => ToggleFloating, None)?;
let border_size = match Keyword::get("general:border_size")?.value {
OptionValue::Int(i) => i,
_ => panic!("border size can only be a int"),
};
println!("{border_size}");
Keyword::set("general:border_size", border_size * 2)?;
let monitors = Monitors::get()?;
let win = Client::get_active()?;
let clients = Clients::get()?;
println!("monitors: {monitors:#?},\nactive window: {win:#?},\nclients {clients:#?}");
let mut event_listener = EventListener::new();
event_listener.add_workspace_change_handler(|id, state| {
if id == WorkspaceType::Regular('9'.to_string()) {
state.active_workspace = WorkspaceType::Regular('2'.to_string());
}
});
event_listener.add_fullscreen_state_change_handler(|fstate, state| {
if fstate {
state.fullscreen_state = false;
}
});
event_listener.add_active_monitor_change_handler(|data, state| {
let hyprland::event_listener::MonitorEventData(monitor, _) = data;
if monitor == *"DP-1".to_string() {
state.active_monitor = "eDP-1".to_string()
}
});
event_listener.add_workspace_change_handler(|id, _| println!("workspace changed to {id:#?}"));
event_listener.start_listener()
}