2008-12-01 19:51:43 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-10-31 18:09:20 +00:00
|
|
|
|
2008-10-31 04:22:44 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2008-11-23 04:12:34 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
2008-12-05 21:50:09 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2008-11-23 04:12:34 +00:00
|
|
|
const Tweener = imports.tweener.tweener;
|
2008-10-31 04:22:44 +00:00
|
|
|
|
2008-10-31 18:09:20 +00:00
|
|
|
const Panel = imports.ui.panel;
|
2008-10-31 23:09:46 +00:00
|
|
|
const Overlay = imports.ui.overlay;
|
2008-12-09 22:10:43 +00:00
|
|
|
const RunDialog = imports.ui.runDialog;
|
|
|
|
const WindowManager = imports.ui.windowManager;
|
2008-10-31 18:09:20 +00:00
|
|
|
|
2008-10-31 18:29:42 +00:00
|
|
|
const DEFAULT_BACKGROUND_COLOR = new Clutter.Color();
|
|
|
|
DEFAULT_BACKGROUND_COLOR.from_pixel(0x2266bbff);
|
|
|
|
|
2008-10-31 18:09:20 +00:00
|
|
|
let panel = null;
|
2008-10-31 23:09:46 +00:00
|
|
|
let overlay = null;
|
2008-12-04 15:16:16 +00:00
|
|
|
let overlayActive = false;
|
2008-12-09 22:10:43 +00:00
|
|
|
let runDialog = null;
|
2008-11-21 14:02:09 +00:00
|
|
|
let wm = null;
|
2008-10-31 18:09:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
// The "FrameTicker" object is an object used to feed new frames to Tweener
|
|
|
|
// so it can update values and redraw. The default frame ticker for
|
|
|
|
// Tweener just uses a simple timeout at a fixed frame rate and has no idea
|
|
|
|
// of "catching up" by dropping frames.
|
|
|
|
//
|
|
|
|
// We substitute it with custom frame ticker here that connects Tweener to
|
|
|
|
// a Clutter.TimeLine. Now, Clutter.Timeline itself isn't a whole lot more
|
|
|
|
// sophisticated than a simple timeout at a fixed frame rate, but at least
|
|
|
|
// it knows how to drop frames. (See HippoAnimationManager for a more
|
|
|
|
// sophisticated view of continous time updates; even better is to pay
|
|
|
|
// attention to the vertical vblank and sync to that when possible.)
|
|
|
|
//
|
2008-11-23 04:12:34 +00:00
|
|
|
function ClutterFrameTicker() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterFrameTicker.prototype = {
|
2008-12-01 19:51:43 +00:00
|
|
|
TARGET_FRAME_RATE : 60,
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
_init : function() {
|
|
|
|
// We don't have a finite duration; tweener will tell us to stop
|
|
|
|
// when we need to stop, so use 1000 seconds as "infinity"
|
|
|
|
this._timeline = new Clutter.Timeline({ fps: this.TARGET_FRAME_RATE,
|
|
|
|
duration: 1000*1000 });
|
|
|
|
this._frame = 0;
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
let me = this;
|
|
|
|
this._timeline.connect('new-frame',
|
2008-11-28 20:12:20 +00:00
|
|
|
function(timeline, frame) {
|
2008-12-01 19:51:43 +00:00
|
|
|
me._onNewFrame(frame);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_onNewFrame : function(frame) {
|
|
|
|
// Unfortunately the interface to to send a new frame to tweener
|
|
|
|
// is a simple "next frame" and there is no provision for signaling
|
|
|
|
// that frames have been skipped or just telling it the new time.
|
|
|
|
// But what it actually does internally is just:
|
|
|
|
//
|
|
|
|
// _currentTime += 1000/_ticker.FRAME_RATE;
|
|
|
|
//
|
|
|
|
// So by dynamically adjusting the value of FRAME_RATE we can trick
|
|
|
|
// it into dealing with dropped frames.
|
|
|
|
|
2009-01-13 20:49:31 +00:00
|
|
|
// If there is a lot of setup to start the animation, then
|
|
|
|
// first frame number we get from clutter might be a long ways
|
|
|
|
// into the animation (or the animation might even be done).
|
|
|
|
// That looks bad, so we always start one frame into the
|
|
|
|
// animation then only do frame dropping from there.
|
|
|
|
let delta;
|
|
|
|
if (this._frame == 0)
|
|
|
|
delta = 1;
|
|
|
|
else
|
|
|
|
delta = frame - this._frame;
|
|
|
|
|
|
|
|
if (delta == 0) // protect against divide-by-0 if we get a frame twice
|
2008-12-01 19:51:43 +00:00
|
|
|
this.FRAME_RATE = this.TARGET_FRAME_RATE;
|
|
|
|
else
|
|
|
|
this.FRAME_RATE = this.TARGET_FRAME_RATE / delta;
|
|
|
|
this._frame = frame;
|
|
|
|
this.emit('prepare-frame');
|
|
|
|
},
|
|
|
|
|
|
|
|
start : function() {
|
|
|
|
this._timeline.start();
|
|
|
|
},
|
|
|
|
|
|
|
|
stop : function() {
|
|
|
|
this._timeline.stop();
|
|
|
|
this._frame = 0;
|
|
|
|
}
|
2008-11-23 04:12:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(ClutterFrameTicker.prototype);
|
|
|
|
|
2008-10-31 04:22:44 +00:00
|
|
|
function start() {
|
2008-11-26 19:14:18 +00:00
|
|
|
let global = Shell.Global.get();
|
2008-10-31 18:29:42 +00:00
|
|
|
|
2008-11-23 04:12:34 +00:00
|
|
|
Tweener.setFrameTicker(new ClutterFrameTicker());
|
|
|
|
|
2008-10-31 18:29:42 +00:00
|
|
|
// The background color really only matters if there is no desktop
|
|
|
|
// window (say, nautilus) running. We set it mostly so things look good
|
|
|
|
// when we are running inside Xephyr.
|
|
|
|
global.stage.color = DEFAULT_BACKGROUND_COLOR;
|
|
|
|
|
|
|
|
// Mutter currently hardcodes putting "Yessir. The compositor is running""
|
|
|
|
// in the overlay. Clear that out.
|
2008-10-31 23:09:46 +00:00
|
|
|
let children = global.overlay_group.get_children();
|
2008-10-31 18:29:42 +00:00
|
|
|
for (let i = 0; i < children.length; i++)
|
2008-11-28 20:12:20 +00:00
|
|
|
children[i].destroy();
|
2008-10-31 18:29:42 +00:00
|
|
|
|
2009-01-13 20:43:03 +00:00
|
|
|
// metacity-clutter currently uses the same prefs as plain metacity,
|
|
|
|
// which probably means we'll be starting out with multiple workspaces;
|
|
|
|
// remove any unused ones
|
|
|
|
let windows = global.get_windows();
|
|
|
|
let maxWorkspace = 0;
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
let win = windows[i];
|
|
|
|
|
|
|
|
if (!win.get_meta_window().is_on_all_workspaces() &&
|
|
|
|
win.get_workspace() > maxWorkspace) {
|
|
|
|
maxWorkspace = win.get_workspace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let screen = global.screen;
|
|
|
|
if (screen.n_workspaces > maxWorkspace) {
|
|
|
|
for (let w = screen.n_workspaces - 1; w > maxWorkspace; w--) {
|
|
|
|
let workspace = screen.get_workspace_by_index(w);
|
|
|
|
screen.remove_workspace(workspace, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-19 23:21:42 +00:00
|
|
|
global.connect('panel-run-dialog', function(panel) {
|
|
|
|
// Make sure not more than one run dialog is shown.
|
2008-12-09 22:10:43 +00:00
|
|
|
if (!runDialog) {
|
|
|
|
runDialog = new RunDialog.RunDialog();
|
2008-11-28 20:12:20 +00:00
|
|
|
let end_handler = function() {
|
2008-12-09 22:10:43 +00:00
|
|
|
runDialog.destroy();
|
|
|
|
runDialog = null;
|
2008-11-19 23:21:42 +00:00
|
|
|
};
|
2008-12-09 22:10:43 +00:00
|
|
|
runDialog.connect('run', end_handler);
|
|
|
|
runDialog.connect('cancel', end_handler);
|
|
|
|
if (!runDialog.show())
|
2008-11-28 20:12:20 +00:00
|
|
|
end_handler();
|
2008-11-19 23:21:42 +00:00
|
|
|
}
|
2008-11-07 18:42:23 +00:00
|
|
|
});
|
|
|
|
|
2008-10-31 18:09:20 +00:00
|
|
|
panel = new Panel.Panel();
|
2008-10-31 23:09:46 +00:00
|
|
|
global.set_stage_input_area(0, 0, global.screen_width, Panel.PANEL_HEIGHT);
|
2008-11-21 14:02:09 +00:00
|
|
|
|
|
|
|
overlay = new Overlay.Overlay();
|
|
|
|
wm = new WindowManager.WindowManager();
|
2008-12-05 21:12:43 +00:00
|
|
|
|
|
|
|
let display = global.screen.get_display();
|
|
|
|
display.connect('overlay-key', function(display) {
|
2009-01-07 22:19:46 +00:00
|
|
|
if (overlay.visible) {
|
|
|
|
hide_overlay();
|
|
|
|
} else {
|
|
|
|
show_overlay();
|
|
|
|
}
|
2008-12-05 21:12:43 +00:00
|
|
|
});
|
2008-10-31 23:09:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
// Used to go into a mode where all keyboard and mouse input goes to
|
|
|
|
// the stage. Returns true if we successfully grabbed the keyboard and
|
|
|
|
// went modal, false otherwise
|
2008-11-24 19:07:18 +00:00
|
|
|
function startModal() {
|
2008-11-26 19:14:18 +00:00
|
|
|
let global = Shell.Global.get();
|
2008-10-31 23:09:46 +00:00
|
|
|
|
2008-11-24 19:07:18 +00:00
|
|
|
if (!global.grab_keyboard())
|
2008-11-28 20:12:20 +00:00
|
|
|
return false;
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2008-10-31 23:09:46 +00:00
|
|
|
global.set_stage_input_area(0, 0, global.screen_width, global.screen_height);
|
2008-11-24 19:07:18 +00:00
|
|
|
|
|
|
|
return true;
|
2008-10-31 23:09:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 19:07:18 +00:00
|
|
|
function endModal() {
|
2008-11-26 19:14:18 +00:00
|
|
|
let global = Shell.Global.get();
|
2008-10-31 23:09:46 +00:00
|
|
|
|
2008-11-24 19:07:18 +00:00
|
|
|
global.ungrab_keyboard();
|
2008-10-31 23:09:46 +00:00
|
|
|
global.set_stage_input_area(0, 0, global.screen_width, Panel.PANEL_HEIGHT);
|
2008-10-31 04:22:44 +00:00
|
|
|
}
|
2008-11-24 19:07:18 +00:00
|
|
|
|
|
|
|
function show_overlay() {
|
2008-12-04 15:16:16 +00:00
|
|
|
if (startModal()) {
|
|
|
|
overlayActive = true;
|
2008-11-28 20:12:20 +00:00
|
|
|
overlay.show();
|
2008-12-04 15:16:16 +00:00
|
|
|
}
|
2008-11-24 19:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hide_overlay() {
|
|
|
|
overlay.hide();
|
2008-12-04 15:16:16 +00:00
|
|
|
overlayActive = false;
|
2008-11-24 19:07:18 +00:00
|
|
|
endModal();
|
|
|
|
}
|