Skip to content

Commit

Permalink
refactor(event listener)!: use removeworkspacev2 event
Browse files Browse the repository at this point in the history
This changes the rename workspace handler to listen to the
`removeworkspacev2` event in place of `removeworkspace`,
which returns the ID and name of the removed workspace.
The previous event only returned the name.
  • Loading branch information
JakeStanger committed May 6, 2024
1 parent 58cef58 commit f9228e3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/event_listener/async_im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/event_listener/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/event_listener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 17 additions & 11 deletions src/event_listener/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub(crate) type AsyncClosures<T> = Vec<AsyncClosure<T>>;
pub(crate) struct Events {
pub(crate) workspace_changed_events: Closures<WorkspaceType>,
pub(crate) workspace_added_events: Closures<WorkspaceType>,
pub(crate) workspace_destroyed_events: Closures<WorkspaceType>,
pub(crate) workspace_destroyed_events: Closures<WorkspaceDestroyedEventData>,
pub(crate) workspace_moved_events: Closures<MonitorEventData>,
pub(crate) workspace_rename_events: Closures<WorkspaceRenameEventData>,
pub(crate) active_monitor_changed_events: Closures<MonitorEventData>,
Expand All @@ -253,7 +253,7 @@ pub(crate) struct Events {
pub(crate) struct AsyncEvents {
pub(crate) workspace_changed_events: AsyncClosures<WorkspaceType>,
pub(crate) workspace_added_events: AsyncClosures<WorkspaceType>,
pub(crate) workspace_destroyed_events: AsyncClosures<WorkspaceType>,
pub(crate) workspace_destroyed_events: AsyncClosures<WorkspaceDestroyedEventData>,
pub(crate) workspace_moved_events: AsyncClosures<MonitorEventData>,
pub(crate) workspace_rename_events: AsyncClosures<WorkspaceRenameEventData>,
pub(crate) active_monitor_changed_events: AsyncClosures<MonitorEventData>,
Expand All @@ -275,6 +275,15 @@ pub(crate) struct AsyncEvents {
pub(crate) screencast_events: AsyncClosures<ScreencastEventData>,
}

/// 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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -520,7 +529,7 @@ static CHECK_TABLE: Lazy<Mutex<HashSet<String>>> = Lazy::new(|| Mutex::new(HashS
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
enum ParsedEventType {
WorkspaceChanged,
WorkspaceDeleted,
WorkspaceDeletedV2,
WorkspaceAdded,
WorkspaceMoved,
WorkspaceRename,
Expand Down Expand Up @@ -551,10 +560,10 @@ static EVENT_SET: Lazy<Box<[(ParsedEventType, Regex)]>> = Lazy::new(|| {
(
ParsedEventType::WorkspaceChanged,
r"\bworkspace>>(?P<workspace>.*)",
),
),
(
ParsedEventType::WorkspaceDeleted,
r"destroyworkspace>>(?P<workspace>.*)",
ParsedEventType::WorkspaceDeletedV2,
r"destroyworkspacev2>>(?P<id>.*),(?P<name>.*)",
),
(
ParsedEventType::WorkspaceAdded,
Expand Down Expand Up @@ -714,10 +723,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
};
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::<WorkspaceId>().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(),
))),
Expand Down
4 changes: 2 additions & 2 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn init_socket_path(socket_type: SocketType) -> crate::Result<PathBuf> {
hypr_err!("Corrupted Hyprland socket variable: Invalid unicode!")
}
};

let mut p: PathBuf;
fn var_path(instance: String) -> Option<PathBuf> {
if let Ok(runtime_path) = var("XDG_RUNTIME_DIR") {
Expand Down Expand Up @@ -364,7 +364,7 @@ fn init_socket_path(socket_type: SocketType) -> crate::Result<PathBuf> {
} else {
hypr_err!("No xdg runtime path found!")
}

p.push(socket_type.socket_name());
Ok(p)
}
Expand Down

0 comments on commit f9228e3

Please sign in to comment.