2023-07-10 02:21:23 -04:00
|
|
|
// Load all required dependencies with the correct versions
|
2023-07-10 02:05:14 -04:00
|
|
|
import '../misc/dependencies.js';
|
|
|
|
|
|
|
|
import {setConsoleLogDomain} from 'console';
|
|
|
|
import * as Gettext from 'gettext';
|
|
|
|
|
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import Gdk from 'gi://Gdk';
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
import Meta from 'gi://Meta';
|
2023-08-31 13:40:43 -04:00
|
|
|
import Mtk from 'gi://Mtk';
|
2023-07-10 02:05:14 -04:00
|
|
|
import Polkit from 'gi://Polkit';
|
|
|
|
import Shell from 'gi://Shell';
|
|
|
|
import St from 'gi://St';
|
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
import * as SignalTracker from '../misc/signalTracker.js';
|
|
|
|
import {adjustAnimationTime} from '../misc/animationUtils.js';
|
2020-02-27 16:46:44 -05:00
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
setConsoleLogDomain('GNOME Shell');
|
|
|
|
|
2022-02-10 18:09:54 -05:00
|
|
|
Gio._promisify(Gio.DataInputStream.prototype, 'fill_async');
|
|
|
|
Gio._promisify(Gio.DataInputStream.prototype, 'read_line_async');
|
|
|
|
Gio._promisify(Gio.DBus, 'get');
|
|
|
|
Gio._promisify(Gio.DBusConnection.prototype, 'call');
|
|
|
|
Gio._promisify(Gio.DBusProxy, 'new');
|
|
|
|
Gio._promisify(Gio.DBusProxy.prototype, 'init_async');
|
|
|
|
Gio._promisify(Gio.DBusProxy.prototype, 'call_with_unix_fd_list');
|
2023-02-12 16:46:07 -05:00
|
|
|
Gio._promisify(Gio.File.prototype, 'query_info_async');
|
2022-02-10 18:09:54 -05:00
|
|
|
Gio._promisify(Polkit.Permission, 'new');
|
2019-12-19 14:50:37 -05:00
|
|
|
|
2011-04-30 10:27:36 -04:00
|
|
|
// We can't import shell JS modules yet, because they may have
|
2023-07-10 02:05:14 -04:00
|
|
|
// variable initializations, etc, that depend on this file's
|
|
|
|
// changes
|
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
|
2019-08-19 13:55:49 -04:00
|
|
|
containerClass.prototype.child_set = function (actor, props) {
|
2009-09-18 15:51:15 -04:00
|
|
|
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.
|
2019-08-19 13:55:49 -04:00
|
|
|
containerClass.prototype.add = function (actor, props) {
|
2009-09-18 15:51:15 -04:00
|
|
|
this.add_actor(actor);
|
|
|
|
if (props)
|
|
|
|
this.child_set(actor, props);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:04:45 -04:00
|
|
|
function _patchLayoutClass(layoutClass, styleProps) {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (styleProps) {
|
2019-08-19 13:55:49 -04:00
|
|
|
layoutClass.prototype.hookup_style = function (container) {
|
2017-10-30 20:38:18 -04:00
|
|
|
container.connect('style-changed', () => {
|
2013-07-09 17:04:45 -04:00
|
|
|
let node = container.get_theme_node();
|
2014-04-24 10:20:01 -04:00
|
|
|
for (let prop in styleProps) {
|
|
|
|
let [found, length] = node.lookup_length(styleProps[prop], false);
|
|
|
|
if (found)
|
|
|
|
this[prop] = length;
|
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-07-09 17:04:45 -04:00
|
|
|
};
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2013-07-09 17:04:45 -04:00
|
|
|
}
|
|
|
|
|
2019-09-13 05:51:41 -04:00
|
|
|
function _makeEaseCallback(params, cleanup) {
|
2017-06-09 20:52:12 -04:00
|
|
|
let onComplete = params.onComplete;
|
|
|
|
delete params.onComplete;
|
|
|
|
|
|
|
|
let onStopped = params.onStopped;
|
|
|
|
delete params.onStopped;
|
|
|
|
|
|
|
|
return isFinished => {
|
2019-09-13 05:51:41 -04:00
|
|
|
cleanup();
|
|
|
|
|
2017-06-09 20:52:12 -04:00
|
|
|
if (onStopped)
|
|
|
|
onStopped(isFinished);
|
|
|
|
if (onComplete && isFinished)
|
|
|
|
onComplete();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:12 -04: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];
|
2020-10-07 19:21:04 -04:00
|
|
|
case '@content':
|
|
|
|
return [actor.content, name];
|
2017-06-09 22:14:12 -04:00
|
|
|
case '@effects':
|
|
|
|
return [actor.get_effect(name), prop];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Invalid property name ${propName}`);
|
|
|
|
}
|
|
|
|
|
2017-06-09 20:52:12 -04:00
|
|
|
function _easeActor(actor, params) {
|
|
|
|
actor.save_easing_state();
|
|
|
|
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.duration !== undefined)
|
2017-06-09 20:52:12 -04:00
|
|
|
actor.set_easing_duration(params.duration);
|
|
|
|
delete params.duration;
|
|
|
|
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.delay !== undefined)
|
2017-06-09 20:52:12 -04:00
|
|
|
actor.set_easing_delay(params.delay);
|
|
|
|
delete params.delay;
|
|
|
|
|
2019-10-15 15:32:21 -04:00
|
|
|
let repeatCount = 0;
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.repeatCount !== undefined)
|
2019-10-15 15:32:21 -04:00
|
|
|
repeatCount = params.repeatCount;
|
|
|
|
delete params.repeatCount;
|
|
|
|
|
|
|
|
let autoReverse = false;
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.autoReverse !== undefined)
|
2019-10-15 15:32:21 -04:00
|
|
|
autoReverse = params.autoReverse;
|
|
|
|
delete params.autoReverse;
|
|
|
|
|
2020-02-22 10:35:32 -05:00
|
|
|
// repeatCount doesn't include the initial iteration
|
|
|
|
const numIterations = repeatCount + 1;
|
|
|
|
// whether the transition should finish where it started
|
|
|
|
const isReversed = autoReverse && numIterations % 2 === 0;
|
|
|
|
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.mode !== undefined)
|
2017-06-09 20:52:12 -04:00
|
|
|
actor.set_easing_mode(params.mode);
|
|
|
|
delete params.mode;
|
|
|
|
|
2020-08-03 12:33:57 -04:00
|
|
|
const prepare = () => {
|
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
|
|
|
global.begin_work();
|
|
|
|
};
|
|
|
|
const cleanup = () => {
|
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
|
|
|
global.end_work();
|
|
|
|
};
|
2019-09-13 05:51:41 -04:00
|
|
|
let callback = _makeEaseCallback(params, cleanup);
|
2017-06-09 20:52:12 -04:00
|
|
|
|
|
|
|
// cancel overwritten transitions
|
|
|
|
let animatedProps = Object.keys(params).map(p => p.replace('_', '-', 'g'));
|
|
|
|
animatedProps.forEach(p => actor.remove_transition(p));
|
|
|
|
|
2020-02-22 10:35:32 -05:00
|
|
|
if (actor.get_easing_duration() > 0 || !isReversed)
|
|
|
|
actor.set(params);
|
2019-08-08 20:58:28 -04:00
|
|
|
actor.restore_easing_state();
|
2017-06-09 20:52:12 -04:00
|
|
|
|
2021-10-21 13:50:18 -04:00
|
|
|
const transitions = animatedProps
|
|
|
|
.map(p => actor.get_transition(p))
|
|
|
|
.filter(t => t !== null);
|
|
|
|
|
2023-08-06 18:40:20 -04:00
|
|
|
transitions.forEach(t => t.set({repeatCount, autoReverse}));
|
2021-10-21 13:50:18 -04:00
|
|
|
|
|
|
|
const [transition] = transitions;
|
2019-09-19 20:50:36 -04:00
|
|
|
|
2019-10-14 03:47:38 -04:00
|
|
|
if (transition && transition.delay)
|
2020-08-03 12:33:57 -04:00
|
|
|
transition.connect('started', () => prepare());
|
2019-10-14 03:47:38 -04:00
|
|
|
else
|
2020-08-03 12:33:57 -04:00
|
|
|
prepare();
|
2019-10-14 03:47:38 -04:00
|
|
|
|
2021-10-21 13:50:18 -04:00
|
|
|
if (transition)
|
2019-09-13 05:51:41 -04:00
|
|
|
transition.connect('stopped', (t, finished) => callback(finished));
|
2021-10-21 13:50:18 -04:00
|
|
|
else
|
2019-09-13 05:51:41 -04:00
|
|
|
callback(true);
|
2017-06-09 20:52:12 -04:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:12 -04: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 15:32:21 -04:00
|
|
|
let repeatCount = 0;
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.repeatCount !== undefined)
|
2019-10-15 15:32:21 -04:00
|
|
|
repeatCount = params.repeatCount;
|
|
|
|
delete params.repeatCount;
|
|
|
|
|
|
|
|
let autoReverse = false;
|
2023-08-06 20:51:19 -04:00
|
|
|
if (params.autoReverse !== undefined)
|
2019-10-15 15:32:21 -04:00
|
|
|
autoReverse = params.autoReverse;
|
|
|
|
delete params.autoReverse;
|
|
|
|
|
2020-02-22 10:35:32 -05:00
|
|
|
// repeatCount doesn't include the initial iteration
|
|
|
|
const numIterations = repeatCount + 1;
|
|
|
|
// whether the transition should finish where it started
|
|
|
|
const isReversed = autoReverse && numIterations % 2 === 0;
|
|
|
|
|
2019-09-10 09:28:42 -04:00
|
|
|
// Copy Clutter's behavior for implicit animations, see
|
|
|
|
// should_skip_implicit_transition()
|
|
|
|
if (actor instanceof Clutter.Actor && !actor.mapped)
|
|
|
|
duration = 0;
|
|
|
|
|
2020-08-03 12:33:57 -04:00
|
|
|
const prepare = () => {
|
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
|
|
|
global.begin_work();
|
|
|
|
};
|
|
|
|
const cleanup = () => {
|
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
|
|
|
global.end_work();
|
|
|
|
};
|
2019-09-13 05:51:41 -04:00
|
|
|
let callback = _makeEaseCallback(params, cleanup);
|
2017-06-09 22:14:12 -04:00
|
|
|
|
|
|
|
// cancel overwritten transition
|
|
|
|
actor.remove_transition(propName);
|
|
|
|
|
2023-08-06 20:51:19 -04:00
|
|
|
if (duration === 0) {
|
2017-06-09 22:14:12 -04:00
|
|
|
let [obj, prop] = _getPropertyTarget(actor, propName);
|
2020-02-22 10:35:32 -05:00
|
|
|
|
|
|
|
if (!isReversed)
|
|
|
|
obj[prop] = target;
|
2017-06-09 22:14:12 -04:00
|
|
|
|
2020-08-03 12:33:57 -04:00
|
|
|
prepare();
|
2019-09-13 05:51:41 -04:00
|
|
|
callback(true);
|
2017-06-09 22:14:12 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pspec = actor.find_property(propName);
|
|
|
|
let transition = new Clutter.PropertyTransition(Object.assign({
|
|
|
|
property_name: propName,
|
2023-08-06 18:40:20 -04:00
|
|
|
interval: new Clutter.Interval({value_type: pspec.value_type}),
|
2019-10-15 15:32:21 -04:00
|
|
|
remove_on_complete: true,
|
|
|
|
repeat_count: repeatCount,
|
|
|
|
auto_reverse: autoReverse,
|
2017-06-09 22:14:12 -04:00
|
|
|
}, params));
|
|
|
|
actor.add_transition(propName, transition);
|
|
|
|
|
|
|
|
transition.set_to(target);
|
|
|
|
|
2019-10-14 03:47:38 -04:00
|
|
|
if (transition.delay)
|
2020-08-03 12:33:57 -04:00
|
|
|
transition.connect('started', () => prepare());
|
2019-10-14 03:47:38 -04:00
|
|
|
else
|
2020-08-03 12:33:57 -04:00
|
|
|
prepare();
|
2019-10-14 03:47:38 -04:00
|
|
|
|
2019-09-13 05:51:41 -04:00
|
|
|
transition.connect('stopped', (t, finished) => callback(finished));
|
2017-06-09 22:14:12 -04:00
|
|
|
}
|
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
// Add some bindings to the global JS namespace
|
|
|
|
globalThis.global = Shell.Global.get();
|
|
|
|
|
|
|
|
globalThis._ = Gettext.gettext;
|
|
|
|
globalThis.C_ = Gettext.pgettext;
|
|
|
|
globalThis.ngettext = Gettext.ngettext;
|
|
|
|
globalThis.N_ = s => s;
|
|
|
|
|
|
|
|
GObject.gtypeNameBasedOnJSPath = true;
|
|
|
|
|
|
|
|
GObject.Object.prototype.connectObject = function (...args) {
|
|
|
|
SignalTracker.connectObject(this, ...args);
|
|
|
|
};
|
|
|
|
GObject.Object.prototype.connect_object = function (...args) {
|
|
|
|
SignalTracker.connectObject(this, ...args);
|
|
|
|
};
|
|
|
|
GObject.Object.prototype.disconnectObject = function (...args) {
|
|
|
|
SignalTracker.disconnectObject(this, ...args);
|
|
|
|
};
|
|
|
|
GObject.Object.prototype.disconnect_object = function (...args) {
|
|
|
|
SignalTracker.disconnectObject(this, ...args);
|
|
|
|
};
|
|
|
|
|
|
|
|
SignalTracker.registerDestroyableType(Clutter.Actor);
|
|
|
|
|
|
|
|
// Miscellaneous monkeypatching
|
|
|
|
_patchContainerClass(St.BoxLayout);
|
|
|
|
|
|
|
|
_patchLayoutClass(Clutter.GridLayout, {
|
|
|
|
row_spacing: 'spacing-rows',
|
|
|
|
column_spacing: 'spacing-columns',
|
|
|
|
});
|
|
|
|
_patchLayoutClass(Clutter.BoxLayout, {spacing: 'spacing'});
|
|
|
|
|
|
|
|
const origSetEasingDuration = Clutter.Actor.prototype.set_easing_duration;
|
|
|
|
Clutter.Actor.prototype.set_easing_duration = function (msecs) {
|
|
|
|
origSetEasingDuration.call(this, adjustAnimationTime(msecs));
|
|
|
|
};
|
|
|
|
const origSetEasingDelay = Clutter.Actor.prototype.set_easing_delay;
|
|
|
|
Clutter.Actor.prototype.set_easing_delay = function (msecs) {
|
|
|
|
origSetEasingDelay.call(this, adjustAnimationTime(msecs));
|
|
|
|
};
|
|
|
|
|
|
|
|
Clutter.Actor.prototype.ease = function (props) {
|
|
|
|
_easeActor(this, props);
|
|
|
|
};
|
|
|
|
Clutter.Actor.prototype.ease_property = function (propName, target, params) {
|
|
|
|
_easeActorProperty(this, propName, target, params);
|
|
|
|
};
|
|
|
|
St.Adjustment.prototype.ease = function (target, params) {
|
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
Clutter.Actor.prototype[Symbol.iterator] = function* () {
|
|
|
|
for (let c = this.get_first_child(); c; c = c.get_next_sibling())
|
|
|
|
yield c;
|
|
|
|
};
|
|
|
|
|
|
|
|
Clutter.Actor.prototype.toString = function () {
|
|
|
|
return St.describe_actor(this);
|
|
|
|
};
|
|
|
|
// 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;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-08-31 13:40:43 -04:00
|
|
|
Meta.Rectangle = function (params = {}) {
|
|
|
|
console.warn('Meta.Rectangle is deprecated, use Mtk.Rectangle instead');
|
|
|
|
return new Mtk.Rectangle(params);
|
|
|
|
};
|
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
Gio.File.prototype.touch_async = function (callback) {
|
|
|
|
Shell.util_touch_file_async(this, callback);
|
|
|
|
};
|
|
|
|
Gio.File.prototype.touch_finish = function (result) {
|
|
|
|
return Shell.util_touch_file_finish(this, result);
|
|
|
|
};
|
|
|
|
|
|
|
|
const origToString = Object.prototype.toString;
|
|
|
|
Object.prototype.toString = function () {
|
|
|
|
let base = origToString.call(this);
|
|
|
|
try {
|
|
|
|
if ('actor' in this && this.actor instanceof Clutter.Actor)
|
|
|
|
return base.replace(/\]$/, ` delegate for ${this.actor.toString().substring(1)}`);
|
|
|
|
else
|
2011-04-06 10:40:01 -04:00
|
|
|
return base;
|
2023-07-10 02:05:14 -04:00
|
|
|
} catch (e) {
|
|
|
|
return base;
|
2011-04-30 10:27:36 -04:00
|
|
|
}
|
2023-07-10 02:05:14 -04:00
|
|
|
};
|
2011-04-30 10:27:36 -04:00
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
const slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
|
|
|
if (slowdownEnv) {
|
|
|
|
let factor = parseFloat(slowdownEnv);
|
|
|
|
if (!isNaN(factor) && factor > 0.0)
|
|
|
|
St.Settings.get().slow_down_factor = factor;
|
|
|
|
}
|
2011-04-30 10:27:36 -04:00
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
// OK, now things are initialized enough that we can import shell JS
|
|
|
|
const Format = imports.format;
|
2020-06-01 23:41:43 -04:00
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
String.prototype.format = Format.format;
|
2023-03-06 10:06:33 -05:00
|
|
|
|
2023-07-10 02:05:14 -04:00
|
|
|
Math.clamp = function (x, lower, upper) {
|
|
|
|
return Math.min(Math.max(x, lower), upper);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Prevent extensions from opening a display connection to ourselves
|
|
|
|
Gdk.set_allowed_backends('');
|