Skip to content

Commit

Permalink
implement monocleMinimizeRest (#33)
Browse files Browse the repository at this point in the history
 * THAT was a hard ride, really. It took so many experiements, but ended
   up with this simple elegant hack.
 * The trick is to delay arranging on window unminimize. Without this
   delay, KWin doesn't register the unminimized window as the current
   window, no matter what you do.
  • Loading branch information
esjeon committed Nov 3, 2019
1 parent 3595edf commit 577fc7f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions res/config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_monocleMinimizeRest">
<property name="text">
<string>Minimize other windows</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
5 changes: 5 additions & 0 deletions res/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
<default>true</default>
</entry>

<entry name="monocleMinimizeRest" type="Bool">
<label>Minimize other tiles than the current one in Monocle layout</label>
<default>false</default>
</entry>

<entry name="adjustLayout" type="Bool">
<label>Adjust layout with mouse</label>
<default>true</default>
Expand Down
2 changes: 1 addition & 1 deletion src/architecture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ interface ILayout {

/* methods */
adjust?(area: Rect, tiles: Window[], basis: Window): void;
apply(tiles: Window[], area: Rect, workingArea?: Rect): void;
apply(tiles: Window[], area: Rect, workingArea?: Rect, driver?: IDriver): void;
toString(): string;

/* overriding */
Expand Down
7 changes: 7 additions & 0 deletions src/driver/kwin/kwinconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class KWinConfig implements IConfig {
public enableFloatingLayout: boolean;
public maximizeSoleTile: boolean;
public monocleMaximize: boolean;
public monocleMinimizeRest: boolean; // KWin-specific
//#endregion

//#region Features
Expand Down Expand Up @@ -82,6 +83,7 @@ class KWinConfig implements IConfig {
this.enableFloatingLayout = KWin.readConfig("enableFloatingLayout", false);
this.maximizeSoleTile = KWin.readConfig("maximizeSoleTile" , false);
this.monocleMaximize = KWin.readConfig("monocleMaximize" , true);
this.monocleMinimizeRest = KWin.readConfig("monocleMinimizeRest" , false);

this.adjustLayout = KWin.readConfig("adjustLayout" , true);
this.adjustLayoutLive = KWin.readConfig("adjustLayoutLive" , true);
Expand Down Expand Up @@ -111,6 +113,11 @@ class KWinConfig implements IConfig {
this.ignoreScreen = commaSeparate(KWin.readConfig("ignoreScreen", ""))
.map((str) => parseInt(str, 10));
this.ignoreTitle = commaSeparate(KWin.readConfig("ignoreTitle" , ""));

if (this.preventMinimize && this.monocleMinimizeRest) {
debug(() => "preventMinimize is disabled because of monocleMinimizeRest.");
this.preventMinimize = false;
}
}

public toString(): string {
Expand Down
6 changes: 5 additions & 1 deletion src/engine/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ class TilingController {
public onWindowChanged(window: Window | null, comment?: string): void {
if (window) {
debugObj(() => ["onWindowChanged", {window, comment}]);
this.engine.arrange();

if (comment === "unminimized")
this.driver.setCurrentWindow(window);

this.driver.setTimeout(() => this.engine.arrange(), 50);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ class TilingEngine implements IEngine {
tiles[0].noBorder = true;
tiles[0].geometry = fullArea;
} else if (tiles.length > 0)
layout.apply(tiles, workingArea, fullArea);
layout.apply(tiles, workingArea, fullArea, this.driver);

visibles.forEach((window) => window.commit());
debugObj(() => ["arrangeScreen/finished", { ctx }]);
}

public enforceSize(window: Window) {
Expand Down
14 changes: 13 additions & 1 deletion src/layouts/monoclelayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ class MonocleLayout implements ILayout {
return CONFIG.enableMonocleLayout;
}

public apply = (tiles: Window[], area: Rect, workingArea?: Rect): void => {
public apply = (tiles: Window[], area: Rect, workingArea?: Rect, driver?: IDriver): void => {
/* KWin-specific `monocleMinimizeRest` option */
if (driver && driver instanceof KWinDriver && KWINCONFIG.monocleMinimizeRest) {
const current = driver.getCurrentWindow();
if (current && current.state === WindowState.Tile) {
tiles.forEach((window) => {
if (window !== current)
(window.window as KWinWindow).client.minimized = true;
});
tiles = [current];
}
}

if (CONFIG.monocleMaximize) {
area = workingArea || area;
tiles.forEach((window) => window.noBorder = true);
Expand Down

1 comment on commit 577fc7f

@seqizz
Copy link

@seqizz seqizz commented on 577fc7f Nov 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy crappo, just saw this 🎉 Thanks, I'll try now.

Please sign in to comment.