Skip to content

Commit

Permalink
Merge pull request #237 from joshurtree/master
Browse files Browse the repository at this point in the history
Expanded examples
  • Loading branch information
yavko authored Jun 4, 2024
2 parents c0171c8 + d14e38c commit 3e74462
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 257 deletions.
26 changes: 0 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ lto = true

[workspace]
members = [
"examples/almost_everything",
"examples/almost_everything_async",
"hyprland-macros",
]

Expand All @@ -44,7 +42,9 @@ serde_repr = "0.1"
tokio = { version = "1", features = [
"io-std",
"io-util",
"macros",
"net",
"rt"
], optional = true }
async-net = { version = "2.0", optional = true }
async-std = { version = "1.12", optional = true }
Expand Down
14 changes: 0 additions & 14 deletions examples/almost_everything/Cargo.toml

This file was deleted.

86 changes: 0 additions & 86 deletions examples/almost_everything/src/main.rs

This file was deleted.

20 changes: 0 additions & 20 deletions examples/almost_everything_async/Cargo.toml

This file was deleted.

108 changes: 0 additions & 108 deletions examples/almost_everything_async/src/main.rs

This file was deleted.

25 changes: 25 additions & 0 deletions examples/bind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// Demonstates the use of Hyprland-rs for creating key bindings
/// and using submaps
///
/// Usage: cargo run --example bind

use std::io::Read;
use hyprland::dispatch;
use hyprland::dispatch::{Dispatch, DispatchType};
use hyprland::keyword::Keyword;

fn main() -> hyprland::Result<()> {
Keyword::set("submap", "example")?;
hyprland::bind!(SUPER, Key, "I" => ToggleFloating, None)?;
hyprland::bind!(l | CTRL ALT, Key, "Delete" => Exec, "sudo reboot"); // Reboot including from lock screen
hyprland::bind!(e | SUPER, Key, "C" => KillActiveWindow); // Kill all your windows
Keyword::set("submap", "reset")?;

dispatch!(Custom, "submap", "example")?;
println!("Press enter to revert to default keymap");
let _ = std::io::stdin().read(&mut [0u8])
.expect("Crashed: Run `hyprctl dispatch submap reset` to return to default submap");
dispatch!(Custom, "submap", "reset")?;

Ok(())
}
24 changes: 24 additions & 0 deletions examples/bind_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// Demonstates the use of Hyprland-rs for asyncronous creation key bindings
/// and using submaps
///
/// Usage: cargo run --example bind

use std::io::Read;
use hyprland::dispatch;
use hyprland::dispatch::{Dispatch, DispatchType};
use hyprland::keyword::Keyword;

#[tokio::main(flavor = "current_thread")]
async fn main() -> hyprland::Result<()> {
Keyword::set_async("submap", "example").await?;
hyprland::bind!(async; SUPER, Key, "I" => ToggleFloating, None).await?;
hyprland::bind!(async; l | CTRL ALT, Key, "Delete" => Exec, "sudo reboot").await?; // Reboot including from lock screen
hyprland::bind!(async; e | SUPER, Key, "C" => KillActiveWindow).await?; // Kill all your windows
Keyword::set_async("submap", "reset").await?;

dispatch!(async; Custom, "submap", "example").await?;
println!("Press enter to revert to default keymap");
let _ = std::io::stdin().read(&mut [0u8]).unwrap();
dispatch!(async; Custom, "submap", "reset").await?;
Ok(())
}
29 changes: 29 additions & 0 deletions examples/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// Demostrates using hyprland-rs to fetch information about clients, workspaces and monitors
///
/// Usage: cargo run --example data <animations|binds|client(s)|workspace(s)|monitor(s)>
/// Example: cargo run --example data client (Gets data on active client)
/// Example: cargo run --example data workspaces (Gets data on all workspaces)

use hyprland::data::{Animations, Binds, Client, Clients, Monitor, Monitors, Workspace, Workspaces};
use hyprland::shared::{HyprData, HyprDataActive, HyprDataActiveOptional};
fn main() -> hyprland::Result<()>{
let args: Vec<_> = std::env::args().skip(1).collect();

if args.len() == 0 {
panic!("You have to specify client, workspace or monitor")
}

match args[0].as_str() {
"client" => println!("{:#?}", Client::get_active()?),
"monitor" => println!("{:#?}", Monitor::get_active()?),
"workspace" => println!("{:#?}", Workspace::get_active()?),
"animations" => println!("{:#?}", Animations::get()?),
"binds" => println!("{:#?}", Binds::get()?),
"clients" => println!("{:#?}", Clients::get()?),
"monitors" => println!("{:#?}", Monitors::get()?),
"workspaces" => println!("{:#?}", Workspaces::get()?),
_ => println!("Specify one of client(s), monitor(s) or workspace(s)")
};

Ok(())
}
Loading

0 comments on commit 3e74462

Please sign in to comment.