@@ -274,55 +274,37 @@ export default class TilingAssistantExtension extends Extension {
274274
275275 this . _wasLocked = true ;
276276
277- const rectToJsObj = rect => rect && {
278- x : rect . x ,
279- y : rect . y ,
280- width : rect . width ,
281- height : rect . height
282- } ;
283-
284- // can't just check for isTiled because maximized windows may
285- // have an untiledRect as well in case window gaps are used
286- const openWindows = this . _twm . getWindows ( true ) ;
287- const savedWindows = openWindows . filter ( w => w . untiledRect ) . map ( w => {
288- return {
289- windowId : w . get_stable_sequence ( ) ,
290- isTiled : w . isTiled ,
291- tiledRect : rectToJsObj ( w . tiledRect ) ,
292- untiledRect : rectToJsObj ( w . untiledRect )
293- } ;
294- } ) ;
295-
296- const saveObj = {
297- 'windows' : savedWindows ,
298- 'tileGroups' : Array . from ( this . _twm . getTileGroups ( ) )
299- } ;
300-
301277 const userPath = GLib . get_user_config_dir ( ) ;
302278 const parentPath = GLib . build_filenamev ( [ userPath , '/tiling-assistant' ] ) ;
303279 const parent = Gio . File . new_for_path ( parentPath ) ;
304280
305281 try {
306282 parent . make_directory_with_parents ( null ) ;
307283 } catch ( e ) {
308- if ( e . code !== Gio . IOErrorEnum . EXISTS ) {
284+ if ( e . code !== Gio . IOErrorEnum . EXISTS )
309285 throw e ;
310- }
311286 }
312287
313- const path = GLib . build_filenamev ( [ parentPath , '/tiledSessionRestore .json' ] ) ;
288+ const path = GLib . build_filenamev ( [ parentPath , '/tiledSessionRestore2 .json' ] ) ;
314289 const file = Gio . File . new_for_path ( path ) ;
315290
316291 try {
317292 file . create ( Gio . FileCreateFlags . NONE , null ) ;
318293 } catch ( e ) {
319- if ( e . code !== Gio . IOErrorEnum . EXISTS ) {
294+ if ( e . code !== Gio . IOErrorEnum . EXISTS )
320295 throw e ;
321- }
322296 }
323297
324- file . replace_contents ( JSON . stringify ( saveObj ) , null , false ,
325- Gio . FileCreateFlags . REPLACE_DESTINATION , null ) ;
298+ file . replace_contents (
299+ JSON . stringify ( {
300+ windows : Object . fromEntries ( this . _twm . getTileStates ( ) ) ,
301+ tileGroups : Object . fromEntries ( this . _twm . getTileGroups ( ) )
302+ } ) ,
303+ null ,
304+ false ,
305+ Gio . FileCreateFlags . REPLACE_DESTINATION ,
306+ null
307+ ) ;
326308 }
327309
328310 /**
@@ -336,47 +318,48 @@ export default class TilingAssistantExtension extends Extension {
336318 this . _wasLocked = false ;
337319
338320 const userPath = GLib . get_user_config_dir ( ) ;
339- const path = GLib . build_filenamev ( [ userPath , '/tiling-assistant/tiledSessionRestore .json' ] ) ;
321+ const path = GLib . build_filenamev ( [ userPath , '/tiling-assistant/tiledSessionRestore2 .json' ] ) ;
340322 const file = Gio . File . new_for_path ( path ) ;
341323 if ( ! file . query_exists ( null ) )
342324 return ;
343325
344326 try {
345327 file . create ( Gio . FileCreateFlags . NONE , null ) ;
346328 } catch ( e ) {
347- if ( e . code !== Gio . IOErrorEnum . EXISTS ) {
329+ if ( e . code !== Gio . IOErrorEnum . EXISTS )
348330 throw e ;
349- }
350331 }
351332
352333 const [ success , contents ] = file . load_contents ( null ) ;
353334 if ( ! success || ! contents . length )
354335 return ;
355336
356- const openWindows = this . _twm . getWindows ( true ) ;
357- const saveObj = JSON . parse ( new TextDecoder ( ) . decode ( contents ) ) ;
337+ const states = JSON . parse ( new TextDecoder ( ) . decode ( contents ) ) ;
338+ const keysAsNumbers = entries => entries . map ( ( [ key , value ] ) => [ parseInt ( key ) , value ] ) ;
339+ const tileGroups = new Map ( keysAsNumbers ( Object . entries ( states . tileGroups ) ) ) ;
340+ const tileStates = new Map ( keysAsNumbers ( Object . entries ( states . windows ) ) ) ;
341+ const openWindows = global . display . list_all_windows ( ) ;
358342
359- const windowObjects = saveObj [ 'windows' ] ;
360- windowObjects . forEach ( wObj => {
361- const { windowId, isTiled, tiledRect, untiledRect } = wObj ;
362- const window = openWindows . find ( w => w . get_stable_sequence ( ) === windowId ) ;
363- if ( ! window )
364- return ;
343+ this . _twm . setTileGroups ( tileGroups ) ;
344+ this . _twm . setTileStates ( tileStates ) ;
365345
366- const jsToRect = jsRect => jsRect && new Rect (
367- jsRect . x , jsRect . y , jsRect . width , jsRect . height
368- ) ;
346+ openWindows . forEach ( window => {
347+ const tileState = tileStates . get ( window . get_id ( ) ) ;
369348
370- window . isTiled = isTiled ;
371- window . tiledRect = jsToRect ( tiledRect ) ;
372- window . untiledRect = jsToRect ( untiledRect ) ;
373- } ) ;
349+ if ( tileState ) {
350+ const { isTiled, tiledRect, untiledRect } = tileState ;
351+ const jsToRect = jsRect => jsRect && new Rect (
352+ jsRect . x , jsRect . y , jsRect . width , jsRect . height
353+ ) ;
374354
375- const tileGroups = new Map ( saveObj [ 'tileGroups' ] ) ;
376- this . _twm . setTileGroups ( tileGroups ) ;
377- openWindows . forEach ( w => {
378- if ( tileGroups . has ( w . get_id ( ) ) ) {
379- const group = this . _twm . getTileGroupFor ( w ) ;
355+ window . isTiled = isTiled ;
356+ window . tiledRect = jsToRect ( tiledRect ) ;
357+ window . untiledRect = jsToRect ( untiledRect ) ;
358+ }
359+
360+
361+ if ( tileGroups . has ( window . get_id ( ) ) ) {
362+ const group = this . _twm . getTileGroupFor ( window ) ;
380363 this . _twm . updateTileGroup ( group ) ;
381364 }
382365 } ) ;
0 commit comments