Skip to content

Commit

Permalink
Fix removing workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter committed Feb 17, 2025
1 parent f0707b0 commit b5e81f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/WindowSystem/DesktopIntegration.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface Dock.DesktopIntegration : GLib.Object {
public signal void running_applications_changed ();
public signal void windows_changed ();
public signal void active_workspace_changed ();
public signal void workspace_removed (int index);

public abstract async RunningApplication[] get_running_applications () throws GLib.DBusError, GLib.IOError;
public abstract async Window[] get_windows () throws GLib.DBusError, GLib.IOError;
Expand Down
3 changes: 3 additions & 0 deletions src/WindowSystem/WindowSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
return instance.once (() => { return new WindowSystem (); });
}

public signal void workspace_removed (int index);

public DesktopIntegration? desktop_integration { get; private set; }
public Gee.List<Window> windows { get; private owned set; }
public int active_workspace { get; private set; default = 0; }
Expand All @@ -33,6 +35,7 @@

desktop_integration.windows_changed.connect (sync_windows);
desktop_integration.active_workspace_changed.connect (sync_active_workspace);
desktop_integration.workspace_removed.connect ((index) => workspace_removed (index));
} catch (Error e) {
critical ("Failed to get desktop integration: %s", e.message);
}
Expand Down
48 changes: 27 additions & 21 deletions src/WorkspaceSystem/WorkspaceSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,19 @@ public class Dock.WorkspaceSystem : Object {

WindowSystem.get_default ().notify["windows"].connect (sync_windows);
WindowSystem.get_default ().notify["active-workspace"].connect (sync_active_workspace);
WindowSystem.get_default ().workspace_removed.connect (remove_workspace);
}

private Workspace add_workspace () {
var workspace = new Workspace ();
workspaces.add (workspace);
workspace.removed.connect_after ((_workspace) => {
workspaces.remove (_workspace);
workspace_removed ();
});
workspace_added (workspace);
return workspace;
}

private async void sync_windows () {
if (WindowSystem.get_default ().desktop_integration == null) {
return;
}

int n_workspaces;
try {
// We subtract 1 because we have separate button for dynamic workspace
n_workspaces = (yield WindowSystem.get_default ().desktop_integration.get_n_workspaces ()) - 1;
} catch (Error e) {
critical (e.message);
return;
}
// We subtract 1 because we have separate button for dynamic workspace
var n_workspaces = (yield get_n_workspaces ()) - 1;

var workspace_window_list = new Gee.ArrayList<Gee.List<Window>> ();
for (var i = 0; i < n_workspaces; i++) {
Expand All @@ -68,11 +55,6 @@ public class Dock.WorkspaceSystem : Object {
workspace_window_list[workspace_index].add (window);
}

// cleanup extra workspaces
for (var i = n_workspaces; i < workspaces.size; i++) {
workspaces[i].remove ();
}

// update windows in existing workspaces
for (var i = 0; i < n_workspaces; i++) {
Workspace workspace;
Expand All @@ -93,4 +75,28 @@ public class Dock.WorkspaceSystem : Object {
workspace.update_active_workspace ();
}
}

private async void remove_workspace (int index) {
if (index == (yield get_n_workspaces ())) {
index--;
}

workspaces[index].remove ();
workspaces.remove_at (index);
workspace_removed ();
}

private async int get_n_workspaces () {
if (WindowSystem.get_default ().desktop_integration == null) {
critical ("DesktopIntegration is null");
return 0;
}

try {
return yield WindowSystem.get_default ().desktop_integration.get_n_workspaces ();
} catch (Error e) {
critical (e.message);
return 0;
}
}
}

0 comments on commit b5e81f5

Please sign in to comment.