Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit c0057f6

Browse files
committed
track activity
1 parent ef5e878 commit c0057f6

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

contents/code/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export class Config {
3333
this.logWindowProperties = readConfig('logWindowProperties', false)
3434
this.doShowOutline = readConfig('showOutline', true) && false
3535
this.rearrangeBetweenMonitors = readConfig('rearrangeBetweenMonitors', false)
36-
this.doMaximizeSingleWindow = false // readConfig('maximizeSingleWindow', true)
37-
this.doMaximizeWhenNoLayoutExists = false
36+
this.doMaximizeSingleWindow = readConfig('maximizeSingleWindow', true)
37+
this.doMaximizeWhenNoLayoutExists = false // We now use the root tile instead.
3838
this.doRearrangeWindows = readConfig('rearrangeWindows', true)
3939
this.maximizeWithPadding = readConfig('maximizeWithPadding', true)
4040
this.rearrangeLayout = readConfig('rearrangeLayout', false)

contents/code/engine.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface EngineInterface{
3030
retileOther(client: AbstractClient|null, affectedTile: Tile|null): void;
3131
layoutModified(output: Output): void;
3232
interactiveMoveResizeFinished(client: AbstractClient, cursPos: QPoint): void;
33+
workspaceChanged(): void;
3334
}
3435

3536
export class Engine implements EngineInterface {
@@ -41,6 +42,9 @@ export class Engine implements EngineInterface {
4142
this.logger = logger
4243
}
4344

45+
public workspaceChanged(): void {
46+
this.handleMaximizeMinimize(workspace.activeScreen, 'workspace-changed')
47+
}
4448
public attachClient(client: AbstractClient): void {
4549
const tile = this.rearrangeLayout(client.output, false)
4650
const affectedTile = this.doTile(client, 'attachClient', tile == null ? null :getTileCenter(tile))
@@ -151,12 +155,13 @@ export class Engine implements EngineInterface {
151155
return
152156
}
153157
// Create new layouts
154-
const tile = this.rearrangeLayout(client.output)
155-
const affectedTile = this.doTile(client, 'unminimized', tile == null ? null :getTileCenter(tile))
156-
this.retileUntiled(client.output, 'unminimized');
158+
const tile = this.rearrangeLayout(client.output, client.minimized)
159+
const label = client.minimized ? 'unminimized' : 'minimized'
160+
const affectedTile = this.doTile(client, label, tile == null ? null :getTileCenter(tile))
161+
this.retileUntiled(client.output, label);
157162
this.retileOther(client, affectedTile)
158163
if(tile === null)
159-
this.handleMaximizeMinimize(client.output, 'unminimized')
164+
this.handleMaximizeMinimize(client.output, label)
160165
}
161166

162167
public layoutModified(output: Output): void{
@@ -190,33 +195,37 @@ export class Engine implements EngineInterface {
190195
return numberOfTilesToCreate
191196
}
192197
public rearrangeLayout(output: Output, isDeletion: boolean = false): Tile|null {
193-
if (!this.config.getRearrangeLayout()) {
198+
if (!this.config.rearrangeLayout) {
194199
return null;
195200
}
196201

197202
const numberOfTilesToCreate = this.getNumberOfTilesToCreate(output)
203+
isDeletion = isDeletion || numberOfTilesToCreate < 0
198204
this.doLogIf(this.config.logRearrangeLayout, LogLevel.ERROR, `rearrangeLayout: ${numberOfTilesToCreate} tile(s) to ${(numberOfTilesToCreate < 0 ? 'delete' : 'add')} on ${output.name}`)
199205

200206
const direction: LayoutDirection = 1 // Horizontal split
201207
const emptyTiles = getEmptyTilesByOutput(output)
208+
this.doLogIf(this.config.logRearrangeLayout, LogLevel.DEBUG, `rearrangeLayout: ${emptyTiles.length} empty tile(s)`)
202209

203210
if(isDeletion && numberOfTilesToCreate < 0 && emptyTiles.length > 0) {
204-
let candidate = emptyTiles[0]
205-
for (const tile of emptyTiles) {
206-
if (tile.canBeRemoved && direction == 1 && tile.absoluteGeometryInScreen.width > candidate.absoluteGeometryInScreen.width) {
207-
candidate = tile
211+
for(let i = numberOfTilesToCreate; i < 0 && emptyTiles.length > 0; i++) {
212+
let candidate = emptyTiles[0]
213+
for (const tile of emptyTiles) {
214+
if (tile.canBeRemoved && direction == 1 && tile.absoluteGeometryInScreen.width > candidate.absoluteGeometryInScreen.width) {
215+
candidate = tile
216+
}
217+
if (tile.canBeRemoved && direction != 1 && tile.absoluteGeometryInScreen.height > candidate.absoluteGeometryInScreen.height) {
218+
candidate = tile
219+
}
208220
}
209-
if (tile.canBeRemoved && direction != 1 && tile.absoluteGeometryInScreen.height > candidate.absoluteGeometryInScreen.height) {
210-
candidate = tile
221+
this.doLogIf(this.config.logRearrangeLayout, LogLevel.DEBUG, 'rearrangeLayout...' + `Remove empty tile ${tileToString(emptyTiles[0])}`)
222+
if (!candidate.canBeRemoved) {
223+
this.logger.error(`Can not remove tile ${tileToString(candidate)}`)
224+
return null
211225
}
226+
emptyTiles.splice(emptyTiles.indexOf(candidate), 1)
227+
candidate.remove()
212228
}
213-
this.doLogIf(this.config.logRearrangeLayout,LogLevel.DEBUG, 'rearrangeLayout...' + `Remove one empty tile ${tileToString(emptyTiles[0])}`)
214-
emptyTiles.splice(emptyTiles.indexOf(candidate), 1)
215-
if(!candidate.canBeRemoved){
216-
this.logger.error(`Can not remove tile ${tileToString(candidate)}`)
217-
return null
218-
}
219-
candidate.remove()
220229
return null
221230
}
222231

contents/code/extern/client.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ declare interface KWinEnums{
4343
}
4444

4545
declare interface VirtualDesktop{
46-
46+
readonly id: string
47+
readonly name: string
48+
readonly x11DesktopNumber: number
49+
nameChanged: Signal<() => void>;
50+
x11DesktopNumberChanged: Signal<() => void>;
51+
aboutToBeDestroyed: Signal<() => void>;
4752
}
53+
4854
declare interface Toplevel {
4955
readonly popupWindow: boolean;
5056
readonly frameGeometry: QRect;

contents/code/tiler.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export class Tiler{
2525
outputChangedHandlers: Map<AbstractClient, () => void>;
2626
interactiveMoveResizeSteppedHandlers: Map<AbstractClient, () => void>;
2727
desktopChangedHandlers: Map<AbstractClient, () => void>;
28+
previousActivity: string
29+
previousDesktop: VirtualDesktop
2830
constructor(config: Config){
2931
this.config = config;
3032
this.logger = new Console(this.config.logLevel)
@@ -35,7 +37,8 @@ export class Tiler{
3537
this.interactiveMoveResizeFinishedHandlers = new Map<AbstractClient, () => void>();
3638
this.interactiveMoveResizeSteppedHandlers = new Map<AbstractClient, () => void>();
3739
this.desktopChangedHandlers = new Map<AbstractClient, () => void>();
38-
40+
this.previousDesktop = workspace.currentDesktop
41+
this.previousActivity = workspace.currentActivity
3942

4043
this.minimizedChanged = (client: AbstractClient) => {
4144
this.event( `minimizedChanged: ${clientToString(client)} ${client.minimized ? 'minimized' : 'unminimized'}`)
@@ -71,6 +74,16 @@ export class Tiler{
7174
}
7275
this.event(`windowActivated: ${clientToString(client)}`)
7376
this.lastWindowActivated = client
77+
if(this.previousDesktop.id !== workspace.currentDesktop.id){
78+
this.event('workspace changed')
79+
this.engine.workspaceChanged()
80+
}
81+
if(this.previousActivity !== workspace.currentActivity){
82+
this.event('Activity changed')
83+
this.engine.workspaceChanged() // TODO add event ?
84+
}
85+
this.previousDesktop = workspace.currentDesktop
86+
this.previousActivity = workspace.currentActivity
7487
})
7588

7689
// Detach old client

0 commit comments

Comments
 (0)