From bdb329c1634d51da8b3df36c767f1df7b69d30bf Mon Sep 17 00:00:00 2001 From: Tim Cuthbertson Date: Fri, 15 Apr 2016 21:14:18 +1000 Subject: [PATCH] attempt at improving external change handling --- src/gjs/workspace.ts | 16 ++++++++++++---- src/tiling.ts | 19 +++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/gjs/workspace.ts b/src/gjs/workspace.ts index 779faf0..7095556 100644 --- a/src/gjs/workspace.ts +++ b/src/gjs/workspace.ts @@ -430,7 +430,15 @@ module Workspace { // NOTE: these two get shellshape `Window` objects as their callback argument, *not* MetaWindow _on_window_moved(win) { this.layout.on_window_moved(win); } _on_window_resized(win) { this.layout.on_window_resized(win); } - _on_window_unexpected_change(win) { this.layout.override_external_change(win); } + _on_window_unexpected_change(win) { + var self = this; + Mainloop.idle_add(function() { + self.layout.override_external_change(win, false); + Mainloop.timeout_add_seconds(1, function() { + self.layout.override_external_change(win, true); + }); + }); + } on_window_moved = _duck_overview(this._on_window_moved) on_window_resized = _duck_overview(this._on_window_resized) on_window_unexpected_change = _duck_overview(this._on_window_unexpected_change) @@ -449,14 +457,14 @@ module Workspace { self.log.debug("on_window_remove for " + win + " (" + self +")"); self.disconnect_window_signals(win); } else if (force) { - self.log.error("Unable to remove window: " + win); + self.log.warn("Unable to remove window: " + win); self.layout.each(function(tile:Tiling.TiledWindow, idx) { var tileWindow = tile.window; if (tileWindow === win) { - self.log.error("And yet: Found window match at index: " + idx); + self.log.error("Logical error: Found window match at index: " + idx); } if (tileWindow.meta_window === meta_window) { - self.log.error("And yet: Found meta_window match at index: " + idx); + self.log.error("Logical error: Found meta_window match at index: " + idx); } // the above code should be impossible to trigger, but it does, so try again for paranoia: removed = self.layout.on_window_killed(win); diff --git a/src/tiling.ts b/src/tiling.ts index b3624eb..689d95b 100644 --- a/src/tiling.ts +++ b/src/tiling.ts @@ -867,7 +867,7 @@ module Tiling { } } - override_external_change(win:Window) { } + override_external_change(win:Window, delayed:boolean) { } // all the actions that are specific to an actual tiling layout are NOOP'd here, // so the keyboard handlers don't have to worry whether it's a valid thing to call @@ -1141,10 +1141,10 @@ module Tiling { }); } - override_external_change(win:Window) { + override_external_change(win:Window, delayed:boolean) { // The window has resized itself. Put it back! var found = this.tile_for(win, function(tile, idx) { - tile.enforce_layout(); + tile.enforce_layout(delayed); }); if(!found) { this.log.warn("override_external_change called for unknown window " + win); @@ -1309,7 +1309,7 @@ module Tiling { rect: Rect offset: Rect original_rect: Rect - enforce_layout: VoidFunc + enforce_layout: (delayed:boolean) => void private static minimized_counter = 0; private static active_window_override = null; @@ -1355,7 +1355,7 @@ module Tiling { update_original_rect = function() { this.original_rect = this.window.rect(); - this.log.debug("window " + this + " remembering new rect of " + (JSON.stringify(this.original_rect))); + this.log.debug("window " + this + " remembering original rect of " + (JSON.stringify(this.original_rect))); } resume_original_state() { @@ -1378,13 +1378,13 @@ module Tiling { this.reset_offset(); } - _enforce_layout() { + _enforce_layout(delayed: boolean) { // The window has unexpectedly moved since last layout(). // Put it back in it's place, but if this has happened // more than a few times in the last 2s then stop (because // it's probably going to keep trying) var now = Date.now(); - var threshold = now = 2000; + var threshold = now - 2000; this._recent_overrides = this._recent_overrides.filter(function(t) { return t > threshold; }); @@ -1393,7 +1393,9 @@ module Tiling { this.enforce_layout = noop; return; } - this._recent_overrides.push(now); + if(!delayed) { + this._recent_overrides.push(now); + } if(Logging.PARANOID) { var expected = this.rect; var actual = this.window.rect(); @@ -1406,6 +1408,7 @@ module Tiling { size_diff.y ); // give some leeway for weird layout conditions + this.log.debug("enforce_layout: max_diff is " + max_diff); if(max_diff > 50) { this.log.debug("enforcing layout after change on " + this.window); this.log.debug("expected size:" + j(expected) + ", actual size: " + j(actual));