feat: fixed display signal handling on disable

This commit is contained in:
Lucas Oskorep
2025-05-02 01:31:46 -04:00
parent 822a7bd2e4
commit 717c240d70
5 changed files with 89 additions and 224 deletions

View File

@@ -26,6 +26,7 @@ export default class aerospike extends Extension {
disable() { disable() {
this.windowManager.disable() this.windowManager.disable()
this.removeKeybindings()
} }

View File

@@ -33,7 +33,7 @@ run:
install-and-run: install run install-and-run: install run
live-debug: live-debug:
journalctl /usr/bin/gnome-shell -f -o cat journalctl /usr/bin/gnome-shell -f -o cat | tee debug.log
#pack: build #pack: build
# gnome-extensions pack dist \ # gnome-extensions pack dist \

View File

@@ -45,6 +45,13 @@ export default class MonitorManager {
} }
} }
disconnectSignals(): void {
this._windows.forEach((window) => {
window.disconnectWindowSignals();
}
)
}
removeAllWindows(): void { removeAllWindows(): void {
this._windows.clear() this._windows.clear()
} }
@@ -72,7 +79,6 @@ export default class MonitorManager {
return; return;
} }
this._tileHorizontally(windows, workArea) this._tileHorizontally(windows, workArea)
} }

View File

