feat: refactoring

This commit is contained in:
Lucas Oskorep
2025-05-04 17:17:33 -04:00
parent 195ada30fb
commit 012f575ad5
5 changed files with 128 additions and 134 deletions

View File

@@ -1,24 +1,16 @@
import Meta from 'gi://Meta';
import St from "gi://St";
import Clutter from "gi://Clutter";
import GObject from "gi://GObject";
import GLib from "gi://GLib";
import * as Main from "resource:///org/gnome/shell/ui/main.js";
import {IWindowManager} from "./windowManager.js";
import {Logger} from "./utils/logger.js";
import MaximizeFlags = Meta.MaximizeFlags;
import {Rect} from "./utils/rect.js";
export type Signal = {
name: string;
id: number;
}
type WindowMinimizedHandler = (window: WindowWrapper) => void;
export class WindowWrapper {
readonly _window: Meta.Window;
readonly _windowMinimizedHandler: WindowMinimizedHandler;
readonly _signals: Signal[];
readonly _signals: number[];
constructor(window: Meta.Window, winMinimized: WindowMinimizedHandler) {
this._window = window;
@@ -37,58 +29,46 @@ 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 => {
Logger.log("REMOVING WINDOW", windowId);
windowManager.handleWindowClosed(this)
});
this._signals.push({name: 'unmanaging', id: destroyId});
this._signals.push(
this._window.connect('unmanaging', window => {
Logger.log("REMOVING WINDOW", windowId);
windowManager.handleWindowClosed(this)
}),
this._window.connect('notify::minimized', () => {
if (this._window.minimized) {
Logger.log(`Window minimized: ${windowId}`);
windowManager.handleWindowMinimized(this);
// 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});
} else if (!this._window.minimized) {
Logger.log(`Window unminimized: ${windowId}`);
windowManager.handleWindowUnminimized(this);
// Handle minimization
const minimizeId = this._window.connect('notify::minimized', () => {
if (this._window.minimized) {
Logger.log(`Window minimized: ${windowId}`);
windowManager.handleWindowMinimized(this);
} else if (!this._window.minimized) {
Logger.log(`Window unminimized: ${windowId}`);
windowManager.handleWindowUnminimized(this);
}
});
this._signals.push({name: 'notify::minimized', id: minimizeId});
// Handle maximization
const maximizeId = 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('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}`);
}
}),
);
}
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) {
Logger.warn("error disconnecting signal", signal, e);
@@ -97,49 +77,24 @@ export class WindowWrapper {
}
}
resizeWindow(x: number, y: number, width: number, height: number) {
Logger.info(this._window.allows_move())
Logger.info(this._window.allows_resize())
if (this._window.get_maximized() == MaximizeFlags.BOTH || this._window.is_fullscreen() || this._window.is_monitor_sized()) {
Logger.info("is monitor sized?", this._window.is_monitor_sized());
Logger.info("is monitor sized?", this._window.is_fullscreen());
Logger.info("is monitor sized?", this._window.get_maximized());
Logger.info("is monitor sized?", this._window.get_maximized() == MaximizeFlags.BOTH);
Logger.info("window is fullscreen or maximized and will not be resized", this._window)
return;
// Logger.log("WINDOW IS FULLSCREEN")
// this._window.unmake_fullscreen();
}
this._window.move_resize_frame(false, x, y, width, height);
}
// This is meant to be an exact copy of Forge's move function, renamed to maintain your API
safelyResizeWindow(x: number, y: number, width: number, height: number): void {
safelyResizeWindow(rect: Rect): void {
// Keep minimal logging
Logger.log("SAFELY RESIZE", x, y, width, height);
// Simple early returns like Forge
if (!this._window) return;
// Skip the this._window.grabbed check since we confirmed it doesn't exist in Meta.Window
// Unmaximize in all directions - no try/catch to match Forge
this._window.unmaximize(Meta.MaximizeFlags.HORIZONTAL);
this._window.unmaximize(Meta.MaximizeFlags.VERTICAL);
this._window.unmaximize(Meta.MaximizeFlags.BOTH);
// Get actor and return early if not available - no try/catch
const windowActor = this._window.get_compositor_private() as Clutter.Actor;
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;
}
let windowActor = this._window.get_compositor_private() as Clutter.Actor;
if (!windowActor) return;
// Remove transitions - no try/catch
windowActor.remove_all_transitions();
// Move and resize in exact order as Forge - no try/catch
this._window.move_frame(true, x, y);
this._window.move_resize_frame(true, x, y, width, height);
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);
}