Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
attempt at improving external change handling
Browse files Browse the repository at this point in the history
  • Loading branch information
timbertson committed Apr 15, 2016
1 parent 839fe66 commit bdb329c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/gjs/workspace.ts
Expand Up @@ -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)
Expand All @@ -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 = <MutterWindow.Window>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);
Expand Down
19 changes: 11 additions & 8 deletions src/tiling.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
});
Expand All @@ -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();
Expand All @@ -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));
Expand Down

0 comments on commit bdb329c

Please sign in to comment.