@@ -1,8 +1,12 @@
import Meta from 'gi://Meta'; import Meta from 'gi://Meta';
import GLib from "gi://GLib"; import St from "gi://St";
import Clutter from "gi://Clutter"; 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 {IWindowManager} from "./windowManager.js";
import {Logger} from "./utils/logger.js"; import {Logger} from "./utils/logger.js";
import MaximizeFlags = Meta.MaximizeFlags;
export type Signal = { export type Signal = {
name: string; name: string;
@@ -36,7 +40,6 @@ export class WindowWrapper {
const windowId = this._window.get_id(); const windowId = this._window.get_id();
// Handle window destruction // Handle window destruction
const destroyId = this._window.connect('unmanaging', window => { const destroyId = this._window.connect('unmanaging', window => {
Logger.log("REMOVING WINDOW", windowId); Logger.log("REMOVING WINDOW", windowId);
@@ -52,52 +55,15 @@ export class WindowWrapper {
}); });
this._signals.push({name: 'notify::has-focus', id: focusId}); 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 // Handle minimization
const minimizeId = this._window.connect('notify::minimized', () => { const minimizeId = this._window.connect('notify::minimized', () => {
if (this._window.minimized) { if (this._window.minimized) {
Logger.log(`Window minimized: ${windowId}`); 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); windowManager.handleWindowMinimized(this);
} else if (!this._window.minimized) { } else if (!this._window.minimized) {
Logger.log(`Window unminimized: ${windowId}`); Logger.log(`Window unminimized: ${windowId}`);
// windowManager.addWindow(this._window);
windowManager.handleWindowUnminimized(this); windowManager.handleWindowUnminimized(this);
} }
@@ -125,107 +91,56 @@ export class WindowWrapper {
this._window.disconnect(signal.id); this._window.disconnect(signal.id);
} }
} catch (e) { } catch (e) {
// Window might already be gone Logger.warn("error disconnecting signal", signal, e);
} }
}); });
} }
} }
resizeWindow(x: number, y: number, width: number, height: number) { resizeWindow(x: number, y: number, width: number, height: number) {
// First, ensure window is not maximized or fullscreen Logger.info(this._window.allows_move())
if (this._window.get_maximized()) { Logger.info(this._window.allows_resize())
Logger.log("WINDOW MAXIMIZED")
this._window.unmaximize(Meta.MaximizeFlags.BOTH);
}
if (this._window.is_fullscreen()) { if (this._window.get_maximized() == MaximizeFlags.BOTH || this._window.is_fullscreen() || this._window.is_monitor_sized()) {
Logger.log("WINDOW IS FULLSCREEN") Logger.info("is monitor sized?", this._window.is_monitor_sized());
this._window.unmake_fullscreen(); Logger.info("is monitor sized?", this._window.is_fullscreen());
} Logger.info("is monitor sized?", this._window.get_maximized());
// Logger.log("WINDOW", this._window.get_window_type(), this._window.allows_move()); Logger.info("is monitor sized?", this._window.get_maximized() == MaximizeFlags.BOTH);
// 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.info("window is fullscreen or maximized and will not be resized", this._window)
Logger.log("SAFELY RESIZE", x, y, width, height);
const actor = this._window.get_compositor_private();
if (!actor) {
Logger.log("No actor available, can't resize safely yet");
return; return;
// Logger.log("WINDOW IS FULLSCREEN")
// this._window.unmake_fullscreen();
}
this._window.move_resize_frame(false, x, y, width, height);
} }
// Set a flag to track if the resize has been done // This is meant to be an exact copy of Forge's move function, renamed to maintain your API
let resizeDone = false; safelyResizeWindow(x: number, y: number, width: number, height: number): void {
// Keep minimal logging
Logger.log("SAFELY RESIZE", x, y, width, height);
// Connect to the first-frame signal // Simple early returns like Forge
const id = actor.connect('first-frame', () => { if (!this._window) return;
// Disconnect the signal handler
actor.disconnect(id);
if (!resizeDone) { // Skip the this._window.grabbed check since we confirmed it doesn't exist in Meta.Window
resizeDone = true;
// Add a small delay // Unmaximize in all directions - no try/catch to match Forge
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => { this._window.unmaximize(Meta.MaximizeFlags.HORIZONTAL);
try { this._window.unmaximize(Meta.MaximizeFlags.VERTICAL);
this.resizeWindow(x, y, width, height); this._window.unmaximize(Meta.MaximizeFlags.BOTH);
} catch (e) {
console.error("Error resizing window:", e);
}
return GLib.SOURCE_REMOVE;
});
}
});
// Fallback timeout in case the first-frame signal doesn't fire // Get actor and return early if not available - no try/catch
// (for windows that are already mapped) const windowActor = this._window.get_compositor_private() as Clutter.Actor;
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => { if (!windowActor) return;
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; // Remove transitions - no try/catch
// this._window.unmaximize(Meta.MaximizeFlags.HORIZONTAL); windowActor.remove_all_transitions();
// this._window.unmaximize(Meta.MaximizeFlags.VERTICAL);
// this._window.unmaximize(Meta.MaximizeFlags.BOTH); // Move and resize in exact order as Forge - no try/catch
// this._window.move_frame(true, x, y);
// let windowActor = this._window.get_compositor_private() as Clutter.Actor; this._window.move_resize_frame(true, x, y, width, height);
// if (!windowActor) return; }
// windowActor.remove_all_transitions();
//
// this._window.move_frame(true, x, y);
// this._window.move_resize_frame(true, x, y, width, 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
};
}

View File

