forked from neffo/bing-wallpaper-gnome-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blur.js
147 lines (131 loc) · 4.99 KB
/
blur.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2021 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (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
const St = imports.gi.St;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Background = imports.ui.background;
const UnlockDialog = imports.ui.unlockDialog.UnlockDialog;
const ExtensionUtils = imports.misc.extensionUtils;
var _createBackground = UnlockDialog.prototype._createBackground;
var _updateBackgroundEffects = UnlockDialog.prototype._updateBackgroundEffects;
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;
var debug = false;
var blurMode = whichVersion();
function log(msg) {
if (debug)
print("BingWallpaper extension/Blur: " + msg); // disable to keep the noise down in journal
}
var Blur = class Blur {
constructor() {
log('Blur mode is '+blurMode);
}
_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);
}
_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,
});
}
}
set_blur_strength(value) {
if (value > 100 )
value = 100;
if (value < 0 )
value = 0;
blur_strength = value;
log("lockscreen blur strength set to "+value);
}
set_blur_brightness(value) {
if (value > 100)
value = 100;
if (value < 0 )
value = 0;
blur_brightness = value;
log("lockscreen brightness set to " + value);
}
_switch(enabled) {
if (enabled) {
this._enable();
}
else {
this._disable();
}
}
_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");
}
}
_disable() {
log("_lockscreen_blur_disable() called");
if (blurMode == 1) {
UnlockDialog.prototype._createBackground = _createBackground;
}
else if (blurMode == 2) {
UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects;
}
else {
log("shell version too old, no overriding");
}
}
};
function whichVersion() {
if ((shellVersionMajor == 3 && shellVersionMinor >= 36) || shellVersionMajor == 40) {
if (shellVersionMajor == 3 && shellVersionMinor == 36 && shellVersionPoint <= 3) {
return 1;
}
else {
return 2;
}
}
else {
return 0;
}
}