Skip to content

Commit

Permalink
Fix horrible docs & Add active special events
Browse files Browse the repository at this point in the history
  • Loading branch information
yavko committed Feb 25, 2024
1 parent 6e2cf6a commit cd47a74
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/data/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ pub enum AnimationStyle {
Slide,
/// Vertical slide animation
SlideVert,
/// Slide with fade animation
SlideFade,
/// Vertical slide with fade animation
SlideFadeVert,
/// Popin animation (with percentage)
PopIn(u8),
Expand Down
16 changes: 9 additions & 7 deletions src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl std::fmt::Display for WorkspaceIdentifier<'_> {
}
}

/// This enum is the params to MoveWindow dispatcher
/// This enum is the params to [DispatchType::MoveWindow] dispatcher
#[derive(Debug, Clone)]
pub enum WindowMove<'a> {
/// Moves the window to a specified monitor
Expand Down Expand Up @@ -325,13 +325,13 @@ pub enum DispatchType<'a> {
MoveWindow(WindowMove<'a>),
/// This dispatcher centers the active window
CenterWindow,
/// This dispatcher resizes the active window using a [`Position`][Position] enum
/// This dispatcher resizes the active window using a [Position] enum
ResizeActive(Position),
/// This dispatcher moves the active window using a [`Position`][Position] enum
/// This dispatcher moves the active window using a [Position] enum
MoveActive(Position),
/// This dispatcher resizes the specified window using a [`Position`][Position] enum
/// This dispatcher resizes the specified window using a [Position] enum
ResizeWindowPixel(Position, WindowIdentifier<'a>),
/// This dispatcher moves the specified window using a [`Position`][Position] enum
/// This dispatcher moves the specified window using a [Position] enum
MoveWindowPixel(Position, WindowIdentifier<'a>),
/// This dispatcher cycles windows using a specified direction
CycleWindow(CycleDirection),
Expand Down Expand Up @@ -438,7 +438,7 @@ pub enum LockType {
ToggleLock,
}

/// Param for [SwapWithMaster] dispatcher
/// Param for [DispatchType::SwapWithMaster] dispatcher
#[derive(Debug, Clone, Display)]
pub enum SwapWithMasterParam {
/// New focus is the new master window
Expand All @@ -452,7 +452,7 @@ pub enum SwapWithMasterParam {
Auto,
}

/// Param for [FocusMaster] dispatcher
/// Param for [DispatchType::FocusMaster] dispatcher
#[derive(Debug, Clone, Display)]
pub enum FocusMasterParam {
/// Focus stays at master, (even if it was selected before)
Expand Down Expand Up @@ -491,7 +491,9 @@ pub(crate) fn gen_dispatch_str(cmd: DispatchType, dispatch: bool) -> crate::Resu
MoveToWorkspace(work, None) => format!("movetoworkspace{sep}{work}"),
MoveToWorkspaceSilent(work, Some(win)) => format!("movetoworkspacesilent{sep}{work},{win}"),
MoveToWorkspaceSilent(work, None) => format!("movetoworkspacesilent{sep}{work}"),
#[allow(deprecated)]
MoveFocusedWindowToWorkspace(work) => format!("movetoworkspace{sep}{work}"),
#[allow(deprecated)]
MoveFocusedWindowToWorkspaceSilent(work) => format!("movetoworkspacesilent{sep}{work}"),
ToggleFloating(Some(v)) => format!("togglefloating{sep}{v}"),
ToggleFloating(None) => "togglefloating".to_string(),
Expand Down
4 changes: 4 additions & 0 deletions src/event_listener/async_im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ impl HasAsyncExecutor for AsyncEventListener {
Event::WindowClosed(addr) => arm_async!(addr.clone(), window_close_events, self),
Event::WindowMoved(even) => arm_async!(even.clone(), window_moved_events, self),
Event::WindowOpened(even) => arm_async!(even.clone(), window_open_events, self),
Event::SpecialRemoved(monitor) => {
arm_async!(monitor.clone(), special_removed_events, self)
}
Event::ChangedSpecial(data) => arm_async!(data.clone(), special_changed_events, self),
Event::LayoutChanged(even) => {
arm_async!(even.clone(), keyboard_layout_change_events, self)
}
Expand Down
2 changes: 2 additions & 0 deletions src/event_listener/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl HasExecutor for EventListener {
WindowClosed(addr) => arm!(addr, window_close_events, self),
WindowMoved(even) => arm!(even, window_moved_events, self),
WindowOpened(even) => arm!(even, window_open_events, self),
SpecialRemoved(monitor) => arm!(monitor, special_removed_events, self),
ChangedSpecial(data) => arm!(data, special_changed_events, self),
LayoutChanged(even) => arm!(even, keyboard_layout_change_events, self),
SubMapChanged(map) => arm!(map, sub_map_changed_events, self),
LayerOpened(namespace) => arm!(namespace, layer_open_events, self),
Expand Down
18 changes: 10 additions & 8 deletions src/event_listener/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! add_listener_reg {
($name:ident $end:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl EventListener {
doc_comment! { concat!("This methods adds a event which ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListener;
let mut listener = EventListener::new();
Expand All @@ -50,7 +50,7 @@ listener.start_listener();"#),
($name:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl EventListener {
doc_comment! { concat!("This methods adds a event which executes when ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListener;
let mut listener = EventListener::new();
Expand All @@ -69,7 +69,7 @@ macro_rules! add_async_listener {
($name:ident $end:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl AsyncEventListener {
doc_comment! { concat!("This methods adds a event which ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListener;
let mut listener = EventListener::new();
Expand All @@ -85,7 +85,7 @@ listener.start_listener();"#),
($name:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl AsyncEventListener {
doc_comment! { concat!("This methods adds a event which executes when ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListener;
let mut listener = EventListener::new();
Expand All @@ -105,7 +105,7 @@ macro_rules! add_mut_async_listener {
($name:ident $end:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl AsyncMutableEventListener {
doc_comment! { concat!("This methods adds a event which ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListener;
let mut listener = EventListener::new();
Expand All @@ -121,7 +121,7 @@ listener.start_listener();"#),
($name:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl AsyncMutableEventListener {
doc_comment! { concat!("This methods adds a event which executes when ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListener;
let mut listener = EventListener::new();
Expand All @@ -140,7 +140,7 @@ macro_rules! mut_add_listener {
($name:ident $end:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl EventListenerMutable {
doc_comment! { concat!("This methods adds a event which ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListenerMutable as EventListener;
let mut listener = EventListener::new();
Expand All @@ -156,7 +156,7 @@ listener.start_listener();"#),
($name:ident,$f:ty,$c:literal,$c2:expr => $id:ident) => {
paste! {
impl EventListenerMutable {
doc_comment! { concat!("This methods adds a event which executes when ", $c, r#"
doc_comment! { concat!("This method adds an event which executes when ", $c, r#"
```rust, no_run
use hyprland::event_listener::EventListenerMutable as EventListener;
let mut listener = EventListener::new();
Expand Down Expand Up @@ -283,6 +283,8 @@ macro_rules! init_events {
window_open_events: vec![],
window_close_events: vec![],
window_moved_events: vec![],
special_removed_events: vec![],
special_changed_events: vec![],
keyboard_layout_change_events: vec![],
sub_map_changed_events: vec![],
layer_open_events: vec![],
Expand Down
8 changes: 5 additions & 3 deletions src/event_listener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ mod immutable;
)]
pub use crate::event_listener::mutable::EventListener as EventListenerMutable;

add_listener!(workspace_change d, WorkspaceType, "on workspace change", "changed workspace to" => id);
add_listener!(workspace_change d, WorkspaceType, "a workspace is changed", "changed workspace to" => id);
add_listener!(workspace_added, WorkspaceType, "a workspace is created", "workspace was added" => id);
add_listener!(workspace_destroy ed, WorkspaceType, "a workspace is destroyed", "workspace was destroyed" => id);
add_listener!(workspace_moved, MonitorEventData, "a workspace is moved", "workspace was moved" => id);
add_listener!(workspace_rename, WorkspaceRenameEventData, "a workspace is renamed", "workspace was renamed" => id);
add_listener!(active_monitor_change d, MonitorEventData, "the active monitor is changed", "Active monitor changed to" => data);
add_listener!(active_window_change d, Option<WindowEventData>, "the active window is changed", "Active window changed" => data);
add_listener!(fullscreen_state_change d, bool, "the active monitor is changed", "Fullscreen is on" => state);
add_listener!(fullscreen_state_change d, bool, "the fullscreen state is changed", "Fullscreen is on" => state);
add_listener!(monitor_added, String, "a new monitor is added", "Monitor added" => data);
add_listener!(monitor_removed, String, "a monitor is removed", "Monitor removed" => data);
add_listener!(window_open, WindowOpenEvent, "a window is opened", "Window opened" => data);
add_listener!(window_close, Address, "a window is closed", "Window closed" => data);
add_listener!(window_moved, WindowMoveEvent, "a window is moved", "Window moved" => data);
add_listener!(special_remove d, String, "a monitor's special workspace is removed", "Special Workspace removed" => monitor);
add_listener!(special_change d, MonitorEventData, "a monitor's special workspace is changed", "Special Workspace changed" => data);
add_listener!(keyboard_layout_change, LayoutEvent, "the keyboard layout is changed", "Layout changed" => data);
add_listener!(sub_map_change d, String, "the sub map is changed", "Submap changed" => data);
add_listener!(sub_map_change d, String, "the submap is changed", "Submap changed" => data);
add_listener!(layer_open, String, "a new layer is opened", "Layer opened" => data);
add_listener!(layer_closed, String, "a layer is closed", "Layer closed" => data);
add_listener!(float_state, WindowFloatEventData, "the float state of a window is changed", "Float state changed" => data);
Expand Down
10 changes: 10 additions & 0 deletions src/event_listener/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ impl HasExecutor for EventListener {
Event::WindowClosed(addr) => mut_arm_sync!(addr.clone(), window_close_events, self),
Event::WindowMoved(even) => mut_arm_sync!(even.clone(), window_moved_events, self),
Event::WindowOpened(even) => mut_arm_sync!(even.clone(), window_open_events, self),
Event::SpecialRemoved(monitor) => {
mut_arm_sync!(monitor.clone(), special_removed_events, self)
}
Event::ChangedSpecial(data) => {
mut_arm_sync!(data.clone(), special_changed_events, self)
}
Event::LayoutChanged(lay) => {
mut_arm_sync!(lay.clone(), keyboard_layout_change_events, self)
}
Expand Down Expand Up @@ -191,6 +197,10 @@ impl EventListener {
Event::WindowMoved(even) => mut_arm!(even.clone(), window_moved_events, self),
Event::WindowOpened(even) => mut_arm!(even.clone(), window_open_events, self),
Event::LayoutChanged(lay) => mut_arm!(lay.clone(), keyboard_layout_change_events, self),
Event::SpecialRemoved(monitor) => {
mut_arm!(monitor.clone(), special_removed_events, self)
}
Event::ChangedSpecial(data) => mut_arm!(data.clone(), special_changed_events, self),
Event::SubMapChanged(map) => mut_arm!(map.clone(), sub_map_changed_events, self),
Event::LayerOpened(even) => mut_arm!(even.clone(), layer_open_events, self),
Event::LayerClosed(even) => mut_arm!(even.clone(), layer_closed_events, self),
Expand Down
31 changes: 28 additions & 3 deletions src/event_listener/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ pub(crate) struct Events {
pub(crate) fullscreen_state_changed_events: Closures<bool>,
pub(crate) monitor_removed_events: Closures<String>,
pub(crate) monitor_added_events: Closures<String>,
pub(crate) special_removed_events: Closures<String>,
pub(crate) special_changed_events: Closures<MonitorEventData>,
pub(crate) keyboard_layout_change_events: Closures<LayoutEvent>,
pub(crate) sub_map_changed_events: Closures<String>,
pub(crate) window_open_events: Closures<WindowOpenEvent>,
Expand All @@ -294,6 +296,8 @@ pub(crate) struct AsyncEvents {
pub(crate) fullscreen_state_changed_events: AsyncClosures<bool>,
pub(crate) monitor_removed_events: AsyncClosures<String>,
pub(crate) monitor_added_events: AsyncClosures<String>,
pub(crate) special_removed_events: AsyncClosures<String>,
pub(crate) special_changed_events: AsyncClosures<MonitorEventData>,
pub(crate) keyboard_layout_change_events: AsyncClosures<LayoutEvent>,
pub(crate) sub_map_changed_events: AsyncClosures<String>,
pub(crate) window_open_events: AsyncClosures<WindowOpenEvent>,
Expand Down Expand Up @@ -532,7 +536,7 @@ pub struct WindowEventData {
unsafe impl Send for WindowEventData {}
#[allow(unsafe_code)]
unsafe impl Sync for WindowEventData {}
/// This tuple struct holds monitor event data
/// This struct holds monitor event data
#[derive(Debug, Clone)]
pub struct MonitorEventData {
/// The monitor name
Expand All @@ -545,7 +549,8 @@ pub struct MonitorEventData {
unsafe impl Send for MonitorEventData {}
#[allow(unsafe_code)]
unsafe impl Sync for MonitorEventData {}
/// This tuple struct holds monitor event data

/// This struct holds monitor event data
#[derive(Debug, Clone)]
pub struct WindowFloatEventData {
/// The window address
Expand Down Expand Up @@ -576,6 +581,8 @@ pub(crate) enum Event {
WindowOpened(WindowOpenEvent),
WindowClosed(Address),
WindowMoved(WindowMoveEvent),
SpecialRemoved(String),
ChangedSpecial(MonitorEventData),
LayoutChanged(LayoutEvent),
SubMapChanged(String),
LayerOpened(String),
Expand Down Expand Up @@ -647,6 +654,7 @@ enum ParsedEventType {
WindowOpened,
WindowClosed,
WindowMoved,
ActiveSpecial,
LayoutChanged,
SubMapChanged,
LayerOpened,
Expand Down Expand Up @@ -723,6 +731,10 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
ParsedEventType::LayoutChanged,
r"activelayout>>(?P<keyboard>.*)(?P<layout>.*)"
),
(
ParsedEventType::ActiveSpecial,
r"activespecial>>(?P<workspace>.*),(?P<monitor>.*)"
),
(ParsedEventType::SubMapChanged, r"submap>>(?P<submap>.*)"),
(
ParsedEventType::LayerOpened,
Expand Down Expand Up @@ -793,7 +805,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
_ => {
return Err(HyprError::IoError(io::Error::new(
io::ErrorKind::InvalidData,
"Event matched more than one regex (not a unknown event issue!)",
"Event matched more than one regex (not an unknown event issue!)",
)));
}
};
Expand Down Expand Up @@ -898,6 +910,19 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
workspace_name: work.to_string(),
}));
}
ParsedEventType::ActiveSpecial => {
let work = &captures["workspace"];
if work.is_empty() {
events.push(Event::SpecialRemoved(work.to_string()));
} else {
let workspace = parse_string_as_work(work.to_string());
let monitor = &captures["monitor"];
events.push(Event::ChangedSpecial(MonitorEventData {
monitor_name: monitor.to_string(),
workspace,
}));
}
}
ParsedEventType::LayoutChanged => {
let keyboard_name = &captures["keyboard"];
let layout = &captures["layout"];
Expand Down
2 changes: 1 addition & 1 deletion src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module provides shared private and public functions, structs, enum, and types
pub use async_trait::async_trait;
use derive_more::Display;
use serde::{Deserialize, Deserializer, Serialize};
use serde::{Deserialize, Serialize};
use std::env::{var, VarError};
use std::hash::{Hash, Hasher};
use std::{error, fmt, io};
Expand Down

0 comments on commit cd47a74

Please sign in to comment.