2008-10-31 23:09:46 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; -*- */
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2008-11-06 14:00:14 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Tweener = imports.tweener.tweener;
|
2008-10-31 23:09:46 +00:00
|
|
|
|
2008-11-09 18:01:59 +00:00
|
|
|
const Main = imports.ui.main;
|
2008-10-31 23:09:46 +00:00
|
|
|
const Panel = imports.ui.panel;
|
|
|
|
|
|
|
|
const OVERLAY_BACKGROUND_COLOR = new Clutter.Color();
|
|
|
|
OVERLAY_BACKGROUND_COLOR.from_pixel(0x000000ff);
|
|
|
|
|
2008-11-06 14:00:14 +00:00
|
|
|
// Time for initial animation going into overlay mode
|
|
|
|
const ANIMATION_TIME = 0.3;
|
|
|
|
|
|
|
|
// How much to scale the desktop down by in overlay mode
|
|
|
|
const DESKTOP_SCALE = 0.75;
|
|
|
|
|
|
|
|
// Windows are slightly translucent in the overlay mode
|
|
|
|
const WINDOW_OPACITY = 0.9 * 255;
|
|
|
|
|
|
|
|
// Define a layout scheme for small window counts. For larger
|
|
|
|
// counts we fall back to an algorithm. We need more schemes here
|
|
|
|
// unless we have a really good algorithm.
|
|
|
|
//
|
2008-11-19 19:23:24 +00:00
|
|
|
// Each triplet is [xCenter, yCenter, scale] where the scale
|
2008-11-06 14:00:14 +00:00
|
|
|
// is relative to the width of the desktop.
|
|
|
|
const POSITIONS = {
|
|
|
|
1: [[0.5, 0.5, 0.8]],
|
|
|
|
2: [[0.25, 0.5, 0.4], [0.75, 0.5, 0.4]],
|
|
|
|
3: [[0.2, 0.33, 0.3], [0.5, 0.67, 0.3], [0.8, 0.33, 0.3]],
|
|
|
|
4: [[0.25, 0.25, 0.3], [0.75, 0.25, 0.3], [0.75, 0.75, 0.3], [0.25, 0.75, 0.3]]
|
|
|
|
};
|
|
|
|
|
2008-10-31 23:09:46 +00:00
|
|
|
function Overlay() {
|
|
|
|
this._init();
|
2008-11-06 14:00:14 +00:00
|
|
|
};
|
2008-10-31 23:09:46 +00:00
|
|
|
|
|
|
|
Overlay.prototype = {
|
|
|
|
_init : function() {
|
|
|
|
let global = Shell.global_get();
|
|
|
|
|
|
|
|
this._group = new Clutter.Group();
|
|
|
|
this.visible = false;
|
|
|
|
|
|
|
|
let background = new Clutter.Rectangle({ color: OVERLAY_BACKGROUND_COLOR,
|
|
|
|
reactive: true,
|
|
|
|
x: 0,
|
|
|
|
y: Panel.PANEL_HEIGHT,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_width - Panel.PANEL_HEIGHT });
|
|
|
|
this._group.add_actor(background);
|
|
|
|
|
|
|
|
this._group.hide();
|
|
|
|
global.overlay_group.add_actor(this._group);
|
2008-11-02 04:18:41 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
this._windowClones = []
|
2008-10-31 23:09:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
show : function() {
|
|
|
|
if (!this.visible) {
|
|
|
|
this.visible = true;
|
2008-11-02 04:18:41 +00:00
|
|
|
|
|
|
|
let global = Shell.global_get();
|
|
|
|
let windows = global.get_windows();
|
2008-11-19 19:23:24 +00:00
|
|
|
let desktopWindow = null;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
let screenWidth = global.screen_width
|
|
|
|
let screenHeight = global.screen_height
|
2008-11-02 04:18:41 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < windows.length; i++)
|
2008-11-06 14:00:14 +00:00
|
|
|
if (windows[i].get_window_type() == Meta.WindowType.DESKTOP)
|
2008-11-19 19:23:24 +00:00
|
|
|
desktopWindow = windows[i];
|
2008-11-06 14:00:14 +00:00
|
|
|
|
|
|
|
// The desktop windows are shown on top of a scaled down version of the
|
|
|
|
// desktop. This is positioned at the right side of the screen
|
2008-11-19 19:23:24 +00:00
|
|
|
this._desktopWidth = screenWidth * DESKTOP_SCALE;
|
|
|
|
this._desktopHeight = screenHeight * DESKTOP_SCALE;
|
|
|
|
this._desktopX = screenWidth - this._desktopWidth - 10;
|
|
|
|
this._desktopY = Panel.PANEL_HEIGHT + (screenHeight - this._desktopHeight - Panel.PANEL_HEIGHT) / 2;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-18 01:33:03 +00:00
|
|
|
// If a file manager is displaying desktop icons, there will be a desktop window.
|
|
|
|
// This window will have the size of the whole desktop. When such window is not present
|
|
|
|
// (e.g. when the preference for showing icons on the desktop is disabled by the user
|
|
|
|
// or we are running inside a Xephyr window), we should create a desktop rectangle
|
|
|
|
// to serve as the background.
|
2008-11-19 19:23:24 +00:00
|
|
|
if (desktopWindow)
|
|
|
|
this._createDesktopClone(desktopWindow);
|
2008-11-18 01:33:03 +00:00
|
|
|
else
|
|
|
|
this._createDesktopRectangle();
|
2008-11-06 14:00:14 +00:00
|
|
|
|
|
|
|
// Count the total number of windows so we know what layout scheme to use
|
2008-11-19 19:23:24 +00:00
|
|
|
let numberOfWindows = 0;
|
2008-11-06 14:00:14 +00:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
let w = windows[i];
|
2008-11-19 19:23:24 +00:00
|
|
|
if (w == desktopWindow || w.is_override_redirect())
|
2008-11-06 14:00:14 +00:00
|
|
|
continue;
|
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
numberOfWindows++;
|
2008-11-06 14:00:14 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 19:33:35 +00:00
|
|
|
// Now create actors for all the desktop windows. Do it in
|
|
|
|
// reverse order so that the active actor ends up on top
|
2008-11-19 19:23:24 +00:00
|
|
|
let windowIndex = 0;
|
2008-11-08 19:33:35 +00:00
|
|
|
for (let i = windows.length - 1; i >= 0; i--) {
|
2008-11-06 14:00:14 +00:00
|
|
|
let w = windows[i];
|
2008-11-19 19:23:24 +00:00
|
|
|
if (w == desktopWindow || w.is_override_redirect())
|
2008-11-06 14:00:14 +00:00
|
|
|
continue;
|
2008-11-19 19:23:24 +00:00
|
|
|
this._createWindowClone(w, numberOfWindows - windowIndex - 1, numberOfWindows);
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
windowIndex++;
|
2008-11-06 14:00:14 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 19:33:33 +00:00
|
|
|
// All the the actors in the window group are completely obscured,
|
|
|
|
// hiding the group holding them while the overlay is displayed greatly
|
|
|
|
// increases performance of the overlay especially when there are many
|
|
|
|
// windows visible.
|
|
|
|
//
|
|
|
|
// If we switched to displaying the actors in the overlay rather than
|
|
|
|
// clones of them, this would obviously no longer be necessary.
|
|
|
|
global.window_group.hide()
|
2008-10-31 23:09:46 +00:00
|
|
|
this._group.show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hide : function() {
|
|
|
|
if (this.visible) {
|
2008-11-08 19:33:33 +00:00
|
|
|
let global = Shell.global_get();
|
|
|
|
|
2008-10-31 23:09:46 +00:00
|
|
|
this.visible = false;
|
2008-11-08 19:33:33 +00:00
|
|
|
global.window_group.show()
|
2008-10-31 23:09:46 +00:00
|
|
|
this._group.hide();
|
2008-11-02 04:18:41 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
for (let i = 0; i < this._windowClones.length; i++) {
|
|
|
|
this._windowClones[i].destroy();
|
2008-11-02 04:18:41 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
this._windowClones = [];
|
2008-10-31 23:09:46 +00:00
|
|
|
}
|
2008-11-06 14:00:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_createDesktopClone : function(w) {
|
|
|
|
let clone = new Clutter.CloneTexture({ parent_texture: w.get_texture(),
|
|
|
|
reactive: true,
|
|
|
|
x: 0,
|
|
|
|
y: 0 });
|
2008-11-18 01:33:03 +00:00
|
|
|
this._addDesktop(clone);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createDesktopRectangle : function() {
|
|
|
|
let global = Shell.global_get();
|
|
|
|
// In the case when we have a desktop window from the file manager, its height is
|
|
|
|
// full-screen, i.e. it includes the height of the panel, so we should not subtract
|
|
|
|
// the height of the panel from global.screen_height here either to have them show
|
|
|
|
// up identically.
|
|
|
|
// We are also using (0,0) coordinates in both cases which makes the background
|
|
|
|
// window animate out from behind the panel.
|
2008-11-19 19:23:24 +00:00
|
|
|
let desktopRectangle = new Clutter.Rectangle({ color: global.stage.color,
|
2008-11-18 01:33:03 +00:00
|
|
|
reactive: true,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_height });
|
2008-11-19 19:23:24 +00:00
|
|
|
this._addDesktop(desktopRectangle);
|
2008-11-18 01:33:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_addDesktop : function(desktop) {
|
2008-11-19 19:23:24 +00:00
|
|
|
this._windowClones.push(desktop);
|
2008-11-18 01:33:03 +00:00
|
|
|
this._group.add_actor(desktop);
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-18 01:33:03 +00:00
|
|
|
Tweener.addTween(desktop,
|
2008-11-19 19:23:24 +00:00
|
|
|
{ x: this._desktopX,
|
|
|
|
y: this._desktopY,
|
2008-11-06 14:00:14 +00:00
|
|
|
scale_x: DESKTOP_SCALE,
|
|
|
|
scale_y: DESKTOP_SCALE,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: "linear"
|
|
|
|
});
|
|
|
|
|
|
|
|
let me = this;
|
2008-11-18 01:33:03 +00:00
|
|
|
desktop.connect("button-press-event",
|
2008-11-06 14:00:14 +00:00
|
|
|
function() {
|
|
|
|
me._deactivate();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
// windowIndex == 0 => top in stacking order
|
|
|
|
_computeWindowPosition : function(windowIndex, numberOfWindows) {
|
|
|
|
if (numberOfWindows in POSITIONS)
|
|
|
|
return POSITIONS[numberOfWindows][windowIndex];
|
2008-11-06 14:00:14 +00:00
|
|
|
|
|
|
|
// If we don't have a predefined scheme for this window count, overlap the windows
|
|
|
|
// along the diagonal of the desktop (improve this!)
|
2008-11-19 19:23:24 +00:00
|
|
|
let fraction = Math.sqrt(1/numberOfWindows);
|
2008-11-08 19:33:35 +00:00
|
|
|
|
|
|
|
// The top window goes at the lower right - this is different from the
|
|
|
|
// fixed position schemes where the windows are in "reading order"
|
|
|
|
// and the top window goes at the upper left.
|
2008-11-19 19:23:24 +00:00
|
|
|
let pos = (numberOfWindows - windowIndex - 1) / (numberOfWindows - 1);
|
|
|
|
let xCenter = (fraction / 2) + (1 - fraction) * pos;
|
|
|
|
let yCenter = xCenter;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
return [xCenter, yCenter, fraction];
|
2008-11-06 14:00:14 +00:00
|
|
|
},
|
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
_createWindowClone : function(w, windowIndex, numberOfWindows) {
|
2008-11-06 14:00:14 +00:00
|
|
|
// We show the window using "clones" of the texture .. separate
|
|
|
|
// actors that mirror the original actors for the window. For
|
|
|
|
// animation purposes, it may be better to actually move the
|
|
|
|
// original actors about instead.
|
|
|
|
|
|
|
|
let clone = new Clutter.CloneTexture({ parent_texture: w.get_texture(),
|
|
|
|
reactive: true,
|
|
|
|
x: w.x,
|
|
|
|
y: w.y });
|
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
let [xCenter, yCenter, fraction] = this._computeWindowPosition(windowIndex, numberOfWindows);
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
let desiredSize = this._desktopWidth * fraction;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-11-19 19:23:24 +00:00
|
|
|
xCenter = this._desktopX + xCenter * this._desktopWidth;
|
|
|
|
yCenter = this._desktopY + yCenter * this._desktopHeight;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
|
|
|
let size = clone.width;
|
|
|
|
if (clone.height > size)
|
|
|
|
size = clone.height;
|
|
|
|
|
|
|
|
// Never scale up
|
2008-11-19 19:23:24 +00:00
|
|
|
let scale = desiredSize / size;
|
2008-11-06 14:00:14 +00:00
|
|
|
if (scale > 1)
|
|
|
|
scale = 1;
|
|
|
|
|
|
|
|
this._group.add_actor(clone);
|
2008-11-19 19:23:24 +00:00
|
|
|
this._windowClones.push(clone);
|
2008-11-06 14:00:14 +00:00
|
|
|
|
|
|
|
Tweener.addTween(clone,
|
2008-11-19 19:23:24 +00:00
|
|
|
{ x: xCenter - 0.5 * scale * w.width,
|
|
|
|
y: yCenter - 0.5 * scale * w.height,
|
2008-11-06 14:00:14 +00:00
|
|
|
scale_x: scale,
|
|
|
|
scale_y: scale,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
opacity: WINDOW_OPACITY,
|
|
|
|
transition: "linear"
|
|
|
|
});
|
|
|
|
|
|
|
|
let me = this;
|
|
|
|
clone.connect("button-press-event",
|
2008-11-07 17:14:26 +00:00
|
|
|
function(clone, event) {
|
|
|
|
me._activateWindow(w, event.get_time());
|
2008-11-06 14:00:14 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-11-07 17:14:26 +00:00
|
|
|
_activateWindow : function(w, time) {
|
2008-11-06 14:00:14 +00:00
|
|
|
this._deactivate();
|
2008-11-07 17:14:26 +00:00
|
|
|
w.get_meta_window().activate(time);
|
2008-11-06 14:00:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_deactivate : function() {
|
|
|
|
Main.hide_overlay();
|
2008-10-31 23:09:46 +00:00
|
|
|
}
|
|
|
|
};
|