Skip to content

Commit

Permalink
fix: adjust behavior of deleting active window in Moncole with Minimi…
Browse files Browse the repository at this point in the history
…zeRest; ref #43, ref #55
  • Loading branch information
bladedvox committed Sep 28, 2021
1 parent d8dae35 commit 86ae8a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
27 changes: 12 additions & 15 deletions src/controller/index.ts
Expand Up @@ -29,7 +29,6 @@ export interface Controller {
* A bunch of surfaces, that represent the user's screens.
*/
readonly screens: DriverSurface[];
readonly currentScreen: number;
/**
* Current active window. In other words the window, that has focus.
*/
Expand Down Expand Up @@ -145,7 +144,6 @@ export interface Controller {
export class TilingController implements Controller {
private engine: Engine;
private driver: DriverContext;
private screen: number;
public constructor(
qmlObjects: Bismuth.Qml.Main,
kwinApi: KWin.Api,
Expand All @@ -154,7 +152,6 @@ export class TilingController implements Controller {
) {
this.engine = new TilingEngine(this, config, debug);
this.driver = new KWinDriver(qmlObjects, kwinApi, this, config, debug);
this.screen = 0;
}

/**
Expand Down Expand Up @@ -193,9 +190,6 @@ export class TilingController implements Controller {
this.driver.currentSurface = value;
}

public get currentScreen(){
return this.screen;
}
public showNotification(text: string): void {
this.driver.showNotification(text);
}
Expand Down Expand Up @@ -242,17 +236,20 @@ export class TilingController implements Controller {
public onWindowRemoved(window: Window): void {
this.debug.debugObj(() => ["onWindowRemoved", { window }]);
console.log(`Window remove: ${window}`);
const active = window === this.currentWindow;
this.screen = window.screen;

if (active && this.currentWindow && this.screen == this.currentWindow.screen
this.engine.unmanage(window);
this.engine.arrange();

// Switch to next window if monocle with config.monocleMinimizeRest
if (!this.currentWindow
&& this.engine.currentLayoutOnCurrentSurface() instanceof MonocleLayout
&& this.config.monocleMinimizeRest) {
this.engine.focusOrder(1, true);
}

this.engine.unmanage(window);
this.engine.arrange();
// HACK: force window to maximize if it isn't already
this.engine.focusOrder(1, true);
this.engine.focusOrder(-1, true);
this.engine.arrange();
}
}

public onWindowMoveStart(_window: Window): void {
Expand Down Expand Up @@ -351,13 +348,13 @@ export class TilingController implements Controller {
public onWindowFocused(window: Window): void {
window.timestamp = new Date().getTime();
this.currentWindow = window;
this.screen = window.screen;
// Minimize other windows if Moncole and config.monocleMinimizeRest
if (this.engine.currentLayoutOnCurrentSurface() instanceof MonocleLayout
&& this.config.monocleMinimizeRest
&& this.engine.windows.getVisibleTiles(window.surface).includes(window)) {
this.engine.currentLayoutOnCurrentSurface().apply(
this,
this.engine.windows.getAllTileables(window.surface, this.screen),
this.engine.windows.getAllTileables(window.surface),
window.surface.workingArea)
this.engine.minimizeOthers(window);
};
Expand Down
11 changes: 9 additions & 2 deletions src/engine/index.ts
Expand Up @@ -354,8 +354,7 @@ export class TilingEngine implements Engine {

if (includeHidden) {
windows = this.windows.getAllWindows(
this.controller.currentSurface,
this.controller.currentScreen);
this.controller.currentSurface);
} else {
windows = this.windows.getVisibleWindows(this.controller.currentSurface);
}
Expand Down Expand Up @@ -551,6 +550,8 @@ export class TilingEngine implements Engine {
);
if (layout) {
this.controller.showNotification(layout.description);

// Minimize inactive windows if Monocle and config.monocleMinimizeRest
if (this.currentLayoutOnCurrentSurface() instanceof MonocleLayout
&& this.config.monocleMinimizeRest && this.controller.currentWindow) {
this.minimizeOthers(this.controller.currentWindow);
Expand All @@ -568,13 +569,19 @@ export class TilingEngine implements Engine {
);
if (layout) {
this.controller.showNotification(layout.description);

// Minimize inactive windows if Monocle and config.monocleMinimizeRest
if (this.currentLayoutOnCurrentSurface() instanceof MonocleLayout
&& this.config.monocleMinimizeRest && this.controller.currentWindow) {
this.minimizeOthers(this.controller.currentWindow);
}
}
}

/**
* Minimize all windows on the surface except the given window.
* Used mainly in Monocle mode with config.monocleMinimizeRest
*/
public minimizeOthers(window: Window): void {
for (const tile of this.windows.getVisibleTiles(window.surface)) {
if (tile.screen == window.screen && tile.id !== window.id
Expand Down
11 changes: 4 additions & 7 deletions src/engine/window_store.ts
Expand Up @@ -98,16 +98,13 @@ export default class WindowStore {
/**
* Return all "tileable" windows on the given surface, including hidden
*/
public getAllTileables(srf: DriverSurface, screen: number): Window[] {
return this.list.filter((win) => win.tileable && win.screen === screen);
public getAllTileables(srf: DriverSurface): Window[] {
return this.list.filter((win) => win.tileable && win.surface.id === srf.id);
}

/** Return all windows on this surface, including minimized windows */
public getAllWindows(
srf: DriverSurface,
screen: number
): Window[] {
return this.list.filter((win) => win.surface.id === srf.id && win.screen === screen);
public getAllWindows(srf: DriverSurface): Window[] {
return this.list.filter((win) => win.surface.id === srf.id);
}

//#endregion
Expand Down

0 comments on commit 86ae8a5

Please sign in to comment.