Skip to content
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

moveHandler: Update tile group when the window changes monitor #279

Merged
merged 1 commit into from
Aug 5, 2023
Merged
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
60 changes: 29 additions & 31 deletions tiling-assistant@leleat-on-github/src/extension/moveHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,7 @@ var Handler = class TilingMoveHandler {
this._pointerDidntMove = false;
this._movingTimerDuration = 20;
this._movingTimeoutsSinceUpdate = 0;

const activeWs = global.workspace_manager.get_active_workspace();
const monitor = global.display.get_current_monitor();
const workArea = new Rect(activeWs.get_work_area_for_monitor(monitor));

const topTileGroup = Twm.getTopTileGroup({ skipTopWindow: true });
const tRects = topTileGroup.map(w => w.tiledRect);
const freeScreenRects = workArea.minus(tRects);
this._topTileGroup = Twm.getTopTileGroup({ skipTopWindow: true });

// When low performance mode is enabled we use a timer to periodically
// update the tile previews so that we don't update the tile preview
Expand All @@ -188,8 +181,6 @@ var Handler = class TilingMoveHandler {
this,
grabOp,
window,
topTileGroup,
freeScreenRects,
true
)
);
Expand All @@ -199,7 +190,7 @@ var Handler = class TilingMoveHandler {
// 'Quick throws' of windows won't create a tile preview since
// the timeout for onMoving may not have happened yet. So force
// 1 call of the tile preview updates for those quick actions.
this._onMoving(grabOp, window, topTileGroup, freeScreenRects);
this._onMoving(grabOp, window);
this._onMoveFinished(window);
});

