2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-09-18 15:51:15 -04:00
|
|
|
|
2011-04-30 10:27:36 -04:00
|
|
|
imports.gi.versions.Clutter = '1.0';
|
|
|
|
imports.gi.versions.Gio = '2.0';
|
|
|
|
imports.gi.versions.Gdk = '3.0';
|
|
|
|
imports.gi.versions.GdkPixbuf = '2.0';
|
|
|
|
imports.gi.versions.Gtk = '3.0';
|
|
|
|
|
2010-06-10 08:15:02 -04:00
|
|
|
const Clutter = imports.gi.Clutter;;
|
2011-04-30 10:34:51 -04:00
|
|
|
const Gettext = imports.gettext;
|
2010-06-19 22:16:06 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2011-04-30 10:27:36 -04:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2010-03-26 16:38:03 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-09-18 15:51:15 -04:00
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2011-04-30 10:27:36 -04: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 15:51:15 -04:00
|
|
|
|
2009-10-04 17:30:18 -04:00
|
|
|
|
2009-09-18 15:51:15 -04: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 12:17:05 -05:00
|
|
|
for (let prop in props)
|
2009-09-18 15:51:15 -04: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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
2011-04-30 10:27:36 -04: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-12 19:41:23 -05:00
|
|
|
|
2011-04-30 09:16:13 -04:00
|
|
|
window._ = Gettext.gettext;
|
|
|
|
window.C_ = Gettext.pgettext;
|
|
|
|
window.ngettext = Gettext.ngettext;
|
|
|
|
|
2011-04-30 10:27:36 -04:00
|
|
|
// Miscellaneous monkeypatching
|
2010-03-26 16:38:03 -04:00
|
|
|
_patchContainerClass(St.BoxLayout);
|
|
|
|
_patchContainerClass(St.Table);
|
|
|
|
|
2010-06-17 13:19:07 -04:00
|
|
|
Clutter.Actor.prototype.toString = function() {
|
|
|
|
return St.describe_actor(this);
|
|
|
|
};
|
2010-06-10 08:15:02 -04:00
|
|
|
|
2011-04-06 10:40:01 -04:00
|
|
|
let origToString = Object.prototype.toString;
|
|
|
|
Object.prototype.toString = function() {
|
|
|
|
let base = origToString.call(this);
|
2012-03-05 15:15:45 -05: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 10:40:01 -04:00
|
|
|
return base;
|
2012-03-05 15:15:45 -05:00
|
|
|
}
|
2011-04-06 10:40:01 -04:00
|
|
|
};
|
|
|
|
|
2011-04-30 10:27:36 -04: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
|
|
|
|
const Format = imports.misc.format;
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
|
|
|
Tweener.init();
|
|
|
|
String.prototype.format = Format.format;
|
2009-09-18 15:51:15 -04:00
|
|
|
}
|