2008-12-01 14:51:43 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-11-21 09:02:09 -05:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Mainloop = imports.mainloop;
|
2008-11-21 16:34:10 -05:00
|
|
|
const Meta = imports.gi.Meta;
|
2008-11-21 09:02:09 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
2009-04-13 10:55:41 -04:00
|
|
|
const AltTab = imports.ui.altTab;
|
2008-11-21 09:02:09 -05:00
|
|
|
const Main = imports.ui.main;
|
2009-02-10 11:12:58 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2008-11-21 09:02:09 -05:00
|
|
|
|
2008-12-28 23:44:03 -05:00
|
|
|
const WINDOW_ANIMATION_TIME = 0.25;
|
2008-11-21 16:34:10 -05:00
|
|
|
|
2008-11-21 10:10:11 -05:00
|
|
|
function WindowManager() {
|
|
|
|
this._init();
|
2008-11-21 09:02:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowManager.prototype = {
|
2008-12-01 14:51:43 -05:00
|
|
|
_init : function() {
|
|
|
|
let me = this;
|
2008-11-21 16:34:10 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
this._global = Shell.Global.get();
|
|
|
|
this._shellwm = this._global.window_manager;
|
2008-12-28 23:44:03 -05:00
|
|
|
this._minimizing = [];
|
|
|
|
this._maximizing = [];
|
|
|
|
this._unmaximizing = [];
|
|
|
|
this._mapping = [];
|
|
|
|
this._destroying = [];
|
2008-11-21 16:34:10 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
this._switchData = null;
|
|
|
|
this._shellwm.connect('switch-workspace',
|
2008-11-21 16:34:10 -05:00
|
|
|
function(o, from, to, direction) {
|
2008-12-01 14:51:43 -05:00
|
|
|
let actors = me._shellwm.get_switch_workspace_actors();
|
2008-12-28 23:44:03 -05:00
|
|
|
me._switchWorkspace(actors, from, to, direction);
|
2008-12-01 14:51:43 -05:00
|
|
|
});
|
|
|
|
this._shellwm.connect('kill-switch-workspace',
|
2008-11-21 16:34:10 -05:00
|
|
|
function(o) {
|
2008-12-28 23:44:03 -05:00
|
|
|
me._switchWorkspaceDone();
|
2008-12-01 14:51:43 -05:00
|
|
|
});
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.connect('minimize',
|
|
|
|
function(o, actor) {
|
|
|
|
me._minimizeWindow(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('kill-minimize',
|
|
|
|
function(o, actor) {
|
|
|
|
me._minimizeWindowDone(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('maximize',
|
|
|
|
function(o, actor, tx, ty, tw, th) {
|
|
|
|
me._maximizeWindow(actor, tx, ty, tw, th);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('kill-maximize',
|
|
|
|
function(o, actor) {
|
|
|
|
me._maximizeWindowDone(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('unmaximize',
|
|
|
|
function(o, actor, tx, ty, tw, th) {
|
|
|
|
me._unmaximizeWindow(actor, tx, ty, tw, th);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('kill-unmaximize',
|
|
|
|
function(o, actor) {
|
|
|
|
me._unmaximizeWindowDone(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('map',
|
|
|
|
function(o, actor) {
|
|
|
|
me._mapWindow(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('kill-map',
|
|
|
|
function(o, actor) {
|
|
|
|
me._mapWindowDone(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('destroy',
|
|
|
|
function(o, actor) {
|
|
|
|
me._destroyWindow(actor);
|
|
|
|
});
|
|
|
|
this._shellwm.connect('kill-destroy',
|
|
|
|
function(o, actor) {
|
|
|
|
me._destroyWindowDone(actor);
|
|
|
|
});
|
2009-04-13 10:55:41 -04:00
|
|
|
|
|
|
|
this._shellwm.connect('begin-alt-tab',
|
|
|
|
function(o, handler) {
|
|
|
|
me._beginAltTab(handler);
|
|
|
|
});
|
2008-12-28 23:44:03 -05:00
|
|
|
},
|
|
|
|
|
2009-02-03 13:25:34 -05:00
|
|
|
_shouldAnimate : function(actor) {
|
2009-05-07 09:47:48 -04:00
|
|
|
if (Main.overlay.visible)
|
2009-02-03 13:25:34 -05:00
|
|
|
return false;
|
|
|
|
if (actor && (actor.get_window_type() != Meta.CompWindowType.NORMAL))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
},
|
2008-12-28 23:44:03 -05:00
|
|
|
|
2009-02-05 19:57:54 -05:00
|
|
|
_removeEffect : function(list, actor) {
|
|
|
|
let idx = list.indexOf(actor);
|
|
|
|
if (idx != -1) {
|
|
|
|
list.splice(idx, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2008-12-28 23:44:03 -05:00
|
|
|
_minimizeWindow : function(actor) {
|
2009-02-03 13:25:34 -05:00
|
|
|
if (!this._shouldAnimate(actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_minimize(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
actor.set_scale(1.0, 1.0);
|
|
|
|
actor.move_anchor_point_from_gravity(Clutter.Gravity.CENTER);
|
|
|
|
|
|
|
|
/* scale window down to 0x0.
|
|
|
|
* maybe TODO: get icon geometry passed through and move the window towards it?
|
|
|
|
*/
|
|
|
|
this._minimizing.push(actor);
|
|
|
|
Tweener.addTween(actor,
|
|
|
|
{ scale_x: 0.0,
|
|
|
|
scale_y: 0.0,
|
|
|
|
time: WINDOW_ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: this._minimizeWindowDone,
|
|
|
|
onCompleteScope: this,
|
2009-02-05 19:57:54 -05:00
|
|
|
onCompleteParams: [actor],
|
|
|
|
onOverwrite: this._minimizeWindowOverwritten,
|
|
|
|
onOverwriteScope: this,
|
|
|
|
onOverwriteParams: [actor]
|
2008-12-28 23:44:03 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_minimizeWindowDone : function(actor) {
|
2009-02-05 19:57:54 -05:00
|
|
|
if (this._removeEffect(this._minimizing, actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
Tweener.removeTweens(actor);
|
|
|
|
actor.set_scale(1.0, 1.0);
|
|
|
|
actor.move_anchor_point_from_gravity(Clutter.Gravity.NORTH_WEST);
|
2009-02-05 19:57:54 -05:00
|
|
|
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_minimize(actor);
|
2009-02-05 19:57:54 -05:00
|
|
|
}
|
|
|
|
},
|
2008-12-28 23:44:03 -05:00
|
|
|
|
2009-02-05 19:57:54 -05:00
|
|
|
_minimizeWindowOverwritten : function(actor) {
|
|
|
|
if (this._removeEffect(this._minimizing, actor)) {
|
|
|
|
this._shellwm.completed_minimize(actor);
|
2008-12-28 23:44:03 -05:00
|
|
|
}
|
|
|
|
},
|
2009-02-05 19:57:54 -05:00
|
|
|
|
2009-05-02 18:33:13 -04:00
|
|
|
_maximizeWindow : function(actor, targetX, targetY, targetWidth, targetHeight) {
|
2009-02-03 13:25:34 -05:00
|
|
|
if (!this._shouldAnimate(actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_maximize(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this doesn't work very well, as simply scaling up the existing
|
|
|
|
* window contents doesn't produce anything like the same results as
|
|
|
|
* actually maximizing the window.
|
|
|
|
*/
|
2009-05-02 18:33:13 -04:00
|
|
|
let scaleX = targetWidth / actor.width;
|
|
|
|
let scaleY = targetHeight / actor.height;
|
|
|
|
let anchorX = (actor.x - targetX) * actor.width/(targetWidth - actor.width);
|
|
|
|
let anchorY = (actor.y - targetY) * actor.height/(targetHeight - actor.height);
|
2008-12-28 23:44:03 -05:00
|
|
|
|
2009-05-02 18:33:13 -04:00
|
|
|
actor.move_anchor_point(anchorX, anchorY);
|
2008-12-28 23:44:03 -05:00
|
|
|
|
|
|
|
this._maximizing.push(actor);
|
|
|
|
Tweener.addTween(actor,
|
2009-05-02 18:33:13 -04:00
|
|
|
{ scale_x: scaleX,
|
|
|
|
scale_y: scaleY,
|
2008-12-28 23:44:03 -05:00
|
|
|
time: WINDOW_ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: this._maximizeWindowDone,
|
|
|
|
onCompleteScope: this,
|
2009-02-05 19:57:54 -05:00
|
|
|
onCompleteParams: [actor],
|
|
|
|
onOverwrite: this._maximizeWindowOverwrite,
|
|
|
|
onOverwriteScope: this,
|
|
|
|
onOverwriteParams: [actor]
|
2008-12-28 23:44:03 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_maximizeWindowDone : function(actor) {
|
2009-02-05 19:57:54 -05:00
|
|
|
if (this._removeEffect(this._maximizing, actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
Tweener.removeTweens(actor);
|
|
|
|
actor.set_scale(1.0, 1.0);
|
|
|
|
actor.move_anchor_point_from_gravity(Clutter.Gravity.NORTH_WEST);
|
|
|
|
this._shellwm.completed_maximize(actor);
|
2009-02-05 19:57:54 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_maximizeWindowOverwrite : function(actor) {
|
|
|
|
if (this._removeEffect(this._maximizing, actor)) {
|
|
|
|
this._shellwm.completed_maximize(actor);
|
2008-12-28 23:44:03 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-05-02 18:33:13 -04:00
|
|
|
_unmaximizeWindow : function(actor, targetX, targetY, targetWidth, targetHeight) {
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_unmaximize(actor);
|
|
|
|
},
|
|
|
|
|
|
|
|
_unmaximizeWindowDone : function(actor) {
|
|
|
|
},
|
|
|
|
|
|
|
|
_mapWindow : function(actor) {
|
2009-02-03 13:25:34 -05:00
|
|
|
if (!this._shouldAnimate(actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_map(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
actor.move_anchor_point_from_gravity(Clutter.Gravity.CENTER);
|
|
|
|
actor.set_scale(0.0, 0.0);
|
|
|
|
actor.show();
|
|
|
|
|
|
|
|
/* scale window up from 0x0 to normal size */
|
|
|
|
this._mapping.push(actor);
|
|
|
|
Tweener.addTween(actor,
|
|
|
|
{ scale_x: 1.0,
|
|
|
|
scale_y: 1.0,
|
|
|
|
time: WINDOW_ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: this._mapWindowDone,
|
|
|
|
onCompleteScope: this,
|
2009-02-05 19:57:54 -05:00
|
|
|
onCompleteParams: [actor],
|
|
|
|
onOverwrite: this._mapWindowOverwrite,
|
|
|
|
onOverwriteScope: this,
|
|
|
|
onOverwriteParams: [actor]
|
2008-12-28 23:44:03 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_mapWindowDone : function(actor) {
|
2009-02-05 19:57:54 -05:00
|
|
|
if (this._removeEffect(this._mapping, actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
Tweener.removeTweens(actor);
|
|
|
|
actor.set_scale(1.0, 1.0);
|
|
|
|
actor.move_anchor_point_from_gravity(Clutter.Gravity.NORTH_WEST);
|
|
|
|
this._shellwm.completed_map(actor);
|
2009-02-05 19:57:54 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_mapWindowOverwrite : function(actor) {
|
|
|
|
if (this._removeEffect(this._mapping, actor)) {
|
|
|
|
this._shellwm.completed_map(actor);
|
2008-12-28 23:44:03 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_destroyWindow : function(actor) {
|
2009-02-03 13:25:34 -05:00
|
|
|
if (!this._shouldAnimate(actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_destroy(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
actor.move_anchor_point_from_gravity(Clutter.Gravity.CENTER);
|
|
|
|
|
|
|
|
/* anachronistic 'tv-like' effect - squash on y axis, leave x alone */
|
|
|
|
this._destroying.push(actor);
|
|
|
|
Tweener.addTween(actor,
|
|
|
|
{ scale_x: 1.0,
|
|
|
|
scale_y: 0.0,
|
|
|
|
time: WINDOW_ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: this._destroyWindowDone,
|
|
|
|
onCompleteScope: this,
|
2009-02-05 19:57:54 -05:00
|
|
|
onCompleteParams: [actor],
|
|
|
|
onOverwrite: this._destroyWindowOverwrite,
|
|
|
|
onOverwriteScope: this,
|
|
|
|
onOverwriteParams: [actor]
|
2008-12-28 23:44:03 -05:00
|
|
|
});
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
2008-12-28 23:44:03 -05:00
|
|
|
|
|
|
|
_destroyWindowDone : function(actor) {
|
2009-02-05 19:57:54 -05:00
|
|
|
if (this._removeEffect(this._destroying, actor)) {
|
2008-12-28 23:44:03 -05:00
|
|
|
this._shellwm.completed_destroy(actor);
|
|
|
|
Tweener.removeTweens(actor);
|
|
|
|
actor.set_scale(1.0, 1.0);
|
2009-02-05 19:57:54 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_destroyWindowOverwrite : function(actor) {
|
|
|
|
if (this._removeEffect(this._destroying, actor)) {
|
|
|
|
this._shellwm.completed_destroy(actor);
|
2008-12-28 23:44:03 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_switchWorkspace : function(windows, from, to, direction) {
|
2009-02-03 13:25:34 -05:00
|
|
|
if (!this._shouldAnimate()) {
|
2008-12-04 10:16:16 -05:00
|
|
|
this._shellwm.completed_switch_workspace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
/* @direction is the direction that the "camera" moves, so the
|
|
|
|
* screen contents have to move one screen's worth in the
|
|
|
|
* opposite direction.
|
|
|
|
*/
|
|
|
|
let xDest = 0, yDest = 0;
|
|
|
|
|
|
|
|
if (direction == Meta.MotionDirection.UP ||
|
2008-11-21 16:34:10 -05:00
|
|
|
direction == Meta.MotionDirection.UP_LEFT ||
|
|
|
|
direction == Meta.MotionDirection.UP_RIGHT)
|
2008-12-01 14:51:43 -05:00
|
|
|
yDest = this._global.screen_height;
|
|
|
|
else if (direction == Meta.MotionDirection.DOWN ||
|
2008-11-21 16:34:10 -05:00
|
|
|
direction == Meta.MotionDirection.DOWN_LEFT ||
|
|
|
|
direction == Meta.MotionDirection.DOWN_RIGHT)
|
2008-12-01 14:51:43 -05:00
|
|
|
yDest = -this._global.screen_height;
|
2008-11-21 16:34:10 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
if (direction == Meta.MotionDirection.LEFT ||
|
2008-11-21 16:34:10 -05:00
|
|
|
direction == Meta.MotionDirection.UP_LEFT ||
|
|
|
|
direction == Meta.MotionDirection.DOWN_LEFT)
|
2008-12-01 14:51:43 -05:00
|
|
|
xDest = this._global.screen_width;
|
|
|
|
else if (direction == Meta.MotionDirection.RIGHT ||
|
|
|
|
direction == Meta.MotionDirection.UP_RIGHT ||
|
|
|
|
direction == Meta.MotionDirection.DOWN_RIGHT)
|
|
|
|
xDest = -this._global.screen_width;
|
|
|
|
|
|
|
|
let switchData = {};
|
|
|
|
this._switchData = switchData;
|
|
|
|
switchData.inGroup = new Clutter.Group();
|
|
|
|
switchData.outGroup = new Clutter.Group();
|
|
|
|
switchData.windows = [];
|
|
|
|
|
|
|
|
let wgroup = this._global.window_group;
|
|
|
|
wgroup.add_actor(switchData.inGroup);
|
|
|
|
wgroup.add_actor(switchData.outGroup);
|
|
|
|
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
let window = windows[i];
|
2009-05-11 13:06:42 -04:00
|
|
|
|
|
|
|
if (!window.meta_window.showing_on_its_workspace())
|
|
|
|
continue;
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
if (window.get_workspace() == from) {
|
|
|
|
switchData.windows.push({ window: window,
|
|
|
|
parent: window.get_parent() });
|
|
|
|
window.reparent(switchData.outGroup);
|
|
|
|
} else if (window.get_workspace() == to) {
|
|
|
|
switchData.windows.push({ window: window,
|
|
|
|
parent: window.get_parent() });
|
|
|
|
window.reparent(switchData.inGroup);
|
|
|
|
window.show_all();
|
|
|
|
}
|
2008-11-21 16:34:10 -05:00
|
|
|
}
|
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
switchData.inGroup.set_position(-xDest, -yDest);
|
|
|
|
switchData.inGroup.raise_top();
|
|
|
|
|
|
|
|
Tweener.addTween(switchData.outGroup,
|
|
|
|
{ x: xDest,
|
|
|
|
y: yDest,
|
2009-05-13 15:24:32 -04:00
|
|
|
time: WINDOW_ANIMATION_TIME,
|
2009-05-11 16:21:39 -04:00
|
|
|
transition: "easeOutQuad",
|
2009-01-08 18:34:19 -05:00
|
|
|
onComplete: this._switchWorkspaceDone,
|
|
|
|
onCompleteScope: this
|
2008-12-01 14:51:43 -05:00
|
|
|
});
|
|
|
|
Tweener.addTween(switchData.inGroup,
|
|
|
|
{ x: 0,
|
|
|
|
y: 0,
|
2009-05-13 15:24:32 -04:00
|
|
|
time: WINDOW_ANIMATION_TIME,
|
2009-05-11 16:21:39 -04:00
|
|
|
transition: "easeOutQuad"
|
2008-12-01 14:51:43 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-12-28 23:44:03 -05:00
|
|
|
_switchWorkspaceDone : function() {
|
2008-12-01 14:51:43 -05:00
|
|
|
let switchData = this._switchData;
|
|
|
|
if (!switchData)
|
|
|
|
return;
|
|
|
|
this._switchData = null;
|
|
|
|
|
|
|
|
for (let i = 0; i < switchData.windows.length; i++) {
|
|
|
|
let w = switchData.windows[i];
|
|
|
|
if (w.window.get_parent() == switchData.outGroup) {
|
|
|
|
w.window.reparent(w.parent);
|
|
|
|
w.window.hide();
|
|
|
|
} else
|
|
|
|
w.window.reparent(w.parent);
|
|
|
|
}
|
|
|
|
Tweener.removeTweens(switchData.inGroup);
|
|
|
|
Tweener.removeTweens(switchData.outGroup);
|
|
|
|
switchData.inGroup.destroy();
|
|
|
|
switchData.outGroup.destroy();
|
2008-11-21 16:34:10 -05:00
|
|
|
|
2008-12-01 14:51:43 -05:00
|
|
|
this._shellwm.completed_switch_workspace();
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_beginAltTab : function(handler) {
|
|
|
|
let popup = new AltTab.AltTabPopup();
|
2008-11-21 16:34:10 -05:00
|
|
|
|
2009-04-13 10:55:41 -04:00
|
|
|
handler.connect('window-added', function(handler, window) { popup.addWindow(window); });
|
|
|
|
handler.connect('show', function(handler, initialSelection) { popup.show(initialSelection); });
|
|
|
|
handler.connect('destroy', function() { popup.destroy(); });
|
|
|
|
handler.connect('notify::selected', function() { popup.select(handler.selected); });
|
|
|
|
}
|
2008-11-21 09:02:09 -05:00
|
|
|
};
|