From 5a056746ae7cf3a058a0a497944e05207b4d0aa5 Mon Sep 17 00:00:00 2001 From: wenjin Date: Mon, 17 Jun 2024 09:35:17 +0800 Subject: [PATCH] fix: active workspace sync error Related #449 Use hyprland socket2 event to update active workspace now. on my PC it doesn't cause Resource temporarily unavailable issue now. --- src/service/hyprland.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/service/hyprland.ts b/src/service/hyprland.ts index fe6e2209..757c5f76 100644 --- a/src/service/hyprland.ts +++ b/src/service/hyprland.ts @@ -223,9 +223,7 @@ export class Hyprland extends Service { this._monitors.set(m.id, m); if (m.focused) { this._active.monitor.update(m.id, m.name); - this._active.workspace.update(m.activeWorkspace.id, m.activeWorkspace.name); this._active.monitor.emit('changed'); - this._active.workspace.emit('changed'); } } if (notify) @@ -235,6 +233,17 @@ export class Hyprland extends Service { } } + private _updateActiveWorksapce(id: number, name: string, notify = true) { + try { + this._active.workspace.update(id, name); + this._active.workspace.emit('changed'); + if (notify) + this.notify('workspaces'); + } catch (error) { + logError(error); + } + } + private async _syncWorkspaces(notify = true) { try { const msg = await this.messageAsync('j/workspaces'); @@ -272,7 +281,9 @@ export class Hyprland extends Service { try { switch (e) { - case 'workspace': + case 'workspacev2': + this._updateActiveWorksapce(Number(argv[0]), argv[1]); + break; case 'focusedmon': await this._syncMonitors(); break;