pub struct Dispatch;
Expand description
The struct that provides all dispatching methods
Implementations§
source§impl Dispatch
impl Dispatch
sourcepub fn call(dispatch_type: DispatchType<'_>) -> Result<()>
pub fn call(dispatch_type: DispatchType<'_>) -> Result<()>
This function calls a specified dispatcher (blocking)
use hyprland::dispatch::{DispatchType,Dispatch};
// This is an example of just one dispatcher, there are many more!
Dispatch::call(DispatchType::Exec("kitty"))
Examples found in repository?
examples/almost_everything.rs (line 17)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() -> hyprland::Result<()> {
// We can call dispatchers with the dispatch macro, and struct!
// You can decide what you want to use, below are some examples of their usage
// Here we are telling hyprland to open kitty using the dispatch macro!
hyprland::dispatch!(Exec, "kitty")?;
// Here we are moving the cursor to the top left corner! We can also just use the Dispatch
// struct!
Dispatch::call(DispatchType::MoveCursorToCorner(Corner::TopLeft))?;
// Here we are adding a keybinding to Hyprland using the bind macro!
hyprland::bind!(SUPER, Key, "i" => ToggleFloating, None)?;
// Here we are getting the border size
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}");
// Here we change a keyword, in this case we are doubling the border size we got above
Keyword::set("general:border_size", border_size * 2)?;
// get all monitors
let monitors = Monitors::get()?;
// and the active window
let win = Client::get_active()?;
// and all open windows
let clients = Clients::get()?;
// and the active workspace
let work = Workspace::get_active()?;
// and printing them all out!
println!("monitors: {monitors:#?},\nactive window: {win:#?},\nclients {clients:#?}\nworkspace: {work:#?}");
// Create a event listener
let mut event_listener = EventListener::new();
// Shows when active window changes
event_listener.add_active_window_change_handler(|data, _| {
println!("{data:#?}");
});
// This changes the workspace to 5 if the workspace is switched to 9
// this is a performance and mutable state test
event_listener.add_workspace_change_handler(|id, state| {
if id == WorkspaceType::Regular('9'.to_string()) {
state.active_workspace = WorkspaceType::Regular('2'.to_string());
}
});
// This makes it so you can't turn on fullscreen lol
event_listener.add_fullscreen_state_change_handler(|fstate, state| {
if fstate {
state.fullscreen_state = false;
}
});
// Makes a monitor unfocusable
event_listener.add_active_monitor_change_handler(|data, state| {
let hyprland::event_listener::MonitorEventData { monitor_name, .. } = data;
if monitor_name == *"DP-1".to_string() {
state.active_monitor = "eDP-1".to_string()
}
});
// add event, yes functions and closures both work!
event_listener.add_workspace_change_handler(|id, _| println!("workspace changed to {id:#?}"));
// and execute the function
// here we are using the blocking variant
// but there is a async version too
event_listener.start_listener()
}
sourcepub async fn call_async(dispatch_type: DispatchType<'_>) -> Result<()>
pub async fn call_async(dispatch_type: DispatchType<'_>) -> Result<()>
This function calls a specified dispatcher (async)
use hyprland::dispatch::{DispatchType,Dispatch};
// This is an example of just one dispatcher, there are many more!
Dispatch::call_async(DispatchType::Exec("kitty")).await?;
Examples found in repository?
examples/almost_everything_async.rs (line 20)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
async fn main() -> hyprland::Result<()> {
// We can call dispatchers with the dispatch function!
// Here we are telling hyprland to open kitty using the dispatch macro!
hyprland::dispatch!(async; Exec, "kitty").await?;
// Here we are adding a keybinding to Hyprland using the bind macro!
hyprland::bind!(async; SUPER, Key, "i" => ToggleFloating, None).await?;
// Here we are moving the cursor to the top left corner! We can also just use the Dispatch
// struct!
Dispatch::call_async(DispatchType::MoveCursorToCorner(Corner::TopLeft)).await?;
let border_size = match Keyword::get_async("general:border_size").await?.value {
OptionValue::Int(i) => i,
_ => panic!("border size can only be a int"),
};
println!("{border_size}");
// Here we change a keyword, yes its a dispatcher don't complain
Keyword::set_async("general:border_size", border_size * 2).await?;
// get all monitors
let monitors = Monitors::get_async().await?;
// and the active window
let win = Client::get_active_async().await?;
// and all open windows
let clients = Clients::get_async().await?;
// and the active workspace
let work = Workspace::get_active_async().await?;
// and printing them all out!
println!("monitors: {monitors:#?},\nactive window: {win:#?},\nclients {clients:#?}\nworkspace:{work:#?}");
let animations = Animations::get_async().await?;
println!("{animations:#?}");
// Create a event listener
let mut event_listener = AsyncEventListener::new();
//This changes the workspace to 5 if the workspace is switched to 9
//this is a performance and mutable state test
// event_listener.add_workspace_change_handler(async_closure! {|id, state| {
// if id == WorkspaceType::Regular('9'.to_string()) {
// *state.workspace = '2'.to_string();
// }
// }});
/*
event_listener.add_workspace_change_handler(|id, state| {
Box::pin(async move {
if id == WorkspaceType::Regular('9'.to_string()) {
*state.workspace = '2'.to_string();
}
})
});
// This makes it so you can't turn on fullscreen lol
event_listener.add_fullscreen_state_change_handler(async_closure! {|fstate, state| {
if fstate {
*state.fullscreen = false;
}
}});
// Makes a monitor unfocusable
event_listener.add_active_monitor_change_handler(async_closure! {|data, state| {
let hyprland::event_listener::MonitorEventData{ monitor_name, .. } = data;
if monitor_name == *"DP-1".to_string() {
*state.monitor = "eDP-1".to_string()
}
}});
*/
// add event, yes functions and closures both work!
event_listener.add_workspace_change_handler(
async_closure! { move |id| println!("workspace changed to {id:#?}")},
);
event_listener.add_active_window_change_handler(
async_closure! { move |data| println!("window changed to {data:#?}")},
);
// Waybar example
// event_listener.add_active_window_change_handler(|data| {
// use hyprland::event_listener::WindowEventData;
// let string = match data {
// Some(WindowEventData(class, title)) => format!("{class}: {title}"),
// None => "".to_string()
// };
// println!(r#"{{"text": "{string}", class: "what is this?"}}"#);
// });
// and execute the function
// here we are using the blocking variant
// but there is a async version too
event_listener.start_listener_async().await
}
Auto Trait Implementations§
impl RefUnwindSafe for Dispatch
impl Send for Dispatch
impl Sync for Dispatch
impl Unpin for Dispatch
impl UnwindSafe for Dispatch
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more