feat: refactored to monitor -> workspace -> container -> window workflow
This commit is contained in:
103
src/container.ts
103
src/container.ts
@@ -13,8 +13,8 @@ enum Orientation {
|
||||
export default class WindowContainer {
|
||||
|
||||
_id: number;
|
||||
_items: Map<number, WindowWrapper | WindowContainer>;
|
||||
_minimizedItems: Map<number, WindowWrapper>;
|
||||
_tiledItems: (WindowWrapper | WindowContainer)[];
|
||||
_tiledWindowLookup: Map<number, WindowWrapper>;
|
||||
_workspace: number;
|
||||
_orientation: Orientation = Orientation.HORIZONTAL;
|
||||
_workArea: Rect;
|
||||
@@ -22,8 +22,8 @@ export default class WindowContainer {
|
||||
constructor(monitorId: number, workspaceArea: Rect, workspace: number) {
|
||||
this._id = monitorId;
|
||||
this._workspace = workspace;
|
||||
this._items = new Map<number, WindowWrapper>();
|
||||
this._minimizedItems = new Map<number, WindowWrapper>();
|
||||
this._tiledItems = [];
|
||||
this._tiledWindowLookup = new Map<number, WindowWrapper>();
|
||||
this._workArea = workspaceArea;
|
||||
}
|
||||
|
||||
@@ -33,47 +33,66 @@ export default class WindowContainer {
|
||||
|
||||
move(rect: Rect): void {
|
||||
this._workArea = rect;
|
||||
this._tileWindows();
|
||||
this.tileWindows();
|
||||
}
|
||||
|
||||
addWindow(winWrap: WindowWrapper): void {
|
||||
// Add window to managed windows
|
||||
if (!winWrap.getWindow().minimized) {
|
||||
this._items.set(winWrap.getWindowId(), winWrap);
|
||||
queueEvent({
|
||||
name: "tiling-windows",
|
||||
callback: () => {
|
||||
this._tileWindows();
|
||||
}
|
||||
}, 100)
|
||||
} else {
|
||||
this._minimizedItems.set(winWrap.getWindowId(), winWrap);
|
||||
}
|
||||
this._tiledItems.push(winWrap);
|
||||
this._tiledWindowLookup.set(winWrap.getWindowId(), winWrap);
|
||||
queueEvent({
|
||||
name: "tiling-windows",
|
||||
callback: () => {
|
||||
this.tileWindows();
|
||||
}
|
||||
}, 100)
|
||||
|
||||
}
|
||||
|
||||
getWindow(win_id: number): WindowWrapper | WindowContainer | undefined {
|
||||
return this._items.get(win_id)
|
||||
getWindow(win_id: number): WindowWrapper | undefined {
|
||||
if (this._tiledWindowLookup.has(win_id)) {
|
||||
return this._tiledWindowLookup.get(win_id);
|
||||
}
|
||||
for (const item of this._tiledItems) {
|
||||
if (item instanceof WindowContainer) {
|
||||
const win = item.getWindow(win_id);
|
||||
if (win) {
|
||||
return win;
|
||||
}
|
||||
} else if (item.getWindowId() === win_id) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
_getIndexOfWindow(win_id: number) {
|
||||
for (let i = 0; i < this._tiledItems.length; i++) {
|
||||
const item = this._tiledItems[i];
|
||||
if (item instanceof WindowWrapper && item.getWindowId() === win_id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
removeWindow(win_id: number): void {
|
||||
this._items.delete(win_id)
|
||||
this._tileWindows()
|
||||
}
|
||||
|
||||
minimizeWindow(winWrap: WindowWrapper): void {
|
||||
this._items.delete(winWrap.getWindowId())
|
||||
this._minimizedItems.set(winWrap.getWindowId(), winWrap)
|
||||
}
|
||||
|
||||
unminimizeWindow(winWrap: WindowWrapper): void {
|
||||
if (this._minimizedItems.has(winWrap.getWindowId())) {
|
||||
this._items.set(winWrap.getWindowId(), winWrap);
|
||||
this._minimizedItems.delete(winWrap.getWindowId());
|
||||
if (this._tiledWindowLookup.has(win_id)) {
|
||||
this._tiledWindowLookup.delete(win_id);
|
||||
const index = this._getIndexOfWindow(win_id)
|
||||
this._tiledItems.splice(index, 1);
|
||||
} else {
|
||||
for (const item of this._tiledItems) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.removeWindow(win_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.tileWindows()
|
||||
}
|
||||
|
||||
disconnectSignals(): void {
|
||||
this._items.forEach((item) => {
|
||||
this._tiledItems.forEach((item) => {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.disconnectSignals()
|
||||
} else {
|
||||
@@ -84,10 +103,11 @@ export default class WindowContainer {
|
||||
}
|
||||
|
||||
removeAllWindows(): void {
|
||||
this._items.clear()
|
||||
this._tiledItems = []
|
||||
this._tiledWindowLookup.clear()
|
||||
}
|
||||
|
||||
_tileWindows() {
|
||||
tileWindows() {
|
||||
Logger.log("TILING WINDOWS ON MONITOR", this._id)
|
||||
|
||||
Logger.log("Workspace", this._workspace);
|
||||
@@ -97,18 +117,17 @@ export default class WindowContainer {
|
||||
let tilable = this._getTilableItems();
|
||||
|
||||
if (tilable.length !== 0) {
|
||||
this._tileHorizontally(tilable, )
|
||||
this._tileItems(tilable)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
_getTilableItems(): (WindowWrapper|WindowContainer)[] {
|
||||
return Array.from(this._items.values())
|
||||
_getTilableItems(): (WindowWrapper | WindowContainer)[] {
|
||||
return Array.from(this._tiledItems.values())
|
||||
}
|
||||
|
||||
|
||||
_tileItems(windows: (WindowWrapper|WindowContainer)[]) {
|
||||
if (windows.length === 0){
|
||||
_tileItems(windows: (WindowWrapper | WindowContainer)[]) {
|
||||
if (windows.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (this._orientation === Orientation.HORIZONTAL) {
|
||||
@@ -118,7 +137,7 @@ export default class WindowContainer {
|
||||
}
|
||||
}
|
||||
|
||||
_tileVertically(items: (WindowWrapper|WindowContainer)[]) {
|
||||
_tileVertically(items: (WindowWrapper | WindowContainer)[]) {
|
||||
const containerHeight = Math.floor(this._workArea.height / items.length);
|
||||
|
||||
items.forEach((item, index) => {
|
||||
@@ -139,7 +158,7 @@ export default class WindowContainer {
|
||||
});
|
||||
}
|
||||
|
||||
_tileHorizontally(windows: (WindowWrapper|WindowContainer)[]) {
|
||||
_tileHorizontally(windows: (WindowWrapper | WindowContainer)[]) {
|
||||
const windowWidth = Math.floor(this._workArea.width / windows.length);
|
||||
|
||||
windows.forEach((item, index) => {
|
||||
|
Reference in New Issue
Block a user