Skip to content
Draft
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
67 changes: 64 additions & 3 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Space extends Array {
// The windows that should be represented by their WindowActor
this.visible = [];
this._floating = [];
this.dock = new Map();
this._populated = false;

let clip = new Clutter.Actor();
Expand Down Expand Up @@ -273,7 +274,18 @@ class Space extends Array {

workArea() {
let workArea = Main.layoutManager.getWorkAreaForMonitor(this.monitor.index);
workArea.x -= this.monitor.x;
let right = 0, left = 0;
for (let [mw] of this.dock) {
let frame = mw.get_frame_rect();
if (frame.x === this.monitor.x) {
left = Math.max(left, frame.width);
}
if (frame.x + frame.width === this.monitor.x + this.monitor.width) {
right = Math.max(right, frame.width);
}
}
workArea.x += left - this.monitor.x;
workArea.width -= left + right;
return workArea;
}

Expand Down Expand Up @@ -335,8 +347,10 @@ class Space extends Array {
mw._targetWidth = targetWidth;
mw._targetHeight = targetHeight;

log('should resize', mw.title, !targetReached, hasNewTarget, f.width, targetWidth)
if (!targetReached && hasNewTarget) {
// Explanation for `hasNewTarget` check in commit message
log('resize', mw.title, 'to', targetWidth);
mw.move_resize_frame(true, f.x, f.y, targetWidth, targetHeight);
}
} else {
Expand Down Expand Up @@ -423,6 +437,7 @@ class Space extends Array {
}
targetWidth = Math.min(targetWidth, workArea.width - 2*minimumMargin());

log('targetWidth', targetWidth);
let resultingWidth, relayout;
if (inGrab && i === selectedIndex) {
[resultingWidth, relayout] =
Expand Down Expand Up @@ -632,6 +647,22 @@ class Space extends Array {
return true;
}

addDocked(metaWindow) {
if (this.dock.get(metaWindow))
return;
this.dock.set(metaWindow, metaWindow);
this.removeWindow(metaWindow);
this.addFloating(metaWindow);
metaWindow.make_above();
showWindow(metaWindow);
}

removeDocked(metaWindow) {
this.dock.delete(metaWindow);
this.removeFloating(metaWindow);
metaWindow.make_above();
}

addFloating(metaWindow) {
if (this._floating.indexOf(metaWindow) !== -1 ||
metaWindow.is_on_all_workspaces())
Expand Down Expand Up @@ -778,7 +809,7 @@ class Space extends Array {
Navigator.navigating || inPreview ||
Main.overview.visible ||
// Only block on grab if we haven't detached the window yet
(inGrab && !inGrab.workspace)
(inGrab && this.indexOf(inGrab.window) !== -1)
) {
return;
}
Expand Down Expand Up @@ -1878,6 +1909,11 @@ function registerWindow(metaWindow) {
metaWindow.clone = clone;
metaWindow.clone.cloneActor = cloneActor;

signals.connect(metaWindow, "notify::maximized-vertically", (metaWindow) => {
log(`foo`)
watchTiled(metaWindow);
});

signals.connect(metaWindow, "focus", focus_wrapper);
signals.connect(metaWindow, 'size-changed', allocateClone);
// Note: runs before gnome-shell's minimize handling code
Expand All @@ -1889,6 +1925,26 @@ function registerWindow(metaWindow) {
return true;
}

function watchTiled(metaWindow) {
let frame = metaWindow.get_frame_rect();
log('tiled', frame.x, frame.width);
if (metaWindow.maximized_horizontally)
return;
// Assume Meta.MaximizeFlags.VERTICAL means tiled
let space = spaces.spaceOfWindow(metaWindow);
if (!metaWindow.maximized_vertically) {
if (space.dock.get(metaWindow))
space.removeDocked(metaWindow);
return;
}
space.addDocked(metaWindow);
// maximized_vertically happens before resize, so we need to queue a layout
// on the space
signals.connectOneShot(metaWindow, 'size-changed', () => {
space.layout();
});
}

function allocateClone(metaWindow) {
let frame = metaWindow.get_frame_rect();
let buffer = metaWindow.get_buffer_rect();
Expand Down Expand Up @@ -1916,6 +1972,7 @@ function destroyHandler(actor) {
}

function resizeHandler(metaWindow) {
log(`resize`, metaWindow.title);
let f = metaWindow.get_frame_rect();
let needLayout = false;
if (metaWindow._targetWidth !== f.width || metaWindow._targetHeight !== f.height) {
Expand Down Expand Up @@ -2031,6 +2088,7 @@ function remove_handler(workspace, meta_window) {

let space = spaces.spaceOf(workspace);
space.removeWindow(meta_window);
space.removeDocked(meta_window);

let actor = meta_window.get_compositor_private();
if (!actor) {
Expand Down Expand Up @@ -2178,6 +2236,9 @@ function insertWindow(metaWindow, {existing}) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
toggleMaximizeHorizontally(metaWindow);
}
if (metaWindow.maximized_vertically) {
metaWindow.unmaximize(Meta.MaximizeFlags.VERTICAL);
}

if (!existing) {
actor.opacity = 0;
Expand Down Expand Up @@ -2279,7 +2340,7 @@ function ensureViewport(meta_window, space, force) {
if (index === -1 || space.length === 0)
return undefined;

debug('Moving', meta_window.title);
log('Moving', meta_window.title);

if (space.selectedWindow.fullscreen ||
space.selectedWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
Expand Down