summaryrefslogtreecommitdiffstats
path: root/impatience/extension.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:59:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:59:21 +0000
commitd8d06026cb993d02e6ab2304fabbda3b60d940b2 (patch)
treeba4d8c052c5ba93cbef35b46060e61fd737ed9af /impatience/extension.js
parentInitial commit. (diff)
downloadgnome-shell-extension-impatience-d8d06026cb993d02e6ab2304fabbda3b60d940b2.tar.xz
gnome-shell-extension-impatience-d8d06026cb993d02e6ab2304fabbda3b60d940b2.zip
Adding upstream version 0.4.5.upstream/0.4.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'impatience/extension.js')
-rw-r--r--impatience/extension.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/impatience/extension.js b/impatience/extension.js
new file mode 100644
index 0000000..2dde979
--- /dev/null
+++ b/impatience/extension.js
@@ -0,0 +1,61 @@
+const St = imports.gi.St;
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+const DEFAULT_SPEED = 0.75;
+const ExtensionUtils = imports.misc.extensionUtils;
+const Extension = ExtensionUtils.getCurrentExtension();
+const Settings = Extension.imports.settings;
+
+function LOG(m){
+ global.log("[impatience] " + m);
+ log("[impatience] " + m);
+};
+function Ext() {
+ this._init.apply(this, arguments);
+};
+var noop = function() {};
+
+Ext.prototype = {};
+Ext.prototype._init = function() {
+ this.enabled = false;
+ this.original_speed = St.get_slow_down_factor();
+ this.modified_speed = DEFAULT_SPEED;
+ this.unbind = noop;
+};
+
+Ext.prototype.enable = function() {
+ this.enabled = true;
+ var pref = (new Settings.Prefs()).SPEED;
+ LOG("enabled");
+ var binding = pref.changed(Lang.bind(this, function() {
+ this.set_speed(pref.get());
+ }));
+ this.unbind = function() {
+ pref.disconnect(binding);
+ this.unbind = noop;
+ };
+ this.set_speed(pref.get());
+};
+
+Ext.prototype.disable = function() {
+ this.enabled = false;
+ this.unbind();
+ St.set_slow_down_factor(this.original_speed);
+};
+
+Ext.prototype.set_speed = function(new_speed) {
+ if(!this.enabled) {
+ LOG("NOT setting new speed, since the extension is disabled.");
+ return;
+ }
+ if(new_speed !== undefined) {
+ this.modified_speed = new_speed;
+ }
+ LOG("setting new speed: " + this.modified_speed);
+ St.set_slow_down_factor(this.modified_speed);
+};
+
+function init() {
+ return new Ext();
+};
+