2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-09-23 14:30:05 -04:00
|
|
|
|
2011-06-27 22:21:02 -04:00
|
|
|
const Lang = imports.lang;
|
2011-08-16 08:19:59 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
2012-01-18 21:30:06 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-09-23 14:30:05 -04:00
|
|
|
|
2011-06-29 20:09:00 -04:00
|
|
|
const Config = imports.misc.config;
|
2011-06-22 22:03:04 -04:00
|
|
|
const ExtensionSystem = imports.ui.extensionSystem;
|
2012-05-25 19:07:31 -04:00
|
|
|
const ExtensionDownloader = imports.ui.extensionDownloader;
|
2012-01-30 20:58:29 -05:00
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
2012-01-24 16:29:56 -05:00
|
|
|
const Flashspot = imports.ui.flashspot;
|
2009-09-23 14:30:05 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2011-08-16 08:19:59 -04:00
|
|
|
const GnomeShellIface = <interface name="org.gnome.Shell">
|
|
|
|
<method name="Eval">
|
|
|
|
<arg type="s" direction="in" name="script" />
|
|
|
|
<arg type="b" direction="out" name="success" />
|
|
|
|
<arg type="s" direction="out" name="result" />
|
|
|
|
</method>
|
|
|
|
<method name="ScreenshotArea">
|
|
|
|
<arg type="i" direction="in" name="x"/>
|
|
|
|
<arg type="i" direction="in" name="y"/>
|
|
|
|
<arg type="i" direction="in" name="width"/>
|
|
|
|
<arg type="i" direction="in" name="height"/>
|
2012-01-24 16:29:56 -05:00
|
|
|
<arg type="b" direction="in" name="flash"/>
|
2011-08-16 08:19:59 -04:00
|
|
|
<arg type="s" direction="in" name="filename"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<method name="ScreenshotWindow">
|
|
|
|
<arg type="b" direction="in" name="include_frame"/>
|
2012-02-14 13:24:41 -05:00
|
|
|
<arg type="b" direction="in" name="include_cursor"/>
|
2012-01-24 16:29:56 -05:00
|
|
|
<arg type="b" direction="in" name="flash"/>
|
2011-08-16 08:19:59 -04:00
|
|
|
<arg type="s" direction="in" name="filename"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<method name="Screenshot">
|
2012-02-14 13:24:41 -05:00
|
|
|
<arg type="b" direction="in" name="include_cursor"/>
|
2012-01-24 16:29:56 -05:00
|
|
|
<arg type="b" direction="in" name="flash"/>
|
2011-08-16 08:19:59 -04:00
|
|
|
<arg type="s" direction="in" name="filename"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
2012-02-09 13:57:29 -05:00
|
|
|
<method name="FlashArea">
|
|
|
|
<arg type="i" direction="in" name="x"/>
|
|
|
|
<arg type="i" direction="in" name="y"/>
|
|
|
|
<arg type="i" direction="in" name="width"/>
|
|
|
|
<arg type="i" direction="in" name="height"/>
|
|
|
|
</method>
|
2011-08-16 08:19:59 -04:00
|
|
|
<property name="OverviewActive" type="b" access="readwrite" />
|
|
|
|
<property name="ShellVersion" type="s" access="read" />
|
|
|
|
</interface>;
|
2009-09-23 14:30:05 -04:00
|
|
|
|
2012-06-02 19:20:31 -04:00
|
|
|
const ScreenSaverIface = <interface name="org.gnome.ScreenSaver">
|
|
|
|
<method name="Lock">
|
|
|
|
</method>
|
|
|
|
<method name="GetActive">
|
|
|
|
<arg name="active" direction="out" type="b" />
|
|
|
|
</method>
|
|
|
|
<method name="SetActive">
|
2012-10-12 19:37:36 -04:00
|
|
|
<arg name="value" direction="in" type="b" />
|
2012-06-02 19:20:31 -04:00
|
|
|
</method>
|
2012-10-16 10:38:32 -04:00
|
|
|
<method name="GetActiveTime">
|
|
|
|
<arg name="value" direction="out" type="u" />
|
|
|
|
</method>
|
2012-06-02 19:20:31 -04:00
|
|
|
<signal name="ActiveChanged">
|
|
|
|
<arg name="new_value" type="b" />
|
|
|
|
</signal>
|
|
|
|
</interface>;
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const GnomeShell = new Lang.Class({
|
|
|
|
Name: 'GnomeShellDBus',
|
2009-09-23 14:30:05 -04:00
|
|
|
|
|
|
|
_init: function() {
|
2011-08-16 08:19:59 -04:00
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GnomeShellIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell');
|
2012-06-27 11:47:51 -04:00
|
|
|
|
|
|
|
this._extensionsSerivce = new GnomeShellExtensions();
|
2009-09-23 14:30:05 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Eval:
|
|
|
|
* @code: A string containing JavaScript code
|
|
|
|
*
|
|
|
|
* This function executes arbitrary code in the main
|
|
|
|
* loop, and returns a boolean success and
|
|
|
|
* JSON representation of the object as a string.
|
|
|
|
*
|
|
|
|
* If evaluation completes without throwing an exception,
|
|
|
|
* then the return value will be [true, JSON.stringify(result)].
|
|
|
|
* If evaluation fails, then the return value will be
|
|
|
|
* [false, JSON.stringify(exception)];
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
Eval: function(code) {
|
2011-10-27 17:41:06 -04:00
|
|
|
if (!global.settings.get_boolean('development-tools'))
|
|
|
|
return [false, null];
|
|
|
|
|
2009-09-23 14:30:05 -04:00
|
|
|
let returnValue;
|
|
|
|
let success;
|
|
|
|
try {
|
|
|
|
returnValue = JSON.stringify(eval(code));
|
2009-11-12 18:17:58 -05:00
|
|
|
// A hack; DBus doesn't have null/undefined
|
|
|
|
if (returnValue == undefined)
|
2010-05-13 15:46:04 -04:00
|
|
|
returnValue = '';
|
2009-09-23 14:30:05 -04:00
|
|
|
success = true;
|
|
|
|
} catch (e) {
|
|
|
|
returnValue = JSON.stringify(e);
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return [success, returnValue];
|
|
|
|
},
|
|
|
|
|
2012-01-25 10:46:30 -05:00
|
|
|
_onScreenshotComplete: function(obj, result, area, flash, invocation) {
|
2012-01-24 16:29:56 -05:00
|
|
|
if (flash) {
|
|
|
|
let flashspot = new Flashspot.Flashspot(area);
|
|
|
|
flashspot.fire();
|
|
|
|
}
|
2012-01-25 10:46:30 -05:00
|
|
|
|
|
|
|
let retval = GLib.Variant.new('(b)', [result]);
|
|
|
|
invocation.return_value(retval);
|
2012-01-24 16:29:56 -05:00
|
|
|
},
|
|
|
|
|
2011-08-24 10:06:13 -04:00
|
|
|
/**
|
|
|
|
* ScreenshotArea:
|
|
|
|
* @x: The X coordinate of the area
|
|
|
|
* @y: The Y coordinate of the area
|
|
|
|
* @width: The width of the area
|
|
|
|
* @height: The height of the area
|
2012-02-14 13:24:41 -05:00
|
|
|
* @flash: Whether to flash the area or not
|
2011-08-24 10:06:13 -04:00
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
*
|
|
|
|
* Takes a screenshot of the passed in area and saves it
|
|
|
|
* in @filename as png image, it returns a boolean
|
|
|
|
* indicating whether the operation was successful or not.
|
|
|
|
*
|
|
|
|
*/
|
2012-01-12 15:28:19 -05:00
|
|
|
ScreenshotAreaAsync : function (params, invocation) {
|
2012-01-24 16:29:56 -05:00
|
|
|
let [x, y, width, height, flash, filename, callback] = params;
|
2012-02-14 14:33:56 -05:00
|
|
|
let screenshot = new Shell.Screenshot();
|
|
|
|
screenshot.screenshot_area (x, y, width, height, filename,
|
|
|
|
Lang.bind(this, this._onScreenshotComplete,
|
2012-01-25 10:46:30 -05:00
|
|
|
flash, invocation));
|
2011-08-24 10:06:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ScreenshotWindow:
|
|
|
|
* @include_frame: Whether to include the frame or not
|
2012-02-14 13:24:41 -05:00
|
|
|
* @include_cursor: Whether to include the cursor image or not
|
|
|
|
* @flash: Whether to flash the window area or not
|
2011-08-24 10:06:13 -04:00
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
*
|
|
|
|
* Takes a screenshot of the focused window (optionally omitting the frame)
|
|
|
|
* and saves it in @filename as png image, it returns a boolean
|
|
|
|
* indicating whether the operation was successful or not.
|
|
|
|
*
|
|
|
|
*/
|
2012-01-22 04:57:42 -05:00
|
|
|
ScreenshotWindowAsync : function (params, invocation) {
|
2012-02-14 13:24:41 -05:00
|
|
|
let [include_frame, include_cursor, flash, filename] = params;
|
2012-02-14 14:33:56 -05:00
|
|
|
let screenshot = new Shell.Screenshot();
|
|
|
|
screenshot.screenshot_window (include_frame, include_cursor, filename,
|
|
|
|
Lang.bind(this, this._onScreenshotComplete,
|
2012-01-25 10:46:30 -05:00
|
|
|
flash, invocation));
|
2011-08-24 10:06:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Screenshot:
|
|
|
|
* @filename: The filename for the screenshot
|
2012-02-14 13:24:41 -05:00
|
|
|
* @include_cursor: Whether to include the cursor image or not
|
|
|
|
* @flash: Whether to flash the screen or not
|
2011-08-24 10:06:13 -04:00
|
|
|
*
|
|
|
|
* Takes a screenshot of the whole screen and saves it
|
|
|
|
* in @filename as png image, it returns a boolean
|
|
|
|
* indicating whether the operation was successful or not.
|
|
|
|
*
|
|
|
|
*/
|
2012-01-12 15:28:19 -05:00
|
|
|
ScreenshotAsync : function (params, invocation) {
|
2012-02-14 13:24:41 -05:00
|
|
|
let [include_cursor, flash, filename] = params;
|
2012-02-14 14:33:56 -05:00
|
|
|
let screenshot = new Shell.Screenshot();
|
|
|
|
screenshot.screenshot(include_cursor, filename,
|
|
|
|
Lang.bind(this, this._onScreenshotComplete,
|
2012-01-25 10:46:30 -05:00
|
|
|
flash, invocation));
|
2011-08-24 10:06:13 -04:00
|
|
|
},
|
|
|
|
|
2012-02-09 13:57:29 -05:00
|
|
|
FlashArea: function(x, y, width, height) {
|
|
|
|
let flashspot = new Flashspot.Flashspot({ x : x, y : y, width: width, height: height});
|
|
|
|
flashspot.fire();
|
|
|
|
},
|
|
|
|
|
2012-06-27 11:47:51 -04:00
|
|
|
get OverviewActive() {
|
|
|
|
return Main.overview.visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
set OverviewActive(visible) {
|
|
|
|
if (visible)
|
|
|
|
Main.overview.show();
|
|
|
|
else
|
|
|
|
Main.overview.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
ShellVersion: Config.PACKAGE_VERSION
|
|
|
|
});
|
|
|
|
|
|
|
|
const GnomeShellExtensionsIface = <interface name="org.gnome.Shell.Extensions">
|
|
|
|
<method name="ListExtensions">
|
|
|
|
<arg type="a{sa{sv}}" direction="out" name="extensions" />
|
|
|
|
</method>
|
|
|
|
<method name="GetExtensionInfo">
|
|
|
|
<arg type="s" direction="in" name="extension" />
|
|
|
|
<arg type="a{sv}" direction="out" name="info" />
|
|
|
|
</method>
|
|
|
|
<method name="GetExtensionErrors">
|
|
|
|
<arg type="s" direction="in" name="extension" />
|
|
|
|
<arg type="as" direction="out" name="errors" />
|
|
|
|
</method>
|
|
|
|
<signal name="ExtensionStatusChanged">
|
|
|
|
<arg type="s" name="uuid"/>
|
|
|
|
<arg type="i" name="state"/>
|
|
|
|
<arg type="s" name="error"/>
|
|
|
|
</signal>
|
|
|
|
<method name="InstallRemoteExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
2012-06-15 23:20:36 -04:00
|
|
|
<arg type="s" direction="out" name="result"/>
|
2012-06-27 11:47:51 -04:00
|
|
|
</method>
|
|
|
|
<method name="UninstallExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<method name="LaunchExtensionPrefs">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
</method>
|
|
|
|
<method name="ReloadExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
</method>
|
2012-06-26 20:47:44 -04:00
|
|
|
<method name="CheckForUpdates">
|
|
|
|
</method>
|
2012-06-27 11:47:51 -04:00
|
|
|
<property name="ShellVersion" type="s" access="read" />
|
|
|
|
</interface>;
|
|
|
|
|
|
|
|
const GnomeShellExtensions = new Lang.Class({
|
|
|
|
Name: 'GnomeShellExtensionsDBus',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GnomeShellExtensionsIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell');
|
|
|
|
ExtensionSystem.connect('extension-state-changed',
|
|
|
|
Lang.bind(this, this._extensionStateChanged));
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2011-06-22 22:03:04 -04:00
|
|
|
ListExtensions: function() {
|
2011-11-15 16:37:57 -05:00
|
|
|
let out = {};
|
2012-01-30 20:58:29 -05:00
|
|
|
for (let uuid in ExtensionUtils.extensions) {
|
2011-08-16 08:19:59 -04:00
|
|
|
let dbusObj = this.GetExtensionInfo(uuid);
|
|
|
|
out[uuid] = dbusObj;
|
|
|
|
}
|
|
|
|
return out;
|
2011-06-22 22:03:04 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
GetExtensionInfo: function(uuid) {
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
let obj = {};
|
|
|
|
Lang.copyProperties(extension.metadata, obj);
|
|
|
|
|
|
|
|
// Only serialize the properties that we actually need.
|
|
|
|
const serializedProperties = ["type", "state", "path", "error", "hasPrefs"];
|
|
|
|
|
|
|
|
serializedProperties.forEach(function(prop) {
|
|
|
|
obj[prop] = extension[prop];
|
|
|
|
});
|
|
|
|
|
2011-11-15 16:37:57 -05:00
|
|
|
let out = {};
|
2012-01-30 20:58:29 -05:00
|
|
|
for (let key in obj) {
|
|
|
|
let val = obj[key];
|
2011-08-16 08:19:59 -04:00
|
|
|
let type;
|
|
|
|
switch (typeof val) {
|
|
|
|
case 'string':
|
|
|
|
type = 's';
|
|
|
|
break;
|
|
|
|
case 'number':
|
|
|
|
type = 'd';
|
|
|
|
break;
|
2012-01-18 21:30:06 -05:00
|
|
|
case 'boolean':
|
|
|
|
type = 'b';
|
|
|
|
break;
|
2011-11-15 16:46:17 -05:00
|
|
|
default:
|
|
|
|
continue;
|
2011-08-16 08:19:59 -04:00
|
|
|
}
|
|
|
|
out[key] = GLib.Variant.new(type, val);
|
|
|
|
}
|
2012-01-30 20:58:29 -05:00
|
|
|
|
2011-08-16 08:19:59 -04:00
|
|
|
return out;
|
2011-06-22 22:03:04 -04:00
|
|
|
},
|
|
|
|
|
2011-06-22 21:41:30 -04:00
|
|
|
GetExtensionErrors: function(uuid) {
|
2012-01-30 20:58:29 -05:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
|
|
|
return [];
|
|
|
|
|
|
|
|
if (!extension.errors)
|
|
|
|
return [];
|
|
|
|
|
|
|
|
return extension.errors;
|
2011-06-22 21:41:30 -04:00
|
|
|
},
|
|
|
|
|
2012-06-15 23:20:36 -04:00
|
|
|
InstallRemoteExtensionAsync: function([uuid], invocation) {
|
2012-06-26 20:46:37 -04:00
|
|
|
return ExtensionDownloader.installExtension(uuid, invocation);
|
2011-08-24 13:08:34 -04:00
|
|
|
},
|
|
|
|
|
2011-09-10 17:10:50 -04:00
|
|
|
UninstallExtension: function(uuid) {
|
2012-06-26 20:46:37 -04:00
|
|
|
return ExtensionDownloader.uninstallExtension(uuid);
|
2011-09-10 17:10:50 -04:00
|
|
|
},
|
|
|
|
|
2012-01-18 21:30:06 -05:00
|
|
|
LaunchExtensionPrefs: function(uuid) {
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');
|
|
|
|
app.launch(global.display.get_current_time_roundtrip(),
|
|
|
|
['extension:///' + uuid], -1, null);
|
|
|
|
},
|
|
|
|
|
2012-06-05 13:06:40 -04:00
|
|
|
ReloadExtension: function(uuid) {
|
2012-08-23 21:37:50 -04:00
|
|
|
let extension = ExtensionUtils.extensions[uuid];
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ExtensionSystem.reloadExtension(extension);
|
2012-06-05 13:06:40 -04:00
|
|
|
},
|
|
|
|
|
2012-06-26 20:47:44 -04:00
|
|
|
CheckForUpdates: function() {
|
|
|
|
ExtensionDownloader.checkForUpdates();
|
|
|
|
},
|
|
|
|
|
2011-06-27 22:21:02 -04:00
|
|
|
ShellVersion: Config.PACKAGE_VERSION,
|
|
|
|
|
|
|
|
_extensionStateChanged: function(_, newState) {
|
2011-11-11 21:45:44 -05:00
|
|
|
this._dbusImpl.emit_signal('ExtensionStatusChanged',
|
|
|
|
GLib.Variant.new('(sis)', [newState.uuid, newState.state, newState.error]));
|
2011-06-27 22:21:02 -04:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2012-06-02 19:20:31 -04:00
|
|
|
|
|
|
|
const ScreenSaverDBus = new Lang.Class({
|
|
|
|
Name: 'ScreenSaverDBus',
|
|
|
|
|
2012-07-08 11:42:15 -04:00
|
|
|
_init: function(screenShield) {
|
2012-06-02 19:20:31 -04:00
|
|
|
this.parent();
|
|
|
|
|
2012-07-08 11:42:15 -04:00
|
|
|
this._screenShield = screenShield;
|
|
|
|
screenShield.connect('lock-status-changed', Lang.bind(this, function(shield) {
|
2012-08-26 10:53:08 -04:00
|
|
|
this._dbusImpl.emit_signal('ActiveChanged', GLib.Variant.new('(b)', [shield.locked]));
|
2012-06-02 19:20:31 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ScreenSaverIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/ScreenSaver');
|
2012-07-08 11:42:15 -04:00
|
|
|
|
|
|
|
Gio.DBus.session.own_name('org.gnome.ScreenSaver', Gio.BusNameOwnerFlags.REPLACE, null, null);
|
2012-06-02 19:20:31 -04:00
|
|
|
},
|
|
|
|
|
2012-09-05 16:19:45 -04:00
|
|
|
LockAsync: function(parameters, invocation) {
|
2012-07-08 11:42:15 -04:00
|
|
|
let tmpId = this._screenShield.connect('lock-screen-shown', Lang.bind(this, function() {
|
|
|
|
this._screenShield.disconnect(tmpId);
|
2012-09-05 16:19:45 -04:00
|
|
|
|
|
|
|
invocation.return_value(null);
|
|
|
|
}));
|
|
|
|
|
2012-07-08 11:42:15 -04:00
|
|
|
this._screenShield.lock(true);
|
2012-06-02 19:20:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
SetActive: function(active) {
|
|
|
|
if (active)
|
2012-07-08 11:42:15 -04:00
|
|
|
this._screenShield.lock(true);
|
2012-06-02 19:20:31 -04:00
|
|
|
else
|
2012-07-08 11:42:15 -04:00
|
|
|
this._screenShield.unlock();
|
2012-06-02 19:20:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
GetActive: function() {
|
2012-07-08 11:42:15 -04:00
|
|
|
return this._screenShield.locked;
|
2012-10-16 10:38:32 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
GetActiveTime: function() {
|
|
|
|
let started = this._screenShield.activationTime;
|
|
|
|
if (started > 0)
|
|
|
|
return Math.floor((GLib.get_monotonic_time() - started) / 1000000);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
},
|
2012-06-02 19:20:31 -04:00
|
|
|
});
|