@@ -7,6 +7,7 @@ import * as Main from "resource:///org/gnome/shell/ui/main.js";
import Mtk from "@girs/mtk-16"; import Mtk from "@girs/mtk-16";
import {Logger} from "./utils/logger.js"; import {Logger} from "./utils/logger.js";
import MonitorManager from "./monitor.js"; import MonitorManager from "./monitor.js";
import {MessageTray} from "@girs/gnome-shell/ui/messageTray";
export interface IWindowManager { export interface IWindowManager {
@@ -23,13 +24,14 @@ export interface IWindowManager {
syncActiveWindow(): number | null; syncActiveWindow(): number | null;
} }
const _UNUSED_MONITOR_ID = -1 const _UNUSED_MONITOR_ID = -1
export default class WindowManager implements IWindowManager { export default class WindowManager implements IWindowManager {
_displaySignals: number[]; _displaySignals: number[];
_windowManagerSignals: number[]; _windowManagerSignals: number[];
_workspaceManagerSignals: number[]; _workspaceManagerSignals: number[];
_shieldScreenSignals: number[];
_overviewSignals: number[]; _overviewSignals: number[];
_activeWindowId: number | null; _activeWindowId: number | null;
_grabbedWindowMonitor: number; _grabbedWindowMonitor: number;
_monitors: Map<number, MonitorManager>; _monitors: Map<number, MonitorManager>;
@@ -42,42 +44,28 @@ export default class WindowManager implements IWindowManager {
this._windowManagerSignals = []; this._windowManagerSignals = [];
this._workspaceManagerSignals = []; this._workspaceManagerSignals = [];
this._overviewSignals = []; this._overviewSignals = [];
this._shieldScreenSignals = [];
this._activeWindowId = null; this._activeWindowId = null;
this._grabbedWindowMonitor = _UNUSED_MONITOR_ID; this._grabbedWindowMonitor = _UNUSED_MONITOR_ID;
this._monitors = new Map<number, MonitorManager>(); this._monitors = new Map<number, MonitorManager>();
this._sessionProxy = null; this._sessionProxy = null;
this._lockedSignalId = null; this._lockedSignalId = null;
this._isScreenLocked = false; this._isScreenLocked = false; // Initialize to unlocked state
} }
public enable(): void { public enable(): void {
Logger.log("Starting Aerospike Window Manager"); Logger.log("Starting Aerospike Window Manager");
this.captureExistingWindows();
// Connect window signals // Connect window signals
this.instantiateDisplaySignals() this.instantiateDisplaySignals();
const mon_count = global.display.get_n_monitors(); const mon_count = global.display.get_n_monitors();
for (let i = 0; i < mon_count; i++) { for (let i = 0; i < mon_count; i++) {
this._monitors.set(i, new MonitorManager(i)); this._monitors.set(i, new MonitorManager(i));
} }
}
public disable(): void { this.captureExistingWindows();
Logger.log("DISABLED AEROSPIKE WINDOW MANAGER!")
// Disconnect the focus signal and remove any existing borders
this.disconnectDisplaySignals();
this.removeAllWindows();
} }
removeAllWindows(): void {
this._monitors.forEach((monitor: MonitorManager) => {
monitor.removeAllWindows();
})
}
instantiateDisplaySignals(): void { instantiateDisplaySignals(): void {
this._displaySignals.push( this._displaySignals.push(
global.display.connect("grab-op-begin", (display, window, op) => { global.display.connect("grab-op-begin", (display, window, op) => {
@@ -95,7 +83,7 @@ export default class WindowManager implements IWindowManager {
global.display.connect("showing-desktop-changed", () => { global.display.connect("showing-desktop-changed", () => {
Logger.log("SHOWING DESKTOP CHANGED"); Logger.log("SHOWING DESKTOP CHANGED");
}), }),
global.display.connect("workareas-changed", () => { global.display.connect("workareas-changed", (display) => {
Logger.log("WORK AREAS CHANGED"); Logger.log("WORK AREAS CHANGED");
}), }),
global.display.connect("in-fullscreen-changed", () => { global.display.connect("in-fullscreen-changed", () => {
@@ -103,20 +91,12 @@ export default class WindowManager implements IWindowManager {
}), }),
) )
this._windowManagerSignals = [ 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) => { global.window_manager.connect("show-tile-preview", (_, _metaWindow, _rect, _num) => {
Logger.log("SHOW TITLE PREVIEW!") Logger.log("SHOW TITLE PREVIEW!")
}), }),
]; ];
this._workspaceManagerSignals = [ this._workspaceManagerSignals = [
global.workspace_manager.connect("showing-desktop-changed", () => { global.workspace_manager.connect("showing-desktop-changed", () => {
Logger.log("SHOWING DESKTOP CHANGED AT WORKSPACE LEVEL"); Logger.log("SHOWING DESKTOP CHANGED AT WORKSPACE LEVEL");
@@ -132,7 +112,6 @@ export default class WindowManager implements IWindowManager {
}), }),
]; ];
this._overviewSignals = [ this._overviewSignals = [
Main.overview.connect("hiding", () => { Main.overview.connect("hiding", () => {
// this.fromOverview = true; // this.fromOverview = true;
@@ -155,34 +134,50 @@ 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()); public disable(): void {
}), Main.screenShield.connect('unlock-screen', () => { Logger.log("DISABLED AEROSPIKE WINDOW MANAGER!")
console.log('Session unlocked at:', new Date().toISOString()); // Disconnect the focus signal and remove any existing borders
this.disconnectSignals();
this.removeAllWindows();
}
removeAllWindows(): void {
this._monitors.forEach((monitor: MonitorManager) => {
monitor.removeAllWindows();
}) })
); }
// Handler for unlock event
// this._signalsBound = true; disconnectSignals(): void {
this.disconnectDisplaySignals();
this.disconnectMonitorSignals();
}
disconnectMonitorSignals(): void {
this._monitors.forEach((monitor: MonitorManager) => {
monitor.disconnectSignals();
})
} }
disconnectDisplaySignals(): void { disconnectDisplaySignals(): void {
this._displaySignals.forEach((signal) => { this._displaySignals.forEach((signal) => {
global.disconnect(signal) global.display.disconnect(signal)
}) })
this._windowManagerSignals.forEach((signal) => { this._windowManagerSignals.forEach((signal) => {
global.disconnect(signal) global.window_manager.disconnect(signal)
}) })
this._workspaceManagerSignals.forEach((signal) => { this._workspaceManagerSignals.forEach((signal) => {
global.disconnect(signal) global.workspace_manager.disconnect(signal)
})
this._overviewSignals.forEach((signal) => {
Main.overview.disconnect(signal)
}) })
} }
handleGrabOpBegin(display: Meta.Display, window: Meta.Window, op: Meta.GrabOp): void { handleGrabOpBegin(display: Meta.Display, window: Meta.Window, op: Meta.GrabOp): void {
Logger.log("Grab Op Start"); Logger.log("Grab Op Start");
Logger.log(display, window, op) Logger.log(display, window, op)
@@ -195,7 +190,6 @@ export default class WindowManager implements IWindowManager {
Logger.log("primary display", display.get_primary_monitor()) Logger.log("primary display", display.get_primary_monitor())
var rect = window.get_frame_rect() var rect = window.get_frame_rect()
Logger.info("Release Location", window.get_monitor(), rect.x, rect.y, rect.width, rect.height) Logger.info("Release Location", window.get_monitor(), rect.x, rect.y, rect.width, rect.height)
this._tileMonitors();
const old_mon_id = this._grabbedWindowMonitor; const old_mon_id = this._grabbedWindowMonitor;
const new_mon_id = window.get_monitor(); const new_mon_id = window.get_monitor();
@@ -215,6 +209,7 @@ export default class WindowManager implements IWindowManager {
} }
new_mon.addWindow(wrapped) new_mon.addWindow(wrapped)
} }
this._tileMonitors();
Logger.info("monitor_start and monitor_end", this._grabbedWindowMonitor, window.get_monitor()); Logger.info("monitor_start and monitor_end", this._grabbedWindowMonitor, window.get_monitor());
} }
@@ -286,17 +281,6 @@ export default class WindowManager implements IWindowManager {
this._monitors.get(window.get_monitor())?.addWindow(wrapper) this._monitors.get(window.get_monitor())?.addWindow(wrapper)
} }
// 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 { _tileMonitors(): void {
for (const monitor of this._monitors.values()) { for (const monitor of this._monitors.values()) {
monitor._tileWindows() monitor._tileWindows()
@@ -329,47 +313,6 @@ export default class WindowManager implements IWindowManager {
* @returns The window ID of the active window, or null if no window is active * @returns The window ID of the active window, or null if no window is active
*/ */
public syncActiveWindow(): number | null { 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; return null;
} }