Skip to content

WindowListModel #2353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ namespace Gala {
}

public interface WindowManager : Meta.Plugin {
/**
* A list of all currently active windows.
*/
public abstract ListStore windows { get; construct; }

/**
* This is the container you'll most likely want to add your component to. It wraps
* every other container listed in this interface and is a direct child of the stage.
Expand Down
37 changes: 2 additions & 35 deletions src/Widgets/MultitaskingView/MonitorClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,12 @@ public class Gala.MonitorClone : ActorTarget {

background = new BackgroundManager (display, monitor, false);

var model = new WindowListModel (wm, STACKING, true, monitor);
var scale = display.get_monitor_scale (monitor);

window_container = new WindowCloneContainer (wm, scale);
window_container = new WindowCloneContainer (wm, model, scale);
window_container.window_selected.connect ((w) => { window_selected (w); });

display.window_entered_monitor.connect (window_entered);
display.window_left_monitor.connect (window_left);

unowned GLib.List<Meta.WindowActor> window_actors = display.get_window_actors ();
foreach (unowned Meta.WindowActor window_actor in window_actors) {
if (window_actor.is_destroyed ())
continue;

unowned Meta.Window window = window_actor.get_meta_window ();
if (window.get_monitor () == monitor) {
window_entered (monitor, window);
}
}

add_child (background);
add_child (window_container);

Expand All @@ -59,12 +46,6 @@ public class Gala.MonitorClone : ActorTarget {
update_allocation ();
}

~MonitorClone () {
unowned var display = wm.get_display ();
display.window_entered_monitor.disconnect (window_entered);
display.window_left_monitor.disconnect (window_left);
}

/**
* Make sure the MonitorClone is at the location of the monitor on the stage
*/
Expand All @@ -80,18 +61,4 @@ public class Gala.MonitorClone : ActorTarget {
var scale = display.get_monitor_scale (monitor);
window_container.monitor_scale = scale;
}

private void window_left (int window_monitor, Meta.Window window) {
if (window_monitor != monitor)
return;

window_container.remove_window (window);
}

private void window_entered (int window_monitor, Meta.Window window) {
if (window_monitor != monitor || window.window_type != Meta.WindowType.NORMAL)
return;

window_container.add_window (window);
}
}
6 changes: 3 additions & 3 deletions src/Widgets/MultitaskingView/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ public class Gala.WindowClone : ActorTarget {
}

/**
* The window unmanaged by the compositor, so we need to destroy ourselves too.
* The window unmanaged by the compositor, so we need to destroy the clone.
* We mustn't destroy ourselves because this is handled by the WindowCloneContainer
* and its model and would fuck up indeces.
*/
private void unmanaged () {
remove_all_transitions ();
Expand All @@ -439,8 +441,6 @@ public class Gala.WindowClone : ActorTarget {
SignalHandler.disconnect (window.get_display (), check_confirm_dialog_cb);
check_confirm_dialog_cb = 0;
}

destroy ();
}

