From cd47a74b158992bd716d5387aba8de58015b6e86 Mon Sep 17 00:00:00 2001 From: yavko Date: Sat, 24 Feb 2024 17:46:41 -0800 Subject: [PATCH] Fix horrible docs & Add active special events --- src/data/regular.rs | 2 ++ src/dispatch.rs | 16 +++++++++------- src/event_listener/async_im.rs | 4 ++++ src/event_listener/immutable.rs | 2 ++ src/event_listener/macros.rs | 18 ++++++++++-------- src/event_listener/mod.rs | 8 +++++--- src/event_listener/mutable.rs | 10 ++++++++++ src/event_listener/shared.rs | 31 ++++++++++++++++++++++++++++--- src/shared.rs | 2 +- 9 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/data/regular.rs b/src/data/regular.rs index a4b1e3a..dfb96a8 100644 --- a/src/data/regular.rs +++ b/src/data/regular.rs @@ -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), diff --git a/src/dispatch.rs b/src/dispatch.rs index 7f5ec38..ae84bba 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -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 @@ -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), @@ -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 @@ -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) @@ -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(), diff --git a/src/event_listener/async_im.rs b/src/event_listener/async_im.rs index aa33eb6..3288289 100644 --- a/src/event_listener/async_im.rs +++ b/src/event_listener/async_im.rs @@ -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) } diff --git a/src/event_listener/immutable.rs b/src/event_listener/immutable.rs index df67271..6ae65fd 100644 --- a/src/event_listener/immutable.rs +++ b/src/event_listener/immutable.rs @@ -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), diff --git a/src/event_listener/macros.rs b/src/event_listener/macros.rs index 24c1a4f..b576f02 100644 --- a/src/event_listener/macros.rs +++ b/src/event_listener/macros.rs @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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![], diff --git a/src/event_listener/mod.rs b/src/event_listener/mod.rs index 8f9943e..3402356 100644 --- a/src/event_listener/mod.rs +++ b/src/event_listener/mod.rs @@ -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, "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); diff --git a/src/event_listener/mutable.rs b/src/event_listener/mutable.rs index da2b443..a68c436 100644 --- a/src/event_listener/mutable.rs +++ b/src/event_listener/mutable.rs @@ -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) } @@ -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), diff --git a/src/event_listener/shared.rs b/src/event_listener/shared.rs index 9a85019..906eae4 100644 --- a/src/event_listener/shared.rs +++ b/src/event_listener/shared.rs @@ -268,6 +268,8 @@ pub(crate) struct Events { pub(crate) fullscreen_state_changed_events: Closures, pub(crate) monitor_removed_events: Closures, pub(crate) monitor_added_events: Closures, + pub(crate) special_removed_events: Closures, + pub(crate) special_changed_events: Closures, pub(crate) keyboard_layout_change_events: Closures, pub(crate) sub_map_changed_events: Closures, pub(crate) window_open_events: Closures, @@ -294,6 +296,8 @@ pub(crate) struct AsyncEvents { pub(crate) fullscreen_state_changed_events: AsyncClosures, pub(crate) monitor_removed_events: AsyncClosures, pub(crate) monitor_added_events: AsyncClosures, + pub(crate) special_removed_events: AsyncClosures, + pub(crate) special_changed_events: AsyncClosures, pub(crate) keyboard_layout_change_events: AsyncClosures, pub(crate) sub_map_changed_events: AsyncClosures, pub(crate) window_open_events: AsyncClosures, @@ -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 @@ -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 @@ -576,6 +581,8 @@ pub(crate) enum Event { WindowOpened(WindowOpenEvent), WindowClosed(Address), WindowMoved(WindowMoveEvent), + SpecialRemoved(String), + ChangedSpecial(MonitorEventData), LayoutChanged(LayoutEvent), SubMapChanged(String), LayerOpened(String), @@ -647,6 +654,7 @@ enum ParsedEventType { WindowOpened, WindowClosed, WindowMoved, + ActiveSpecial, LayoutChanged, SubMapChanged, LayerOpened, @@ -723,6 +731,10 @@ pub(crate) fn event_parser(event: String) -> crate::Result> { ParsedEventType::LayoutChanged, r"activelayout>>(?P.*)(?P.*)" ), + ( + ParsedEventType::ActiveSpecial, + r"activespecial>>(?P.*),(?P.*)" + ), (ParsedEventType::SubMapChanged, r"submap>>(?P.*)"), ( ParsedEventType::LayerOpened, @@ -793,7 +805,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result> { _ => { 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!)", ))); } }; @@ -898,6 +910,19 @@ pub(crate) fn event_parser(event: String) -> crate::Result> { 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"]; diff --git a/src/shared.rs b/src/shared.rs index 4dadbe8..f3c2a86 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -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};