Skip to content

Commit 3a2317b

Browse files
committed
Add 'time-appeared-on-workspace' property
1 parent 75a4e56 commit 3a2317b

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/DesktopIntegration.vala

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,46 @@ public class Gala.DesktopIntegration : GLib.Object {
1616
GLib.HashTable<unowned string, Variant> properties;
1717
}
1818

19-
private unowned WindowManagerGala wm;
2019
public uint version { get; default = 1; }
2120
public signal void running_applications_changed ();
2221
public signal void windows_changed ();
22+
public signal void active_workspace_changed ();
23+
public signal void workspace_removed (int index);
24+
25+
private unowned WindowManagerGala wm;
26+
private GLib.HashTable<Meta.Window, int64?> time_appeared_on_workspace;
2327

2428
public DesktopIntegration (WindowManagerGala wm) {
2529
this.wm = wm;
30+
time_appeared_on_workspace = new GLib.HashTable<Meta.Window, int64?> (GLib.direct_hash, GLib.direct_equal);
31+
2632
wm.window_tracker.windows_changed.connect (() => windows_changed ());
27-
wm.get_display ().get_workspace_manager ().active_workspace_changed.connect (() => windows_changed ());
33+
workspace_manager.active_workspace_changed.connect (() => {
34+
active_workspace_changed ();
35+
windows_changed (); // windows have 'on-active-workspace' property that we need to update
36+
});
37+
workspace_manager.workspaces_reordered.connect (() => windows_changed ());
38+
workspace_manager.workspace_added.connect (() => windows_changed ());
39+
workspace_manager.workspace_removed.connect ((index) => {
40+
workspace_removed (index);
41+
windows_changed ();
42+
});
43+
44+
// TODO: figure out if there's a better way to handle ws rearrangement
45+
display.window_created.connect ((window) => {
46+
time_appeared_on_workspace[window] = GLib.get_real_time ();
47+
48+
window.workspace_changed.connect ((_window) => {
49+
time_appeared_on_workspace[_window] = GLib.get_real_time ();
50+
windows_changed ();
51+
});
52+
53+
window.unmanaging.connect ((_window) => {
54+
time_appeared_on_workspace.remove (_window);
55+
});
56+
});
2857
}
2958

30-
public RunningApplication[] get_running_applications () throws GLib.DBusError, GLib.IOError {
3159
RunningApplication[] returned_apps = {};
3260
var apps = Gala.AppSystem.get_default ().get_running_apps ();
3361
foreach (unowned var app in apps) {
@@ -97,6 +125,10 @@ public class Gala.DesktopIntegration : GLib.Object {
97125
properties.insert ("sandboxed-app-id", new GLib.Variant.string (sandboxed_app_id));
98126
}
99127

128+
if (window in time_appeared_on_workspace && time_appeared_on_workspace[window] != null) {
129+
properties.insert ("time-appeared-on-workspace", new GLib.Variant.int64 (time_appeared_on_workspace[window]));
130+
}
131+
100132
returned_windows += Window () {
101133
uid = window.get_id (),
102134
properties = properties

0 commit comments

Comments
 (0)