2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-09-18 19:51:15 +00:00
|
|
|
|
2016-11-28 04:54:38 +00:00
|
|
|
const Config = imports.misc.config;
|
|
|
|
|
|
|
|
imports.gi.versions.Clutter = Config.LIBMUTTER_API_VERSION;
|
2011-04-30 14:27:36 +00:00
|
|
|
imports.gi.versions.Gio = '2.0';
|
|
|
|
imports.gi.versions.GdkPixbuf = '2.0';
|
|
|
|
imports.gi.versions.Gtk = '3.0';
|
2014-03-25 17:02:02 +00:00
|
|
|
imports.gi.versions.TelepathyGLib = '0.12';
|
|
|
|
imports.gi.versions.TelepathyLogger = '0.2';
|
2011-04-30 14:27:36 +00:00
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Clutter, GLib, Shell, St } = imports.gi;
|
2011-04-30 14:34:51 +00:00
|
|
|
const Gettext = imports.gettext;
|
2009-09-18 19:51:15 +00:00
|
|
|
|
2011-04-30 14:27:36 +00:00
|
|
|
// We can't import shell JS modules yet, because they may have
|
|
|
|
// variable initializations, etc, that depend on init() already having
|
|
|
|
// been run.
|
2009-09-18 19:51:15 +00:00
|
|
|
|
2009-10-04 21:30:18 +00:00
|
|
|
|
2009-09-18 19:51:15 +00:00
|
|
|
// "monkey patch" in some varargs ClutterContainer methods; we need
|
|
|
|
// to do this per-container class since there is no representation
|
|
|
|
// of interfaces in Javascript
|
|
|
|
function _patchContainerClass(containerClass) {
|
|
|
|
// This one is a straightforward mapping of the C method
|
|
|
|
containerClass.prototype.child_set = function(actor, props) {
|
|
|
|
let meta = this.get_child_meta(actor);
|
2011-02-24 17:17:05 +00:00
|
|
|
for (let prop in props)
|
2009-09-18 19:51:15 +00:00
|
|
|
meta[prop] = props[prop];
|
|
|
|
};
|
|
|
|
|
|
|
|
// clutter_container_add() actually is a an add-many-actors
|
|
|
|
// method. We conveniently, but somewhat dubiously, take the
|
|
|
|
// this opportunity to make it do something more useful.
|
|
|
|
containerClass.prototype.add = function(actor, props) {
|
|
|
|
this.add_actor(actor);
|
|
|
|
if (props)
|
|
|
|
this.child_set(actor, props);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-09 21:04:45 +00:00
|
|
|
function _patchLayoutClass(layoutClass, styleProps) {
|
|
|
|
if (styleProps)
|
|
|
|
layoutClass.prototype.hookup_style = function(container) {
|
2017-10-31 00:38:18 +00:00
|
|
|
container.connect('style-changed', () => {
|
2013-07-09 21:04:45 +00:00
|
|
|
let node = container.get_theme_node();
|
2014-04-24 14:20:01 +00:00
|
|
|
for (let prop in styleProps) {
|
|
|
|
let [found, length] = node.lookup_length(styleProps[prop], false);
|
|
|
|
if (found)
|
|
|
|
this[prop] = length;
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-07-09 21:04:45 +00:00
|
|
|
};
|
|
|
|
layoutClass.prototype.child_set = function(actor, props) {
|
|
|
|
let meta = this.get_child_meta(actor.get_parent(), actor);
|
|
|
|
for (let prop in props)
|
|
|
|
meta[prop] = props[prop];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-06-04 22:13:14 +00:00
|
|
|
function _adjustEasingTime(msecs) {
|
|
|
|
return St.get_slow_down_factor() * msecs;
|
|
|
|
}
|
|
|
|
|
2016-10-03 23:09:39 +00:00
|
|
|
function _loggingFunc() {
|
|
|
|
let fields = {'MESSAGE': [].join.call(arguments, ', ')};
|
|
|
|
let domain = "GNOME Shell";
|
|
|
|
|
|
|
|
// If the caller is an extension, add it as metadata
|
|
|
|
let extension = imports.misc.extensionUtils.getCurrentExtension();
|
|
|
|
if (extension != null) {
|
|
|
|
domain = extension.metadata.name;
|
|
|
|
fields['GNOME_SHELL_EXTENSION_UUID'] = extension.uuid;
|
|
|
|
fields['GNOME_SHELL_EXTENSION_NAME'] = extension.metadata.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLib.log_structured(domain, GLib.LogLevelFlags.LEVEL_MESSAGE, fields);
|
2012-04-29 20:41:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 19:51:15 +00:00
|
|
|
function init() {
|
2011-04-30 14:27:36 +00:00
|
|
|
// Add some bindings to the global JS namespace; (gjs keeps the web
|
|
|
|
// browser convention of having that namespace be called 'window'.)
|
|
|
|
window.global = Shell.Global.get();
|
2011-03-13 00:41:23 +00:00
|
|
|
|
2016-10-03 23:09:39 +00:00
|
|
|
window.log = _loggingFunc;
|
2012-04-29 20:41:08 +00:00
|
|
|
|
2011-04-30 13:16:13 +00:00
|
|
|
window._ = Gettext.gettext;
|
|
|
|
window.C_ = Gettext.pgettext;
|
|
|
|
window.ngettext = Gettext.ngettext;
|
2017-10-31 00:38:18 +00:00
|
|
|
window.N_ = s => s;
|
2011-04-30 13:16:13 +00:00
|
|
|
|
2011-04-30 14:27:36 +00:00
|
|
|
// Miscellaneous monkeypatching
|
2010-03-26 20:38:03 +00:00
|
|
|
_patchContainerClass(St.BoxLayout);
|
|
|
|
|
2013-07-09 21:04:45 +00:00
|
|
|
_patchLayoutClass(Clutter.TableLayout, { row_spacing: 'spacing-rows',
|
|
|
|
column_spacing: 'spacing-columns' });
|
|
|
|
_patchLayoutClass(Clutter.GridLayout, { row_spacing: 'spacing-rows',
|
|
|
|
column_spacing: 'spacing-columns' });
|
|
|
|
_patchLayoutClass(Clutter.BoxLayout, { spacing: 'spacing' });
|
|
|
|
|
2014-06-04 22:13:14 +00:00
|
|
|
let origSetEasingDuration = Clutter.Actor.prototype.set_easing_duration;
|
|
|
|
Clutter.Actor.prototype.set_easing_duration = function(msecs) {
|
|
|
|
origSetEasingDuration.call(this, _adjustEasingTime(msecs));
|
|
|
|
};
|
|
|
|
let origSetEasingDelay = Clutter.Actor.prototype.set_easing_delay;
|
|
|
|
Clutter.Actor.prototype.set_easing_delay = function(msecs) {
|
|
|
|
origSetEasingDelay.call(this, _adjustEasingTime(msecs));
|
|
|
|
};
|
|
|
|
|
2010-06-17 17:19:07 +00:00
|
|
|
Clutter.Actor.prototype.toString = function() {
|
|
|
|
return St.describe_actor(this);
|
|
|
|
};
|
2019-04-13 18:34:29 +00:00
|
|
|
// Deprecation warning for former JS classes turned into an actor subclass
|
|
|
|
Object.defineProperty(Clutter.Actor.prototype, 'actor', {
|
|
|
|
get() {
|
|
|
|
let klass = this.constructor.name;
|
|
|
|
let { stack } = new Error();
|
|
|
|
log(`Usage of object.actor is deprecated for ${klass}\n${stack}`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
2010-06-10 12:15:02 +00:00
|
|
|
|
2011-04-06 14:40:01 +00:00
|
|
|
let origToString = Object.prototype.toString;
|
|
|
|
Object.prototype.toString = function() {
|
|
|
|
let base = origToString.call(this);
|
2012-03-05 20:15:45 +00:00
|
|
|
try {
|
|
|
|
if ('actor' in this && this.actor instanceof Clutter.Actor)
|
|
|
|
return base.replace(/\]$/, ' delegate for ' + this.actor.toString().substring(1));
|
|
|
|
else
|
|
|
|
return base;
|
|
|
|
} catch(e) {
|
2011-04-06 14:40:01 +00:00
|
|
|
return base;
|
2012-03-05 20:15:45 +00:00
|
|
|
}
|
2011-04-06 14:40:01 +00:00
|
|
|
};
|
|
|
|
|
2011-04-30 14:27:36 +00:00
|
|
|
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=508783
|
|
|
|
Date.prototype.toLocaleFormat = function(format) {
|
|
|
|
return Shell.util_format_date(format, this.getTime());
|
|
|
|
};
|
|
|
|
|
|
|
|
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
|
|
|
if (slowdownEnv) {
|
|
|
|
let factor = parseFloat(slowdownEnv);
|
|
|
|
if (!isNaN(factor) && factor > 0.0)
|
|
|
|
St.set_slow_down_factor(factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK, now things are initialized enough that we can import shell JS
|
2012-05-04 21:23:08 +00:00
|
|
|
const Format = imports.format;
|
2011-04-30 14:27:36 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
|
|
|
Tweener.init();
|
|
|
|
String.prototype.format = Format.format;
|
2009-09-18 19:51:15 +00:00
|
|
|
}
|