private void actor_clicked (uint32 button, Clutter.InputDeviceType device_type = POINTER_DEVICE) {
Expand Down
124 changes: 29 additions & 95 deletions src/Widgets/MultitaskingView/WindowCloneContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Gala.WindowCloneContainer : ActorTarget {
public int padding_bottom { get; set; default = 12; }

public WindowManager wm { get; construct; }
public ListModel windows { get; construct; }
public bool overview_mode { get; construct; }

private float _monitor_scale = 1.0f;
Expand All @@ -40,8 +41,13 @@ public class Gala.WindowCloneContainer : ActorTarget {
*/
private unowned WindowClone? current_window = null;

public WindowCloneContainer (WindowManager wm, float scale, bool overview_mode = false) {
Object (wm: wm, monitor_scale: scale, overview_mode: overview_mode);
public WindowCloneContainer (WindowManager wm, ListModel windows, float scale, bool overview_mode = false) {
Object (wm: wm, windows: windows, monitor_scale: scale, overview_mode: overview_mode);
}

construct {
windows.items_changed.connect (on_items_changed);
on_items_changed (0, 0, windows.get_n_items ());
}

private void reallocate () {
Expand All @@ -51,106 +57,37 @@ public class Gala.WindowCloneContainer : ActorTarget {
}
}

/**
* Create a WindowClone for a MetaWindow and add it to the group
*
* @param window The window for which to create the WindowClone for
*/
public void add_window (Meta.Window window) {
var windows = new List<Meta.Window> ();
foreach (unowned var child in get_children ()) {
unowned var clone = (WindowClone) child;
windows.append (clone.window);
}
windows.append (window);

unowned var display = wm.get_display ();
var windows_ordered = InternalUtils.sort_windows (display, windows);

var new_window = new WindowClone (wm, window, monitor_scale, overview_mode);
private void on_items_changed (uint pos, uint removed, uint added) {
var to_remove = new HashTable<Meta.Window, WindowClone> (null, null);

new_window.selected.connect ((clone) => window_selected (clone.window));
new_window.destroy.connect ((_new_window) => {
// make sure to release reference if the window is selected
if (_new_window == current_window) {
select_next_window (Meta.MotionDirection.RIGHT, false);
}

// if window is still selected, reset the selection
if (_new_window == current_window) {
current_window = null;
}

reflow (false);
});
new_window.request_reposition.connect (() => reflow (false));

unowned Meta.Window? target = null;
foreach (unowned var w in windows_ordered) {
if (w != window) {
target = w;
continue;
}
break;
}

// top most or no other children
if (target == null) {
add_child (new_window);
for (uint i = 0; i < removed; i++) {
var window_clone = (WindowClone) get_child_at_index ((int) pos);
to_remove[window_clone.window] = window_clone;
remove_child (window_clone);
}

foreach (unowned var child in get_children ()) {
unowned var clone = (WindowClone) child;
if (target == clone.window) {
insert_child_below (new_window, clone);
break;
for (uint i = pos; i < pos + added; i++) {
var window = (Meta.Window) windows.get_item (i);
var window_clone = to_remove.take (window);
if (window_clone == null) {
window_clone = new WindowClone (wm, window, monitor_scale, overview_mode);
window_clone.selected.connect ((clone) => window_selected (clone.window));
window_clone.request_reposition.connect (() => reflow (false));
}
insert_child_at_index (window_clone, (int) pos);
}

reflow (false);
}
// Make sure we release the reference on the window
if (current_window != null && current_window.window in to_remove) {
select_next_window (RIGHT, false);

/**
* Find and remove the WindowClone for a MetaWindow
*/
public void remove_window (Meta.Window window) {
foreach (unowned var child in get_children ()) {
if (((WindowClone) child).window == window) {
remove_child (child);
reflow (false);
break;
// There is no next window so select nothing
if (current_window.window in to_remove) {
current_window = null;
}
}
}

/**
* Sort the windows z-order by their actual stacking to make intersections
* during animations correct.
*/
private void restack_windows () {
unowned var display = wm.get_display ();

var children = get_children ();

var windows = new List<Meta.Window> ();
foreach (unowned Clutter.Actor child in children) {
windows.prepend (((WindowClone) child).window);
}

var windows_ordered = InternalUtils.sort_windows (display, windows);
windows_ordered.reverse ();

var i = 0;
foreach (unowned var window in windows_ordered) {
foreach (unowned var child in children) {
if (((WindowClone) child).window == window) {
set_child_at_index (child, i);
children.remove (child);
i++;
break;
}
}
}
reflow (false);
}

/**
Expand Down Expand Up @@ -371,10 +308,7 @@ public class Gala.WindowCloneContainer : ActorTarget {
}
}

restack_windows ();
reflow (true);
} else if (action == MULTITASKING_VIEW) { // If we are open we only want to restack when we close
restack_windows ();
}
}

Expand Down
80 changes: 8 additions & 72 deletions src/Widgets/MultitaskingView/WorkspaceClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public class Gala.WorkspaceClone : ActorTarget {
}

private BackgroundManager background;
private WindowListModel model;
private bool opened;

private uint hover_activate_timeout = 0;
Expand All @@ -166,7 +167,9 @@ public class Gala.WorkspaceClone : ActorTarget {
background = new FramedBackground (display);
background.add_action (background_click_action);

window_container = new WindowCloneContainer (wm, scale_factor) {
model = new WindowListModel (wm, STACKING, true, primary_monitor, workspace);

window_container = new WindowCloneContainer (wm, model, scale_factor) {
width = monitor_geometry.width,
height = monitor_geometry.height,
};
Expand Down Expand Up @@ -197,42 +200,16 @@ public class Gala.WorkspaceClone : ActorTarget {
}
});

display.window_entered_monitor.connect (window_entered_monitor);
display.window_left_monitor.connect (window_left_monitor);
workspace.window_added.connect (add_window);
workspace.window_removed.connect (remove_window);

add_child (background);
add_child (window_container);

// add existing windows
var windows = workspace.list_windows ();
foreach (var window in windows) {
if (window.window_type == Meta.WindowType.NORMAL
&& !window.on_all_workspaces
&& window.is_on_primary_monitor ()) {
window_container.add_window (window);
icon_group.add_window (window, true);
}
}

var static_windows = StaticWindowContainer.get_instance (display);
static_windows.window_changed.connect (on_window_static_changed);

unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (update_targets);

update_targets ();
}

~WorkspaceClone () {
unowned Meta.Display display = workspace.get_display ();

display.window_entered_monitor.disconnect (window_entered_monitor);
display.window_left_monitor.disconnect (window_left_monitor);
workspace.window_added.disconnect (add_window);
workspace.window_removed.disconnect (remove_window);

background.destroy ();
window_container.destroy ();
icon_group.destroy ();
Expand All @@ -243,50 +220,6 @@ public class Gala.WorkspaceClone : ActorTarget {
window_container.monitor_scale = scale_factor;
}

/**
* Add a window to the WindowCloneContainer and the IconGroup if it really
* belongs to this workspace and this monitor.
*/
private void add_window (Meta.Window window) {
if (window.window_type != Meta.WindowType.NORMAL
|| window.get_workspace () != workspace
|| StaticWindowContainer.get_instance (workspace.get_display ()).is_static (window)
|| !window.is_on_primary_monitor ())
return;

foreach (var child in window_container.get_children ())
if (((WindowClone) child).window == window)
return;

window_container.add_window (window);
icon_group.add_window (window);
}

/**
* Remove a window from the WindowCloneContainer and the IconGroup
*/
private void remove_window (Meta.Window window) {
window_container.remove_window (window);
icon_group.remove_window (window, opened);
}

private void window_entered_monitor (Meta.Display display, int monitor, Meta.Window window) {
add_window (window);
}

private void window_left_monitor (Meta.Display display, int monitor, Meta.Window window) {
if (monitor == display.get_primary_monitor ())
remove_window (window);
}

private void on_window_static_changed (Meta.Window window, bool is_static) {
if (is_static) {
remove_window (window);
} else {
add_window (window);
}
}

public void update_size (Mtk.Rectangle monitor_geometry) {
if (window_container.width != monitor_geometry.width || window_container.height != monitor_geometry.height) {
window_container.set_size (monitor_geometry.width, monitor_geometry.height);
Expand All @@ -298,8 +231,11 @@ public class Gala.WorkspaceClone : ActorTarget {
remove_all_targets ();

unowned var display = workspace.get_display ();
var primary = display.get_primary_monitor ();

model.monitor_filter = primary;

var monitor = display.get_monitor_geometry (display.get_primary_monitor ());
var monitor = display.get_monitor_geometry (primary);

var scale = (float)(monitor.height - InternalUtils.scale_to_int (TOP_OFFSET + BOTTOM_OFFSET, scale_factor)) / monitor.height;
var pivot_y = InternalUtils.scale_to_int (TOP_OFFSET, scale_factor) / (monitor.height - monitor.height * scale);
Expand Down
Loading
Loading