diff --git a/src/event_listener/async_im.rs b/src/event_listener/async_im.rs index 5e902d9..0be2577 100644 --- a/src/event_listener/async_im.rs +++ b/src/event_listener/async_im.rs @@ -32,7 +32,9 @@ impl HasAsyncExecutor for AsyncEventListener { match event { Event::WorkspaceChanged(id) => arm_async!(id, workspace_changed_events, self), Event::WorkspaceAdded(id) => arm_async!(id, workspace_added_events, self), - Event::WorkspaceDeleted(id) => arm_async!(id, workspace_destroyed_events, self), + Event::WorkspaceDeleted(data) => { + arm_async!(data, workspace_destroyed_events, self) + } Event::WorkspaceMoved(evend) => arm_async!(evend, workspace_moved_events, self), Event::WorkspaceRename(even) => arm_async!(even, workspace_rename_events, self), Event::ActiveMonitorChanged(evend) => { diff --git a/src/event_listener/immutable.rs b/src/event_listener/immutable.rs index ed79206..59311c5 100644 --- a/src/event_listener/immutable.rs +++ b/src/event_listener/immutable.rs @@ -31,7 +31,7 @@ impl HasExecutor for EventListener { match event { WorkspaceChanged(id) => arm!(id, workspace_changed_events, self), WorkspaceAdded(id) => arm!(id, workspace_added_events, self), - WorkspaceDeleted(id) => arm!(id, workspace_destroyed_events, self), + WorkspaceDeleted(data) => arm!(data, workspace_destroyed_events, self), WorkspaceMoved(evend) => arm!(evend, workspace_moved_events, self), WorkspaceRename(even) => arm!(even, workspace_rename_events, self), ActiveMonitorChanged(evend) => arm!(evend, active_monitor_changed_events, self), diff --git a/src/event_listener/mod.rs b/src/event_listener/mod.rs index 2aa8b5d..57545d8 100644 --- a/src/event_listener/mod.rs +++ b/src/event_listener/mod.rs @@ -14,7 +14,7 @@ pub use crate::event_listener::async_im::AsyncEventListener; add_listener!(workspace_change d, WorkspaceType, "on workspace change", "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_destroy ed, WorkspaceDestroyedEventData, "a workspace is destroyed", "a workspace was destroyed" => data); 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); diff --git a/src/event_listener/shared.rs b/src/event_listener/shared.rs index f356611..84feaa5 100644 --- a/src/event_listener/shared.rs +++ b/src/event_listener/shared.rs @@ -227,7 +227,7 @@ pub(crate) type AsyncClosures = Vec>; pub(crate) struct Events { pub(crate) workspace_changed_events: Closures, pub(crate) workspace_added_events: Closures, - pub(crate) workspace_destroyed_events: Closures, + pub(crate) workspace_destroyed_events: Closures, pub(crate) workspace_moved_events: Closures, pub(crate) workspace_rename_events: Closures, pub(crate) active_monitor_changed_events: Closures, @@ -253,7 +253,7 @@ pub(crate) struct Events { pub(crate) struct AsyncEvents { pub(crate) workspace_changed_events: AsyncClosures, pub(crate) workspace_added_events: AsyncClosures, - pub(crate) workspace_destroyed_events: AsyncClosures, + pub(crate) workspace_destroyed_events: AsyncClosures, pub(crate) workspace_moved_events: AsyncClosures, pub(crate) workspace_rename_events: AsyncClosures, pub(crate) active_monitor_changed_events: AsyncClosures, @@ -275,6 +275,15 @@ pub(crate) struct AsyncEvents { pub(crate) screencast_events: AsyncClosures, } +/// Event data for destroyworkspacev2 event +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct WorkspaceDestroyedEventData { + /// Workspace Id + pub workspace_id: WorkspaceId, + /// Workspace name + pub workspace_name: String, +} + /// Event data for renameworkspace event #[derive(Debug, Clone, PartialEq, Eq)] pub struct WorkspaceRenameEventData { @@ -451,7 +460,7 @@ pub struct WindowFloatEventData { #[derive(Debug, Clone)] pub(crate) enum Event { WorkspaceChanged(WorkspaceType), - WorkspaceDeleted(WorkspaceType), + WorkspaceDeleted(WorkspaceDestroyedEventData), WorkspaceAdded(WorkspaceType), WorkspaceMoved(MonitorEventData), WorkspaceRename(WorkspaceRenameEventData), @@ -520,7 +529,7 @@ static CHECK_TABLE: Lazy>> = Lazy::new(|| Mutex::new(HashS #[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] enum ParsedEventType { WorkspaceChanged, - WorkspaceDeleted, + WorkspaceDeletedV2, WorkspaceAdded, WorkspaceMoved, WorkspaceRename, @@ -551,10 +560,10 @@ static EVENT_SET: Lazy> = Lazy::new(|| { ( ParsedEventType::WorkspaceChanged, r"\bworkspace>>(?P.*)", - ), + ), ( - ParsedEventType::WorkspaceDeleted, - r"destroyworkspace>>(?P.*)", + ParsedEventType::WorkspaceDeletedV2, + r"destroyworkspacev2>>(?P.*),(?P.*)", ), ( ParsedEventType::WorkspaceAdded, @@ -714,10 +723,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result> { }; Ok(Event::WorkspaceChanged(workspace)) } - ParsedEventType::WorkspaceDeleted => Ok(Event::WorkspaceDeleted(parse_string_as_work( - captures["workspace"].to_string(), - ))), - + ParsedEventType::WorkspaceDeletedV2 => Ok(Event::WorkspaceDeleted(WorkspaceDestroyedEventData { workspace_id: captures["id"].parse::().map_err(|e| HyprError::Internal(format!("Workspace delete v2: invalid integer error: {e}")))?, workspace_name: captures["name"].to_string() })), ParsedEventType::WorkspaceAdded => Ok(Event::WorkspaceAdded(parse_string_as_work( captures["workspace"].to_string(), ))), diff --git a/src/shared.rs b/src/shared.rs index f7aa918..f9ec13e 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -330,7 +330,7 @@ fn init_socket_path(socket_type: SocketType) -> crate::Result { hypr_err!("Corrupted Hyprland socket variable: Invalid unicode!") } }; - + let mut p: PathBuf; fn var_path(instance: String) -> Option { if let Ok(runtime_path) = var("XDG_RUNTIME_DIR") { @@ -364,7 +364,7 @@ fn init_socket_path(socket_type: SocketType) -> crate::Result { } else { hypr_err!("No xdg runtime path found!") } - + p.push(socket_type.socket_name()); Ok(p) }