Skip to content

Commit

Permalink
0.2.3 release part 3 (forgot to format)
Browse files Browse the repository at this point in the history
  • Loading branch information
yavko committed Aug 18, 2022
1 parent 24af8f3 commit 53df59b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/bin/example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hyprland::data::blocking::{get_active_window, get_monitors, get_clients, get_keyword};
use hyprland::data::blocking::{get_active_window, get_clients, get_keyword, get_monitors};
use hyprland::data::OptionValue;
use hyprland::dispatch::{dispatch_blocking, Corner, DispatchType};
use hyprland::event_listener::EventListenerMutable as EventListener;
Expand All @@ -15,7 +15,7 @@ fn main() -> std::io::Result<()> {

let border_size = match get_keyword("general:border_size".to_string())?.value {
OptionValue::Int(i) => i,
_ => panic!("border size can only be a int")
_ => panic!("border size can only be a int"),
};

// Here we change a keyword, yes its a dispatcher don't complain
Expand All @@ -29,7 +29,7 @@ fn main() -> std::io::Result<()> {

// and the active window
let win = get_active_window();

// and all open windows
let clients = get_clients();

Expand Down
4 changes: 3 additions & 1 deletion src/data/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub fn get_workspaces() -> Result<Workspaces> {
),
};
let deserialized: WorkspacesRaw = serde_json::from_str(&data)?;
let new = deserialized.iter().map(|work| Workspace::from(work.clone()));
let new = deserialized
.iter()
.map(|work| Workspace::from(work.clone()));
Ok(new.collect())
}

Expand Down
8 changes: 4 additions & 4 deletions src/data/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ impl From<WorkspaceRaw> for Workspace {
-99 => WorkspaceType::Special,
0.. => WorkspaceType::Regular(match raw.id.try_into() {
Ok(num) => num,
Err(e) => panic!("Issue with parsing id (i8) as u8: {e}")
Err(e) => panic!("Issue with parsing id (i8) as u8: {e}"),
}),
_ => panic!("Unrecognised id")
_ => panic!("Unrecognised id"),
},
name: raw.name,
monitor: raw.monitor,
windows: raw.windows,
fullscreen: raw.fullscreen
fullscreen: raw.fullscreen,
}
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ pub type Clients = Vec<Client>;
pub struct ActiveWindow(
/// The client data
#[serde(deserialize_with = "object_empty_as_none")]
Option<Client>
Option<Client>,
);

/// This struct holds information about a layer surface/client
Expand Down
19 changes: 14 additions & 5 deletions src/event_listener/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ impl EventListener {
/// listener.add_workspace_change_handler(|id, _| println!("changed workspace to {id:?}"));
/// listener.start_listener_blocking();
/// ```
pub fn add_workspace_change_handler(&mut self, f: impl Fn(WorkspaceType, &mut State) + 'static) {
pub fn add_workspace_change_handler(
&mut self,
f: impl Fn(WorkspaceType, &mut State) + 'static,
) {
self.events
.workspace_changed_events
.push(EventTypes::MutableState(Box::new(f)));
Expand Down Expand Up @@ -107,7 +110,10 @@ impl EventListener {
/// listener.add_workspace_destroy_handler(|id, _| println!("workspace {id:?} was destroyed"));
/// listener.start_listener_blocking();
/// ```
pub fn add_workspace_destroy_handler(&mut self, f: impl Fn(WorkspaceType, &mut State) + 'static) {
pub fn add_workspace_destroy_handler(
&mut self,
f: impl Fn(WorkspaceType, &mut State) + 'static,
) {
self.events
.workspace_destroyed_events
.push(EventTypes::MutableState(Box::new(f)));
Expand Down Expand Up @@ -195,21 +201,24 @@ impl EventListener {
let handlers = &self.events.workspace_changed_events;
self.state.active_workspace = id.clone();
for item in handlers.iter() {
let new_state = execute_closure_mut(self.state.clone(), item, id.clone()).await?;
let new_state =
execute_closure_mut(self.state.clone(), item, id.clone()).await?;
self.state = new_state;
}
}
Event::WorkspaceAdded(id) => {
let events = &self.events.workspace_added_events;
for item in events.iter() {
let new_state = execute_closure_mut(self.state.clone(), item, id.clone()).await?;
let new_state =
execute_closure_mut(self.state.clone(), item, id.clone()).await?;
self.state = new_state;
}
}
Event::WorkspaceDeleted(id) => {
let events = &self.events.workspace_destroyed_events;
for item in events.iter() {
let new_state = execute_closure_mut(self.state.clone(), item, id.clone()).await?;
let new_state =
execute_closure_mut(self.state.clone(), item, id.clone()).await?;
self.state = new_state;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/event_listener/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl State {
use crate::dispatch::WorkspaceIdentifierWithSpecial;
dispatch(DispatchType::Workspace(match state.active_workspace {
WorkspaceType::Regular(id) => WorkspaceIdentifierWithSpecial::Id(id),
WorkspaceType::Special => WorkspaceIdentifierWithSpecial::Special
WorkspaceType::Special => WorkspaceIdentifierWithSpecial::Special,
}))
.await?;
}
Expand All @@ -74,7 +74,7 @@ impl State {
use crate::dispatch::WorkspaceIdentifierWithSpecial;
dispatch_blocking(DispatchType::Workspace(match state.active_workspace {
WorkspaceType::Regular(id) => WorkspaceIdentifierWithSpecial::Id(id),
WorkspaceType::Special => WorkspaceIdentifierWithSpecial::Special
WorkspaceType::Special => WorkspaceIdentifierWithSpecial::Special,
}))?;
}
if old.active_monitor != state.active_monitor {
Expand Down Expand Up @@ -185,7 +185,7 @@ fn parse_string_as_work(str: String) -> WorkspaceType {
if str == "special" {
WorkspaceType::Special
} else {
match str.parse::<i8>() {
match str.parse::<i8>() {
Ok(num) => WorkspaceType::from(num),
Err(e) => panic!("error parsing string as u8:\nthe string:{str}\nerror message: {e}"),
}
Expand Down
26 changes: 13 additions & 13 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ pub enum WorkspaceType {
/// A regular workspace
Regular(
/// The workspace id
WorkspaceId
WorkspaceId,
),
/// The special workspace
Special
Special,
}

impl From<i8> for WorkspaceType {
fn from(int: i8) -> Self {
match int {
-99 => WorkspaceType::Special,
0.. => WorkspaceType::Regular(match int.try_into() {
Ok(num) => num,
Err(e) => panic!("Issue with parsing id (i8) as u8: {e}")
}),
_ => panic!("Unrecognised id")
}
-99 => WorkspaceType::Special,
0.. => WorkspaceType::Regular(match int.try_into() {
Ok(num) => num,
Err(e) => panic!("Issue with parsing id (i8) as u8: {e}"),
}),
_ => panic!("Unrecognised id"),
}
}
}

Expand Down Expand Up @@ -136,18 +136,18 @@ where
}

pub(crate) fn de_work_id<'de, D>(deserializer: D) -> Result<WorkspaceType, D::Error>
where
D: Deserializer<'de>
where
D: Deserializer<'de>,
{
#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum Aux {
Special(i8),
Reg(u8)
Reg(u8),
}

match Deserialize::deserialize(deserializer)? {
Aux::Special(_) => Ok(WorkspaceType::Special),
Aux::Reg(int) => Ok(WorkspaceType::Regular(int))
Aux::Reg(int) => Ok(WorkspaceType::Regular(int)),
}
}

0 comments on commit 53df59b

Please sign in to comment.