Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 prevent KWin freeze in various scenarious
Browse files Browse the repository at this point in the history
This removes some hacks and functionality. Those could be added later.
  • Loading branch information
Mikhail Zolotukhin committed Oct 22, 2021
1 parent caf7d08 commit 34d24a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 48 deletions.
63 changes: 17 additions & 46 deletions src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@ export class ControllerImpl implements Controller {
public onCurrentSurfaceChanged(): void {
this.log.log(["onCurrentSurfaceChanged", { srf: this.currentSurface }]);
this.engine.arrange();
/* HACK: minimize others and change geometry with Monocle Layout and
* config.monocleMinimizeRest
*/
if (this.currentWindow) {
this.onWindowFocused(this.currentWindow);
}
}

public onWindowAdded(window: EngineWindow): void {
Expand All @@ -236,24 +230,21 @@ export class ControllerImpl implements Controller {
}

public onWindowRemoved(window: EngineWindow): void {
this.log.log(["onWindowRemoved", { window }]);
this.log.log(`[Controller#onWindowRemoved] Window removed: ${window}`);

this.engine.unmanage(window);
this.engine.arrange();

// Switch to next window if monocle with config.monocleMinimizeRest
if (
!window.isDialog &&
!this.currentWindow &&
this.engine.isLayoutMonocleAndMinimizeRest()
) {
this.engine.focusOrder(1, true);
/* HACK: force window to maximize if it isn't already
* This is ultimately to trigger onWindowFocused() at the right time
*/
this.engine.focusOrder(1, true);
this.engine.focusOrder(-1, true);
if (this.engine.isLayoutMonocleAndMinimizeRest()) {
// Switch to the next window if needed
if (!this.currentWindow) {
this.log.log(
`[Controller#onWindowRemoved] Switching to the minimized window`
);
this.engine.focusOrder(1, true);
}
}

this.engine.arrange();
}

public onWindowMoveStart(_window: EngineWindow): void {
Expand Down Expand Up @@ -353,32 +344,12 @@ export class ControllerImpl implements Controller {
}
}

public onWindowFocused(window: EngineWindow): void {
try {
window.timestamp = new Date().getTime();
this.currentWindow = window;
// Minimize other windows if Monocle and config.monocleMinimizeRest
if (
this.engine.isLayoutMonocleAndMinimizeRest() &&
this.engine.windows
.visibleTiledWindowsOn(window.surface)
.includes(window)
) {
/* If a window hasn't been focused in this layout yet, ensure its geometry
* gets maximized.
*/
this.engine
.currentLayoutOnCurrentSurface()
.apply(
this,
this.engine.windows.tileableWindowsOn(window.surface),
window.surface.workingArea
);

this.engine.minimizeOthers(window);
}
} catch {
return;
public onWindowFocused(win: EngineWindow): void {
win.timestamp = new Date().getTime();

// Minimize other windows if Monocle and config.monocleMinimizeRest
if (this.engine.isLayoutMonocleAndMinimizeRest()) {
this.engine.minimizeOthers(win);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export interface Engine {

/**
* Minimize all windows on the surface except the given window.
* Used mainly in Monocle mode with config.monocleMinimizeRest
*/
minimizeOthers(window: EngineWindow): void;

Expand Down Expand Up @@ -409,7 +408,8 @@ export class EngineImpl implements Engine {
this.windows.remove(window);
}

/** Focus next or previous window
/**
* Focus next or previous window
* @param step direction to step in (1 for forward, -1 for back)
* @param includeHidden whether to switch to or skip minimized windows
*/
Expand Down

0 comments on commit 34d24a4

Please sign in to comment.