2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported init */
|
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-10-28 17:44:24 +00:00
|
|
|
const { Clutter, GLib, GObject, Meta, 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
|
2019-08-19 17:55:49 +00:00
|
|
|
containerClass.prototype.child_set = function (actor, props) {
|
2009-09-18 19:51:15 +00:00
|
|
|
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.
|
2019-08-19 17:55:49 +00:00
|
|
|
containerClass.prototype.add = function (actor, props) {
|
2009-09-18 19:51:15 +00:00
|
|
|
this.add_actor(actor);
|
|
|
|
if (props)
|
|
|
|
this.child_set(actor, props);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-09 21:04:45 +00:00
|
|
|
function _patchLayoutClass(layoutClass, styleProps) {
|
2019-08-20 00:51:42 +00:00
|
|
|
if (styleProps) {
|
2019-08-19 17:55:49 +00:00
|
|
|
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
|
|
|
};
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2013-07-09 21:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 09:51:41 +00:00
|
|
|
function _makeEaseCallback(params, cleanup) {
|
2017-06-10 00:52:12 +00:00
|
|
|
let onComplete = params.onComplete;
|
|
|
|
delete params.onComplete;
|
|
|
|
|
|
|
|
let onStopped = params.onStopped;
|
|
|
|
delete params.onStopped;
|
|
|
|
|
|
|
|
return isFinished => {
|
2019-09-13 09:51:41 +00:00
|
|
|
cleanup();
|
|
|
|
|
2017-06-10 00:52:12 +00:00
|
|
|
if (onStopped)
|
|
|
|
onStopped(isFinished);
|
|
|
|
if (onComplete && isFinished)
|
|
|
|
onComplete();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:14:12 +00:00
|
|
|
function _getPropertyTarget(actor, propName) {
|
|
|
|
if (!propName.startsWith('@'))
|
|
|
|
return [actor, propName];
|
|
|
|
|
|
|
|
let [type, name, prop] = propName.split('.');
|
|
|
|
switch (type) {
|
|
|
|
case '@layout':
|
|
|
|
return [actor.layout_manager, name];
|
|
|
|
case '@actions':
|
|
|
|
return [actor.get_action(name), prop];
|
|
|
|
case '@constraints':
|
|
|
|
return [actor.get_constraint(name), prop];
|
|
|
|
case '@effects':
|
|
|
|
return [actor.get_effect(name), prop];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Invalid property name ${propName}`);
|
|
|
|
}
|
|
|
|
|
2017-06-10 00:52:12 +00:00
|
|
|
function _easeActor(actor, params) {
|
|
|
|
actor.save_easing_state();
|
|
|
|
|
|
|
|
if (params.duration != undefined)
|
|
|
|
actor.set_easing_duration(params.duration);
|
|
|
|
delete params.duration;
|
|
|
|
|
|
|
|
if (params.delay != undefined)
|
|
|
|
actor.set_easing_delay(params.delay);
|
|
|
|
delete params.delay;
|
|
|
|
|
2019-10-15 19:32:21 +00:00
|
|
|
let repeatCount = 0;
|
|
|
|
if (params.repeatCount != undefined)
|
|
|
|
repeatCount = params.repeatCount;
|
|
|
|
delete params.repeatCount;
|
|
|
|
|
|
|
|
let autoReverse = false;
|
|
|
|
if (params.autoReverse != undefined)
|
|
|
|
autoReverse = params.autoReverse;
|
|
|
|
delete params.autoReverse;
|
|
|
|
|
2017-06-10 00:52:12 +00:00
|
|
|
if (params.mode != undefined)
|
|
|
|
actor.set_easing_mode(params.mode);
|
|
|
|
delete params.mode;
|
|
|
|
|
2019-09-13 09:51:41 +00:00
|
|
|
let cleanup = () => Meta.enable_unredirect_for_display(global.display);
|
|
|
|
let callback = _makeEaseCallback(params, cleanup);
|
2017-06-10 00:52:12 +00:00
|
|
|
|
|
|
|
// cancel overwritten transitions
|
|
|
|
let animatedProps = Object.keys(params).map(p => p.replace('_', '-', 'g'));
|
|
|
|
animatedProps.forEach(p => actor.remove_transition(p));
|
|
|
|
|
|
|
|
actor.set(params);
|
2019-08-09 00:58:28 +00:00
|
|
|
actor.restore_easing_state();
|
2017-06-10 00:52:12 +00:00
|
|
|
|
2019-09-20 00:50:36 +00:00
|
|
|
let transition = animatedProps.map(p => actor.get_transition(p))
|
|
|
|
.find(t => t !== null);
|
|
|
|
|
2019-10-14 07:47:38 +00:00
|
|
|
if (transition && transition.delay)
|
|
|
|
transition.connect('started', () => Meta.disable_unredirect_for_display(global.display));
|
|
|
|
else
|
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
|
|
|
|
2019-10-15 19:32:21 +00:00
|
|
|
if (transition) {
|
|
|
|
transition.set({ repeatCount, autoReverse });
|
2019-09-13 09:51:41 +00:00
|
|
|
transition.connect('stopped', (t, finished) => callback(finished));
|
2019-10-15 19:32:21 +00:00
|
|
|
} else {
|
2019-09-13 09:51:41 +00:00
|
|
|
callback(true);
|
2019-10-15 19:32:21 +00:00
|
|
|
}
|
2017-06-10 00:52:12 +00:00
|
|
|
}
|
|
|
|
|
2017-06-10 02:14:12 +00:00
|
|
|
function _easeActorProperty(actor, propName, target, params) {
|
|
|
|
// Avoid pointless difference with ease()
|
|
|
|
if (params.mode)
|
|
|
|
params.progress_mode = params.mode;
|
|
|
|
delete params.mode;
|
|
|
|
|
|
|
|
if (params.duration)
|
|
|
|
params.duration = adjustAnimationTime(params.duration);
|
|
|
|
let duration = Math.floor(params.duration || 0);
|
|
|
|
|
2019-10-15 19:32:21 +00:00
|
|
|
let repeatCount = 0;
|
|
|
|
if (params.repeatCount != undefined)
|
|
|
|
repeatCount = params.repeatCount;
|
|
|
|
delete params.repeatCount;
|
|
|
|
|
|
|
|
let autoReverse = false;
|
|
|
|
if (params.autoReverse != undefined)
|
|
|
|
autoReverse = params.autoReverse;
|
|
|
|
delete params.autoReverse;
|
|
|
|
|
2019-09-10 13:28:42 +00:00
|
|
|
// Copy Clutter's behavior for implicit animations, see
|
|
|
|
// should_skip_implicit_transition()
|
|
|
|
if (actor instanceof Clutter.Actor && !actor.mapped)
|
|
|
|
duration = 0;
|
|
|
|
|
2019-09-13 09:51:41 +00:00
|
|
|
let cleanup = () => Meta.enable_unredirect_for_display(global.display);
|
|
|
|
let callback = _makeEaseCallback(params, cleanup);
|
2017-06-10 02:14:12 +00:00
|
|
|
|
|
|
|
// cancel overwritten transition
|
|
|
|
actor.remove_transition(propName);
|
|
|
|
|
|
|
|
if (duration == 0) {
|
|
|
|
let [obj, prop] = _getPropertyTarget(actor, propName);
|
|
|
|
obj[prop] = target;
|
|
|
|
|
2019-10-14 07:47:38 +00:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
2019-09-13 09:51:41 +00:00
|
|
|
callback(true);
|
2017-06-10 02:14:12 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pspec = actor.find_property(propName);
|
|
|
|
let transition = new Clutter.PropertyTransition(Object.assign({
|
|
|
|
property_name: propName,
|
|
|
|
interval: new Clutter.Interval({ value_type: pspec.value_type }),
|
2019-10-15 19:32:21 +00:00
|
|
|
remove_on_complete: true,
|
|
|
|
repeat_count: repeatCount,
|
|
|
|
auto_reverse: autoReverse,
|
2017-06-10 02:14:12 +00:00
|
|
|
}, params));
|
|
|
|
actor.add_transition(propName, transition);
|
|
|
|
|
|
|
|
transition.set_to(target);
|
|
|
|
|
2019-10-14 07:47:38 +00:00
|
|
|
if (transition.delay)
|
|
|
|
transition.connect('started', () => Meta.disable_unredirect_for_display(global.display));
|
|
|
|
else
|
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
|
|
|
|
2019-09-13 09:51:41 +00:00
|
|
|
transition.connect('stopped', (t, finished) => callback(finished));
|
2017-06-10 02:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-12 11:24:30 +00:00
|
|
|
function _loggingFunc(...args) {
|
2019-01-29 01:27:05 +00:00
|
|
|
let fields = { 'MESSAGE': args.join(', ') };
|
2016-10-03 23:09:39 +00:00
|
|
|
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
|
|
|
|
2019-10-28 17:44:24 +00:00
|
|
|
GObject.gtypeNameBasedOnJSPath = true;
|
|
|
|
|
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.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;
|
2019-08-19 17:55:49 +00:00
|
|
|
Clutter.Actor.prototype.set_easing_duration = function (msecs) {
|
2014-06-04 22:13:14 +00:00
|
|
|
origSetEasingDuration.call(this, adjustAnimationTime(msecs));
|
|
|
|
};
|
|
|
|
let origSetEasingDelay = Clutter.Actor.prototype.set_easing_delay;
|
2019-08-19 17:55:49 +00:00
|
|
|
Clutter.Actor.prototype.set_easing_delay = function (msecs) {
|
2014-06-04 22:13:14 +00:00
|
|
|
origSetEasingDelay.call(this, adjustAnimationTime(msecs));
|
|
|
|
};
|
|
|
|
|
2019-12-19 22:08:44 +00:00
|
|
|
Clutter.Actor.prototype.ease = function (props) {
|
|
|
|
_easeActor(this, props);
|
2017-06-10 00:52:12 +00:00
|
|
|
};
|
2019-08-19 17:55:49 +00:00
|
|
|
Clutter.Actor.prototype.ease_property = function (propName, target, params) {
|
2017-06-10 02:14:12 +00:00
|
|
|
_easeActorProperty(this, propName, target, params);
|
|
|
|
};
|
2019-08-19 17:55:49 +00:00
|
|
|
St.Adjustment.prototype.ease = function (target, params) {
|
2019-07-25 14:21:46 +00:00
|
|
|
// we're not an actor of course, but we implement the same
|
|
|
|
// transition API as Clutter.Actor, so this works anyway
|
|
|
|
_easeActorProperty(this, 'value', target, params);
|
|
|
|
};
|
2017-06-10 00:52:12 +00:00
|
|
|
|
2019-08-19 17:55:49 +00:00
|
|
|
Clutter.Actor.prototype.toString = function () {
|
2010-06-17 17:19:07 +00:00
|
|
|
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;
|
2019-08-20 21:43:54 +00:00
|
|
|
},
|
2019-04-13 18:34:29 +00:00
|
|
|
});
|
2010-06-10 12:15:02 +00:00
|
|
|
|
2019-08-19 17:55:49 +00:00
|
|
|
St.set_slow_down_factor = function (factor) {
|
2019-07-25 10:50:26 +00:00
|
|
|
let { stack } = new Error();
|
|
|
|
log(`St.set_slow_down_factor() is deprecated, use St.Settings.slow_down_factor\n${stack}`);
|
|
|
|
St.Settings.get().slow_down_factor = factor;
|
|
|
|
};
|
|
|
|
|
2011-04-06 14:40:01 +00:00
|
|
|
let origToString = Object.prototype.toString;
|
2019-08-19 17:55:49 +00:00
|
|
|
Object.prototype.toString = function () {
|
2011-04-06 14:40:01 +00:00
|
|
|
let base = origToString.call(this);
|
2012-03-05 20:15:45 +00:00
|
|
|
try {
|
|
|
|
if ('actor' in this && this.actor instanceof Clutter.Actor)
|
2019-01-30 00:18:24 +00:00
|
|
|
return base.replace(/\]$/, ` delegate for ${this.actor.toString().substring(1)}`);
|
2012-03-05 20:15:45 +00:00
|
|
|
else
|
|
|
|
return base;
|
2019-01-29 01:26:39 +00:00
|
|
|
} 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
|
2019-08-19 17:55:49 +00:00
|
|
|
Date.prototype.toLocaleFormat = function (format) {
|
2019-09-10 03:10:01 +00:00
|
|
|
let dt = GLib.DateTime.new_from_unix_local(this.getTime() / 1000);
|
|
|
|
return dt ? dt.format(format) : '';
|
2011-04-30 14:27:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
|
|
|
if (slowdownEnv) {
|
|
|
|
let factor = parseFloat(slowdownEnv);
|
|
|
|
if (!isNaN(factor) && factor > 0.0)
|
2019-07-25 10:50:26 +00:00
|
|
|
St.Settings.get().slow_down_factor = factor;
|
2011-04-30 14:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2014-06-04 22:13:14 +00:00
|
|
|
|
|
|
|
// adjustAnimationTime:
|
|
|
|
// @msecs: time in milliseconds
|
|
|
|
//
|
|
|
|
// Adjust @msecs to account for St's enable-animations
|
|
|
|
// and slow-down-factor settings
|
|
|
|
function adjustAnimationTime(msecs) {
|
|
|
|
let settings = St.Settings.get();
|
|
|
|
|
|
|
|
if (!settings.enable_animations)
|
|
|
|
return 1;
|
|
|
|
return settings.slow_down_factor * msecs;
|
|
|
|
}
|
|
|
|
|