2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 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;
|
2009-05-01 18:13:51 +00:00
|
|
|
const Gdk = imports.gi.Gdk;
|
2009-01-22 21:28:19 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2009-08-28 19:11:25 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
2009-05-07 13:47:48 +00:00
|
|
|
const Lang = imports.lang;
|
2008-12-05 21:50:09 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2009-04-29 18:01:09 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-09-10 05:36:41 +00:00
|
|
|
const St = imports.gi.St;
|
2008-10-31 04:22:44 +00:00
|
|
|
|
2011-06-20 19:16:40 +00:00
|
|
|
const AutomountManager = imports.ui.automountManager;
|
2011-07-12 13:47:43 +00:00
|
|
|
const AutorunManager = imports.ui.autorunManager;
|
2010-07-01 18:13:42 +00:00
|
|
|
const CtrlAltTab = imports.ui.ctrlAltTab;
|
2011-01-06 15:30:15 +00:00
|
|
|
const EndSessionDialog = imports.ui.endSessionDialog;
|
2011-02-21 17:17:34 +00:00
|
|
|
const PolkitAuthenticationAgent = imports.ui.polkitAuthenticationAgent;
|
2012-01-10 15:37:26 +00:00
|
|
|
const KeyringPrompt = imports.ui.keyringPrompt;
|
2009-09-18 19:51:15 +00:00
|
|
|
const Environment = imports.ui.environment;
|
2009-10-25 22:53:10 +00:00
|
|
|
const ExtensionSystem = imports.ui.extensionSystem;
|
2012-05-25 23:07:31 +00:00
|
|
|
const ExtensionDownloader = imports.ui.extensionDownloader;
|
2011-08-29 15:11:22 +00:00
|
|
|
const Keyboard = imports.ui.keyboard;
|
2010-01-13 20:05:20 +00:00
|
|
|
const MessageTray = imports.ui.messageTray;
|
2009-08-11 11:46:10 +00:00
|
|
|
const Overview = imports.ui.overview;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Panel = imports.ui.panel;
|
2009-11-01 02:25:28 +00:00
|
|
|
const PlaceDisplay = imports.ui.placeDisplay;
|
2008-12-09 22:10:43 +00:00
|
|
|
const RunDialog = imports.ui.runDialog;
|
2011-06-13 13:54:05 +00:00
|
|
|
const Layout = imports.ui.layout;
|
2009-08-02 07:46:01 +00:00
|
|
|
const LookingGlass = imports.ui.lookingGlass;
|
2011-08-19 18:29:39 +00:00
|
|
|
const NetworkAgent = imports.ui.networkAgent;
|
2010-01-13 20:05:20 +00:00
|
|
|
const NotificationDaemon = imports.ui.notificationDaemon;
|
2010-02-22 18:53:41 +00:00
|
|
|
const WindowAttentionHandler = imports.ui.windowAttentionHandler;
|
2010-05-09 17:42:35 +00:00
|
|
|
const Scripting = imports.ui.scripting;
|
2012-05-16 22:26:44 +00:00
|
|
|
const SessionMode = imports.ui.sessionMode;
|
2009-09-23 18:30:05 +00:00
|
|
|
const ShellDBus = imports.ui.shellDBus;
|
2012-06-20 21:23:34 +00:00
|
|
|
const ShellMountOperation = imports.ui.shellMountOperation;
|
2010-02-02 15:21:47 +00:00
|
|
|
const TelepathyClient = imports.ui.telepathyClient;
|
2008-12-09 22:10:43 +00:00
|
|
|
const WindowManager = imports.ui.windowManager;
|
2010-05-10 16:40:03 +00:00
|
|
|
const Magnifier = imports.ui.magnifier;
|
2011-01-05 14:47:27 +00:00
|
|
|
const XdndHandler = imports.ui.xdndHandler;
|
2010-08-09 16:33:34 +00:00
|
|
|
const StatusIconDispatcher = imports.ui.statusIconDispatcher;
|
2010-11-17 16:43:08 +00:00
|
|
|
const Util = imports.misc.util;
|
2008-10-31 18:09:20 +00:00
|
|
|
|
2012-03-08 00:29:17 +00:00
|
|
|
const OVERRIDES_SCHEMA = 'org.gnome.shell.overrides';
|
2008-10-31 18:29:42 +00:00
|
|
|
const DEFAULT_BACKGROUND_COLOR = new Clutter.Color();
|
|
|
|
DEFAULT_BACKGROUND_COLOR.from_pixel(0x2266bbff);
|
|
|
|
|
2011-06-20 19:16:40 +00:00
|
|
|
let automountManager = null;
|
2011-07-12 13:47:43 +00:00
|
|
|
let autorunManager = null;
|
2008-10-31 18:09:20 +00:00
|
|
|
let panel = null;
|
2011-02-23 14:17:25 +00:00
|
|
|
let hotCorners = [];
|
2009-08-11 11:46:10 +00:00
|
|
|
let overview = null;
|
2008-12-09 22:10:43 +00:00
|
|
|
let runDialog = null;
|
2009-08-02 07:46:01 +00:00
|
|
|
let lookingGlass = null;
|
2008-11-21 14:02:09 +00:00
|
|
|
let wm = null;
|
2010-01-13 20:05:20 +00:00
|
|
|
let messageTray = null;
|
2010-02-02 15:21:47 +00:00
|
|
|
let notificationDaemon = null;
|
2010-02-22 18:53:41 +00:00
|
|
|
let windowAttentionHandler = null;
|
2010-02-02 15:21:47 +00:00
|
|
|
let telepathyClient = null;
|
2010-07-01 18:13:42 +00:00
|
|
|
let ctrlAltTabManager = null;
|
2009-03-13 21:14:31 +00:00
|
|
|
let recorder = null;
|
2012-05-16 22:26:44 +00:00
|
|
|
let sessionMode = null;
|
2009-09-23 18:30:05 +00:00
|
|
|
let shellDBusService = null;
|
2012-06-20 21:23:34 +00:00
|
|
|
let shellMountOpDBusService = null;
|
2009-09-15 19:53:07 +00:00
|
|
|
let modalCount = 0;
|
|
|
|
let modalActorFocusStack = [];
|
2010-05-06 21:18:10 +00:00
|
|
|
let uiGroup = null;
|
2010-05-10 16:40:03 +00:00
|
|
|
let magnifier = null;
|
2011-01-05 14:47:27 +00:00
|
|
|
let xdndHandler = null;
|
2010-08-09 16:33:34 +00:00
|
|
|
let statusIconDispatcher = null;
|
2011-08-29 15:11:22 +00:00
|
|
|
let keyboard = null;
|
2011-06-13 13:54:05 +00:00
|
|
|
let layoutManager = null;
|
2011-08-19 18:29:39 +00:00
|
|
|
let networkAgent = null;
|
2009-10-24 17:36:52 +00:00
|
|
|
let _startDate;
|
2011-02-01 15:11:00 +00:00
|
|
|
let _defaultCssStylesheet = null;
|
|
|
|
let _cssStylesheet = null;
|
2012-03-08 00:29:17 +00:00
|
|
|
let _overridesSettings = null;
|
2008-10-31 18:09:20 +00:00
|
|
|
|
2010-02-03 19:47:52 +00:00
|
|
|
let background = null;
|
|
|
|
|
2012-05-17 13:50:51 +00:00
|
|
|
function createUserSession() {
|
2011-08-24 01:53:02 +00:00
|
|
|
// Load the calendar server. Note that we are careful about
|
|
|
|
// not loading any events until the user presses the clock
|
|
|
|
global.launch_calendar_server();
|
|
|
|
|
|
|
|
telepathyClient = new TelepathyClient.Client();
|
|
|
|
automountManager = new AutomountManager.AutomountManager();
|
|
|
|
autorunManager = new AutorunManager.AutorunManager();
|
|
|
|
networkAgent = new NetworkAgent.NetworkAgent();
|
2012-05-17 13:47:32 +00:00
|
|
|
|
|
|
|
_initRecorder();
|
2011-08-24 01:53:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 13:50:51 +00:00
|
|
|
function createGDMSession() {
|
2011-08-24 02:12:57 +00:00
|
|
|
// We do this this here instead of at the top to prevent GDM
|
|
|
|
// related code from getting loaded in normal user sessions
|
|
|
|
const LoginDialog = imports.gdm.loginDialog;
|
|
|
|
|
|
|
|
let loginDialog = new LoginDialog.LoginDialog();
|
|
|
|
loginDialog.connect('loaded', function() {
|
|
|
|
loginDialog.open();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-24 03:37:09 +00:00
|
|
|
function createInitialSetupSession() {
|
|
|
|
networkAgent = new NetworkAgent.NetworkAgent();
|
|
|
|
}
|
|
|
|
|
2011-08-24 01:53:02 +00:00
|
|
|
function _initRecorder() {
|
|
|
|
let recorderSettings = new Gio.Settings({ schema: 'org.gnome.shell.recorder' });
|
2012-06-02 12:45:55 +00:00
|
|
|
let desktopLockdownSettings = new Gio.Settings({ schema: 'org.gnome.desktop.lockdown' });
|
2012-04-18 18:45:09 +00:00
|
|
|
let bindingSettings = new Gio.Settings({ schema: 'org.gnome.shell.keybindings' });
|
2011-08-24 01:53:02 +00:00
|
|
|
|
2012-04-18 18:45:09 +00:00
|
|
|
global.display.add_keybinding('toggle-recording',
|
|
|
|
bindingSettings,
|
|
|
|
Meta.KeyBindingFlags.NONE, function() {
|
2011-08-24 01:53:02 +00:00
|
|
|
if (recorder == null) {
|
|
|
|
recorder = new Shell.Recorder({ stage: global.stage });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recorder.is_recording()) {
|
2012-05-02 14:44:40 +00:00
|
|
|
recorder.close();
|
2011-08-29 21:55:42 +00:00
|
|
|
Meta.enable_unredirect_for_screen(global.screen);
|
2012-06-02 12:45:55 +00:00
|
|
|
} else if (!desktopLockdownSettings.get_boolean('disable-save-to-disk')) {
|
2011-08-24 01:53:02 +00:00
|
|
|
// read the parameters from GSettings always in case they have changed
|
|
|
|
recorder.set_framerate(recorderSettings.get_int('framerate'));
|
2012-02-24 23:51:44 +00:00
|
|
|
/* Translators: this is a filename used for screencast recording */
|
|
|
|
// xgettext:no-c-format
|
2012-02-26 17:09:49 +00:00
|
|
|
recorder.set_filename(_("Screencast from %d %t") + '.' + recorderSettings.get_string('file-extension'));
|
2011-08-24 01:53:02 +00:00
|
|
|
let pipeline = recorderSettings.get_string('pipeline');
|
|
|
|
|
|
|
|
if (!pipeline.match(/^\s*$/))
|
|
|
|
recorder.set_pipeline(pipeline);
|
|
|
|
else
|
|
|
|
recorder.set_pipeline(null);
|
|
|
|
|
2011-08-29 21:55:42 +00:00
|
|
|
Meta.disable_unredirect_for_screen(global.screen);
|
2011-08-24 01:53:02 +00:00
|
|
|
recorder.record();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-10-31 04:22:44 +00:00
|
|
|
function start() {
|
2012-04-29 20:42:45 +00:00
|
|
|
// These are here so we don't break compatibility.
|
|
|
|
global.logError = window.log;
|
|
|
|
global.log = window.log;
|
2009-10-24 17:36:52 +00:00
|
|
|
|
2011-03-15 22:31:16 +00:00
|
|
|
// Chain up async errors reported from C
|
|
|
|
global.connect('notify-error', function (global, msg, detail) { notifyError(msg, detail); });
|
|
|
|
|
2010-05-13 19:46:04 +00:00
|
|
|
Gio.DesktopAppInfo.set_desktop_env('GNOME');
|
2009-01-22 21:28:19 +00:00
|
|
|
|
2012-05-16 22:26:44 +00:00
|
|
|
sessionMode = new SessionMode.SessionMode();
|
2009-09-23 18:30:05 +00:00
|
|
|
shellDBusService = new ShellDBus.GnomeShell();
|
2012-06-20 21:23:34 +00:00
|
|
|
shellMountOpDBusService = new ShellMountOperation.GnomeShellMountOpHandler();
|
2008-10-31 18:29:42 +00:00
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
// Ensure ShellWindowTracker and ShellAppUsage are initialized; this will
|
2009-08-12 17:32:54 +00:00
|
|
|
// also initialize ShellAppSystem first. ShellAppSystem
|
2009-10-15 23:28:29 +00:00
|
|
|
// needs to load all the .desktop files, and ShellWindowTracker
|
2009-08-12 17:32:54 +00:00
|
|
|
// will use those to associate with windows. Right now
|
|
|
|
// the Monitor doesn't listen for installed app changes
|
|
|
|
// and recalculate application associations, so to avoid
|
|
|
|
// races for now we initialize it here. It's better to
|
|
|
|
// be predictable anyways.
|
2012-02-17 14:57:27 +00:00
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
2009-10-15 23:28:29 +00:00
|
|
|
Shell.AppUsage.get_default();
|
2009-08-12 17:32:54 +00:00
|
|
|
|
2012-02-17 14:57:27 +00:00
|
|
|
tracker.connect('startup-sequence-changed', _queueCheckWorkspaces);
|
|
|
|
|
2010-11-13 18:02:39 +00:00
|
|
|
// The stage is always covered so Clutter doesn't need to clear it; however
|
2010-11-14 18:13:44 +00:00
|
|
|
// the color is used as the default contents for the Mutter root background
|
|
|
|
// actor so set it anyways.
|
2008-10-31 18:29:42 +00:00
|
|
|
global.stage.color = DEFAULT_BACKGROUND_COLOR;
|
2010-11-13 18:02:39 +00:00
|
|
|
global.stage.no_clear_hint = true;
|
2008-10-31 18:29:42 +00:00
|
|
|
|
2011-02-01 15:11:00 +00:00
|
|
|
_defaultCssStylesheet = global.datadir + '/theme/gnome-shell.css';
|
2011-01-04 19:30:03 +00:00
|
|
|
loadTheme();
|
2009-09-10 05:36:41 +00:00
|
|
|
|
2010-05-06 21:18:10 +00:00
|
|
|
// Set up stage hierarchy to group all UI actors under one container.
|
2011-09-01 14:20:52 +00:00
|
|
|
uiGroup = new Shell.GenericContainer({ name: 'uiGroup' });
|
|
|
|
uiGroup.connect('allocate',
|
|
|
|
function (actor, box, flags) {
|
|
|
|
let children = uiGroup.get_children();
|
|
|
|
for (let i = 0; i < children.length; i++)
|
|
|
|
children[i].allocate_preferred_size(flags);
|
|
|
|
});
|
2012-02-22 17:18:15 +00:00
|
|
|
uiGroup.connect('get-preferred-width',
|
|
|
|
function(actor, forHeight, alloc) {
|
|
|
|
let width = global.stage.width;
|
|
|
|
[alloc.min_size, alloc.natural_size] = [width, width];
|
|
|
|
});
|
|
|
|
uiGroup.connect('get-preferred-height',
|
|
|
|
function(actor, forWidth, alloc) {
|
|
|
|
let height = global.stage.height;
|
|
|
|
[alloc.min_size, alloc.natural_size] = [height, height];
|
|
|
|
});
|
2010-05-06 21:18:10 +00:00
|
|
|
global.window_group.reparent(uiGroup);
|
|
|
|
global.overlay_group.reparent(uiGroup);
|
|
|
|
global.stage.add_actor(uiGroup);
|
|
|
|
|
2011-06-13 13:54:05 +00:00
|
|
|
layoutManager = new Layout.LayoutManager();
|
2011-01-05 14:47:27 +00:00
|
|
|
xdndHandler = new XdndHandler.XdndHandler();
|
2011-02-07 16:29:34 +00:00
|
|
|
ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager();
|
2012-05-16 22:59:02 +00:00
|
|
|
overview = new Overview.Overview();
|
2010-07-21 08:44:59 +00:00
|
|
|
magnifier = new Magnifier.Magnifier();
|
2010-08-09 16:33:34 +00:00
|
|
|
statusIconDispatcher = new StatusIconDispatcher.StatusIconDispatcher();
|
2008-10-31 18:09:20 +00:00
|
|
|
panel = new Panel.Panel();
|
2008-11-21 14:02:09 +00:00
|
|
|
wm = new WindowManager.WindowManager();
|
2010-02-02 15:21:47 +00:00
|
|
|
messageTray = new MessageTray.MessageTray();
|
2011-08-29 15:11:22 +00:00
|
|
|
keyboard = new Keyboard.Keyboard();
|
2010-01-13 20:05:20 +00:00
|
|
|
notificationDaemon = new NotificationDaemon.NotificationDaemon();
|
2010-02-22 18:53:41 +00:00
|
|
|
windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler();
|
2011-08-24 02:12:57 +00:00
|
|
|
|
2012-05-17 13:50:51 +00:00
|
|
|
sessionMode.createSession();
|
2011-01-31 17:48:18 +00:00
|
|
|
|
2011-08-22 21:47:59 +00:00
|
|
|
panel.startStatusArea();
|
2009-08-12 17:32:54 +00:00
|
|
|
|
2011-09-01 17:35:15 +00:00
|
|
|
layoutManager.init();
|
2011-08-24 01:53:02 +00:00
|
|
|
keyboard.init();
|
|
|
|
overview.init();
|
2009-03-13 21:14:31 +00:00
|
|
|
|
2012-05-17 13:32:32 +00:00
|
|
|
if (sessionMode.hasWorkspaces)
|
|
|
|
global.screen.override_workspace_layout(Meta.ScreenCorner.TOPLEFT,
|
|
|
|
false, -1, 1);
|
|
|
|
|
2012-05-17 00:08:56 +00:00
|
|
|
if (sessionMode.allowExtensions) {
|
2012-05-25 23:07:31 +00:00
|
|
|
ExtensionDownloader.init();
|
2012-05-17 00:08:56 +00:00
|
|
|
ExtensionSystem.loadExtensions();
|
|
|
|
}
|
|
|
|
|
2012-05-17 11:41:02 +00:00
|
|
|
if (sessionMode.hasRunDialog) {
|
|
|
|
Meta.keybindings_set_custom_handler('panel-run-dialog', function() {
|
|
|
|
getRunDialog().open();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-16 22:59:02 +00:00
|
|
|
if (sessionMode.hasOverview) {
|
|
|
|
Meta.keybindings_set_custom_handler('panel-main-menu', function () {
|
|
|
|
overview.toggle();
|
|
|
|
});
|
|
|
|
|
|
|
|
global.display.connect('overlay-key',
|
|
|
|
Lang.bind(overview, overview.toggle));
|
|
|
|
}
|
|
|
|
|
2011-08-24 01:53:02 +00:00
|
|
|
statusIconDispatcher.start(messageTray.actor);
|
2011-01-30 23:21:31 +00:00
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
// Provide the bus object for gnome-session to
|
|
|
|
// initiate logouts.
|
|
|
|
EndSessionDialog.init();
|
|
|
|
|
2011-02-21 17:17:34 +00:00
|
|
|
// Attempt to become a PolicyKit authentication agent
|
|
|
|
PolkitAuthenticationAgent.init()
|
|
|
|
|
2012-01-10 15:37:26 +00:00
|
|
|
// Become a prompter for gnome keyring
|
|
|
|
KeyringPrompt.init();
|
|
|
|
|
2011-08-24 01:53:02 +00:00
|
|
|
_startDate = new Date();
|
2009-08-28 19:11:25 +00:00
|
|
|
|
|
|
|
global.stage.connect('captured-event', _globalKeyPressHandler);
|
|
|
|
|
2010-01-08 16:27:52 +00:00
|
|
|
log('GNOME Shell started at ' + _startDate);
|
2009-10-24 17:36:52 +00:00
|
|
|
|
2010-05-09 17:42:35 +00:00
|
|
|
let perfModuleName = GLib.getenv("SHELL_PERF_MODULE");
|
|
|
|
if (perfModuleName) {
|
|
|
|
let perfOutput = GLib.getenv("SHELL_PERF_OUTPUT");
|
|
|
|
let module = eval('imports.perf.' + perfModuleName + ';');
|
|
|
|
Scripting.runPerfScript(module, perfOutput);
|
|
|
|
}
|
2011-01-25 21:29:45 +00:00
|
|
|
|
2012-03-08 00:29:17 +00:00
|
|
|
_overridesSettings = new Gio.Settings({ schema: OVERRIDES_SCHEMA });
|
|
|
|
_overridesSettings.connect('changed::dynamic-workspaces', _queueCheckWorkspaces);
|
|
|
|
|
2011-01-25 21:29:45 +00:00
|
|
|
global.screen.connect('notify::n-workspaces', _nWorkspacesChanged);
|
2011-03-16 10:37:08 +00:00
|
|
|
|
|
|
|
global.screen.connect('window-entered-monitor', _windowEnteredMonitor);
|
|
|
|
global.screen.connect('window-left-monitor', _windowLeftMonitor);
|
2011-06-10 13:51:55 +00:00
|
|
|
global.screen.connect('restacked', _windowsRestacked);
|
2011-03-16 10:37:08 +00:00
|
|
|
|
2011-03-19 23:36:17 +00:00
|
|
|
_nWorkspacesChanged();
|
2011-01-25 21:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let _workspaces = [];
|
|
|
|
let _checkWorkspacesId = 0;
|
|
|
|
|
2011-02-16 16:48:41 +00:00
|
|
|
/*
|
|
|
|
* When the last window closed on a workspace is a dialog or splash
|
|
|
|
* screen, we assume that it might be an initial window shown before
|
|
|
|
* the main window of an application, and give the app a grace period
|
|
|
|
* where it can map another window before we remove the workspace.
|
|
|
|
*/
|
|
|
|
const LAST_WINDOW_GRACE_TIME = 1000;
|
|
|
|
|
2011-01-25 21:29:45 +00:00
|
|
|
function _checkWorkspaces() {
|
|
|
|
let i;
|
|
|
|
let emptyWorkspaces = [];
|
|
|
|
|
2012-03-08 00:29:17 +00:00
|
|
|
if (!Meta.prefs_get_dynamic_workspaces()) {
|
|
|
|
_checkWorkspacesId = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-16 16:48:41 +00:00
|
|
|
for (i = 0; i < _workspaces.length; i++) {
|
|
|
|
let lastRemoved = _workspaces[i]._lastRemovedWindow;
|
2012-02-17 14:57:27 +00:00
|
|
|
if ((lastRemoved &&
|
|
|
|
(lastRemoved.get_window_type() == Meta.WindowType.SPLASHSCREEN ||
|
|
|
|
lastRemoved.get_window_type() == Meta.WindowType.DIALOG ||
|
|
|
|
lastRemoved.get_window_type() == Meta.WindowType.MODAL_DIALOG)) ||
|
|
|
|
_workspaces[i]._keepAliveId)
|
2011-02-16 16:48:41 +00:00
|
|
|
emptyWorkspaces[i] = false;
|
|
|
|
else
|
|
|
|
emptyWorkspaces[i] = true;
|
|
|
|
}
|
2011-01-25 21:29:45 +00:00
|
|
|
|
2012-02-17 14:57:27 +00:00
|
|
|
let sequences = Shell.WindowTracker.get_default().get_startup_sequences();
|
|
|
|
for (i = 0; i < sequences.length; i++) {
|
|
|
|
let index = sequences[i].get_workspace();
|
|
|
|
if (index >= 0 && index <= global.screen.n_workspaces)
|
|
|
|
emptyWorkspaces[index] = false;
|
|
|
|
}
|
|
|
|
|
2011-01-25 21:29:45 +00:00
|
|
|
let windows = global.get_window_actors();
|
|
|
|
for (i = 0; i < windows.length; i++) {
|
|
|
|
let win = windows[i];
|
|
|
|
|
|
|
|
if (win.get_meta_window().is_on_all_workspaces())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let workspaceIndex = win.get_workspace();
|
|
|
|
emptyWorkspaces[workspaceIndex] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have an empty workspace at the end, add one
|
|
|
|
if (!emptyWorkspaces[emptyWorkspaces.length -1]) {
|
|
|
|
global.screen.append_new_workspace(false, global.get_current_time());
|
|
|
|
emptyWorkspaces.push(false);
|
|
|
|
}
|
|
|
|
|
2011-02-16 20:07:45 +00:00
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
2011-03-11 23:37:40 +00:00
|
|
|
let removingCurrentWorkspace = (emptyWorkspaces[activeWorkspaceIndex] &&
|
|
|
|
activeWorkspaceIndex < emptyWorkspaces.length - 1);
|
|
|
|
// Don't enter the overview when removing multiple empty workspaces at startup
|
|
|
|
let showOverview = (removingCurrentWorkspace &&
|
|
|
|
!emptyWorkspaces.every(function(x) { return x; }));
|
2011-02-16 20:07:45 +00:00
|
|
|
|
2011-03-11 23:37:40 +00:00
|
|
|
if (removingCurrentWorkspace) {
|
2011-02-16 20:07:45 +00:00
|
|
|
// "Merge" the empty workspace we are removing with the one at the end
|
|
|
|
wm.blockAnimations();
|
|
|
|
}
|
|
|
|
|
2011-01-25 21:29:45 +00:00
|
|
|
// Delete other empty workspaces; do it from the end to avoid index changes
|
|
|
|
for (i = emptyWorkspaces.length - 2; i >= 0; i--) {
|
|
|
|
if (emptyWorkspaces[i])
|
|
|
|
global.screen.remove_workspace(_workspaces[i], global.get_current_time());
|
|
|
|
}
|
|
|
|
|
2011-03-11 23:37:40 +00:00
|
|
|
if (removingCurrentWorkspace) {
|
2011-02-16 20:07:45 +00:00
|
|
|
global.screen.get_workspace_by_index(global.screen.n_workspaces - 1).activate(global.get_current_time());
|
|
|
|
wm.unblockAnimations();
|
|
|
|
|
2011-03-11 23:37:40 +00:00
|
|
|
if (!overview.visible && showOverview)
|
2011-02-16 20:07:45 +00:00
|
|
|
overview.show();
|
|
|
|
}
|
|
|
|
|
2011-01-25 21:29:45 +00:00
|
|
|
_checkWorkspacesId = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:57:27 +00:00
|
|
|
function keepWorkspaceAlive(workspace, duration) {
|
|
|
|
if (workspace._keepAliveId)
|
|
|
|
Mainloop.source_remove(workspace._keepAliveId);
|
|
|
|
|
|
|
|
workspace._keepAliveId = Mainloop.timeout_add(duration, function() {
|
|
|
|
workspace._keepAliveId = 0;
|
|
|
|
_queueCheckWorkspaces();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-16 16:48:41 +00:00
|
|
|
function _windowRemoved(workspace, window) {
|
|
|
|
workspace._lastRemovedWindow = window;
|
|
|
|
_queueCheckWorkspaces();
|
|
|
|
Mainloop.timeout_add(LAST_WINDOW_GRACE_TIME, function() {
|
|
|
|
if (workspace._lastRemovedWindow == window) {
|
|
|
|
workspace._lastRemovedWindow = null;
|
|
|
|
_queueCheckWorkspaces();
|
|
|
|
}
|
2012-01-17 11:17:34 +00:00
|
|
|
return false;
|
2011-02-16 16:48:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-03-16 10:37:08 +00:00
|
|
|
function _windowLeftMonitor(metaScreen, monitorIndex, metaWin) {
|
|
|
|
// If the window left the primary monitor, that
|
|
|
|
// might make that workspace empty
|
2011-06-13 13:54:05 +00:00
|
|
|
if (monitorIndex == layoutManager.primaryIndex)
|
2011-03-16 10:37:08 +00:00
|
|
|
_queueCheckWorkspaces();
|
|
|
|
}
|
|
|
|
|
|
|
|
function _windowEnteredMonitor(metaScreen, monitorIndex, metaWin) {
|
|
|
|
// If the window entered the primary monitor, that
|
|
|
|
// might make that workspace non-empty
|
2011-06-13 13:54:05 +00:00
|
|
|
if (monitorIndex == layoutManager.primaryIndex)
|
2011-03-16 10:37:08 +00:00
|
|
|
_queueCheckWorkspaces();
|
|
|
|
}
|
|
|
|
|
2011-06-10 13:51:55 +00:00
|
|
|
function _windowsRestacked() {
|
|
|
|
// Figure out where the pointer is in case we lost track of
|
|
|
|
// it during a grab. (In particular, if a trayicon popup menu
|
|
|
|
// is dismissed, see if we need to close the message tray.)
|
|
|
|
global.sync_pointer();
|
|
|
|
}
|
|
|
|
|
2011-01-25 21:29:45 +00:00
|
|
|
function _queueCheckWorkspaces() {
|
|
|
|
if (_checkWorkspacesId == 0)
|
|
|
|
_checkWorkspacesId = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, _checkWorkspaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _nWorkspacesChanged() {
|
|
|
|
let oldNumWorkspaces = _workspaces.length;
|
|
|
|
let newNumWorkspaces = global.screen.n_workspaces;
|
|
|
|
|
|
|
|
if (oldNumWorkspaces == newNumWorkspaces)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let lostWorkspaces = [];
|
|
|
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
|
|
|
let w;
|
|
|
|
|
|
|
|
// Assume workspaces are only added at the end
|
|
|
|
for (w = oldNumWorkspaces; w < newNumWorkspaces; w++)
|
|
|
|
_workspaces[w] = global.screen.get_workspace_by_index(w);
|
|
|
|
|
|
|
|
for (w = oldNumWorkspaces; w < newNumWorkspaces; w++) {
|
|
|
|
let workspace = _workspaces[w];
|
|
|
|
workspace._windowAddedId = workspace.connect('window-added', _queueCheckWorkspaces);
|
2011-02-16 16:48:41 +00:00
|
|
|
workspace._windowRemovedId = workspace.connect('window-removed', _windowRemoved);
|
2011-01-25 21:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Assume workspaces are only removed sequentially
|
|
|
|
// (e.g. 2,3,4 - not 2,4,7)
|
|
|
|
let removedIndex;
|
|
|
|
let removedNum = oldNumWorkspaces - newNumWorkspaces;
|
|
|
|
for (let w = 0; w < oldNumWorkspaces; w++) {
|
|
|
|
let workspace = global.screen.get_workspace_by_index(w);
|
|
|
|
if (_workspaces[w] != workspace) {
|
|
|
|
removedIndex = w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let lostWorkspaces = _workspaces.splice(removedIndex, removedNum);
|
|
|
|
lostWorkspaces.forEach(function(workspace) {
|
|
|
|
workspace.disconnect(workspace._windowAddedId);
|
|
|
|
workspace.disconnect(workspace._windowRemovedId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_queueCheckWorkspaces();
|
|
|
|
|
|
|
|
return false;
|
2009-02-16 19:32:04 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 11:15:26 +00:00
|
|
|
/**
|
2011-02-01 14:44:15 +00:00
|
|
|
* getThemeStylesheet:
|
|
|
|
*
|
|
|
|
* Get the theme CSS file that the shell will load
|
|
|
|
*
|
|
|
|
* Returns: A file path that contains the theme CSS,
|
|
|
|
* null if using the default
|
|
|
|
*/
|
|
|
|
function getThemeStylesheet()
|
|
|
|
{
|
2011-02-01 15:11:00 +00:00
|
|
|
return _cssStylesheet;
|
2011-02-01 14:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setThemeStylesheet:
|
2011-02-01 15:11:00 +00:00
|
|
|
* @cssStylesheet: A file path that contains the theme CSS,
|
2011-01-11 11:15:26 +00:00
|
|
|
* set it to null to use the default
|
|
|
|
*
|
|
|
|
* Set the theme CSS file that the shell will load
|
|
|
|
*/
|
2011-02-01 15:11:00 +00:00
|
|
|
function setThemeStylesheet(cssStylesheet)
|
2011-01-11 11:15:26 +00:00
|
|
|
{
|
2011-02-01 15:11:00 +00:00
|
|
|
_cssStylesheet = cssStylesheet;
|
2011-01-11 11:15:26 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 19:30:03 +00:00
|
|
|
/**
|
|
|
|
* loadTheme:
|
|
|
|
*
|
2011-01-11 11:15:26 +00:00
|
|
|
* Reloads the theme CSS file
|
2011-01-04 19:30:03 +00:00
|
|
|
*/
|
|
|
|
function loadTheme() {
|
|
|
|
let themeContext = St.ThemeContext.get_for_stage (global.stage);
|
2011-06-02 15:05:08 +00:00
|
|
|
let previousTheme = themeContext.get_theme();
|
2011-01-11 11:15:26 +00:00
|
|
|
|
2011-02-01 15:11:00 +00:00
|
|
|
let cssStylesheet = _defaultCssStylesheet;
|
|
|
|
if (_cssStylesheet != null)
|
|
|
|
cssStylesheet = _cssStylesheet;
|
2011-01-11 11:15:26 +00:00
|
|
|
|
2011-02-01 15:11:00 +00:00
|
|
|
let theme = new St.Theme ({ application_stylesheet: cssStylesheet });
|
2011-06-02 15:05:08 +00:00
|
|
|
|
2012-05-17 13:52:02 +00:00
|
|
|
if (sessionMode.extraStylesheet)
|
|
|
|
theme.load_stylesheet(sessionMode.extraStylesheet);
|
2011-08-24 02:12:57 +00:00
|
|
|
|
2011-06-02 15:05:08 +00:00
|
|
|
if (previousTheme) {
|
|
|
|
let customStylesheets = previousTheme.get_custom_stylesheets();
|
|
|
|
|
|
|
|
for (let i = 0; i < customStylesheets.length; i++)
|
|
|
|
theme.load_stylesheet(customStylesheets[i]);
|
|
|
|
}
|
|
|
|
|
2011-01-04 19:30:03 +00:00
|
|
|
themeContext.set_theme (theme);
|
|
|
|
}
|
|
|
|
|
2011-07-28 18:06:24 +00:00
|
|
|
/**
|
|
|
|
* notify:
|
|
|
|
* @msg: A message
|
|
|
|
* @details: Additional information
|
|
|
|
*/
|
|
|
|
function notify(msg, details) {
|
|
|
|
let source = new MessageTray.SystemNotificationSource();
|
|
|
|
messageTray.add(source);
|
|
|
|
let notification = new MessageTray.Notification(source, msg, details);
|
|
|
|
notification.setTransient(true);
|
|
|
|
source.notify(notification);
|
|
|
|
}
|
|
|
|
|
2011-03-15 22:31:16 +00:00
|
|
|
/**
|
|
|
|
* notifyError:
|
|
|
|
* @msg: An error message
|
|
|
|
* @details: Additional information
|
|
|
|
*
|
|
|
|
* See shell_global_notify_problem().
|
|
|
|
*/
|
|
|
|
function notifyError(msg, details) {
|
|
|
|
// Also print to stderr so it's logged somewhere
|
|
|
|
if (details)
|
2011-09-30 21:30:47 +00:00
|
|
|
log('error: ' + msg + ': ' + details);
|
2011-03-15 22:31:16 +00:00
|
|
|
else
|
2011-09-30 21:30:47 +00:00
|
|
|
log('error: ' + msg);
|
2011-03-15 22:31:16 +00:00
|
|
|
|
2011-07-28 18:06:24 +00:00
|
|
|
notify(msg, details);
|
2011-03-15 22:31:16 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 01:05:30 +00:00
|
|
|
function isWindowActorDisplayedOnWorkspace(win, workspaceIndex) {
|
|
|
|
return win.get_workspace() == workspaceIndex ||
|
|
|
|
(win.get_meta_window() && win.get_meta_window().is_on_all_workspaces());
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWindowActorsForWorkspace(workspaceIndex) {
|
|
|
|
return global.get_window_actors().filter(function (win) {
|
|
|
|
return isWindowActorDisplayedOnWorkspace(win, workspaceIndex);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-08-28 19:11:25 +00:00
|
|
|
// This function encapsulates hacks to make certain global keybindings
|
|
|
|
// work even when we are in one of our modes where global keybindings
|
|
|
|
// are disabled with a global grab. (When there is a global grab, then
|
|
|
|
// all key events will be delivered to the stage, so ::captured-event
|
|
|
|
// on the stage can be used for global keybindings.)
|
|
|
|
function _globalKeyPressHandler(actor, event) {
|
2009-09-15 19:53:07 +00:00
|
|
|
if (modalCount == 0)
|
2009-08-28 19:11:25 +00:00
|
|
|
return false;
|
2011-01-06 19:39:07 +00:00
|
|
|
if (event.type() != Clutter.EventType.KEY_PRESS)
|
2010-10-14 14:38:33 +00:00
|
|
|
return false;
|
|
|
|
|
2012-05-17 13:55:35 +00:00
|
|
|
if (!sessionMode.allowKeybindingsWhenModal) {
|
|
|
|
if (modalCount > (overview.visible ? 1 : 0))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-14 14:38:33 +00:00
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
let keyCode = event.get_key_code();
|
2012-03-13 15:25:50 +00:00
|
|
|
let ignoredModifiers = global.display.get_ignored_modifier_mask();
|
|
|
|
let modifierState = event.get_state() & ~ignoredModifiers;
|
2010-10-14 14:38:33 +00:00
|
|
|
|
2011-01-06 20:30:24 +00:00
|
|
|
// This relies on the fact that Clutter.ModifierType is the same as Gdk.ModifierType
|
2011-07-13 16:34:31 +00:00
|
|
|
let action = global.display.get_keybinding_action(keyCode, modifierState);
|
2011-01-06 20:30:24 +00:00
|
|
|
|
|
|
|
// This isn't a Meta.KeyBindingAction yet
|
|
|
|
if (symbol == Clutter.Super_L || symbol == Clutter.Super_R) {
|
|
|
|
overview.hide();
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-28 19:11:25 +00:00
|
|
|
|
2011-08-24 01:53:02 +00:00
|
|
|
if (action == Meta.KeyBindingAction.SWITCH_PANELS) {
|
2011-09-07 02:38:38 +00:00
|
|
|
ctrlAltTabManager.popup(modifierState & Clutter.ModifierType.SHIFT_MASK,
|
|
|
|
modifierState);
|
2011-08-24 01:53:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-14 14:38:33 +00:00
|
|
|
switch (action) {
|
2011-02-09 16:43:58 +00:00
|
|
|
// left/right would effectively act as synonyms for up/down if we enabled them;
|
|
|
|
// but that could be considered confusing; we also disable them in the main view.
|
|
|
|
//
|
|
|
|
// case Meta.KeyBindingAction.WORKSPACE_LEFT:
|
2012-05-17 13:32:32 +00:00
|
|
|
// if (!sessionMode.hasWorkspaces)
|
|
|
|
// return false;
|
|
|
|
//
|
2011-02-09 16:43:58 +00:00
|
|
|
// wm.actionMoveWorkspaceLeft();
|
|
|
|
// return true;
|
|
|
|
// case Meta.KeyBindingAction.WORKSPACE_RIGHT:
|
2012-05-17 13:32:32 +00:00
|
|
|
// if (!sessionMode.hasWorkspaces)
|
|
|
|
// return false;
|
|
|
|
//
|
2011-02-09 16:43:58 +00:00
|
|
|
// wm.actionMoveWorkspaceRight();
|
|
|
|
// return true;
|
2011-01-30 23:21:31 +00:00
|
|
|
case Meta.KeyBindingAction.WORKSPACE_UP:
|
2012-05-17 13:32:32 +00:00
|
|
|
if (!sessionMode.hasWorkspaces)
|
|
|
|
return false;
|
|
|
|
|
2011-01-30 23:21:31 +00:00
|
|
|
wm.actionMoveWorkspaceUp();
|
|
|
|
return true;
|
|
|
|
case Meta.KeyBindingAction.WORKSPACE_DOWN:
|
2012-05-17 13:32:32 +00:00
|
|
|
if (!sessionMode.hasWorkspaces)
|
|
|
|
return false;
|
|
|
|
|
2011-01-30 23:21:31 +00:00
|
|
|
wm.actionMoveWorkspaceDown();
|
|
|
|
return true;
|
2010-10-14 14:38:33 +00:00
|
|
|
case Meta.KeyBindingAction.PANEL_RUN_DIALOG:
|
|
|
|
case Meta.KeyBindingAction.COMMAND_2:
|
2012-05-17 11:41:02 +00:00
|
|
|
if (!sessionMode.hasRunDialog)
|
|
|
|
return false;
|
|
|
|
|
2010-10-14 14:38:33 +00:00
|
|
|
getRunDialog().open();
|
2009-08-28 19:11:25 +00:00
|
|
|
return true;
|
2011-01-06 19:39:07 +00:00
|
|
|
case Meta.KeyBindingAction.PANEL_MAIN_MENU:
|
2011-01-06 20:30:24 +00:00
|
|
|
overview.hide();
|
2011-01-06 19:39:07 +00:00
|
|
|
return true;
|
2009-08-28 19:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
function _findModal(actor) {
|
|
|
|
for (let i = 0; i < modalActorFocusStack.length; i++) {
|
2011-02-24 22:29:20 +00:00
|
|
|
if (modalActorFocusStack[i].actor == actor)
|
2009-09-15 19:53:07 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pushModal:
|
|
|
|
* @actor: #ClutterActor which will be given keyboard focus
|
2010-10-20 19:08:14 +00:00
|
|
|
* @timestamp: optional timestamp
|
2009-09-15 19:53:07 +00:00
|
|
|
*
|
|
|
|
* Ensure we are in a mode where all keyboard and mouse input goes to
|
2010-11-03 17:30:08 +00:00
|
|
|
* the stage, and focus @actor. Multiple calls to this function act in
|
|
|
|
* a stacking fashion; the effect will be undone when an equal number
|
|
|
|
* of popModal() invocations have been made.
|
2009-09-15 19:53:07 +00:00
|
|
|
*
|
2010-11-03 17:30:08 +00:00
|
|
|
* Next, record the current Clutter keyboard focus on a stack. If the
|
|
|
|
* modal stack returns to this actor, reset the focus to the actor
|
|
|
|
* which was focused at the time pushModal() was invoked.
|
2009-09-16 15:37:51 +00:00
|
|
|
*
|
2010-10-20 19:08:14 +00:00
|
|
|
* @timestamp is optionally used to associate the call with a specific user
|
|
|
|
* initiated event. If not provided then the value of
|
|
|
|
* global.get_current_time() is assumed.
|
|
|
|
*
|
2011-10-21 07:12:17 +00:00
|
|
|
* @options: optional Meta.ModalOptions flags to indicate that the
|
|
|
|
* pointer is alrady grabbed
|
|
|
|
*
|
2009-09-16 15:37:51 +00:00
|
|
|
* Returns: true iff we successfully acquired a grab or already had one
|
2009-09-15 19:53:07 +00:00
|
|
|
*/
|
2011-10-21 07:12:17 +00:00
|
|
|
function pushModal(actor, timestamp, options) {
|
2010-10-20 19:08:14 +00:00
|
|
|
if (timestamp == undefined)
|
|
|
|
timestamp = global.get_current_time();
|
|
|
|
|
2009-09-16 15:37:51 +00:00
|
|
|
if (modalCount == 0) {
|
2011-10-21 07:12:17 +00:00
|
|
|
if (!global.begin_modal(timestamp, options ? options : 0)) {
|
2010-05-13 19:46:04 +00:00
|
|
|
log('pushModal: invocation of begin_modal failed');
|
2009-09-16 15:37:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-19 17:48:02 +00:00
|
|
|
Meta.disable_unredirect_for_screen(global.screen);
|
2009-09-16 15:37:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
global.set_stage_input_mode(Shell.StageInputMode.FULLSCREEN);
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
modalCount += 1;
|
2011-02-24 22:29:20 +00:00
|
|
|
let actorDestroyId = actor.connect('destroy', function() {
|
2009-09-15 19:53:07 +00:00
|
|
|
let index = _findModal(actor);
|
|
|
|
if (index >= 0)
|
|
|
|
modalActorFocusStack.splice(index, 1);
|
|
|
|
});
|
|
|
|
let curFocus = global.stage.get_key_focus();
|
2011-02-24 22:29:20 +00:00
|
|
|
let curFocusDestroyId;
|
2009-09-15 19:53:07 +00:00
|
|
|
if (curFocus != null) {
|
2011-02-24 22:29:20 +00:00
|
|
|
curFocusDestroyId = curFocus.connect('destroy', function() {
|
2009-09-15 19:53:07 +00:00
|
|
|
let index = _findModal(actor);
|
|
|
|
if (index >= 0)
|
2011-02-24 22:29:20 +00:00
|
|
|
modalActorFocusStack[index].actor = null;
|
2009-09-15 19:53:07 +00:00
|
|
|
});
|
|
|
|
}
|
2011-02-24 22:29:20 +00:00
|
|
|
modalActorFocusStack.push({ actor: actor,
|
|
|
|
focus: curFocus,
|
|
|
|
destroyId: actorDestroyId,
|
|
|
|
focusDestroyId: curFocusDestroyId });
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2010-11-03 17:30:08 +00:00
|
|
|
global.stage.set_key_focus(actor);
|
2009-09-16 15:37:51 +00:00
|
|
|
return true;
|
2008-10-31 23:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
/**
|
|
|
|
* popModal:
|
|
|
|
* @actor: #ClutterActor passed to original invocation of pushModal().
|
2010-10-20 19:08:14 +00:00
|
|
|
* @timestamp: optional timestamp
|
2009-09-15 19:53:07 +00:00
|
|
|
*
|
|
|
|
* Reverse the effect of pushModal(). If this invocation is undoing
|
|
|
|
* the topmost invocation, then the focus will be restored to the
|
|
|
|
* previous focus at the time when pushModal() was invoked.
|
2010-10-20 19:08:14 +00:00
|
|
|
*
|
|
|
|
* @timestamp is optionally used to associate the call with a specific user
|
|
|
|
* initiated event. If not provided then the value of
|
|
|
|
* global.get_current_time() is assumed.
|
2009-09-15 19:53:07 +00:00
|
|
|
*/
|
2010-10-20 19:08:14 +00:00
|
|
|
function popModal(actor, timestamp) {
|
|
|
|
if (timestamp == undefined)
|
|
|
|
timestamp = global.get_current_time();
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
let focusIndex = _findModal(actor);
|
2011-02-24 22:29:20 +00:00
|
|
|
if (focusIndex < 0) {
|
|
|
|
global.stage.set_key_focus(null);
|
|
|
|
global.end_modal(timestamp);
|
|
|
|
global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
|
|
|
|
|
|
|
|
throw new Error('incorrect pop');
|
|
|
|
}
|
|
|
|
|
|
|
|
modalCount -= 1;
|
|
|
|
|
|
|
|
let record = modalActorFocusStack[focusIndex];
|
|
|
|
record.actor.disconnect(record.destroyId);
|
|
|
|
|
|
|
|
if (focusIndex == modalActorFocusStack.length - 1) {
|
|
|
|
if (record.focus)
|
|
|
|
record.focus.disconnect(record.focusDestroyId);
|
|
|
|
global.stage.set_key_focus(record.focus);
|
|
|
|
} else {
|
|
|
|
let t = modalActorFocusStack[modalActorFocusStack.length - 1];
|
|
|
|
if (t.focus)
|
|
|
|
t.focus.disconnect(t.focusDestroyId);
|
|
|
|
// Remove from the middle, shift the focus chain up
|
|
|
|
for (let i = modalActorFocusStack.length - 1; i > focusIndex; i--) {
|
|
|
|
modalActorFocusStack[i].focus = modalActorFocusStack[i - 1].focus;
|
|
|
|
modalActorFocusStack[i].focusDestroyId = modalActorFocusStack[i - 1].focusDestroyId;
|
2009-09-15 19:53:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-24 22:29:20 +00:00
|
|
|
modalActorFocusStack.splice(focusIndex, 1);
|
|
|
|
|
2009-09-15 19:53:07 +00:00
|
|
|
if (modalCount > 0)
|
|
|
|
return;
|
|
|
|
|
2010-10-20 19:08:14 +00:00
|
|
|
global.end_modal(timestamp);
|
2009-04-29 18:01:09 +00:00
|
|
|
global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
|
2012-06-19 17:48:02 +00:00
|
|
|
Meta.enable_unredirect_for_screen(global.screen);
|
2008-10-31 04:22:44 +00:00
|
|
|
}
|
2008-11-24 19:07:18 +00:00
|
|
|
|
2009-08-02 07:46:01 +00:00
|
|
|
function createLookingGlass() {
|
|
|
|
if (lookingGlass == null) {
|
|
|
|
lookingGlass = new LookingGlass.LookingGlass();
|
|
|
|
}
|
|
|
|
return lookingGlass;
|
|
|
|
}
|
|
|
|
|
2009-09-14 19:08:20 +00:00
|
|
|
function getRunDialog() {
|
|
|
|
if (runDialog == null) {
|
|
|
|
runDialog = new RunDialog.RunDialog();
|
|
|
|
}
|
|
|
|
return runDialog;
|
|
|
|
}
|
|
|
|
|
2009-09-21 20:29:37 +00:00
|
|
|
/**
|
|
|
|
* activateWindow:
|
|
|
|
* @window: the Meta.Window to activate
|
|
|
|
* @time: (optional) current event time
|
2010-02-19 16:42:36 +00:00
|
|
|
* @workspaceNum: (optional) window's workspace number
|
2009-09-21 20:29:37 +00:00
|
|
|
*
|
2010-02-17 19:05:06 +00:00
|
|
|
* Activates @window, switching to its workspace first if necessary,
|
|
|
|
* and switching out of the overview if it's currently active
|
2009-09-21 20:29:37 +00:00
|
|
|
*/
|
2010-02-19 16:42:36 +00:00
|
|
|
function activateWindow(window, time, workspaceNum) {
|
2009-09-21 20:29:37 +00:00
|
|
|
let activeWorkspaceNum = global.screen.get_active_workspace_index();
|
2010-02-19 16:42:36 +00:00
|
|
|
let windowWorkspaceNum = (workspaceNum !== undefined) ? workspaceNum : window.get_workspace().index();
|
2009-09-21 20:29:37 +00:00
|
|
|
|
|
|
|
if (!time)
|
2009-12-03 20:59:52 +00:00
|
|
|
time = global.get_current_time();
|
2009-09-21 20:29:37 +00:00
|
|
|
|
|
|
|
if (windowWorkspaceNum != activeWorkspaceNum) {
|
|
|
|
let workspace = global.screen.get_workspace_by_index(windowWorkspaceNum);
|
|
|
|
workspace.activate_with_focus(window, time);
|
|
|
|
} else {
|
|
|
|
window.activate(time);
|
|
|
|
}
|
2010-02-17 19:05:06 +00:00
|
|
|
|
|
|
|
overview.hide();
|
2009-09-21 20:29:37 +00:00
|
|
|
}
|
2009-12-03 17:19:38 +00:00
|
|
|
|
|
|
|
// TODO - replace this timeout with some system to guess when the user might
|
|
|
|
// be e.g. just reading the screen and not likely to interact.
|
|
|
|
const DEFERRED_TIMEOUT_SECONDS = 20;
|
|
|
|
var _deferredWorkData = {};
|
|
|
|
// Work scheduled for some point in the future
|
|
|
|
var _deferredWorkQueue = [];
|
|
|
|
// Work we need to process before the next redraw
|
|
|
|
var _beforeRedrawQueue = [];
|
|
|
|
// Counter to assign work ids
|
|
|
|
var _deferredWorkSequence = 0;
|
|
|
|
var _deferredTimeoutId = 0;
|
|
|
|
|
|
|
|
function _runDeferredWork(workId) {
|
|
|
|
if (!_deferredWorkData[workId])
|
|
|
|
return;
|
|
|
|
let index = _deferredWorkQueue.indexOf(workId);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_deferredWorkQueue.splice(index, 1);
|
|
|
|
_deferredWorkData[workId].callback();
|
|
|
|
if (_deferredWorkQueue.length == 0 && _deferredTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(_deferredTimeoutId);
|
|
|
|
_deferredTimeoutId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _runAllDeferredWork() {
|
|
|
|
while (_deferredWorkQueue.length > 0)
|
|
|
|
_runDeferredWork(_deferredWorkQueue[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _runBeforeRedrawQueue() {
|
|
|
|
for (let i = 0; i < _beforeRedrawQueue.length; i++) {
|
|
|
|
let workId = _beforeRedrawQueue[i];
|
|
|
|
_runDeferredWork(workId);
|
|
|
|
}
|
|
|
|
_beforeRedrawQueue = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
function _queueBeforeRedraw(workId) {
|
|
|
|
_beforeRedrawQueue.push(workId);
|
|
|
|
if (_beforeRedrawQueue.length == 1) {
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, function () {
|
|
|
|
_runBeforeRedrawQueue();
|
|
|
|
return false;
|
2010-04-12 22:05:50 +00:00
|
|
|
});
|
2009-12-03 17:19:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initializeDeferredWork:
|
|
|
|
* @actor: A #ClutterActor
|
|
|
|
* @callback: Function to invoke to perform work
|
|
|
|
*
|
|
|
|
* This function sets up a callback to be invoked when either the
|
|
|
|
* given actor is mapped, or after some period of time when the machine
|
|
|
|
* is idle. This is useful if your actor isn't always visible on the
|
|
|
|
* screen (for example, all actors in the overview), and you don't want
|
|
|
|
* to consume resources updating if the actor isn't actually going to be
|
|
|
|
* displaying to the user.
|
|
|
|
*
|
|
|
|
* Note that queueDeferredWork is called by default immediately on
|
|
|
|
* initialization as well, under the assumption that new actors
|
|
|
|
* will need it.
|
|
|
|
*
|
|
|
|
* Returns: A string work identifer
|
|
|
|
*/
|
|
|
|
function initializeDeferredWork(actor, callback, props) {
|
|
|
|
// Turn into a string so we can use as an object property
|
2010-05-13 19:46:04 +00:00
|
|
|
let workId = '' + (++_deferredWorkSequence);
|
2009-12-03 17:19:38 +00:00
|
|
|
_deferredWorkData[workId] = { 'actor': actor,
|
|
|
|
'callback': callback };
|
|
|
|
actor.connect('notify::mapped', function () {
|
|
|
|
if (!(actor.mapped && _deferredWorkQueue.indexOf(workId) >= 0))
|
|
|
|
return;
|
|
|
|
_queueBeforeRedraw(workId);
|
|
|
|
});
|
|
|
|
actor.connect('destroy', function() {
|
|
|
|
let index = _deferredWorkQueue.indexOf(workId);
|
|
|
|
if (index >= 0)
|
|
|
|
_deferredWorkQueue.splice(index, 1);
|
|
|
|
delete _deferredWorkData[workId];
|
|
|
|
});
|
|
|
|
queueDeferredWork(workId);
|
|
|
|
return workId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* queueDeferredWork:
|
|
|
|
* @workId: work identifier
|
|
|
|
*
|
|
|
|
* Ensure that the work identified by @workId will be
|
|
|
|
* run on map or timeout. You should call this function
|
|
|
|
* for example when data being displayed by the actor has
|
|
|
|
* changed.
|
|
|
|
*/
|
|
|
|
function queueDeferredWork(workId) {
|
|
|
|
let data = _deferredWorkData[workId];
|
|
|
|
if (!data) {
|
2012-05-10 01:37:42 +00:00
|
|
|
let message = 'Invalid work id %d'.format(workId);
|
|
|
|
logError(new Error(message), message);
|
2009-12-03 17:19:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_deferredWorkQueue.indexOf(workId) < 0)
|
|
|
|
_deferredWorkQueue.push(workId);
|
|
|
|
if (data.actor.mapped) {
|
|
|
|
_queueBeforeRedraw(workId);
|
|
|
|
return;
|
|
|
|
} else if (_deferredTimeoutId == 0) {
|
|
|
|
_deferredTimeoutId = Mainloop.timeout_add_seconds(DEFERRED_TIMEOUT_SECONDS, function () {
|
|
|
|
_runAllDeferredWork();
|
|
|
|
_deferredTimeoutId = 0;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|