@@ -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
3536export 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
0 commit comments