Compare commits
5 Commits
feat/add-w
...
feat/bad-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d911f434af | ||
|
|
5aef762e5f | ||
|
|
c4d4768d29 | ||
|
|
fe069b1de0 | ||
|
|
2446520ced |
18
extension.ts
18
extension.ts
@@ -53,9 +53,9 @@ export default class aerospike extends Extension {
|
||||
this.refreshKeybinding('join-with-right');
|
||||
});
|
||||
|
||||
this.settings.connect('changed::remove-all-dividers', () => {
|
||||
log(`Keybinding remove-all-dividers changed to: ${this.settings.get_strv('remove-all-dividers')}`);
|
||||
this.refreshKeybinding('remove-all-dividers');
|
||||
this.settings.connect('changed::reset-window-sizes', () => {
|
||||
log(`Reset window sizes keybinding changed to: ${this.settings.get_strv('reset-window-sizes')}`);
|
||||
this.refreshKeybinding('reset-window-sizes');
|
||||
});
|
||||
|
||||
this.settings.connect('changed::dropdown-option', () => {
|
||||
@@ -93,10 +93,9 @@ export default class aerospike extends Extension {
|
||||
Logger.info('Keybinding 4 was pressed!');
|
||||
});
|
||||
break;
|
||||
case 'remove-all-dividers':
|
||||
this.bindKeybinding('remove-all-dividers', () => {
|
||||
Logger.info('Remove all dividers keybinding pressed!');
|
||||
this.windowManager.removeAllDividersFromActiveContainer();
|
||||
case 'reset-window-sizes':
|
||||
this.bindKeybinding('reset-window-sizes', () => {
|
||||
this.windowManager.resetAllWindowSizes();
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -126,9 +125,8 @@ export default class aerospike extends Extension {
|
||||
Logger.info('Keybinding 4 was pressed!');
|
||||
});
|
||||
|
||||
this.bindKeybinding('remove-all-dividers', () => {
|
||||
Logger.info('Remove all dividers keybinding pressed!');
|
||||
this.windowManager.removeAllDividersFromActiveContainer();
|
||||
this.bindKeybinding('reset-window-sizes', () => {
|
||||
this.windowManager.resetAllWindowSizes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
2
justfile
2
justfile
@@ -28,7 +28,7 @@ install: build
|
||||
cp -r dist/* ~/.local/share/gnome-shell/extensions/{{NAME}}@{{DOMAIN}}/
|
||||
|
||||
run:
|
||||
env MUTTER_DEBUG_DUMMY_MODE_SPECS=1280x720 dbus-run-session -- gnome-shell --nested --wayland
|
||||
env MUTTER_DEBUG_DUMMY_MODE_SPECS=1280x720 dbus-run-session -- gnome-shell --devkit
|
||||
|
||||
install-and-run: install run
|
||||
|
||||
|
||||
BIN
prettyborders.zip
Normal file
BIN
prettyborders.zip
Normal file
Binary file not shown.
@@ -37,10 +37,10 @@
|
||||
<description>Keyboard shortcut for triggering action 4</description>
|
||||
</key>
|
||||
|
||||
<key name="remove-all-dividers" type="as">
|
||||
<key name="reset-window-sizes" type="as">
|
||||
<default><![CDATA[['<Alt>z']]]></default>
|
||||
<summary>Remove all dividers from active container</summary>
|
||||
<description>Keyboard shortcut for removing all dividers from the container with the active window</description>
|
||||
<summary>Reset all window sizes</summary>
|
||||
<description>Remove all custom window sizes and return to equal distribution</description>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
|
||||
@@ -3,27 +3,26 @@ import {Logger} from "../utils/logger.js";
|
||||
import Meta from "gi://Meta";
|
||||
import queueEvent from "../utils/events.js";
|
||||
import {Rect} from "../utils/rect.js";
|
||||
import {Divider} from "./divider.js";
|
||||
|
||||
enum Orientation {
|
||||
HORIZONTAL = 0,
|
||||
VERTICAL = 1,
|
||||
}
|
||||
|
||||
type ContainerItem = WindowWrapper | WindowContainer | Divider;
|
||||
|
||||
export default class WindowContainer {
|
||||
|
||||
_tiledItems: ContainerItem[];
|
||||
_tiledItems: (WindowWrapper | WindowContainer)[];
|
||||
_tiledWindowLookup: Map<number, WindowWrapper>;
|
||||
_orientation: Orientation = Orientation.HORIZONTAL;
|
||||
_workArea: Rect;
|
||||
_customSizes: Map<number, number>; // Maps index to custom width (horizontal) or height (vertical)
|
||||
|
||||
constructor(workspaceArea: Rect,) {
|
||||
// this._id = monitorId;
|
||||
this._tiledItems = [];
|
||||
this._tiledWindowLookup = new Map<number, WindowWrapper>();
|
||||
this._workArea = workspaceArea;
|
||||
this._customSizes = new Map<number, number>();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +35,6 @@ export default class WindowContainer {
|
||||
// Add window to managed windows
|
||||
this._tiledItems.push(winWrap);
|
||||
this._tiledWindowLookup.set(winWrap.getWindowId(), winWrap);
|
||||
// winWrap.setParent(this);
|
||||
queueEvent({
|
||||
name: "tiling-windows",
|
||||
callback: () => {
|
||||
@@ -51,14 +49,12 @@ export default class WindowContainer {
|
||||
return this._tiledWindowLookup.get(win_id);
|
||||
}
|
||||
for (const item of this._tiledItems) {
|
||||
if (Divider.isDivider(item)) {
|
||||
continue; // Skip dividers
|
||||
} else if (item instanceof WindowContainer) {
|
||||
if (item instanceof WindowContainer) {
|
||||
const win = item.getWindow(win_id);
|
||||
if (win) {
|
||||
return win;
|
||||
}
|
||||
} else if (item instanceof WindowWrapper && item.getWindowId() === win_id) {
|
||||
} else if (item.getWindowId() === win_id) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +76,8 @@ export default class WindowContainer {
|
||||
this._tiledWindowLookup.delete(win_id);
|
||||
const index = this._getIndexOfWindow(win_id)
|
||||
this._tiledItems.splice(index, 1);
|
||||
this._cleanupInvalidDividers();
|
||||
// Shift custom sizes after removed index
|
||||
this._shiftCustomSizesAfterRemoval(index);
|
||||
} else {
|
||||
for (const item of this._tiledItems) {
|
||||
if (item instanceof WindowContainer) {
|
||||
@@ -91,44 +88,105 @@ export default class WindowContainer {
|
||||
this.tileWindows()
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes invalid dividers from the items list.
|
||||
* Invalid dividers are:
|
||||
* - Dividers at the start or end of the list (no window on one side)
|
||||
* - Consecutive dividers (two dividers in a row)
|
||||
*/
|
||||
_cleanupInvalidDividers(): void {
|
||||
let i = 0;
|
||||
while (i < this._tiledItems.length) {
|
||||
const item = this._tiledItems[i];
|
||||
_shiftCustomSizesAfterRemoval(removedIndex: number): void {
|
||||
Logger.log(`=== _shiftCustomSizesAfterRemoval called ===`);
|
||||
Logger.log(`Removed index: ${removedIndex}`);
|
||||
Logger.log(`Total items after removal: ${this._tiledItems.length}`);
|
||||
Logger.log(`Custom sizes Map size: ${this._customSizes.size}`);
|
||||
|
||||
if (Divider.isDivider(item)) {
|
||||
// Check if divider is at start or end
|
||||
const isAtStart = i === 0;
|
||||
const isAtEnd = i === this._tiledItems.length - 1;
|
||||
// Convert Map to readable string
|
||||
let customSizesStr = "{ ";
|
||||
this._customSizes.forEach((size, index) => {
|
||||
customSizesStr += `${index}: ${size}px, `;
|
||||
});
|
||||
customSizesStr += "}";
|
||||
Logger.log(`Custom sizes before shift: ${customSizesStr}`);
|
||||
|
||||
// Check if next item is also a divider
|
||||
const nextIsDivider = i < this._tiledItems.length - 1 &&
|
||||
Divider.isDivider(this._tiledItems[i + 1]);
|
||||
// Calculate the removed window's size (could be custom or flexible)
|
||||
let removedSize = this._customSizes.get(removedIndex);
|
||||
|
||||
if (isAtStart || isAtEnd || nextIsDivider) {
|
||||
Logger.log(`Removing invalid divider at index ${i}`);
|
||||
this._tiledItems.splice(i, 1);
|
||||
continue; // Don't increment i, check the same position again
|
||||
}
|
||||
}
|
||||
i++;
|
||||
if (removedSize === undefined) {
|
||||
// Window didn't have custom size, calculate its flexible size
|
||||
// Count items BEFORE removal (add 1 to current length)
|
||||
const numItemsBeforeRemoval = this._tiledItems.length + 1;
|
||||
let totalCustomSize = 0;
|
||||
let numFlexibleItemsBeforeRemoval = 0;
|
||||
|
||||
this._customSizes.forEach((size, index) => {
|
||||
totalCustomSize += size;
|
||||
// Don't count this in flexible if it's the removed index
|
||||
});
|
||||
numFlexibleItemsBeforeRemoval = numItemsBeforeRemoval - this._customSizes.size;
|
||||
|
||||
const containerSize = this._orientation === Orientation.HORIZONTAL ? this._workArea.width : this._workArea.height;
|
||||
const remainingSize = containerSize - totalCustomSize;
|
||||
removedSize = numFlexibleItemsBeforeRemoval > 0 ? Math.floor(remainingSize / numFlexibleItemsBeforeRemoval) : 0;
|
||||
|
||||
Logger.log(`Removed window was flexible, calculated size: ${removedSize}px (${numFlexibleItemsBeforeRemoval} flexible windows before removal)`);
|
||||
} else {
|
||||
Logger.log(`Removed window had custom size: ${removedSize}px`);
|
||||
}
|
||||
|
||||
// Rebuild the custom sizes map with shifted indices
|
||||
const newCustomSizes = new Map<number, number>();
|
||||
this._customSizes.forEach((size, index) => {
|
||||
if (index < removedIndex) {
|
||||
// Keep indices before removal
|
||||
Logger.log(`Keeping index ${index} with size ${size}`);
|
||||
newCustomSizes.set(index, size);
|
||||
} else if (index > removedIndex) {
|
||||
// Shift down indices after removal
|
||||
Logger.log(`Shifting index ${index} -> ${index - 1} with size ${size}`);
|
||||
newCustomSizes.set(index - 1, size);
|
||||
}
|
||||
// Skip the removed index
|
||||
});
|
||||
|
||||
Logger.log(`New custom sizes Map size after shift: ${newCustomSizes.size}`);
|
||||
let afterShiftStr = "{ ";
|
||||
newCustomSizes.forEach((size, index) => {
|
||||
afterShiftStr += `${index}: ${size}px, `;
|
||||
});
|
||||
afterShiftStr += "}";
|
||||
Logger.log(`Custom sizes after index shift: ${afterShiftStr}`);
|
||||
|
||||
// Distribute removed window's size among remaining custom-sized windows only
|
||||
// Flexible windows will naturally absorb their share through the bounds calculation
|
||||
const remainingWindowCount = this._tiledItems.length;
|
||||
const numCustomWindows = newCustomSizes.size;
|
||||
|
||||
if (removedSize > 0 && remainingWindowCount > 0 && numCustomWindows > 0) {
|
||||
const sizePerCustomWindow = Math.floor(removedSize / numCustomWindows);
|
||||
|
||||
Logger.log(`Distributing ${removedSize}px among ${numCustomWindows} custom-sized windows (${sizePerCustomWindow}px each)`);
|
||||
Logger.log(`Flexible windows will naturally absorb remaining space`);
|
||||
|
||||
// Add proportional size only to windows that already have custom sizes
|
||||
newCustomSizes.forEach((size, index) => {
|
||||
const newSize = size + sizePerCustomWindow;
|
||||
Logger.log(`Index ${index}: ${size}px + ${sizePerCustomWindow}px = ${newSize}px`);
|
||||
newCustomSizes.set(index, newSize);
|
||||
});
|
||||
} else {
|
||||
Logger.log(`Not distributing space - removedSize: ${removedSize}, remainingWindows: ${remainingWindowCount}, customWindows: ${numCustomWindows}`);
|
||||
}
|
||||
|
||||
let finalStr = "{ ";
|
||||
newCustomSizes.forEach((size, index) => {
|
||||
finalStr += `${index}: ${size}px, `;
|
||||
});
|
||||
finalStr += "}";
|
||||
Logger.log(`Final custom sizes: ${finalStr}`);
|
||||
|
||||
this._customSizes = newCustomSizes;
|
||||
Logger.log(`=== _shiftCustomSizesAfterRemoval complete ===`);
|
||||
}
|
||||
|
||||
disconnectSignals(): void {
|
||||
this._tiledItems.forEach((item) => {
|
||||
if (Divider.isDivider(item)) {
|
||||
// Skip dividers - they don't have signals
|
||||
return;
|
||||
} else if (item instanceof WindowContainer) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.disconnectSignals()
|
||||
} else if (item instanceof WindowWrapper) {
|
||||
} else {
|
||||
item.disconnectWindowSignals();
|
||||
}
|
||||
}
|
||||
@@ -140,37 +198,26 @@ export default class WindowContainer {
|
||||
this._tiledWindowLookup.clear()
|
||||
}
|
||||
|
||||
tileWindows() {
|
||||
tileWindows(skipRetry: boolean = false) {
|
||||
Logger.log("TILING WINDOWS IN CONTAINER")
|
||||
|
||||
Logger.log("WorkArea", this._workArea);
|
||||
|
||||
// Get all windows for current workspaceArea
|
||||
this._tileItems()
|
||||
this._tileItems(skipRetry)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
_tileItems() {
|
||||
_tileItems(skipRetry: boolean = false) {
|
||||
if (this._tiledItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
const bounds = this.getBounds();
|
||||
|
||||
// Apply bounds to non-divider items
|
||||
let boundsIndex = 0;
|
||||
this._tiledItems.forEach((item) => {
|
||||
if (Divider.isDivider(item)) {
|
||||
return; // Skip dividers
|
||||
}
|
||||
|
||||
const rect = bounds[boundsIndex];
|
||||
this._tiledItems.forEach((item, index) => {
|
||||
const rect = bounds[index];
|
||||
if (item instanceof WindowContainer) {
|
||||
item.move(rect);
|
||||
} else if (item instanceof WindowWrapper) {
|
||||
item.safelyResizeWindow(rect);
|
||||
} else {
|
||||
item.safelyResizeWindow(rect, 2, skipRetry);
|
||||
}
|
||||
boundsIndex++;
|
||||
})
|
||||
}
|
||||
|
||||
@@ -183,177 +230,100 @@ export default class WindowContainer {
|
||||
}
|
||||
|
||||
getVerticalBounds(): Rect[] {
|
||||
// Filter out dividers to get only windows/containers
|
||||
const nonDividerItems = this._tiledItems.filter(item => !Divider.isDivider(item));
|
||||
// Calculate available height after accounting for custom-sized windows
|
||||
let totalCustomHeight = 0;
|
||||
let numFlexibleItems = 0;
|
||||
|
||||
if (nonDividerItems.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// If no dividers, use equal distribution
|
||||
const hasDividers = this._tiledItems.some(item => Divider.isDivider(item));
|
||||
if (!hasDividers) {
|
||||
const containerHeight = Math.floor(this._workArea.height / nonDividerItems.length);
|
||||
return nonDividerItems.map((_, index) => {
|
||||
const y = this._workArea.y + (index * containerHeight);
|
||||
return {
|
||||
x: this._workArea.x,
|
||||
y: y,
|
||||
width: this._workArea.width,
|
||||
height: containerHeight
|
||||
} as Rect;
|
||||
});
|
||||
}
|
||||
|
||||
// Calculate bounds based on divider positions
|
||||
const bounds: Rect[] = [];
|
||||
let currentY = this._workArea.y;
|
||||
let itemIndex = 0;
|
||||
|
||||
for (let i = 0; i < this._tiledItems.length; i++) {
|
||||
const item = this._tiledItems[i];
|
||||
|
||||
if (Divider.isDivider(item)) {
|
||||
// Next segment starts at divider position
|
||||
currentY = this._workArea.y + Math.floor(item.getPosition() * this._workArea.height);
|
||||
this._tiledItems.forEach((item, index) => {
|
||||
if (this._customSizes.has(index)) {
|
||||
totalCustomHeight += this._customSizes.get(index)!;
|
||||
} else {
|
||||
// Find the end position for this item
|
||||
let endY: number = this._workArea.y + this._workArea.height;
|
||||
|
||||
// Look ahead to find next divider or end of container
|
||||
for (let j = i + 1; j < this._tiledItems.length; j++) {
|
||||
if (Divider.isDivider(this._tiledItems[j])) {
|
||||
const divider = this._tiledItems[j] as Divider;
|
||||
endY = this._workArea.y + Math.floor(divider.getPosition() * this._workArea.height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Count non-divider items until next divider
|
||||
let itemCount = 0;
|
||||
let itemsInSegment: number[] = [];
|
||||
for (let j = i; j < this._tiledItems.length; j++) {
|
||||
if (Divider.isDivider(this._tiledItems[j])) {
|
||||
break;
|
||||
}
|
||||
itemsInSegment.push(j);
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
// Divide space equally among items in this segment
|
||||
const segmentHeight = endY - currentY;
|
||||
const itemHeight = Math.floor(segmentHeight / itemCount);
|
||||
|
||||
for (let k = 0; k < itemsInSegment.length; k++) {
|
||||
const itemY = currentY + (k * itemHeight);
|
||||
bounds.push({
|
||||
x: this._workArea.x,
|
||||
y: itemY,
|
||||
width: this._workArea.width,
|
||||
height: itemHeight
|
||||
} as Rect);
|
||||
}
|
||||
|
||||
// Skip the items we just processed
|
||||
i += itemCount - 1;
|
||||
currentY = endY;
|
||||
numFlexibleItems++;
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure custom sizes don't exceed container height
|
||||
if (totalCustomHeight > this._workArea.height) {
|
||||
Logger.warn("Custom heights exceed container, resetting all sizes");
|
||||
this._customSizes.clear();
|
||||
totalCustomHeight = 0;
|
||||
numFlexibleItems = this._tiledItems.length;
|
||||
}
|
||||
|
||||
return bounds;
|
||||
const remainingHeight = this._workArea.height - totalCustomHeight;
|
||||
const flexHeight = numFlexibleItems > 0 ? Math.floor(remainingHeight / numFlexibleItems) : 0;
|
||||
|
||||
// Build the bounds array
|
||||
let currentY = this._workArea.y;
|
||||
return this._tiledItems.map((item, index) => {
|
||||
let height = flexHeight;
|
||||
if (this._customSizes.has(index)) {
|
||||
height = this._customSizes.get(index)!;
|
||||
}
|
||||
|
||||
const rect = {
|
||||
x: this._workArea.x,
|
||||
y: currentY,
|
||||
width: this._workArea.width,
|
||||
height: height
|
||||
} as Rect;
|
||||
currentY += height;
|
||||
return rect;
|
||||
});
|
||||
}
|
||||
|
||||
getHorizontalBounds(): Rect[] {
|
||||
// Filter out dividers to get only windows/containers
|
||||
const nonDividerItems = this._tiledItems.filter(item => !Divider.isDivider(item));
|
||||
// Calculate available width after accounting for custom-sized windows
|
||||
let totalCustomWidth = 0;
|
||||
let numFlexibleItems = 0;
|
||||
|
||||
if (nonDividerItems.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// If no dividers, use equal distribution
|
||||
const hasDividers = this._tiledItems.some(item => Divider.isDivider(item));
|
||||
if (!hasDividers) {
|
||||
const windowWidth = Math.floor(this._workArea.width / nonDividerItems.length);
|
||||
return nonDividerItems.map((_, index) => {
|
||||
const x = this._workArea.x + (index * windowWidth);
|
||||
return {
|
||||
x: x,
|
||||
y: this._workArea.y,
|
||||
width: windowWidth,
|
||||
height: this._workArea.height
|
||||
} as Rect;
|
||||
});
|
||||
}
|
||||
|
||||
// Calculate bounds based on divider positions
|
||||
const bounds: Rect[] = [];
|
||||
let currentX = this._workArea.x;
|
||||
|
||||
for (let i = 0; i < this._tiledItems.length; i++) {
|
||||
const item = this._tiledItems[i];
|
||||
|
||||
if (Divider.isDivider(item)) {
|
||||
// Next segment starts at divider position
|
||||
currentX = this._workArea.x + Math.floor(item.getPosition() * this._workArea.width);
|
||||
this._tiledItems.forEach((item, index) => {
|
||||
if (this._customSizes.has(index)) {
|
||||
totalCustomWidth += this._customSizes.get(index)!;
|
||||
} else {
|
||||
// Find the end position for this item
|
||||
let endX: number = this._workArea.x + this._workArea.width;
|
||||
|
||||
// Look ahead to find next divider or end of container
|
||||
for (let j = i + 1; j < this._tiledItems.length; j++) {
|
||||
if (Divider.isDivider(this._tiledItems[j])) {
|
||||
const divider = this._tiledItems[j] as Divider;
|
||||
endX = this._workArea.x + Math.floor(divider.getPosition() * this._workArea.width);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Count non-divider items until next divider
|
||||
let itemCount = 0;
|
||||
let itemsInSegment: number[] = [];
|
||||
for (let j = i; j < this._tiledItems.length; j++) {
|
||||
if (Divider.isDivider(this._tiledItems[j])) {
|
||||
break;
|
||||
}
|
||||
itemsInSegment.push(j);
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
// Divide space equally among items in this segment
|
||||
const segmentWidth = endX - currentX;
|
||||
const itemWidth = Math.floor(segmentWidth / itemCount);
|
||||
|
||||
for (let k = 0; k < itemsInSegment.length; k++) {
|
||||
const itemX = currentX + (k * itemWidth);
|
||||
bounds.push({
|
||||
x: itemX,
|
||||
y: this._workArea.y,
|
||||
width: itemWidth,
|
||||
height: this._workArea.height
|
||||
} as Rect);
|
||||
}
|
||||
|
||||
// Skip the items we just processed
|
||||
i += itemCount - 1;
|
||||
currentX = endX;
|
||||
numFlexibleItems++;
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure custom sizes don't exceed container width
|
||||
if (totalCustomWidth > this._workArea.width) {
|
||||
Logger.warn("Custom widths exceed container, resetting all sizes");
|
||||
this._customSizes.clear();
|
||||
totalCustomWidth = 0;
|
||||
numFlexibleItems = this._tiledItems.length;
|
||||
}
|
||||
|
||||
return bounds;
|
||||
const remainingWidth = this._workArea.width - totalCustomWidth;
|
||||
const flexWidth = numFlexibleItems > 0 ? Math.floor(remainingWidth / numFlexibleItems) : 0;
|
||||
|
||||
// Build the bounds array
|
||||
let currentX = this._workArea.x;
|
||||
return this._tiledItems.map((item, index) => {
|
||||
let width = flexWidth;
|
||||
if (this._customSizes.has(index)) {
|
||||
width = this._customSizes.get(index)!;
|
||||
}
|
||||
|
||||
const rect = {
|
||||
x: currentX,
|
||||
y: this._workArea.y,
|
||||
width: width,
|
||||
height: this._workArea.height
|
||||
} as Rect;
|
||||
currentX += width;
|
||||
return rect;
|
||||
});
|
||||
}
|
||||
|
||||
getIndexOfItemNested(item: WindowWrapper): number {
|
||||
for (let i = 0; i < this._tiledItems.length; i++) {
|
||||
const container = this._tiledItems[i];
|
||||
if (Divider.isDivider(container)) {
|
||||
continue; // Skip dividers
|
||||
} else if (container instanceof WindowContainer) {
|
||||
if (container instanceof WindowContainer) {
|
||||
const index = container.getIndexOfItemNested(item);
|
||||
if (index !== -1) {
|
||||
return i;
|
||||
}
|
||||
} else if (container instanceof WindowWrapper && container.getWindowId() === item.getWindowId()) {
|
||||
} else if (container.getWindowId() === item.getWindowId()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -362,271 +332,152 @@ export default class WindowContainer {
|
||||
|
||||
// TODO: update this to work with nested containers - all other logic should already be working
|
||||
itemDragged(item: WindowWrapper, x: number, y: number): void {
|
||||
// Find the actual index in _tiledItems (including dividers)
|
||||
const original_actual_index = this._getIndexOfWindow(item.getWindowId());
|
||||
let original_index = this.getIndexOfItemNested(item);
|
||||
|
||||
if (original_actual_index === -1) {
|
||||
if (original_index === -1) {
|
||||
Logger.error("Item not found in container during drag op", item.getWindowId());
|
||||
return;
|
||||
}
|
||||
|
||||
// Find which visual slot (non-divider index) we're moving to
|
||||
let new_visual_index = this.getIndexOfItemNested(item);
|
||||
const bounds = this.getBounds();
|
||||
bounds.forEach((rect, index) => {
|
||||
let new_index = original_index;
|
||||
this.getBounds().forEach((rect, index) => {
|
||||
if (rect.x < x && rect.x + rect.width > x && rect.y < y && rect.y + rect.height > y) {
|
||||
new_visual_index = index;
|
||||
new_index = index;
|
||||
}
|
||||
})
|
||||
|
||||
// Get current visual index (counting only non-dividers before this item)
|
||||
let original_visual_index = 0;
|
||||
for (let i = 0; i < original_actual_index; i++) {
|
||||
if (!Divider.isDivider(this._tiledItems[i])) {
|
||||
original_visual_index++;
|
||||
}
|
||||
if (original_index !== new_index) {
|
||||
this._tiledItems.splice(original_index, 1);
|
||||
this._tiledItems.splice(new_index, 0, item);
|
||||
this.tileWindows()
|
||||
}
|
||||
|
||||
if (original_visual_index === new_visual_index) {
|
||||
return; // No movement needed
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log(`Swapping window from visual index ${original_visual_index} to ${new_visual_index}`);
|
||||
|
||||
// Find the target window at the new visual index
|
||||
let target_actual_index = -1;
|
||||
let visual_count = 0;
|
||||
for (let i = 0; i < this._tiledItems.length; i++) {
|
||||
if (!Divider.isDivider(this._tiledItems[i])) {
|
||||
if (visual_count === new_visual_index) {
|
||||
target_actual_index = i;
|
||||
break;
|
||||
windowManuallyResized(win_id: number): void {
|
||||
const window = this.getWindow(win_id);
|
||||
if (!window) {
|
||||
// Check nested containers
|
||||
for (const item of this._tiledItems) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.windowManuallyResized(win_id);
|
||||
}
|
||||
visual_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (target_actual_index === -1) {
|
||||
Logger.warn("Could not find target position for drag");
|
||||
return;
|
||||
}
|
||||
|
||||
// Simply swap the two windows in place, leaving dividers where they are
|
||||
const temp = this._tiledItems[original_actual_index];
|
||||
this._tiledItems[original_actual_index] = this._tiledItems[target_actual_index];
|
||||
this._tiledItems[target_actual_index] = temp;
|
||||
// Find the index of the window
|
||||
const index = this._getIndexOfWindow(win_id);
|
||||
if (index === -1) {
|
||||
Logger.error("Window not found in container during resize");
|
||||
return;
|
||||
}
|
||||
|
||||
this.tileWindows();
|
||||
const rect = window.getRect();
|
||||
if (this._orientation === Orientation.HORIZONTAL) {
|
||||
this._customSizes.set(index, rect.width);
|
||||
Logger.log(`Window at index ${index} manually resized to width: ${rect.width}`);
|
||||
} else {
|
||||
this._customSizes.set(index, rect.height);
|
||||
Logger.log(`Window at index ${index} manually resized to height: ${rect.height}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles window resize operations. Creates or updates dividers based on resize direction.
|
||||
* @param item - The window being resized
|
||||
* @param resizeEdge - The edge being resized (N, S, E, W, etc.)
|
||||
* @param newRect - The new rectangle after resize
|
||||
*/
|
||||
handleWindowResize(item: WindowWrapper, resizeEdge: Meta.GrabOp, newRect: Rect): void {
|
||||
const itemIndex = this._getIndexOfWindow(item.getWindowId());
|
||||
if (itemIndex === -1) {
|
||||
Logger.warn("Window not found in container during resize", item.getWindowId());
|
||||
resetAllWindowSizes(): void {
|
||||
Logger.log("Clearing all custom window sizes in container");
|
||||
this._customSizes.clear();
|
||||
// Also clear nested containers
|
||||
for (const item of this._tiledItems) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.resetAllWindowSizes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
windowResizing(win_id: number, resizeOp: Meta.GrabOp): void {
|
||||
const window = this.getWindow(win_id);
|
||||
if (!window) {
|
||||
// Check nested containers
|
||||
for (const item of this._tiledItems) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.windowResizing(win_id, resizeOp);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine if this is a valid resize for this container orientation
|
||||
const isHorizontalResize = this._isHorizontalResizeOp(resizeEdge);
|
||||
const isVerticalResize = this._isVerticalResizeOp(resizeEdge);
|
||||
// Check if the resize direction matches the container orientation
|
||||
const isHorizontalResize = resizeOp === Meta.GrabOp.RESIZING_E || resizeOp === Meta.GrabOp.RESIZING_W;
|
||||
const isVerticalResize = resizeOp === Meta.GrabOp.RESIZING_N || resizeOp === Meta.GrabOp.RESIZING_S;
|
||||
|
||||
// Only allow horizontal resizes in horizontal containers
|
||||
// Only allow vertical resizes in vertical containers
|
||||
if (this._orientation === Orientation.HORIZONTAL && !isHorizontalResize) {
|
||||
Logger.log("Ignoring vertical resize in horizontal container");
|
||||
return;
|
||||
}
|
||||
if (this._orientation === Orientation.VERTICAL && !isVerticalResize) {
|
||||
Logger.log("Ignoring horizontal resize in vertical container");
|
||||
if ((this._orientation === Orientation.HORIZONTAL && !isHorizontalResize) ||
|
||||
(this._orientation === Orientation.VERTICAL && !isVerticalResize)) {
|
||||
// Resize direction doesn't match container orientation, ignore
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine which edge is being resized and find adjacent window
|
||||
// Find the index of the window
|
||||
const index = this._getIndexOfWindow(win_id);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the new size
|
||||
const rect = window.getRect();
|
||||
const newSize = this._orientation === Orientation.HORIZONTAL ? rect.width : rect.height;
|
||||
const oldSize = this._customSizes.get(index);
|
||||
|
||||
if (oldSize === undefined) {
|
||||
// First time resizing this window, just set the size
|
||||
this._customSizes.set(index, newSize);
|
||||
this.tileWindows(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate the delta (how much the window changed)
|
||||
const delta = newSize - oldSize;
|
||||
|
||||
// If delta is 0, the window didn't actually resize (hit its minimum)
|
||||
if (delta === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine which adjacent window to adjust based on resize direction
|
||||
let adjacentIndex = -1;
|
||||
let dividerPosition = 0;
|
||||
if (resizeOp === Meta.GrabOp.RESIZING_E || resizeOp === Meta.GrabOp.RESIZING_S) {
|
||||
// Resizing right/down edge - adjust the next window
|
||||
adjacentIndex = index + 1;
|
||||
} else if (resizeOp === Meta.GrabOp.RESIZING_W || resizeOp === Meta.GrabOp.RESIZING_N) {
|
||||
// Resizing left/up edge - adjust the previous window
|
||||
adjacentIndex = index - 1;
|
||||
}
|
||||
|
||||
if (this._orientation === Orientation.HORIZONTAL) {
|
||||
// East/West resize
|
||||
if (this._isEastResizeOp(resizeEdge)) {
|
||||
// Resizing east edge - divider goes after this window
|
||||
adjacentIndex = itemIndex + 1;
|
||||
// Calculate divider position as ratio of container width
|
||||
const rightEdge = newRect.x + newRect.width;
|
||||
dividerPosition = (rightEdge - this._workArea.x) / this._workArea.width;
|
||||
} else if (this._isWestResizeOp(resizeEdge)) {
|
||||
// Resizing west edge - divider goes before this window
|
||||
adjacentIndex = itemIndex - 1;
|
||||
dividerPosition = (newRect.x - this._workArea.x) / this._workArea.width;
|
||||
}
|
||||
} else {
|
||||
// Vertical orientation - North/South resize
|
||||
if (this._isSouthResizeOp(resizeEdge)) {
|
||||
// Resizing south edge - divider goes after this window
|
||||
adjacentIndex = itemIndex + 1;
|
||||
const bottomEdge = newRect.y + newRect.height;
|
||||
dividerPosition = (bottomEdge - this._workArea.y) / this._workArea.height;
|
||||
} else if (this._isNorthResizeOp(resizeEdge)) {
|
||||
// Resizing north edge - divider goes before this window
|
||||
adjacentIndex = itemIndex - 1;
|
||||
dividerPosition = (newRect.y - this._workArea.y) / this._workArea.height;
|
||||
// Update current window size
|
||||
this._customSizes.set(index, newSize);
|
||||
|
||||
// Adjust adjacent window only if it has a custom size
|
||||
// When both windows have custom sizes, always apply opposite delta to maintain total width
|
||||
let oldAdjacentSize: number | undefined = undefined;
|
||||
if (adjacentIndex >= 0 && adjacentIndex < this._tiledItems.length &&
|
||||
this._customSizes.has(adjacentIndex)) {
|
||||
const adjacentItem = this._tiledItems[adjacentIndex];
|
||||
if (adjacentItem instanceof WindowWrapper) {
|
||||
oldAdjacentSize = this._customSizes.get(adjacentIndex)!;
|
||||
const newAdjacentSize = oldAdjacentSize - delta;
|
||||
|
||||
// Check if adjacent window allows resize
|
||||
if (!adjacentItem.getWindow().allows_resize()) {
|
||||
Logger.log("Adjacent window doesn't allow resize, reverting");
|
||||
this._customSizes.set(index, oldSize);
|
||||
} else {
|
||||
// Always apply the opposite delta to the adjacent window
|
||||
// This keeps the total width constant
|
||||
this._customSizes.set(adjacentIndex, newAdjacentSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure there's an adjacent item
|
||||
if (adjacentIndex < 0 || adjacentIndex >= this._tiledItems.length) {
|
||||
Logger.log("No adjacent window for resize operation");
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if adjacent item is already a divider
|
||||
if (Divider.isDivider(this._tiledItems[adjacentIndex])) {
|
||||
// Update existing divider
|
||||
const divider = this._tiledItems[adjacentIndex] as Divider;
|
||||
divider.setPosition(dividerPosition);
|
||||
Logger.log(`Updated divider at index ${adjacentIndex} to position ${dividerPosition}`);
|
||||
} else {
|
||||
// Insert new divider between items
|
||||
const dividerIndex = Math.max(itemIndex, adjacentIndex);
|
||||
const newDivider = new Divider(dividerPosition, this._orientation);
|
||||
this._tiledItems.splice(dividerIndex, 0, newDivider);
|
||||
Logger.log(`Inserted new divider at index ${dividerIndex} with position ${dividerPosition}`);
|
||||
}
|
||||
|
||||
this.tileWindows();
|
||||
}
|
||||
|
||||
private _isHorizontalResizeOp(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_E ||
|
||||
op === Meta.GrabOp.RESIZING_W ||
|
||||
op === Meta.GrabOp.RESIZING_NE ||
|
||||
op === Meta.GrabOp.RESIZING_NW ||
|
||||
op === Meta.GrabOp.RESIZING_SE ||
|
||||
op === Meta.GrabOp.RESIZING_SW;
|
||||
}
|
||||
|
||||
private _isVerticalResizeOp(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_N ||
|
||||
op === Meta.GrabOp.RESIZING_S ||
|
||||
op === Meta.GrabOp.RESIZING_NE ||
|
||||
op === Meta.GrabOp.RESIZING_NW ||
|
||||
op === Meta.GrabOp.RESIZING_SE ||
|
||||
op === Meta.GrabOp.RESIZING_SW;
|
||||
}
|
||||
|
||||
private _isEastResizeOp(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_E ||
|
||||
op === Meta.GrabOp.RESIZING_NE ||
|
||||
op === Meta.GrabOp.RESIZING_SE;
|
||||
}
|
||||
|
||||
private _isWestResizeOp(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_W ||
|
||||
op === Meta.GrabOp.RESIZING_NW ||
|
||||
op === Meta.GrabOp.RESIZING_SW;
|
||||
}
|
||||
|
||||
private _isSouthResizeOp(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_S ||
|
||||
op === Meta.GrabOp.RESIZING_SE ||
|
||||
op === Meta.GrabOp.RESIZING_SW;
|
||||
}
|
||||
|
||||
private _isNorthResizeOp(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_N ||
|
||||
op === Meta.GrabOp.RESIZING_NE ||
|
||||
op === Meta.GrabOp.RESIZING_NW;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all dividers from this container, reverting to equal space distribution
|
||||
*/
|
||||
removeAllDividers(): void {
|
||||
Logger.log("Removing all dividers from container");
|
||||
this._tiledItems = this._tiledItems.filter(item => !Divider.isDivider(item));
|
||||
this.tileWindows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates divider position during a live resize operation (or creates if doesn't exist)
|
||||
* This is called repeatedly during resize for live feedback
|
||||
*/
|
||||
updateDividerDuringResize(item: WindowWrapper, resizeEdge: Meta.GrabOp, newRect: Rect): void {
|
||||
const itemIndex = this._getIndexOfWindow(item.getWindowId());
|
||||
if (itemIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine if this is a valid resize for this container orientation
|
||||
const isHorizontalResize = this._isHorizontalResizeOp(resizeEdge);
|
||||
const isVerticalResize = this._isVerticalResizeOp(resizeEdge);
|
||||
|
||||
if (this._orientation === Orientation.HORIZONTAL && !isHorizontalResize) {
|
||||
return;
|
||||
}
|
||||
if (this._orientation === Orientation.VERTICAL && !isVerticalResize) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine which edge is being resized and find adjacent window
|
||||
let adjacentIndex = -1;
|
||||
let dividerPosition = 0;
|
||||
|
||||
if (this._orientation === Orientation.HORIZONTAL) {
|
||||
if (this._isEastResizeOp(resizeEdge)) {
|
||||
adjacentIndex = itemIndex + 1;
|
||||
const rightEdge = newRect.x + newRect.width;
|
||||
dividerPosition = (rightEdge - this._workArea.x) / this._workArea.width;
|
||||
} else if (this._isWestResizeOp(resizeEdge)) {
|
||||
adjacentIndex = itemIndex - 1;
|
||||
dividerPosition = (newRect.x - this._workArea.x) / this._workArea.width;
|
||||
}
|
||||
} else {
|
||||
if (this._isSouthResizeOp(resizeEdge)) {
|
||||
adjacentIndex = itemIndex + 1;
|
||||
const bottomEdge = newRect.y + newRect.height;
|
||||
dividerPosition = (bottomEdge - this._workArea.y) / this._workArea.height;
|
||||
} else if (this._isNorthResizeOp(resizeEdge)) {
|
||||
adjacentIndex = itemIndex - 1;
|
||||
dividerPosition = (newRect.y - this._workArea.y) / this._workArea.height;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure there's an adjacent item (window or container, not out of bounds)
|
||||
if (adjacentIndex < 0 || adjacentIndex >= this._tiledItems.length) {
|
||||
Logger.log(`No adjacent item at index ${adjacentIndex}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine where divider should be inserted/updated
|
||||
// For East/South resizes: divider between current (itemIndex) and next (itemIndex+1)
|
||||
// For West/North resizes: divider between previous (itemIndex-1) and current (itemIndex)
|
||||
let dividerIndex: number;
|
||||
|
||||
if (this._orientation === Orientation.HORIZONTAL) {
|
||||
dividerIndex = this._isEastResizeOp(resizeEdge) ? itemIndex + 1 : itemIndex;
|
||||
} else {
|
||||
dividerIndex = this._isSouthResizeOp(resizeEdge) ? itemIndex + 1 : itemIndex;
|
||||
}
|
||||
|
||||
// Check if there's already a divider at this position
|
||||
if (dividerIndex < this._tiledItems.length && Divider.isDivider(this._tiledItems[dividerIndex])) {
|
||||
// Update existing divider
|
||||
const divider = this._tiledItems[dividerIndex] as Divider;
|
||||
divider.setPosition(dividerPosition);
|
||||
} else {
|
||||
// Insert new divider
|
||||
const newDivider = new Divider(dividerPosition, this._orientation);
|
||||
this._tiledItems.splice(dividerIndex, 0, newDivider);
|
||||
}
|
||||
|
||||
// Retile to show live updates
|
||||
this.tileWindows();
|
||||
// Call tileWindows during resize to update all window positions
|
||||
// Skip retry logic during active resize to avoid jitter
|
||||
this.tileWindows(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import {Logger} from "../utils/logger.js";
|
||||
|
||||
enum Orientation {
|
||||
HORIZONTAL = 0,
|
||||
VERTICAL = 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a divider between windows in a container.
|
||||
* Dividers track the split position as a ratio (0-1) of the container's size.
|
||||
*/
|
||||
export class Divider {
|
||||
private _position: number; // Position as ratio 0-1
|
||||
private _orientation: Orientation;
|
||||
|
||||
/**
|
||||
* Creates a new divider
|
||||
* @param position - Position as ratio between 0 and 1
|
||||
* @param orientation - Orientation of the divider (HORIZONTAL or VERTICAL)
|
||||
*/
|
||||
constructor(position: number, orientation: Orientation) {
|
||||
this._position = Math.max(0, Math.min(1, position)); // Clamp between 0 and 1
|
||||
this._orientation = orientation;
|
||||
}
|
||||
|
||||
getPosition(): number {
|
||||
return this._position;
|
||||
}
|
||||
|
||||
setPosition(position: number): void {
|
||||
this._position = Math.max(0, Math.min(1, position)); // Clamp between 0 and 1
|
||||
Logger.log(`Divider position updated to ${this._position}`);
|
||||
}
|
||||
|
||||
getOrientation(): Orientation {
|
||||
return this._orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this is a divider instance
|
||||
*/
|
||||
static isDivider(item: any): item is Divider {
|
||||
return item instanceof Divider;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,6 @@ export default class Monitor {
|
||||
this._workArea = global.workspace_manager.get_active_workspace().get_work_area_for_monitor(this._id);
|
||||
const activeWorkspace = global.workspace_manager.get_active_workspace();
|
||||
this._workspaces[activeWorkspace.index()].move(this._workArea);
|
||||
this._workspaces[activeWorkspace.index()].tileWindows()
|
||||
}
|
||||
|
||||
removeWorkspace(workspaceId: number): void {
|
||||
@@ -83,17 +82,32 @@ export default class Monitor {
|
||||
this._workspaces[item.getWorkspace()].itemDragged(item, x, y);
|
||||
}
|
||||
|
||||
handleWindowResize(item: WindowWrapper, resizeEdge: Meta.GrabOp, newRect: Rect): void {
|
||||
this._workspaces[item.getWorkspace()].handleWindowResize(item, resizeEdge, newRect);
|
||||
windowManuallyResized(win_id: number): void {
|
||||
// Find which workspace contains the window and notify it
|
||||
for (const container of this._workspaces) {
|
||||
const win = container.getWindow(win_id);
|
||||
if (win) {
|
||||
container.windowManuallyResized(win_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateDividerDuringResize(item: WindowWrapper, resizeEdge: Meta.GrabOp, newRect: Rect): void {
|
||||
this._workspaces[item.getWorkspace()].updateDividerDuringResize(item, resizeEdge, newRect);
|
||||
resetAllWindowSizes(): void {
|
||||
for (const container of this._workspaces) {
|
||||
container.resetAllWindowSizes();
|
||||
}
|
||||
}
|
||||
|
||||
removeAllDividersFromActiveContainer(): void {
|
||||
const activeWorkspace = global.workspace_manager.get_active_workspace();
|
||||
this._workspaces[activeWorkspace.index()].removeAllDividers();
|
||||
windowResizing(win_id: number, resizeOp: Meta.GrabOp): void {
|
||||
// Find which workspace contains the window and notify it
|
||||
for (const container of this._workspaces) {
|
||||
const win = container.getWindow(win_id);
|
||||
if (win) {
|
||||
container.windowResizing(win_id, resizeOp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,6 @@ export class WindowWrapper {
|
||||
readonly _signals: number[] = [];
|
||||
_parent: WindowContainer | null = null;
|
||||
_dragging: boolean = false;
|
||||
_resizing: boolean = false;
|
||||
|
||||
constructor(
|
||||
window: Meta.Window,
|
||||
@@ -54,13 +53,6 @@ export class WindowWrapper {
|
||||
this._dragging = false;
|
||||
}
|
||||
|
||||
startResizing(): void {
|
||||
this._resizing = true;
|
||||
}
|
||||
stopResizing(): void {
|
||||
this._resizing = false;
|
||||
}
|
||||
|
||||
// setParent(parent: WindowContainer): void {
|
||||
// this._parent = parent;
|
||||
// }
|
||||
@@ -112,6 +104,9 @@ export class WindowWrapper {
|
||||
this._window.connect("position-changed", (_metaWindow) => {
|
||||
windowManager.handleWindowPositionChanged(this);
|
||||
}),
|
||||
this._window.connect("size-changed", (_metaWindow) => {
|
||||
windowManager.handleWindowSizeChanged(this);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,12 +125,10 @@ export class WindowWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
safelyResizeWindow(rect: Rect, _retry: number = 2): void {
|
||||
safelyResizeWindow(rect: Rect, _retry: number = 2, _skipRetry: boolean = false): void {
|
||||
// Keep minimal logging
|
||||
if (this._dragging && !this._resizing) {
|
||||
// During drag operations (not resize), skip this entirely
|
||||
return;
|
||||
}
|
||||
// Note: we allow resizing even during drag operations to support position updates
|
||||
// The dragging flag only prevents REORDERING, not position/size changes
|
||||
// Logger.log("SAFELY RESIZE", rect.x, rect.y, rect.width, rect.height);
|
||||
const actor = this._window.get_compositor_private();
|
||||
|
||||
@@ -150,19 +143,13 @@ export class WindowWrapper {
|
||||
this._window.move_frame(true, rect.x, rect.y);
|
||||
// Logger.info("RESIZING MOVING")
|
||||
this._window.move_resize_frame(true, rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
// Don't retry during live resize operations - it causes spam and isn't needed
|
||||
if (this._resizing) {
|
||||
return;
|
||||
}
|
||||
|
||||
let new_rect = this._window.get_frame_rect();
|
||||
if ( _retry > 0 && (new_rect.x != rect.x || rect.y != new_rect.y || rect.width < new_rect.width || rect.height < new_rect.height)) {
|
||||
if (!_skipRetry && _retry > 0 && (new_rect.x != rect.x || rect.y != new_rect.y || rect.width < new_rect.width || rect.height < new_rect.height)) {
|
||||
Logger.warn("RESIZING FAILED AS SMALLER", new_rect.x, new_rect.y, new_rect.width, new_rect.height, rect.x, rect.y, rect.width, rect.height);
|
||||
queueEvent({
|
||||
name: "attempting_delayed_resize",
|
||||
callback: () => {
|
||||
this.safelyResizeWindow(rect, _retry-1);
|
||||
this.safelyResizeWindow(rect, _retry-1, _skipRetry);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ export interface IWindowManager {
|
||||
|
||||
handleWindowPositionChanged(winWrap: WindowWrapper): void;
|
||||
|
||||
handleWindowSizeChanged(winWrap: WindowWrapper): void;
|
||||
|
||||
syncActiveWindow(): number | null;
|
||||
}
|
||||
|
||||
@@ -44,8 +46,9 @@ export default class WindowManager implements IWindowManager {
|
||||
|
||||
_grabbedWindowMonitor: number = _UNUSED_MONITOR_ID;
|
||||
_grabbedWindowId: number = _UNUSED_WINDOW_ID;
|
||||
_grabbedOp: Meta.GrabOp | null = null;
|
||||
_changingGrabbedMonitor: boolean = false;
|
||||
_resizingWindow: boolean = false;
|
||||
_resizeOp: Meta.GrabOp | null = null;
|
||||
|
||||
_showingOverview: boolean = false;
|
||||
|
||||
@@ -200,50 +203,24 @@ export default class WindowManager implements IWindowManager {
|
||||
|
||||
|
||||
handleGrabOpBegin(display: Meta.Display, window: Meta.Window, op: Meta.GrabOp): void {
|
||||
if (op === Meta.GrabOp.MOVING_UNCONSTRAINED){
|
||||
|
||||
}
|
||||
Logger.log("Grab Op Start", op);
|
||||
Logger.log(display, window, op)
|
||||
Logger.log(window.get_monitor())
|
||||
|
||||
const winWrap = this._getWrappedWindow(window);
|
||||
if (this._isResizeOp(op)) {
|
||||
winWrap?.startResizing();
|
||||
const isResizing = this._isResizeOperation(op);
|
||||
if (isResizing) {
|
||||
this._resizingWindow = true;
|
||||
this._resizeOp = op;
|
||||
// Don't mark as dragging during resize - we need to update positions freely
|
||||
} else {
|
||||
winWrap?.startDragging();
|
||||
this._getWrappedWindow(window)?.startDragging();
|
||||
}
|
||||
|
||||
this._grabbedWindowMonitor = window.get_monitor();
|
||||
this._grabbedWindowId = window.get_id();
|
||||
this._grabbedOp = op;
|
||||
}
|
||||
|
||||
handleGrabOpEnd(display: Meta.Display, window: Meta.Window, op: Meta.GrabOp): void {
|
||||
Logger.log("Grab Op End ", op);
|
||||
Logger.log("primary display", display.get_primary_monitor())
|
||||
|
||||
// Handle resize operations
|
||||
if (this._isResizeOp(op)) {
|
||||
const winWrap = this._getWrappedWindow(window);
|
||||
if (winWrap && this._grabbedOp) {
|
||||
const newRect = window.get_frame_rect();
|
||||
const monitorId = window.get_monitor();
|
||||
Logger.log(`Handling resize operation: ${op}, new rect:`, newRect);
|
||||
this._monitors.get(monitorId)?.handleWindowResize(winWrap, this._grabbedOp, newRect);
|
||||
winWrap.stopResizing();
|
||||
}
|
||||
} else {
|
||||
this._getWrappedWindow(window)?.stopDragging();
|
||||
}
|
||||
|
||||
this._grabbedWindowId = _UNUSED_WINDOW_ID;
|
||||
this._grabbedOp = null;
|
||||
this._tileMonitors();
|
||||
Logger.info("monitor_start and monitor_end", this._grabbedWindowMonitor, window.get_monitor());
|
||||
}
|
||||
|
||||
private _isResizeOp(op: Meta.GrabOp): boolean {
|
||||
_isResizeOperation(op: Meta.GrabOp): boolean {
|
||||
return op === Meta.GrabOp.RESIZING_E ||
|
||||
op === Meta.GrabOp.RESIZING_W ||
|
||||
op === Meta.GrabOp.RESIZING_N ||
|
||||
@@ -254,6 +231,26 @@ export default class WindowManager implements IWindowManager {
|
||||
op === Meta.GrabOp.RESIZING_SW;
|
||||
}
|
||||
|
||||
handleGrabOpEnd(display: Meta.Display, window: Meta.Window, op: Meta.GrabOp): void {
|
||||
Logger.log("Grab Op End ", op);
|
||||
Logger.log("primary display", display.get_primary_monitor())
|
||||
|
||||
// Check if this was a resize operation
|
||||
if (this._isResizeOperation(op)) {
|
||||
const monitor = this._monitors.get(window.get_monitor());
|
||||
if (monitor) {
|
||||
monitor.windowManuallyResized(window.get_id());
|
||||
}
|
||||
}
|
||||
|
||||
this._resizingWindow = false;
|
||||
this._resizeOp = null;
|
||||
this._grabbedWindowId = _UNUSED_WINDOW_ID;
|
||||
this._getWrappedWindow(window)?.stopDragging();
|
||||
this._tileMonitors();
|
||||
Logger.info("monitor_start and monitor_end", this._grabbedWindowMonitor, window.get_monitor());
|
||||
}
|
||||
|
||||
_getWrappedWindow(window: Meta.Window): WindowWrapper | undefined {
|
||||
let wrapped = undefined;
|
||||
for (const monitor of this._monitors.values()) {
|
||||
@@ -281,7 +278,7 @@ export default class WindowManager implements IWindowManager {
|
||||
let wrapped = this._getAndRemoveWrappedWindow(window);
|
||||
if (wrapped === undefined) {
|
||||
Logger.error("WINDOW NOT DEFINED")
|
||||
wrapped = new WindowWrapper(window, this.handleWindowMinimized);
|
||||
wrapped = new WindowWrapper(window, this.handleWindowMinimized.bind(this));
|
||||
wrapped.connectWindowSignals(this);
|
||||
}
|
||||
let new_mon = this._monitors.get(monitorId);
|
||||
@@ -293,17 +290,21 @@ export default class WindowManager implements IWindowManager {
|
||||
if (this._changingGrabbedMonitor) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle resize operations - update dividers in real-time
|
||||
if (this._grabbedOp && this._isResizeOp(this._grabbedOp)) {
|
||||
const window = winWrap.getWindow();
|
||||
const newRect = window.get_frame_rect();
|
||||
const monitorId = window.get_monitor();
|
||||
this._monitors.get(monitorId)?.updateDividerDuringResize(winWrap, this._grabbedOp, newRect);
|
||||
return;
|
||||
}
|
||||
|
||||
if (winWrap.getWindowId() === this._grabbedWindowId) {
|
||||
// Check if we're doing a pure NSEW resize - if so, don't allow position-based swapping
|
||||
if (this._resizingWindow && this._resizeOp) {
|
||||
const isPureNSEWResize =
|
||||
this._resizeOp === Meta.GrabOp.RESIZING_E ||
|
||||
this._resizeOp === Meta.GrabOp.RESIZING_W ||
|
||||
this._resizeOp === Meta.GrabOp.RESIZING_N ||
|
||||
this._resizeOp === Meta.GrabOp.RESIZING_S;
|
||||
|
||||
if (isPureNSEWResize) {
|
||||
// Skip itemDragged - don't allow swaps during NSEW resize
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const [mouseX, mouseY, _] = global.get_pointer();
|
||||
|
||||
let monitorIndex = -1;
|
||||
@@ -328,6 +329,16 @@ export default class WindowManager implements IWindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
public handleWindowSizeChanged(winWrap: WindowWrapper): void {
|
||||
if (this._resizingWindow && winWrap.getWindowId() === this._grabbedWindowId) {
|
||||
// Check if this is a valid resize direction for the container
|
||||
const monitor = this._monitors.get(winWrap.getWindow().get_monitor());
|
||||
if (monitor && this._resizeOp) {
|
||||
monitor.windowResizing(winWrap.getWindowId(), this._resizeOp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public handleWindowMinimized(winWrap: WindowWrapper): void {
|
||||
const monitor_id = winWrap.getWindow().get_monitor()
|
||||
@@ -392,7 +403,7 @@ export default class WindowManager implements IWindowManager {
|
||||
public addWindowToMonitor(window: Meta.Window) {
|
||||
|
||||
Logger.log("ADDING WINDOW TO MONITOR", window, window);
|
||||
var wrapper = new WindowWrapper(window, this.handleWindowMinimized)
|
||||
var wrapper = new WindowWrapper(window, this.handleWindowMinimized.bind(this))
|
||||
wrapper.connectWindowSignals(this);
|
||||
this._addWindowWrapperToMonitor(wrapper);
|
||||
|
||||
@@ -464,25 +475,12 @@ export default class WindowManager implements IWindowManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all dividers from the container with the currently active window
|
||||
*/
|
||||
public removeAllDividersFromActiveContainer(): void {
|
||||
const activeWindow = global.display.focus_window;
|
||||
if (!activeWindow) {
|
||||
Logger.log("No active window, cannot remove dividers");
|
||||
return;
|
||||
}
|
||||
|
||||
const monitorId = activeWindow.get_monitor();
|
||||
const monitor = this._monitors.get(monitorId);
|
||||
|
||||
if (monitor) {
|
||||
Logger.log(`Removing all dividers from monitor ${monitorId}`);
|
||||
monitor.removeAllDividersFromActiveContainer();
|
||||
} else {
|
||||
Logger.warn(`Monitor ${monitorId} not found`);
|
||||
}
|
||||
public resetAllWindowSizes(): void {
|
||||
Logger.log("Resetting all custom window sizes");
|
||||
this._monitors.forEach((monitor: Monitor) => {
|
||||
monitor.resetAllWindowSizes();
|
||||
});
|
||||
this._tileMonitors();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user