Skip to content

Commit

Permalink
#290 supporting using a vec of hooks as a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Jan 19, 2024
1 parent 7b7ed75 commit 6a6de92
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
43 changes: 43 additions & 0 deletions src/core/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ where
}
}

impl<X> EventHook<X> for Vec<Box<dyn EventHook<X>>>
where
X: XConn,
{
fn call(&mut self, event: &XEvent, state: &mut State<X>, x: &X) -> Result<bool> {
let mut call_next = true;
for hook in self.iter_mut() {
call_next = hook.call(event, state, x)?;
if !call_next {
return Ok(false);
}
}

Ok(call_next)
}
}

impl<X: XConn> fmt::Debug for Box<dyn EventHook<X>> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EventHook").finish()
Expand Down Expand Up @@ -224,6 +241,19 @@ where
}
}

impl<X> ManageHook<X> for Vec<Box<dyn ManageHook<X>>>
where
X: XConn,
{
fn call(&mut self, id: Xid, state: &mut State<X>, x: &X) -> Result<()> {
for hook in self.iter_mut() {
hook.call(id, state, x)?;
}

Ok(())
}
}

impl<X: XConn> fmt::Debug for Box<dyn ManageHook<X>> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ManageHook").finish()
Expand Down Expand Up @@ -301,6 +331,19 @@ where
}
}

impl<X> StateHook<X> for Vec<Box<dyn StateHook<X>>>
where
X: XConn,
{
fn call(&mut self, state: &mut State<X>, x: &X) -> Result<()> {
for hook in self.iter_mut() {
hook.call(state, x)?;
}

Ok(())
}
}

impl<X: XConn> fmt::Debug for Box<dyn StateHook<X>> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StateHook").finish()
Expand Down
13 changes: 0 additions & 13 deletions src/extensions/hooks/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ where
}
}

impl<X> ManageHook<X> for Vec<Box<dyn ManageHook<X>>>
where
X: XConn,
{
fn call(&mut self, id: Xid, state: &mut State<X>, x: &X) -> Result<()> {
for hook in self.iter_mut() {
hook.call(id, state, x)?;
}

Ok(())
}
}

fn float<X: XConn>(client: Xid, r: Rect, state: &mut State<X>, _: &X) -> Result<()> {
state.client_set.float(client, r)
}
Expand Down

0 comments on commit 6a6de92

Please sign in to comment.