🔧 Previewing effects works again
This commit is contained in:
+70
-17
@@ -31,6 +31,7 @@ try {
|
|||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
||||||
const utils = Me.imports.src.utils;
|
const utils = Me.imports.src.utils;
|
||||||
|
const ProfileManager = Me.imports.src.ProfileManager.ProfileManager;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// This extensions modifies the window-close and window-open animations with all kinds //
|
// This extensions modifies the window-close and window-open animations with all kinds //
|
||||||
@@ -80,6 +81,15 @@ class Extension {
|
|||||||
// Store a reference to the settings object.
|
// Store a reference to the settings object.
|
||||||
this._settings = ExtensionUtils.getSettings();
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
|
// We reload all effect profiles whenever the currently edited profile in the
|
||||||
|
// preferences dialog changes. This is most likely a bit too often, but it will also
|
||||||
|
// happen whenever a new profile is created and whenever an old profile is deleted.
|
||||||
|
this._settings.connect('changed::active-profile', () => {
|
||||||
|
this._loadProfiles();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._loadProfiles();
|
||||||
|
|
||||||
// We will use extensionThis to refer to the extension inside the patched methods.
|
// We will use extensionThis to refer to the extension inside the patched methods.
|
||||||
const extensionThis = this;
|
const extensionThis = this;
|
||||||
|
|
||||||
@@ -363,6 +373,32 @@ class Extension {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- private stuff
|
// ----------------------------------------------------------------------- private stuff
|
||||||
|
|
||||||
|
_loadProfiles() {
|
||||||
|
const profileManager = new ProfileManager();
|
||||||
|
|
||||||
|
utils.debug('load profiles!');
|
||||||
|
|
||||||
|
const updatePriority = (p) => {
|
||||||
|
utils.debug('sort profiles!');
|
||||||
|
p.priority = profileManager.getProfilePriority(p.settings);
|
||||||
|
this._profiles.sort((a, b) => b.priority - a.priority);
|
||||||
|
};
|
||||||
|
|
||||||
|
this._profiles = profileManager.getProfiles();
|
||||||
|
this._profiles.forEach(p => {
|
||||||
|
p.settings.connect('changed::profile-animation-type', () => updatePriority(p));
|
||||||
|
p.settings.connect('changed::profile-window-type', () => updatePriority(p));
|
||||||
|
p.settings.connect('changed::profile-desktop-style', () => updatePriority(p));
|
||||||
|
p.settings.connect('changed::profile-power-mode', () => updatePriority(p));
|
||||||
|
p.settings.connect('changed::profile-power-profile', () => updatePriority(p));
|
||||||
|
|
||||||
|
p.priority = profileManager.getProfilePriority(p.settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
utils.debug('sort profiles!');
|
||||||
|
this._profiles.sort((a, b) => b.priority - a.priority);
|
||||||
|
}
|
||||||
|
|
||||||
// This method adds one of the configured effects to the given actor. If forOpening is
|
// This method adds one of the configured effects to the given actor. If forOpening is
|
||||||
// set to true, a effect from the enabled window-open animations is chosen, else an
|
// set to true, a effect from the enabled window-open animations is chosen, else an
|
||||||
// enabled window-close animation is used. This will also tweak the transitions of the
|
// enabled window-close animation is used. This will also tweak the transitions of the
|
||||||
@@ -379,7 +415,6 @@ class Extension {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const previewNick = this._settings.get_string('preview-effect');
|
|
||||||
|
|
||||||
// TODO!.
|
// TODO!.
|
||||||
// We may have to do nothing if running on battery power or if in power-save mode.
|
// We may have to do nothing if running on battery power or if in power-save mode.
|
||||||
@@ -407,34 +442,52 @@ class Extension {
|
|||||||
|
|
||||||
// ------------------------------------------------------------------ choose an effect
|
// ------------------------------------------------------------------ choose an effect
|
||||||
|
|
||||||
// Now we chose a random effect from all enabled effects.
|
// Usually, we use the effect profile with the highest priority which matches the
|
||||||
let effect = null;
|
// current circumstances. From this profile, we choose a random effect. However, if an
|
||||||
|
// effect is to be previewed, we choose the currently edited profile regardless of the
|
||||||
|
// circumstances.
|
||||||
|
let profile = null;
|
||||||
|
let effect = null;
|
||||||
|
|
||||||
|
// Hence, we first check if an effect is to be previewed.
|
||||||
|
const previewNick = this._settings.get_string('preview-effect');
|
||||||
|
|
||||||
// First we check if an effect is to be previewed.
|
|
||||||
if (previewNick != '') {
|
if (previewNick != '') {
|
||||||
effect = this._ALL_EFFECTS.find(effect => effect.getNick() == previewNick);
|
const activeProfile = this._settings.get_string('active-profile');
|
||||||
|
effect = this._ALL_EFFECTS.find(effect => effect.getNick() == previewNick);
|
||||||
|
profile = this._profiles.find(p => p.path == activeProfile);
|
||||||
|
|
||||||
// Only preview the effect once.
|
// Only preview the effect until the preview window is closed.
|
||||||
if (!forOpening) {
|
if (!profile || !forOpening) {
|
||||||
this._settings.set_string('preview-effect', '');
|
this._settings.set_string('preview-effect', '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Else we choose a random effect from all enabled effects.
|
// If no effect is previewed, we use the effect profile with the highest priority
|
||||||
|
// which matches the current circumstances. From this profile, we choose a random
|
||||||
|
// effect.
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// Therefore, we first create a list of all currently enabled effects.
|
const profile = this._profiles.find(p => {
|
||||||
const enabled = this._ALL_EFFECTS.filter(effect => {
|
utils.debug('PRIO: ' + p.priority);
|
||||||
return this._settings.get_boolean(`${effect.getNick()}-enable-effect`);
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// And then choose a random effect.
|
if (profile) {
|
||||||
if (enabled.length > 0) {
|
|
||||||
effect = enabled[Math.floor(Math.random() * enabled.length)];
|
// Create a list of all enabled effects of this profile.
|
||||||
|
const enabled = this._ALL_EFFECTS.filter(effect => {
|
||||||
|
return profile.settings.get_boolean(`${effect.getNick()}-enable-effect`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// And then choose a random effect.
|
||||||
|
if (enabled.length > 0) {
|
||||||
|
effect = enabled[Math.floor(Math.random() * enabled.length)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If nothing was enabled, we have to do nothing :)
|
// If nothing was enabled, we have to do nothing :)
|
||||||
if (effect == null) {
|
if (!effect || !profile) {
|
||||||
this._fixAnimationTimes(isDialogWindow, forOpening, null);
|
this._fixAnimationTimes(isDialogWindow, forOpening, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -449,12 +502,12 @@ class Extension {
|
|||||||
// windows are faded in / out scaled up / down slightly by GNOME Shell. Here, we tweak
|
// windows are faded in / out scaled up / down slightly by GNOME Shell. Here, we tweak
|
||||||
// the transitions so that nothing changes. The window stays opaque and is scaled to
|
// the transitions so that nothing changes. The window stays opaque and is scaled to
|
||||||
// actorScale.
|
// actorScale.
|
||||||
const actorScale = effect.getActorScale(this._settings, forOpening, actor);
|
const actorScale = effect.getActorScale(profile.settings, forOpening, actor);
|
||||||
|
|
||||||
// To make things deterministic during testing, we set the effect duration to 5
|
// To make things deterministic during testing, we set the effect duration to 5
|
||||||
// seconds.
|
// seconds.
|
||||||
const duration =
|
const duration =
|
||||||
testMode ? 5000 : this._settings.get_int(effect.getNick() + '-animation-time');
|
testMode ? 5000 : profile.settings.get_int(effect.getNick() + '-animation-time');
|
||||||
|
|
||||||
// All animations are relative to the window's center.
|
// All animations are relative to the window's center.
|
||||||
actor.set_pivot_point(0.5, 0.5);
|
actor.set_pivot_point(0.5, 0.5);
|
||||||
|
|||||||
@@ -124,6 +124,19 @@ var ProfileManager = class {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each profile has a priority. It is higher, the more specific it is.
|
||||||
|
getProfilePriority(settings) {
|
||||||
|
let priority = 0;
|
||||||
|
|
||||||
|
if (settings.get_int('profile-animation-type') > 0) ++priority;
|
||||||
|
if (settings.get_int('profile-window-type') > 0) ++priority;
|
||||||
|
if (settings.get_int('profile-desktop-style') > 0) ++priority;
|
||||||
|
if (settings.get_int('profile-power-mode') > 0) ++priority;
|
||||||
|
if (settings.get_int('profile-power-profile') > 0) ++priority;
|
||||||
|
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
// Profiles are named according to their configuration. This method returns a localized
|
// Profiles are named according to their configuration. This method returns a localized
|
||||||
// string describing the settings of the profile.
|
// string describing the settings of the profile.
|
||||||
getProfileName(settings) {
|
getProfileName(settings) {
|
||||||
|
|||||||
Reference in New Issue
Block a user