Expand All @@ -211,8 +202,6 @@ var Handler = class TilingMoveHandler {
this,
grabOp,
window,
topTileGroup,
freeScreenRects,
false
)
);
Expand Down Expand Up @@ -276,7 +265,9 @@ var Handler = class TilingMoveHandler {
this._favoriteLayout = [];
this._favoritePreviews?.forEach(p => p.destroy());
this._favoritePreviews = [];
this._freeScreenRects = [];
this._anchorRect = null;
this._topTileGroup = null;
this._tilePreview.close();
this._currPreviewMode = MoveModes.ADAPTIVE_TILING;
this._isGrabOp = false;
Expand All @@ -291,7 +282,7 @@ var Handler = class TilingMoveHandler {
// the current position.
// Without the lowPerfMode enabled this will be called whenever the window is
// moved (by listening to the position-changed signal)
_onMoving(grabOp, window, topTileGroup, freeScreenRects, lowPerfMode = false) {
_onMoving(grabOp, window, lowPerfMode = false) {
const [x, y] = global.get_pointer();
const currPointerPos = { x, y };

Expand Down Expand Up @@ -378,7 +369,7 @@ var Handler = class TilingMoveHandler {
this._edgeTilingPreview(window, grabOp);
break;
case MoveModes.ADAPTIVE_TILING:
this._adaptiveTilingPreview(window, grabOp, topTileGroup, freeScreenRects);
this._adaptiveTilingPreview(window, grabOp);
break;
case MoveModes.FAVORITE_LAYOUT:
this._favoriteLayoutTilingPreview(window);
Expand All @@ -392,13 +383,22 @@ var Handler = class TilingMoveHandler {
_preparePreviewModeChange(newMode, window) {
this._tileRect = null;
this._ignoreTA = false;
this._topTileGroup = Twm.getTopTileGroup({ skipTopWindow: true });

const activeWs = global.workspace_manager.get_active_workspace();
const monitor = global.display.get_current_monitor();
const workArea = new Rect(activeWs.get_work_area_for_monitor(monitor));
const tRects = this._topTileGroup.map(w => w.tiledRect);
this._freeScreenRects = workArea.minus(tRects);

switch (this._currPreviewMode) {
case MoveModes.ADAPTIVE_TILING:
this._monitorNr = global.display.get_current_monitor();
this._splitRects.clear();
this._anchorRect = null;
break;
case MoveModes.FAVORITE_LAYOUT:
this._monitorNr = global.display.get_current_monitor();
this._favoritePreviews.forEach(p => {
p.ease({
opacity: 0,
Expand Down Expand Up @@ -606,16 +606,16 @@ var Handler = class TilingMoveHandler {
*
* @param {Meta.Window} window
* @param {Meta.GrabOp} grabOp
* @param {Meta.Window[]} topTileGroup
* @param {Rect[]} freeScreenRects
*/
_adaptiveTilingPreview(window, grabOp, topTileGroup, freeScreenRects) {
if (!topTileGroup.length) {
_adaptiveTilingPreview(window, grabOp) {
if (!this._topTileGroup.length) {
this._edgeTilingPreview(window, grabOp);
return;
}

const screenRects = topTileGroup.map(w => w.tiledRect).concat(freeScreenRects);
const screenRects = this._topTileGroup
.map(w => w.tiledRect)
.concat(this._freeScreenRects);
const hoveredRect = screenRects.find(r => r.containsPoint(this._lastPointerPos));
if (!hoveredRect) {
this._tilePreview.close();
Expand Down Expand Up @@ -645,9 +645,9 @@ var Handler = class TilingMoveHandler {
const atRightEdge = this._lastPointerPos.x > hoveredRect.x2 - edgeRadius;

atTopEdge || atBottomEdge || atLeftEdge || atRightEdge
? this._adaptiveTilingPreviewGroup(window, hoveredRect, topTileGroup,
? this._adaptiveTilingPreviewGroup(window, hoveredRect,
{ atTopEdge, atBottomEdge, atLeftEdge, atRightEdge })
: this._adaptiveTilingPreviewSingle(window, hoveredRect, topTileGroup);
: this._adaptiveTilingPreviewSingle(window, hoveredRect);
}
}

Expand All @@ -662,9 +662,8 @@ var Handler = class TilingMoveHandler {
*
* @param {Meta.Window} window
* @param {Rect} hoveredRect
* @param {Meta.Window[]} topTileGroup
*/
_adaptiveTilingPreviewSingle(window, hoveredRect, topTileGroup) {
_adaptiveTilingPreviewSingle(window, hoveredRect) {
const atTop = this._lastPointerPos.y < hoveredRect.y + hoveredRect.height * .25;
const atBottom = this._lastPointerPos.y > hoveredRect.y + hoveredRect.height * .75;
const atRight = this._lastPointerPos.x > hoveredRect.x + hoveredRect.width * .75;
Expand All @@ -688,7 +687,7 @@ var Handler = class TilingMoveHandler {
this._tilePreview.open(window, this._tileRect.meta, monitor);
this._splitRects.clear();

const hoveredWindow = topTileGroup.find(w => {
const hoveredWindow = this._topTileGroup.find(w => {
return w.tiledRect.containsPoint(this._lastPointerPos);
});

Expand All @@ -713,15 +712,14 @@ var Handler = class TilingMoveHandler {
*
* @param {Meta.Window} window
* @param {Rect} hoveredRect
* @param {Meta.Window[]} topTileGroup
* @param {object} hovered contains booleans at which position the
* `hoveredRect` is hovered.
*/
_adaptiveTilingPreviewGroup(window, hoveredRect, topTileGroup, hovered) {
_adaptiveTilingPreviewGroup(window, hoveredRect, hovered) {
// Find the smallest window that will be affected and use it to calculate
// the sizes of the preview. Determine the new tileRects for the rest
// of the tileGroup via Rect.minus().
const smallestWindow = topTileGroup.reduce((smallest, w) => {
const smallestWindow = this._topTileGroup.reduce((smallest, w) => {
if (hovered.atTopEdge) {
if (w.tiledRect.y === hoveredRect.y || w.tiledRect.y2 === hoveredRect.y)
return w.tiledRect.height < smallest.tiledRect.height ? w : smallest;
Expand Down Expand Up @@ -756,7 +754,7 @@ var Handler = class TilingMoveHandler {
// of the smallestWindow.
if (hovered.atTopEdge || hovered.atBottomEdge) {
const getX1X2 = alignsAt => {
return topTileGroup.reduce((x1x2, w) => {
return this._topTileGroup.reduce((x1x2, w) => {
const currX = x1x2[0];
const currX2 = x1x2[1];
return alignsAt(w)
Expand Down Expand Up @@ -790,7 +788,7 @@ var Handler = class TilingMoveHandler {
// the smallestWindow.
} else {
const getY1Y2 = alignsAt => {
return topTileGroup.reduce((y1y2, w) => {
return this._topTileGroup.reduce((y1y2, w) => {
const currY = y1y2[0];
const currY2 = y1y2[1];
return alignsAt(w)
Expand Down Expand Up @@ -827,7 +825,7 @@ var Handler = class TilingMoveHandler {
this._tilePreview.open(window, this._tileRect.meta, monitor);
this._splitRects.clear();

topTileGroup.forEach(w => {
this._topTileGroup.forEach(w => {
const leftOver = w.tiledRect.minus(this._tileRect);
const splitRect = leftOver[0];
// w isn't an affected window.
Expand Down