Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded examples #237

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions Cargo.lock

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

3 changes: 1 addition & 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 @@ -42,6 +40,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_repr = "0.1"
tokio = { version = "1", features = [
"full",
joshurtree marked this conversation as resolved.
Show resolved Hide resolved
"io-std",
"io-util",
"net",
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;
//use hyprland::config::binds::Flag;
joshurtree marked this conversation as resolved.
Show resolved Hide resolved

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]).unwrap();
joshurtree marked this conversation as resolved.
Show resolved Hide resolved
dispatch!(Custom, "submap", "reset")?;

return Ok(());
}
25 changes: 25 additions & 0 deletions examples/bind_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// 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;
//use hyprland::config::binds::Flag;

#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
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?;
return 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)")
};

return Ok(());
joshurtree marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading