Skip to content

Commit

Permalink
Version 44 (#189)
Browse files Browse the repository at this point in the history
* update french translation (#188)
* adjustable icon size for menu controls #192
* GNOME default blur for login prompt #176
* code clean ups and refactoring
* streamline menu and improve ui/ux

Co-authored-by: 0xMRTT <[email protected]>
  • Loading branch information
neffo and 0xMRTT committed Jan 13, 2023
1 parent 707ad97 commit 33a35fc
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 269 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Also, check out my related [Google Earth View wallpaper extension](https://githu

* In China, users are limited to 'Chinese – China', 'English - International' markets (this is the way Bing handles the Chinese market/locale, not an extension 'bug' - sorry!)
* Bing may detect your location incorrectly (and force a locale as above) - if you see this, please let me know what Bing.com itself does
* GNOME Shell themes can break some GNOME popup menu elements (toggle switches for example). This impacts GNOME more generally, not just this extension. Double check you are running latest versions of your themes (or disable them).

## Requirements

Expand Down
184 changes: 99 additions & 85 deletions blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,113 @@
// (at your option) any later version.
// See the GNU General Public License, version 3 or later for details.
// Based on GNOME shell extension NASA APOD by Elia Argentieri https://github.com/Elinvention/gnome-shell-extension-nasa-apod
// This code based on https://github.com/PRATAP-KUMAR/Control_Blur_Effect_On_Lock_Screen
// This code based on https://github.com/PRATAP-KUMAR/Control_Blur_Effect_On_Lock_Screen
// and https://github.com/sunwxg/gnome-shell-extension-unlockDialogBackground

const St = imports.gi.St;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Background = imports.ui.background;
const ScreenShield = imports.ui.screenShield;
const UnlockDialog = imports.ui.unlockDialog.UnlockDialog;
const ExtensionUtils = imports.misc.extensionUtils;
var _createBackground = UnlockDialog.prototype._createBackground;
var _updateBackgroundEffects = UnlockDialog.prototype._updateBackgroundEffects;
var _showClock = UnlockDialog.prototype._showClock;
var _showPrompt = UnlockDialog.prototype._showPrompt;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;

var shellVersionMajor = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[0]);
var shellVersionMinor = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
var shellVersionPoint = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[2]);

var blur_strength = 2;
var blur_brightness = 55;
// default BWP mild blur
var BWP_BLUR_SIGMA = 2;
var BWP_BLUR_BRIGHTNESS = 55;
// GNOME defaults
var BLUR_BRIGHTNESS = 0.55;
var BLUR_SIGMA = 60;
var debug = false;

let blurEnabled = false;
var blurMode = whichVersion();
var promptActive = false; // default GNOME method of testing this relies on state of a transisiton
// so we are being explicit here (do not want any races, thanks)

function log(msg) {
if (debug)
print("BingWallpaper extension/Blur: " + msg); // disable to keep the noise down in journal
if (debug) // set 'debug' above to false to keep the noise down in journal
print("BingWallpaper extension/Blur: " + msg);
}

var Blur = class Blur {
constructor() {
log('Blur mode is '+blurMode);
// we patch UnlockDialog._updateBackgroundEffects()
function _updateBackgroundEffects_BWP(monitorIndex) {
// GNOME shell 3.36.4 and above
log("_updateBackgroundEffects_BWP() called for shell >= 3.36.4");
const themeContext = St.ThemeContext.get_for_stage(global.stage);
for (const widget of this._backgroundGroup.get_children()) {
// set blur effects, we have two modes in lockscreen: login prompt or clock
// blur on when clock is visible is adjustable
const effect = widget.get_effect('blur');
if (promptActive) {
log('default blur active');
if (effect) {
effect.set({ // GNOME defaults when login prompt is visible
brightness: BLUR_BRIGHTNESS,
sigma: BLUR_SIGMA * themeContext.scale_factor,
});
}
}
else {
log('adjustable blur active');
if (effect) {
effect.set({ // adjustable blur when clock is visible
brightness: BWP_BLUR_BRIGHTNESS * 0.01, // we use 0-100 rather than 0-1, so divide by 100
sigma: BWP_BLUR_SIGMA * themeContext.scale_factor,
});
}
}
}
}

_do_blur_v1(monitorIndex) {
// GNOME shell 3.36.3 and below (FIXME: this needs work)
log("_do_blur() called for shell < 3.36.4");
let monitor = Main.layoutManager.monitors[monitorIndex];
let widget = new St.Widget({
style_class: 'screen-shield-background',
x: monitor.x,
y: monitor.y,
width: monitor.width,
height: monitor.height,
});

let bgManager = new Background.BackgroundManager({
container: widget,
monitorIndex,
controlPosition: false,
});
this._bgManagers.push(bgManager);
this._backgroundGroup.add_child(widget);
const themeContext = St.ThemeContext.get_for_stage(global.stage);
log("blur strength: " + blur_strength +" blur brightness: "+blur_brightness);
let effect = new Shell.BlurEffect({ brightness: blur_brightness * 0.01, sigma: blur_strength * themeContext.scale_factor / 5 }); // fix me, should this be /5?
this._scaleChangedId = themeContext.connect('notify::scale-factor', () => { effect.sigma = blur_strength * themeContext.scale_factor / 5; });
widget.add_effect(effect);
blurEnabled = true;
}
// we patch both UnlockDialog._showClock() and UnlockDialog._showPrompt() to let us
// adjustable blur in a Windows-like way (this ensures login prompt is readable)
function _showClock_BWP() {
promptActive = false;
this._showClock_GNOME(); // pass to default GNOME function
this._updateBackgroundEffects();
}

_do_blur_v2(monitorIndex) {
// GNOME shell 3.36.4 and above
log("_do_blur() called for shell >= 3.36.4");
const themeContext = St.ThemeContext.get_for_stage(global.stage);
for (const widget of this._backgroundGroup.get_children()) {
widget.get_effect('blur').set({
brightness: blur_brightness * 0.01,
sigma: blur_strength * themeContext.scale_factor,
});
}
blurEnabled = true;
function _showPrompt_BWP() {
promptActive = true;
this._showPrompt_GNOME(); // pass to default GNOME function
this._updateBackgroundEffects();
}

var Blur = class Blur {
constructor() {
this.enabled = false;
log('Bing Wallpaper adjustable blur is '+supportedVersion()?'available':'not available');
}

set_blur_strength(value) {
if (value > 100 )
value = 100;
if (value < 0 )
value = 0;
blur_strength = value;
log("lockscreen blur strength set to "+value);
BWP_BLUR_SIGMA = this._clampValue(value);
log("lockscreen blur strength set to "+BWP_BLUR_SIGMA);
}

set_blur_brightness(value) {
BWP_BLUR_BRIGHTNESS = this._clampValue(value);
log("lockscreen brightness set to " + BWP_BLUR_BRIGHTNESS);
}

// valid values are 0 to 100
_clampValue(value) {
if (value > 100)
value = 100;
if (value < 0 )
value = 0;
blur_brightness = value;
log("lockscreen brightness set to " + value);
return value;
}

_switch(enabled) {
if (enabled) {
if (enabled && !this.enabled) {
this._enable();
}
else {
Expand All @@ -108,44 +121,45 @@ var Blur = class Blur {
}

_enable() {
log("_enable() called on GNOME "+imports.misc.config.PACKAGE_VERSION);
if (blurMode == 1) {
UnlockDialog.prototype._createBackground = this._do_blur_v1;
}
else if (blurMode == 2) {
UnlockDialog.prototype._updateBackgroundEffects = this._do_blur_v2;
}
else {
log("shell version too old, no overriding");
if (supportedVersion()) {
log("Blur._enable() called on GNOME "+imports.misc.config.PACKAGE_VERSION);
UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects_BWP;
// we override _showClock and _showPrompt to patch in updates to blur effect before calling the GNOME functions
UnlockDialog.prototype._showClock = _showClock_BWP;
UnlockDialog.prototype._showPrompt = _showPrompt_BWP;

// this are the original functions which we call into from our versions above
UnlockDialog.prototype._showClock_GNOME = _showClock;
UnlockDialog.prototype._showPrompt_GNOME = _showPrompt;

}
this.enabled = true;
}

_disable() {
if (blurEnabled == false) // nothing to do, don't clash without other extensions that do the same
if (!this.enabled)
return;
log("_lockscreen_blur_disable() called");
if (blurMode == 1) {
UnlockDialog.prototype._createBackground = _createBackground;
}
else if (blurMode == 2) {
if (supportedVersion()) {
// restore default functions
UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects;
UnlockDialog.prototype._showClock = _showClock;
UnlockDialog.prototype._showPrompt = _showPrompt;
// clean up unused functions we created
UnlockDialog.prototype._showClock_GNOME = null;
delete UnlockDialog.prototype._showClock_GNOME;
UnlockDialog.prototype._showPrompt_GNOME = null;
delete UnlockDialog.prototype._showPrompt_GNOME;
}
else {
log("shell version too old, no overriding");
}
this.enabled = false;
}
};

function whichVersion() {
if ((shellVersionMajor == 3 && shellVersionMinor >= 36) || shellVersionMajor >= 40) {
if (shellVersionMajor == 3 && shellVersionMinor == 36 && shellVersionPoint <= 3) {
return 1;
}
else {
return 2;
}
}
else {
return 0;
function supportedVersion() { // when current lockscren blur implementation was first shipped (we ignore earlier weird version)
if (shellVersionMajor >= 40 ||
(shellVersionMajor == 3 && shellVersionMinor == 36 && shellVersionPoint >= 4)) {
return true;
}

return false;
}
1 change: 1 addition & 0 deletions carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var Carousel = class Carousel {
this.flowBox = null;
this.window = null;
this.imageList = Utils.imageListSortByDate(Utils.getImageList(this.settings)).reverse(); // get images and reverse order
this.searchEntry = null;

this.log('create carousel...');

Expand Down
Loading

0 comments on commit 33a35fc

Please sign in to comment.