2009-09-18 15:51:15 -04:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
2010-06-10 08:15:02 -04:00
|
|
|
const Clutter = imports.gi.Clutter;;
|
2010-06-19 22:16:06 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
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;
|
2010-11-29 15:47:54 -05:00
|
|
|
const Gettext_gtk30 = imports.gettext.domain('gtk30');
|
2009-09-18 15:51:15 -04:00
|
|
|
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2009-10-04 17:30:18 -04:00
|
|
|
const Format = imports.misc.format;
|
|
|
|
|
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);
|
|
|
|
for (prop in props)
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-03-26 16:38:03 -04:00
|
|
|
// Replace @method with something that throws an error instead
|
|
|
|
function _blockMethod(method, replacement, reason) {
|
|
|
|
let match = method.match(/^(.+)\.([^.]+)$/);
|
|
|
|
if (!match)
|
|
|
|
throw new Error('Bad method name "' + method + '"');
|
|
|
|
let proto = 'imports.gi.' + match[1] + '.prototype';
|
|
|
|
let property = match[2];
|
|
|
|
|
|
|
|
if (!global.set_property_mutable(proto, property, true))
|
|
|
|
throw new Error('Bad method name "' + method + '"');
|
|
|
|
|
|
|
|
// eval() is evil in general, but we know it's safe here since
|
|
|
|
// set_property_mutable() would have failed if proto was
|
|
|
|
// malformed.
|
|
|
|
let node = eval(proto);
|
|
|
|
|
|
|
|
let msg = 'Do not use "' + method + '".';
|
|
|
|
if (replacement)
|
|
|
|
msg += ' Use "' + replacement + '" instead.';
|
|
|
|
if (reason)
|
|
|
|
msg += ' (' + reason + ')';
|
|
|
|
|
|
|
|
node[property] = function() {
|
|
|
|
throw new Error(msg);
|
|
|
|
};
|
|
|
|
|
|
|
|
global.set_property_mutable(proto, property, false);
|
|
|
|
}
|
2009-09-18 15:51:15 -04:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
Tweener.init();
|
2009-10-04 17:30:18 -04:00
|
|
|
String.prototype.format = Format.format;
|
2009-11-14 12:08:27 -05:00
|
|
|
|
|
|
|
// Set the default direction for St widgets (this needs to be done before any use of St)
|
2010-11-29 15:47:54 -05:00
|
|
|
if (Gettext_gtk30.gettext('default:LTR') == 'default:RTL') {
|
2009-11-14 12:08:27 -05:00
|
|
|
St.Widget.set_default_direction(St.TextDirection.RTL);
|
|
|
|
}
|
2010-03-26 16:38:03 -04:00
|
|
|
|
2010-06-19 22:16:06 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-10-02 22:16:07 -04:00
|
|
|
if (window.global === undefined) // test environment
|
|
|
|
return;
|
|
|
|
|
2010-03-26 16:38:03 -04:00
|
|
|
_blockMethod('Clutter.Event.get_state', 'Shell.get_event_state',
|
|
|
|
'gjs\'s handling of Clutter.ModifierType is broken. See bug 597292.');
|
2010-06-19 14:26:16 -04:00
|
|
|
_blockMethod('Gdk.Window.get_device_position', 'global.get_pointer',
|
2010-03-26 16:38:03 -04:00
|
|
|
'gjs\'s handling of Gdk.ModifierType is broken. See bug 597292.');
|
|
|
|
|
|
|
|
// Now close the back door to prevent extensions from trying to
|
|
|
|
// abuse it. We can't actually delete it since
|
|
|
|
// Shell.Global.prototype itself is read-only.
|
|
|
|
global.set_property_mutable('imports.gi.Shell.Global.prototype', 'set_property_mutable', true);
|
|
|
|
Shell.Global.prototype.set_property_mutable = undefined;
|
2009-09-18 15:51:15 -04:00
|
|
|
}
|