11/*
2- * Copyright 2022 elementary, Inc. <https://elementary.io>
2+ * Copyright 2022-2025 elementary, Inc. <https://elementary.io>
33 * Copyright 2022 Corentin Noël <[email protected] > 44 * SPDX-License-Identifier: GPL-3.0-or-later
55 */
@@ -21,7 +21,6 @@ public class Gala.DesktopIntegration : GLib.Object {
2121 public signal void windows_changed ();
2222 public signal void active_workspace_changed ();
2323 public signal void workspace_removed (int index );
24-
2524 private unowned WindowManagerGala wm;
2625 private GLib . HashTable<Meta . Window , int64 ? > time_appeared_on_workspace;
2726
@@ -30,6 +29,9 @@ public class Gala.DesktopIntegration : GLib.Object {
3029 time_appeared_on_workspace = new GLib .HashTable<Meta . Window , int64?> (GLib . direct_hash, GLib . direct_equal);
3130
3231 wm. window_tracker. windows_changed. connect (() = > windows_changed ());
32+
33+ unowned var display = wm. get_display ();
34+ unowned var workspace_manager = display. get_workspace_manager ();
3335 workspace_manager. active_workspace_changed. connect (() = > {
3436 active_workspace_changed ();
3537 windows_changed (); // windows have 'on-active-workspace' property that we need to update
@@ -53,6 +55,8 @@ public class Gala.DesktopIntegration : GLib.Object {
5355 window. unmanaging. connect ((_window) = > {
5456 time_appeared_on_workspace. remove (_window);
5557 });
58+
59+ window. workspace_changed. connect (() = > windows_changed ());
5660 });
5761 }
5862
@@ -91,7 +95,7 @@ public class Gala.DesktopIntegration : GLib.Object {
9195 public Window [] get_windows () throws GLib . DBusError , GLib . IOError {
9296 Window [] returned_windows = {};
9397 var apps = Gala . AppSystem . get_default (). get_running_apps ();
94- var active_workspace = wm. get_display (). get_workspace_manager (). get_active_workspace ();
98+ unowned var active_workspace = wm. get_display (). get_workspace_manager (). get_active_workspace ();
9599 foreach (unowned var app in apps) {
96100 foreach (weak Meta . Window window in app. get_windows ()) {
97101 if (! is_eligible_window (window)) {
@@ -109,6 +113,7 @@ public class Gala.DesktopIntegration : GLib.Object {
109113 properties. insert (" is-hidden" , new GLib .Variant .boolean (window. is_hidden ()));
110114 properties. insert (" has-focus" , new GLib .Variant .boolean (window. has_focus ()));
111115 properties. insert (" on-active-workspace" , new GLib .Variant .boolean (window. located_on_workspace (active_workspace)));
116+ properties. insert (" workspace-index" , new GLib .Variant .int32 (window. get_workspace (). index ()));
112117 properties. insert (" width" , new GLib .Variant .uint32 (frame_rect. width));
113118 properties. insert (" height" , new GLib .Variant .uint32 (frame_rect. height));
114119
@@ -154,6 +159,29 @@ public class Gala.DesktopIntegration : GLib.Object {
154159 }
155160 }
156161
162+ public void activate_workspace (int index) throws GLib . DBusError , GLib . IOError {
163+ unowned var workspace = wm. get_display (). get_workspace_manager (). get_workspace_by_index (index);
164+ if (workspace == null ) {
165+ throw new IOError .NOT_FOUND (" Workspace not found" );
166+ }
167+
168+ unowned var display = wm. get_display ();
169+ unowned var active_workspace_index = display. get_workspace_manager (). get_active_workspace_index ();
170+ if (active_workspace_index == index) {
171+ InternalUtils . bell_notify (display);
172+ } else {
173+ workspace. activate (display. get_current_time ());
174+ }
175+ }
176+
177+ public int get_n_workspaces () throws GLib . DBusError , GLib . IOError {
178+ return wm. get_display (). get_workspace_manager (). n_workspaces;
179+ }
180+
181+ public int get_active_workspace () throws GLib . DBusError , GLib . IOError {
182+ return wm. get_display (). get_workspace_manager (). get_active_workspace_index ();
183+ }
184+
157185 private bool notifying = false ;
158186 private void notify_already_focused (Meta . Window window) {
159187 if (notifying) {
0 commit comments