Skip to content

Commit

Permalink
Add window spread for an app (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jan 21, 2024
1 parent 2bf7197 commit bd300d9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
25 changes: 10 additions & 15 deletions src/DBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace Gala {
[DBus (name="org.pantheon.gala")]
public class DBus {
private static DBus? instance;
private static WindowManager wm;
private static WindowManagerGala wm;

[DBus (visible = false)]
public static void init (WindowManager _wm) {
public static void init (WindowManagerGala _wm) {
wm = _wm;

Bus.own_name (BusType.SESSION, "org.pantheon.gala", BusNameOwnerFlags.NONE,
Expand Down Expand Up @@ -65,19 +65,14 @@ namespace Gala {
() => {},
() => critical ("Could not acquire name") );

unowned WindowManagerGala? gala_wm = wm as WindowManagerGala;
if (gala_wm != null) {
var screensaver_manager = gala_wm.screensaver;

Bus.own_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameOwnerFlags.REPLACE,
(connection) => {
try {
connection.register_object ("/org/gnome/ScreenSaver", screensaver_manager);
} catch (Error e) { warning (e.message); }
},
() => {},
() => critical ("Could not acquire ScreenSaver bus") );
}
Bus.own_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameOwnerFlags.REPLACE,
(connection) => {
try {
connection.register_object ("/org/gnome/ScreenSaver", wm.screensaver);
} catch (Error e) { warning (e.message); }
},
() => {},
() => critical ("Could not acquire ScreenSaver bus") );
}

private DBus () {
Expand Down
34 changes: 28 additions & 6 deletions src/DesktopIntegration.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ public class Gala.DesktopIntegration : GLib.Object {
GLib.HashTable<unowned string, Variant> properties;
}

private unowned WindowManager wm;
private unowned WindowManagerGala wm;
public uint version { get; default = 1; }
public signal void running_applications_changed ();
public signal void windows_changed ();

public DesktopIntegration (WindowManager wm) {
public DesktopIntegration (WindowManagerGala wm) {
this.wm = wm;
unowned WindowManagerGala? gala_wm = wm as WindowManagerGala;
if (gala_wm != null) {
gala_wm.window_tracker.windows_changed.connect (() => windows_changed ());
}
wm.window_tracker.windows_changed.connect (() => windows_changed ());
}

public RunningApplication[] get_running_applications () throws GLib.DBusError, GLib.IOError {
Expand Down Expand Up @@ -102,4 +99,29 @@ public class Gala.DesktopIntegration : GLib.Object {

return (owned) returned_windows;
}

public void show_windows_for (string app_id) throws IOError, DBusError {
if (wm.window_overview == null) {
throw new IOError.FAILED ("Window overview not provided by window manager");
}

App app;
if ((app = AppSystem.get_default ().lookup_app (app_id)) == null) {
throw new IOError.NOT_FOUND ("App not found");
}

uint64[] window_ids = {};
foreach (var window in app.get_windows ()) {
window_ids += window.get_id ();
}

var hints = new HashTable<string, Variant> (str_hash, str_equal);
hints["windows"] = window_ids;

if (wm.window_overview.is_opened ()) {
wm.window_overview.close ();
}

wm.window_overview.open (hints);
}
}
9 changes: 8 additions & 1 deletion src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent {
workspaces.append (workspace);
}

uint64[]? window_ids = null;
if (hints != null && "windows" in hints) {
window_ids = (uint64[]) hints["windows"];
}

var windows = new List<Meta.Window> ();
foreach (var workspace in workspaces) {
foreach (unowned var window in workspace.list_windows ()) {
Expand All @@ -85,7 +90,9 @@ public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent {

if (window.window_type != Meta.WindowType.NORMAL &&
window.window_type != Meta.WindowType.DIALOG ||
window.is_attached_dialog ()) {
window.is_attached_dialog () ||
(window_ids != null && !(window.get_id () in window_ids))
) {
unowned var actor = (Meta.WindowActor) window.get_compositor_private ();
actor.hide ();

Expand Down
3 changes: 2 additions & 1 deletion src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ namespace Gala {
private Meta.PluginInfo info;

private WindowSwitcher? window_switcher = null;
private ActivatableComponent? window_overview = null;

public ActivatableComponent? window_overview { get; private set; }

public ScreenSaverManager? screensaver { get; private set; }

Expand Down

0 comments on commit bd300d9

Please sign in to comment.