Skip to content

Commit

Permalink
WorkspaceSystem: sort windows by the time they appeared on workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter committed Feb 18, 2025
1 parent d4e4198 commit a63f1bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/WindowSystem/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Dock.Window : GLib.Object {
public string app_id { get; private set; default = ""; }
public bool has_focus { get; private set; default = false; }
public int workspace_index { get; private set; default = 0; }
public int64 time_appeared_on_workspace { get; private set; default = 0; }
public bool on_active_workspace { get; private set; default = false; }

public GLib.Icon icon { get; private set; default = new GLib.ThemedIcon ("application-default-icon"); }
Expand All @@ -31,6 +32,10 @@ public class Dock.Window : GLib.Object {
workspace_index = (int) properties["workspace-index"];
}

if ("time-appeared-on-workspace" in properties) {
time_appeared_on_workspace = (int64) properties["time-appeared-on-workspace"];
}

if ("on-active-workspace" in properties) {
on_active_workspace = (bool) properties["on-active-workspace"];
}
Expand Down
8 changes: 8 additions & 0 deletions src/WorkspaceSystem/WorkspaceSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class Dock.WorkspaceSystem : Object {
workspace_window_list[workspace_index].add (window);
}



// update windows in existing workspaces
for (var i = 0; i < n_workspaces; i++) {
Workspace workspace;
Expand All @@ -64,12 +66,18 @@ public class Dock.WorkspaceSystem : Object {
workspace = add_workspace ();
}

workspace_window_list[i].sort (compare_func);

workspace.windows = workspace_window_list[i];
workspace.index = i;
workspace.update_active_workspace ();
}
}

private int compare_func (Window a, Window b) {
return (int) (a.time_appeared_on_workspace - b.time_appeared_on_workspace);
}

private async void sync_active_workspace () {
foreach (var workspace in workspaces) {
workspace.update_active_workspace ();
Expand Down

0 comments on commit a63f1bb

Please sign in to comment.