Skip to content

Commit 8cb6d15

Browse files
authored
WorkspaceSystem: sort windows by time they appeared on the workspace (#388)
1 parent 59919f6 commit 8cb6d15

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/WindowSystem/Window.vala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Dock.Window : GLib.Object {
1010
public string app_id { get; private set; default = ""; }
1111
public bool has_focus { get; private set; default = false; }
1212
public int workspace_index { get; private set; default = 0; }
13+
public int64 time_appeared_on_workspace { get; private set; default = 0; }
1314
public bool on_active_workspace { get; private set; default = false; }
1415

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

35+
if ("time-appeared-on-workspace" in properties) {
36+
time_appeared_on_workspace = (int64) properties["time-appeared-on-workspace"];
37+
}
38+
3439
if ("on-active-workspace" in properties) {
3540
on_active_workspace = (bool) properties["on-active-workspace"];
3641
}

src/WorkspaceSystem/WorkspaceSystem.vala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ public class Dock.WorkspaceSystem : Object {
6464
workspace = add_workspace ();
6565
}
6666

67+
workspace_window_list[i].sort (compare_func);
68+
6769
workspace.windows = workspace_window_list[i];
6870
workspace.index = i;
6971
workspace.update_active_workspace ();
7072
}
7173
}
7274

75+
private int compare_func (Window a, Window b) {
76+
return (int) (a.time_appeared_on_workspace - b.time_appeared_on_workspace);
77+
}
78+
7379
private async void sync_active_workspace () {
7480
foreach (var workspace in workspaces) {
7581
workspace.update_active_workspace ();

0 commit comments

Comments
 (0)