Compare commits
6 Commits
feat/fix-l
...
c7f45ecf3b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7f45ecf3b | ||
|
|
c23b9113ab | ||
|
|
50ceb02124 | ||
|
|
717c240d70 | ||
|
|
822a7bd2e4 | ||
|
|
d59a0fef6d |
@@ -26,6 +26,7 @@ export default class aerospike extends Extension {
|
||||
|
||||
disable() {
|
||||
this.windowManager.disable()
|
||||
this.removeKeybindings()
|
||||
}
|
||||
|
||||
|
||||
|
||||
2
justfile
2
justfile
@@ -33,7 +33,7 @@ run:
|
||||
install-and-run: install run
|
||||
|
||||
live-debug:
|
||||
journalctl /usr/bin/gnome-shell -f -o cat
|
||||
journalctl /usr/bin/gnome-shell -f -o cat | tee debug.log
|
||||
|
||||
#pack: build
|
||||
# gnome-extensions pack dist \
|
||||
|
||||
182
src/container.ts
Normal file
182
src/container.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
import {WindowWrapper} from "./window.js";
|
||||
import {Logger} from "./utils/logger.js";
|
||||
import Meta from "gi://Meta";
|
||||
import queueEvent from "./utils/events.js";
|
||||
import {Rect} from "./utils/rect.js";
|
||||
|
||||
enum Orientation {
|
||||
HORIZONTAL = 0,
|
||||
VERTICAL = 1,
|
||||
}
|
||||
|
||||
|
||||
export default class WindowContainer {
|
||||
|
||||
_id: number;
|
||||
_tiledItems: (WindowWrapper | WindowContainer)[];
|
||||
_tiledWindowLookup: Map<number, WindowWrapper>;
|
||||
_workspace: number;
|
||||
_orientation: Orientation = Orientation.HORIZONTAL;
|
||||
_workArea: Rect;
|
||||
|
||||
constructor(monitorId: number, workspaceArea: Rect, workspace: number) {
|
||||
this._id = monitorId;
|
||||
this._workspace = workspace;
|
||||
this._tiledItems = [];
|
||||
this._tiledWindowLookup = new Map<number, WindowWrapper>();
|
||||
this._workArea = workspaceArea;
|
||||
}
|
||||
|
||||
getWorkspace(): number {
|
||||
return this._workspace;
|
||||
}
|
||||
|
||||
move(rect: Rect): void {
|
||||
this._workArea = rect;
|
||||
this.tileWindows();
|
||||
}
|
||||
|
||||
addWindow(winWrap: WindowWrapper): void {
|
||||
// Add window to managed windows
|
||||
this._tiledItems.push(winWrap);
|
||||
this._tiledWindowLookup.set(winWrap.getWindowId(), winWrap);
|
||||
queueEvent({
|
||||
name: "tiling-windows",
|
||||
callback: () => {
|
||||
this.tileWindows();
|
||||
}
|
||||
}, 100)
|
||||
|
||||
}
|
||||
|
||||
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 {
|
||||
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._tiledItems.forEach((item) => {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.disconnectSignals()
|
||||
} else {
|
||||
item.disconnectWindowSignals();
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
removeAllWindows(): void {
|
||||
this._tiledItems = []
|
||||
this._tiledWindowLookup.clear()
|
||||
}
|
||||
|
||||
tileWindows() {
|
||||
Logger.log("TILING WINDOWS ON MONITOR", this._id)
|
||||
|
||||
Logger.log("Workspace", this._workspace);
|
||||
Logger.log("WorkArea", this._workArea);
|
||||
|
||||
// Get all windows for current workspace
|
||||
let tilable = this._getTilableItems();
|
||||
|
||||
if (tilable.length !== 0) {
|
||||
this._tileItems(tilable)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
_getTilableItems(): (WindowWrapper | WindowContainer)[] {
|
||||
return Array.from(this._tiledItems.values())
|
||||
}
|
||||
|
||||
_tileItems(windows: (WindowWrapper | WindowContainer)[]) {
|
||||
if (windows.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (this._orientation === Orientation.HORIZONTAL) {
|
||||
this._tileHorizontally(windows);
|
||||
} else {
|
||||
this._tileVertically(windows);
|
||||
}
|
||||
}
|
||||
|
||||
_tileVertically(items: (WindowWrapper | WindowContainer)[]) {
|
||||
const containerHeight = Math.floor(this._workArea.height / items.length);
|
||||
|
||||
items.forEach((item, index) => {
|
||||
const y = this._workArea.y + (index * containerHeight);
|
||||
const rect = {
|
||||
x: this._workArea.x,
|
||||
y: y,
|
||||
width: this._workArea.width,
|
||||
height: containerHeight
|
||||
};
|
||||
if (item != null) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.move(rect)
|
||||
} else {
|
||||
item.safelyResizeWindow(rect);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_tileHorizontally(windows: (WindowWrapper | WindowContainer)[]) {
|
||||
const windowWidth = Math.floor(this._workArea.width / windows.length);
|
||||
|
||||
windows.forEach((item, index) => {
|
||||
const x = this._workArea.x + (index * windowWidth);
|
||||
const rect = {
|
||||
x: x,
|
||||
y: this._workArea.y,
|
||||
width: windowWidth,
|
||||
height: this._workArea.height
|
||||
};
|
||||
if (item != null) {
|
||||
if (item instanceof WindowContainer) {
|
||||
item.move(rect)
|
||||
} else {
|
||||
item.safelyResizeWindow(rect);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
119
src/monitor.ts
119
src/monitor.ts
@@ -1,96 +1,75 @@
|
||||
import {WindowWrapper} from "./window.js";
|
||||
import {Rect} from "./utils/rect.js";
|
||||
import queueEvent from "./utils/events.js";
|
||||
import {Logger} from "./utils/logger.js";
|
||||
import Mtk from "@girs/mtk-16";
|
||||
import Meta from "gi://Meta";
|
||||
import Mtk from "@girs/mtk-16";
|
||||
|
||||
import WindowContainer from "./container.js";
|
||||
import Window = Meta.Window;
|
||||
|
||||
export default class MonitorManager {
|
||||
export default class Monitor {
|
||||
|
||||
_id: number;
|
||||
_windows: Map<number, WindowWrapper>;
|
||||
_minimized: Map<number, WindowWrapper>;
|
||||
|
||||
_workArea: Rect;
|
||||
_workspaces: WindowContainer[] = [];
|
||||
|
||||
constructor(monitorId: number) {
|
||||
this._windows = new Map<number, WindowWrapper>();
|
||||
this._minimized = new Map<number, WindowWrapper>();
|
||||
|
||||
this._id = monitorId;
|
||||
const workspace = global.workspace_manager.get_active_workspace();
|
||||
this._workArea = workspace.get_work_area_for_monitor(this._id);
|
||||
Logger.log("CREATING MONITOR", monitorId);
|
||||
Logger.log("WorkArea", this._workArea.x, this._workArea.y, this._workArea.width, this._workArea.height);
|
||||
const workspaceCount = global.workspace_manager.get_n_workspaces()
|
||||
Logger.log("Workspace Count", workspaceCount);
|
||||
for (let i = 0; i < workspaceCount; i++) {
|
||||
this._workspaces.push(new WindowContainer(monitorId, this._workArea, i));
|
||||
}
|
||||
}
|
||||
|
||||
addWindow(winWrap: WindowWrapper): void {
|
||||
// Add window to managed windows
|
||||
this._windows.set(winWrap.getWindowId(), winWrap);
|
||||
this._tileWindows();
|
||||
}
|
||||
|
||||
getWindow(win_id: number): WindowWrapper | undefined {
|
||||
return this._windows.get(win_id)
|
||||
}
|
||||
|
||||
removeWindow(win_id: number): void {
|
||||
this._windows.delete(win_id)
|
||||
this._tileWindows()
|
||||
}
|
||||
|
||||
minimizeWindow(winWrap: WindowWrapper): void {
|
||||
this._windows.delete(winWrap.getWindowId())
|
||||
this._minimized.set(winWrap.getWindowId(), winWrap)
|
||||
}
|
||||
|
||||
unminimizeWindow(winWrap: WindowWrapper): void {
|
||||
if (this._minimized.has(winWrap.getWindowId())) {
|
||||
this._windows.set(winWrap.getWindowId(), winWrap);
|
||||
this._minimized.delete(winWrap.getWindowId());
|
||||
disconnectSignals() {
|
||||
for (const container of this._workspaces) {
|
||||
container.disconnectSignals();
|
||||
}
|
||||
}
|
||||
|
||||
removeAllWindows(): void {
|
||||
this._windows.clear()
|
||||
for (const container of this._workspaces) {
|
||||
container.removeAllWindows();
|
||||
}
|
||||
}
|
||||
|
||||
_tileWindows() {
|
||||
Logger.log("TILING WINDOWS ON MONITOR", this._id)
|
||||
const workspace = global.workspace_manager.get_active_workspace();
|
||||
const workArea = workspace.get_work_area_for_monitor(
|
||||
this._id
|
||||
);
|
||||
Logger.log("Workspace", workspace);
|
||||
Logger.log("WorkArea", workArea);
|
||||
|
||||
// Get all windows for current workspace
|
||||
const windows = Array.from(this._windows.values())
|
||||
.filter(({_window}) => {
|
||||
|
||||
if (_window != null) {
|
||||
return _window.get_workspace() === workspace;
|
||||
getWindow(windowId: number): WindowWrapper | undefined {
|
||||
for (const container of this._workspaces) {
|
||||
const win = container.getWindow(windowId);
|
||||
if (win) {
|
||||
return win;
|
||||
}
|
||||
})
|
||||
.map(x => x);
|
||||
|
||||
if (windows.length === 0) {
|
||||
return;
|
||||
}
|
||||
this._tileHorizontally(windows, workArea)
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
_tileHorizontally(windows: (WindowWrapper | null)[], workArea: Mtk.Rectangle) {
|
||||
const windowWidth = Math.floor(workArea.width / windows.length);
|
||||
|
||||
windows.forEach((window, index) => {
|
||||
const x = workArea.x + (index * windowWidth);
|
||||
const rect = {
|
||||
x: x,
|
||||
y: workArea.y,
|
||||
width: windowWidth,
|
||||
height: workArea.height
|
||||
};
|
||||
if (window != null) {
|
||||
window.safelyResizeWindow(rect.x, rect.y, rect.width, rect.height);
|
||||
removeWindow(winWrap: WindowWrapper) {
|
||||
const windowId = winWrap.getWindowId();
|
||||
for (const container of this._workspaces) {
|
||||
const win = container.getWindow(windowId);
|
||||
if (win) {
|
||||
container.removeWindow(windowId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addWindow(winWrap: WindowWrapper) {
|
||||
const window_workspace = winWrap.getWindow().get_workspace().index();
|
||||
Logger.log("Adding window to workspace", window_workspace);
|
||||
this._workspaces[window_workspace].addWindow(winWrap);
|
||||
}
|
||||
|
||||
tileWindows(): void {
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
20
src/utils/events.ts
Normal file
20
src/utils/events.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
|
||||
export type QueuedEvent = {
|
||||
name: string;
|
||||
callback: () => void;
|
||||
}
|
||||
|
||||
const queuedEvents: QueuedEvent[] = [];
|
||||
|
||||
export default function queueEvent(event: QueuedEvent, interval = 200) {
|
||||
queuedEvents.push(event);
|
||||
GLib.timeout_add(GLib.PRIORITY_DEFAULT, interval, () => {
|
||||
const e = queuedEvents.pop()
|
||||
if (e) {
|
||||
e.callback();
|
||||
}
|
||||
return queuedEvents.length !== 0;
|
||||
});
|
||||
}
|
||||
6
src/utils/rect.ts
Normal file
6
src/utils/rect.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export type Rect = {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
199
src/window.ts
199
src/window.ts
@@ -1,22 +1,24 @@
|
||||
import Meta from 'gi://Meta';
|
||||
import GLib from "gi://GLib";
|
||||
import Clutter from "gi://Clutter";
|
||||
import {IWindowManager} from "./windowManager.js";
|
||||
import {Logger} from "./utils/logger.js";
|
||||
import {Rect} from "./utils/rect.js";
|
||||
import WindowContainer from "./container.js";
|
||||
|
||||
export type Signal = {
|
||||
name: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
type WindowMinimizedHandler = (window: WindowWrapper) => void;
|
||||
type WindowWorkspaceChangedHandler = (window: WindowWrapper) => void;
|
||||
|
||||
export class WindowWrapper {
|
||||
readonly _window: Meta.Window;
|
||||
readonly _windowMinimizedHandler: WindowMinimizedHandler;
|
||||
readonly _signals: Signal[];
|
||||
// readonly _windowWorkspaceChangedHandler: WindowWorkspaceChangedHandler;
|
||||
readonly _signals: number[];
|
||||
|
||||
constructor(window: Meta.Window, winMinimized: WindowMinimizedHandler) {
|
||||
constructor(
|
||||
window: Meta.Window,
|
||||
winMinimized: WindowMinimizedHandler
|
||||
) {
|
||||
this._window = window;
|
||||
this._signals = [];
|
||||
this._windowMinimizedHandler = winMinimized;
|
||||
@@ -33,199 +35,76 @@ export class WindowWrapper {
|
||||
connectWindowSignals(
|
||||
windowManager: IWindowManager,
|
||||
): void {
|
||||
|
||||
const windowId = this._window.get_id();
|
||||
|
||||
|
||||
const windowId = this._window.get_id()
|
||||
// Handle window destruction
|
||||
const destroyId = this._window.connect('unmanaging', window => {
|
||||
this._signals.push(
|
||||
this._window.connect('unmanaging', window => {
|
||||
Logger.log("REMOVING WINDOW", windowId);
|
||||
windowManager.handleWindowClosed(this)
|
||||
});
|
||||
this._signals.push({name: 'unmanaging', id: destroyId});
|
||||
|
||||
// Handle focus changes
|
||||
const focusId = this._window.connect('notify::has-focus', () => {
|
||||
if (this._window.has_focus()) {
|
||||
windowManager._activeWindowId = windowId;
|
||||
}
|
||||
});
|
||||
this._signals.push({name: 'notify::has-focus', id: focusId});
|
||||
|
||||
// Track window movement using position-changed signal
|
||||
let lastPositionChangeTime = 0;
|
||||
let dragInProgress = false;
|
||||
|
||||
// const positionChangedId = this._window.connect('position-changed', window => {
|
||||
// Logger.log("position-changed", window.get_id());
|
||||
// Logger.log(window.get_monitor())
|
||||
// // const currentTime = Date.now();
|
||||
// // const [x, y, _] = global.get_pointer();
|
||||
// //
|
||||
// // // If this is the first move or it's been a while since the last move, consider it the start of a drag
|
||||
// // if (!dragInProgress) {
|
||||
// // dragInProgress = true;
|
||||
// // Logger.log(`Window drag started for window ${windowId}. Mouse position: ${x}, ${y}`);
|
||||
// // }
|
||||
// //
|
||||
// // // Update the time of the last position change
|
||||
// // lastPositionChangeTime = currentTime;
|
||||
// //
|
||||
// // // Set a timeout to detect when dragging stops (when position changes stop coming in)
|
||||
// // GLib.timeout_add(GLib.PRIORITY_DEFAULT, 300, () => {
|
||||
// // const timeSinceLastMove = Date.now() - lastPositionChangeTime;
|
||||
// // // If it's been more than 200ms since the last move and we were dragging, consider the drag ended
|
||||
// // if (timeSinceLastMove >= 200 && dragInProgress) {
|
||||
// // dragInProgress = false;
|
||||
// // const [endX, endY, _] = global.get_pointer();
|
||||
// // Logger.log(`Window drag ended for window ${windowId}. Mouse position: ${endX}, ${endY}`);
|
||||
// // }
|
||||
// // return GLib.SOURCE_REMOVE; // Remove the timeout
|
||||
// // });
|
||||
// });
|
||||
// this._signals.push({name: 'position-changed', id: positionChangedId});
|
||||
|
||||
// Handle minimization
|
||||
const minimizeId = this._window.connect('notify::minimized', () => {
|
||||
}),
|
||||
this._window.connect('notify::minimized', (we) => {
|
||||
if (this._window.minimized) {
|
||||
Logger.log(`Window minimized: ${windowId}`);
|
||||
// Remove window from managed windows temporarily
|
||||
// windowManager.removeFromTree(this._window);
|
||||
// If this was the active window, find a new one
|
||||
// Retile remaining windows
|
||||
windowManager.handleWindowMinimized(this);
|
||||
|
||||
} else if (!this._window.minimized) {
|
||||
Logger.log(`Window unminimized: ${windowId}`);
|
||||
// windowManager.addWindow(this._window);
|
||||
windowManager.handleWindowUnminimized(this);
|
||||
|
||||
}
|
||||
});
|
||||
this._signals.push({name: 'notify::minimized', id: minimizeId});
|
||||
|
||||
// Handle maximization
|
||||
const maximizeId = this._window.connect('notify::maximized-horizontally', () => {
|
||||
}),
|
||||
this._window.connect('notify::has-focus', () => {
|
||||
if (this._window.has_focus()) {
|
||||
windowManager._activeWindowId = windowId;
|
||||
}
|
||||
}),
|
||||
this._window.connect('notify::maximized-horizontally', () => {
|
||||
if (this._window.get_maximized()) {
|
||||
Logger.log(`Window maximized: ${windowId}`);
|
||||
} else {
|
||||
Logger.log(`Window unmaximized: ${windowId}`);
|
||||
}
|
||||
});
|
||||
this._signals.push({name: 'notify::maximized-horizontally', id: maximizeId});
|
||||
}),
|
||||
this._window.connect("workspace-changed", (_metaWindow) => {
|
||||
Logger.log("WORKSPACE CHANGED FOR WINDOW", this._window.get_id());
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
disconnectWindowSignals(): void {
|
||||
|
||||
// Disconnect signals
|
||||
if (this._signals) {
|
||||
this._signals.forEach(signal => {
|
||||
try {
|
||||
if (this._window != null) {
|
||||
this._window.disconnect(signal.id);
|
||||
this._window.disconnect(signal);
|
||||
}
|
||||
} catch (e) {
|
||||
// Window might already be gone
|
||||
Logger.warn("error disconnecting signal", signal, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
resizeWindow(x: number, y: number, width: number, height: number) {
|
||||
// First, ensure window is not maximized or fullscreen
|
||||
if (this._window.get_maximized()) {
|
||||
Logger.log("WINDOW MAXIMIZED")
|
||||
this._window.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
}
|
||||
|
||||
if (this._window.is_fullscreen()) {
|
||||
Logger.log("WINDOW IS FULLSCREEN")
|
||||
this._window.unmake_fullscreen();
|
||||
}
|
||||
// Logger.log("WINDOW", this._window.get_window_type(), this._window.allows_move());
|
||||
// Logger.log("MONITOR INFO", getUsableMonitorSpace(this._window));
|
||||
// Logger.log("NEW_SIZE", x, y, width, height);
|
||||
// win.move_resize_frame(false, 50, 50, 300, 300);
|
||||
this._window.move_resize_frame(false, x, y, width, height);
|
||||
// Logger.log("RESIZED WINDOW", this._window.get_frame_rect().height, this._window.get_frame_rect().width, this._window.get_frame_rect().x, this._window.get_frame_rect().y);
|
||||
}
|
||||
|
||||
safelyResizeWindow(x: number, y: number, width: number, height: number): void {
|
||||
Logger.log("SAFELY RESIZE", x, y, width, height);
|
||||
// This is meant to be an exact copy of Forge's move function, renamed to maintain your API
|
||||
safelyResizeWindow(rect: Rect): void {
|
||||
// Keep minimal logging
|
||||
Logger.log("SAFELY RESIZE", rect.x, rect.y, rect.width, rect.height);
|
||||
const actor = this._window.get_compositor_private();
|
||||
|
||||
if (!actor) {
|
||||
Logger.log("No actor available, can't resize safely yet");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set a flag to track if the resize has been done
|
||||
let resizeDone = false;
|
||||
|
||||
// Connect to the first-frame signal
|
||||
const id = actor.connect('first-frame', () => {
|
||||
// Disconnect the signal handler
|
||||
actor.disconnect(id);
|
||||
|
||||
if (!resizeDone) {
|
||||
resizeDone = true;
|
||||
|
||||
// Add a small delay
|
||||
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => {
|
||||
try {
|
||||
this.resizeWindow(x, y, width, height);
|
||||
} catch (e) {
|
||||
console.error("Error resizing window:", e);
|
||||
}
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Fallback timeout in case the first-frame signal doesn't fire
|
||||
// (for windows that are already mapped)
|
||||
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => {
|
||||
if (!resizeDone) {
|
||||
resizeDone = true;
|
||||
try {
|
||||
this.resizeWindow(x, y, width, height);
|
||||
} catch (e) {
|
||||
console.error("Error resizing window (fallback):", e);
|
||||
}
|
||||
}
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
}
|
||||
|
||||
// if (!this._window) return;
|
||||
// this._window.unmaximize(Meta.MaximizeFlags.HORIZONTAL);
|
||||
// this._window.unmaximize(Meta.MaximizeFlags.VERTICAL);
|
||||
// this._window.unmaximize(Meta.MaximizeFlags.BOTH);
|
||||
//
|
||||
// let windowActor = this._window.get_compositor_private() as Clutter.Actor;
|
||||
// if (!windowActor) return;
|
||||
// windowActor.remove_all_transitions();
|
||||
//
|
||||
// this._window.move_frame(true, x, y);
|
||||
// this._window.move_resize_frame(true, x, y, width, height);
|
||||
|
||||
let windowActor = this._window.get_compositor_private() as Clutter.Actor;
|
||||
if (!windowActor) return;
|
||||
windowActor.remove_all_transitions();
|
||||
Logger.info("MOVING")
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
function getUsableMonitorSpace(window: Meta.Window) {
|
||||
// Get the current workspace
|
||||
const workspace = window.get_workspace();
|
||||
|
||||
// Get the monitor index that this window is on
|
||||
const monitorIndex = window.get_monitor();
|
||||
|
||||
// Get the work area
|
||||
const workArea = workspace.get_work_area_for_monitor(monitorIndex);
|
||||
|
||||
return {
|
||||
x: workArea.x,
|
||||
y: workArea.y,
|
||||
width: workArea.width,
|
||||
height: workArea.height
|
||||
};
|
||||
}
|
||||
@@ -6,7 +6,10 @@ import {WindowWrapper} from './window.js';
|
||||
import * as Main from "resource:///org/gnome/shell/ui/main.js";
|
||||
import Mtk from "@girs/mtk-16";
|
||||
import {Logger} from "./utils/logger.js";
|
||||
import MonitorManager from "./monitor.js";
|
||||
import WindowContainer from "./container.js";
|
||||
import {MessageTray} from "@girs/gnome-shell/ui/messageTray";
|
||||
import queueEvent, {QueuedEvent} from "./utils/events.js";
|
||||
import Monitor from "./monitor.js";
|
||||
|
||||
|
||||
export interface IWindowManager {
|
||||
@@ -15,7 +18,9 @@ export interface IWindowManager {
|
||||
// addWindow(window: Meta.Window): void;
|
||||
|
||||
handleWindowClosed(winWrap: WindowWrapper): void;
|
||||
|
||||
handleWindowMinimized(winWrap: WindowWrapper): void;
|
||||
|
||||
handleWindowUnminimized(winWrap: WindowWrapper): void;
|
||||
|
||||
|
||||
@@ -23,61 +28,52 @@ export interface IWindowManager {
|
||||
syncActiveWindow(): number | null;
|
||||
}
|
||||
|
||||
|
||||
const _UNUSED_MONITOR_ID = -1
|
||||
export default class WindowManager implements IWindowManager {
|
||||
_displaySignals: number[];
|
||||
_windowManagerSignals: number[];
|
||||
_workspaceManagerSignals: number[];
|
||||
_shieldScreenSignals: number[];
|
||||
_overviewSignals: number[];
|
||||
|
||||
_activeWindowId: number | null;
|
||||
_grabbedWindowMonitor: number;
|
||||
_monitors: Map<number, MonitorManager>;
|
||||
_monitors: Map<number, Monitor>;
|
||||
_sessionProxy: Gio.DBusProxy | null;
|
||||
_lockedSignalId: number | null;
|
||||
_isScreenLocked: boolean;
|
||||
|
||||
_minimizedItems: Map<number, WindowWrapper>;
|
||||
|
||||
constructor() {
|
||||
this._displaySignals = [];
|
||||
this._windowManagerSignals = [];
|
||||
this._workspaceManagerSignals = [];
|
||||
this._overviewSignals = [];
|
||||
this._shieldScreenSignals = [];
|
||||
this._activeWindowId = null;
|
||||
this._grabbedWindowMonitor = _UNUSED_MONITOR_ID;
|
||||
this._monitors = new Map<number, MonitorManager>();
|
||||
this._monitors = new Map<number, Monitor>();
|
||||
this._sessionProxy = null;
|
||||
this._lockedSignalId = null;
|
||||
this._isScreenLocked = false;
|
||||
this._isScreenLocked = false; // Initialize to unlocked state
|
||||
|
||||
this._minimizedItems = new Map<number, WindowWrapper>();
|
||||
|
||||
}
|
||||
|
||||
public enable(): void {
|
||||
Logger.log("Starting Aerospike Window Manager");
|
||||
this.captureExistingWindows();
|
||||
// Connect window signals
|
||||
this.instantiateDisplaySignals()
|
||||
this.instantiateDisplaySignals();
|
||||
|
||||
const mon_count = global.display.get_n_monitors();
|
||||
for (let i = 0; i < mon_count; i++) {
|
||||
this._monitors.set(i, new MonitorManager(i));
|
||||
}
|
||||
this._monitors.set(i, new Monitor(i));
|
||||
}
|
||||
|
||||
public disable(): void {
|
||||
Logger.log("DISABLED AEROSPIKE WINDOW MANAGER!")
|
||||
// Disconnect the focus signal and remove any existing borders
|
||||
this.disconnectDisplaySignals();
|
||||
this.removeAllWindows();
|
||||
this.captureExistingWindows();
|
||||
}
|
||||
|
||||
removeAllWindows(): void {
|
||||
this._monitors.forEach((monitor: MonitorManager) => {
|
||||
monitor.removeAllWindows();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
instantiateDisplaySignals(): void {
|
||||
this._displaySignals.push(
|
||||
global.display.connect("grab-op-begin", (display, window, op) => {
|
||||
@@ -92,61 +88,51 @@ export default class WindowManager implements IWindowManager {
|
||||
global.display.connect('window-created', (display, window) => {
|
||||
this.handleWindowCreated(display, window);
|
||||
}),
|
||||
|
||||
global.display.connect("showing-desktop-changed", () => {
|
||||
Logger.log("SHOWING DESKTOP CHANGED");
|
||||
}),
|
||||
global.display.connect("workareas-changed", () => {
|
||||
Logger.log("WORK AREAS CHANGED");
|
||||
global.display.connect("workareas-changed", (display) => {
|
||||
Logger.log("WORK AREAS CHANGED", );
|
||||
console.log(display.get_workspace_manager().get_active_workspace_index())
|
||||
}),
|
||||
global.display.connect("in-fullscreen-changed", () => {
|
||||
Logger.log("IN FULL SCREEN CHANGED");
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
this._windowManagerSignals = [
|
||||
// global.window_manager.connect("minimize", (_source, window) => {
|
||||
// Logger.log("MINIMIZING WINDOW")
|
||||
// }),
|
||||
// global.window_manager.connect("unminimize", (_source, window) => {
|
||||
// Logger.log("WINDOW UNMINIMIZED");
|
||||
// }),
|
||||
global.window_manager.connect("show-tile-preview", (_, _metaWindow, _rect, _num) => {
|
||||
Logger.log("SHOW TITLE PREVIEW!")
|
||||
}),
|
||||
];
|
||||
|
||||
|
||||
this._workspaceManagerSignals = [
|
||||
global.workspace_manager.connect("showing-desktop-changed", () => {
|
||||
Logger.log("SHOWING DESKTOP CHANGED AT WORKSPACE LEVEL");
|
||||
}),
|
||||
global.workspace_manager.connect("workspace-added", (_, wsIndex) => {
|
||||
Logger.log("WORKSPACE ADDED");
|
||||
Logger.log("WORKSPACE ADDED", wsIndex);
|
||||
}),
|
||||
global.workspace_manager.connect("workspace-removed", (_, wsIndex) => {
|
||||
Logger.log("WORKSPACE REMOVED");
|
||||
Logger.log("WORKSPACE REMOVED", wsIndex);
|
||||
}),
|
||||
global.workspace_manager.connect("active-workspace-changed", () => {
|
||||
Logger.log("Active workspace-changed");
|
||||
global.workspace_manager.connect("active-workspace-changed", (source) => {
|
||||
Logger.log("Active workspace-changed", source.get_active_workspace().index());
|
||||
}),
|
||||
];
|
||||
|
||||
|
||||
this._overviewSignals = [
|
||||
Main.overview.connect("hiding", () => {
|
||||
// this.fromOverview = true;
|
||||
Logger.log("HIDING OVERVIEW")
|
||||
const eventObj = {
|
||||
name: "focus-after-overview",
|
||||
callback: () => {
|
||||
// const focusNodeWindow = this.tree.findNode(this.focusMetaWindow);
|
||||
// this.updateStackedFocus(focusNodeWindow);
|
||||
// this.updateTabbedFocus(focusNodeWindow);
|
||||
// this.movePointerWith(focusNodeWindow);
|
||||
Logger.log("FOCUSING AFTER OVERVIEW");
|
||||
},
|
||||
};
|
||||
this._tileMonitors();
|
||||
// const eventObj = {
|
||||
// name: "focus-after-overview",
|
||||
// callback: () => {
|
||||
// Logger.log("FOCUSING AFTER OVERVIEW");
|
||||
// },
|
||||
// };
|
||||
// this.queueEvent(eventObj);
|
||||
}),
|
||||
Main.overview.connect("showing", () => {
|
||||
@@ -155,34 +141,58 @@ export default class WindowManager implements IWindowManager {
|
||||
}),
|
||||
];
|
||||
|
||||
// Main.screenShield;
|
||||
|
||||
// Handler for lock event
|
||||
this._shieldScreenSignals.push(Main.screenShield.connect('lock-screen', () => {
|
||||
console.log('Session locked at:', new Date().toISOString());
|
||||
}), Main.screenShield.connect('unlock-screen', () => {
|
||||
console.log('Session unlocked at:', new Date().toISOString());
|
||||
}
|
||||
|
||||
public disable(): void {
|
||||
Logger.log("DISABLED AEROSPIKE WINDOW MANAGER!")
|
||||
// Disconnect the focus signal and remove any existing borders
|
||||
this.disconnectSignals();
|
||||
this.removeAllWindows();
|
||||
}
|
||||
|
||||
removeAllWindows(): void {
|
||||
this._monitors.forEach((monitor: Monitor) => {
|
||||
monitor.removeAllWindows();
|
||||
})
|
||||
);
|
||||
this._minimizedItems.clear();
|
||||
}
|
||||
|
||||
// Handler for unlock event
|
||||
|
||||
// this._signalsBound = true;
|
||||
disconnectSignals(): void {
|
||||
this.disconnectDisplaySignals();
|
||||
this.disconnectMonitorSignals();
|
||||
this.disconnectMinimizedSignals();
|
||||
}
|
||||
|
||||
disconnectMonitorSignals(): void {
|
||||
this._monitors.forEach((monitor: Monitor) => {
|
||||
monitor.disconnectSignals();
|
||||
})
|
||||
}
|
||||
|
||||
disconnectDisplaySignals(): void {
|
||||
this._displaySignals.forEach((signal) => {
|
||||
global.disconnect(signal)
|
||||
global.display.disconnect(signal)
|
||||
})
|
||||
this._windowManagerSignals.forEach((signal) => {
|
||||
global.disconnect(signal)
|
||||
global.window_manager.disconnect(signal)
|
||||
})
|
||||
this._workspaceManagerSignals.forEach((signal) => {
|
||||
global.disconnect(signal)
|
||||
global.workspace_manager.disconnect(signal)
|
||||
})
|
||||
this._overviewSignals.forEach((signal) => {
|
||||
Main.overview.disconnect(signal)
|
||||
})
|
||||
}
|
||||
|
||||
disconnectMinimizedSignals(): void {
|
||||
this._minimizedItems.forEach((item) => {
|
||||
item.disconnectWindowSignals();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
handleGrabOpBegin(display: Meta.Display, window: Meta.Window, op: Meta.GrabOp): void {
|
||||
Logger.log("Grab Op Start");
|
||||
Logger.log(display, window, op)
|
||||
@@ -195,7 +205,6 @@ export default class WindowManager implements IWindowManager {
|
||||
Logger.log("primary display", display.get_primary_monitor())
|
||||
var rect = window.get_frame_rect()
|
||||
Logger.info("Release Location", window.get_monitor(), rect.x, rect.y, rect.width, rect.height)
|
||||
this._tileMonitors();
|
||||
const old_mon_id = this._grabbedWindowMonitor;
|
||||
const new_mon_id = window.get_monitor();
|
||||
|
||||
@@ -207,31 +216,40 @@ export default class WindowManager implements IWindowManager {
|
||||
if (old_mon === undefined || new_mon === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
let wrapped = old_mon.getWindow(window.get_id())
|
||||
if (wrapped === undefined) {
|
||||
wrapped = new WindowWrapper(window, this.handleWindowMinimized);
|
||||
} else {
|
||||
old_mon.removeWindow(window.get_id())
|
||||
old_mon.removeWindow(wrapped)
|
||||
}
|
||||
new_mon.addWindow(wrapped)
|
||||
}
|
||||
this._tileMonitors();
|
||||
Logger.info("monitor_start and monitor_end", this._grabbedWindowMonitor, window.get_monitor());
|
||||
}
|
||||
|
||||
public handleWindowMinimized(winWrap: WindowWrapper): void {
|
||||
Logger.warn("WARNING MINIMIZING WINDOW");
|
||||
Logger.log("WARNING MINIMIZED", winWrap);
|
||||
Logger.log("WARNING MINIMIZED", JSON.stringify(winWrap));
|
||||
const monitor_id = winWrap.getWindow().get_monitor()
|
||||
Logger.log("WARNING MINIMIZED", monitor_id);
|
||||
Logger.warn("WARNING MINIMIZED", this._monitors);
|
||||
this._monitors.get(monitor_id)?.minimizeWindow(winWrap);
|
||||
|
||||
this._minimizedItems.set(winWrap.getWindowId(), winWrap);
|
||||
this._monitors.get(monitor_id)?.removeWindow(winWrap);
|
||||
|
||||
Logger.warn("WARNING MINIMIZED ITEMS", JSON.stringify(this._minimizedItems));
|
||||
this._tileMonitors()
|
||||
}
|
||||
|
||||
public handleWindowUnminimized(winWrap: WindowWrapper): void {
|
||||
Logger.log("WINDOW UNMINIMIZED");
|
||||
const monitor_id = winWrap.getWindow().get_monitor()
|
||||
this._monitors.get(monitor_id)?.unminimizeWindow(winWrap);
|
||||
Logger.log("WINDOW UNMINIMIZED", winWrap == null);
|
||||
// Logger.log("WINDOW UNMINIMIZED", winWrap);
|
||||
// Logger.log("WINDOW UNMINIMIZED", winWrap.getWindowId());
|
||||
this._minimizedItems.delete(winWrap.getWindowId());
|
||||
this._addWindowWrapperToMonitor(winWrap);
|
||||
this._tileMonitors()
|
||||
}
|
||||
|
||||
@@ -256,10 +274,6 @@ export default class WindowManager implements IWindowManager {
|
||||
return;
|
||||
}
|
||||
Logger.log("WINDOW IS TILABLE");
|
||||
const actor = window.get_compositor_private();
|
||||
if (!actor) {
|
||||
return;
|
||||
}
|
||||
this.addWindowToMonitor(window);
|
||||
}
|
||||
|
||||
@@ -269,10 +283,11 @@ export default class WindowManager implements IWindowManager {
|
||||
*/
|
||||
handleWindowClosed(window: WindowWrapper): void {
|
||||
|
||||
window.disconnectWindowSignals()
|
||||
const mon_id = window._window.get_monitor();
|
||||
this._monitors.get(mon_id)?.removeWindow(window.getWindowId());
|
||||
|
||||
this._monitors.get(mon_id)?.removeWindow(window);
|
||||
|
||||
window.disconnectWindowSignals()
|
||||
// Remove from managed windows
|
||||
this.syncActiveWindow();
|
||||
// Retile remaining windows
|
||||
@@ -281,29 +296,29 @@ 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)
|
||||
wrapper.connectWindowSignals(this)
|
||||
this._monitors.get(window.get_monitor())?.addWindow(wrapper)
|
||||
wrapper.connectWindowSignals(this);
|
||||
this._addWindowWrapperToMonitor(wrapper);
|
||||
|
||||
}
|
||||
_addWindowWrapperToMonitor(winWrap: WindowWrapper) {
|
||||
if (winWrap.getWindow().minimized) {
|
||||
this._minimizedItems.set(winWrap.getWindow().get_id(), winWrap);
|
||||
}
|
||||
this._monitors.get(winWrap.getWindow().get_monitor())?.addWindow(winWrap)
|
||||
}
|
||||
|
||||
// public UnmanageWindow(window: Meta.Window) {
|
||||
// this._windows.delete(window.get_id());
|
||||
// this._unmanagedWindows.add(window.get_id())
|
||||
// }
|
||||
//
|
||||
// public ManageWindow(window: Meta.Window) {
|
||||
// this._windows.set(window.get_id(), {
|
||||
// window,
|
||||
// })
|
||||
// }
|
||||
|
||||
_tileMonitors(): void {
|
||||
|
||||
for (const monitor of this._monitors.values()) {
|
||||
monitor._tileWindows()
|
||||
monitor.tileWindows()
|
||||
}
|
||||
}
|
||||
|
||||
_isWindowTileable(window: Meta.Window) {
|
||||
|
||||
if (!window || !window.get_compositor_private()) {
|
||||
return false;
|
||||
}
|
||||
@@ -329,47 +344,6 @@ export default class WindowManager implements IWindowManager {
|
||||
* @returns The window ID of the active window, or null if no window is active
|
||||
*/
|
||||
public syncActiveWindow(): number | null {
|
||||
// // Get the active workspace
|
||||
// const workspace = global.workspace_manager.get_active_workspace();
|
||||
//
|
||||
// // Check if there is an active window
|
||||
// const activeWindow = global.display.get_focus_window();
|
||||
//
|
||||
// if (!activeWindow) {
|
||||
// Logger.log("No active window found in GNOME");
|
||||
// this._activeWindowId = null;
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // Get the window ID
|
||||
// const windowId = activeWindow.get_id();
|
||||
//
|
||||
// // Check if this window is being managed by our extension
|
||||
// if (this._windows.has(windowId)) {
|
||||
// Logger.log(`Setting active window to ${windowId}`);
|
||||
// this._activeWindowId = windowId;
|
||||
// return windowId;
|
||||
// } else {
|
||||
// Logger.log(`Window ${windowId} is not managed by this extension`);
|
||||
//
|
||||
// // Try to find a managed window on the current workspace to make active
|
||||
// const managedWindows = Array.from(this._windows.entries())
|
||||
// .filter(([_, wrapper]) =>
|
||||
// wrapper.window && wrapper.window.get_workspace() === workspace);
|
||||
//
|
||||
// if (managedWindows.length > 0) {
|
||||
// // Take the first managed window on this workspace
|
||||
// const firstWindowId = managedWindows[0][0];
|
||||
// Logger.log(`Using managed window ${firstWindowId} as active instead`);
|
||||
// this._activeWindowId = firstWindowId;
|
||||
// return firstWindowId;
|
||||
// }
|
||||
//
|
||||
// // No managed windows on this workspace
|
||||
// Logger.log("No managed windows found on the active workspace");
|
||||
// this._activeWindowId = null;
|
||||
// return null;
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user