-
Notifications
You must be signed in to change notification settings - Fork 27
/
prefs.js
134 lines (117 loc) · 5.06 KB
/
prefs.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
'use strict';
const {GObject, Gdk, Gtk} = imports.gi;
// It's common practice to keep GNOME API and JS imports in separate blocks
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const JConstants = Me.imports.constants;
const JLog = Me.imports.log;
const JSettings = Me.imports.settings;
const {Effects} = Me.imports.effects;
let provider = new Gtk.CssProvider();
provider.load_from_path(Me.dir.get_path() + '/prefs.css');
if (JConstants.IS_GNOME_40) {
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} else {
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
const PrefsWidget = GObject.registerClass({
GTypeName: 'PrefsWidget',
CssName: 'PrefsWidget',
Template: Me.dir.get_child('ui').get_child(JConstants.IS_GNOME_40 ? 'gtk4.ui' : 'gtk3.ui').get_uri(),
// required to enable reading children from template
InternalChildren: [
// main settings
'effect',
'shake_threshold',
'log_level',
// effects switcher and children
'effect_stack',
'jiggle_opts_cursor_scaling',
'jiggle_opts_fireworks',
'jiggle_opts_spotlight',
'jiggle_opts_trail',
// Cursor Scaling settings
'use_system',
'hide_original',
'growth_speed',
'shrink_speed',
// Fireworks settings
'fireworks_burst_speed',
'fireworks_spark_count',
'fireworks_spark_trail',
// Spotlight settings
'spotlight_size',
'spotlight_show_speed',
'spotlight_hide_speed',
// Trail settings
'trail_speed',
],
}, class PrefsWidget extends Gtk.Box {
_init(params = {}) {
super._init(params);
this._settings = JSettings.settings();
let effect = this._settings.get_value('effect').deep_unpack();
// set the main effect combobox value
this._effect.set_active(effect);
this._shake_threshold.set_value(this._settings.get_value('shake-threshold').deep_unpack());
this._log_level.set_active(this._settings.get_value('log-level').deep_unpack());
this._use_system.set_active(this._settings.get_value('use-system').deep_unpack());
this._hide_original.set_active(this._settings.get_value('hide-original').deep_unpack());
this._growth_speed.set_value(this._settings.get_value('growth-speed').deep_unpack());
this._shrink_speed.set_value(this._settings.get_value('shrink-speed').deep_unpack());
this._fireworks_burst_speed.set_value(this._settings.get_value('fireworks-burst-speed').deep_unpack());
this._fireworks_spark_count.set_value(this._settings.get_value('fireworks-spark-count').deep_unpack());
this._fireworks_spark_trail.set_value(this._settings.get_value('fireworks-spark-trail').deep_unpack());
this._spotlight_size.set_value(this._settings.get_value('spotlight-size').deep_unpack());
this._spotlight_show_speed.set_value(this._settings.get_value('spotlight-show-speed').deep_unpack());
this._spotlight_hide_speed.set_value(this._settings.get_value('spotlight-hide-speed').deep_unpack());
this._trail_speed.set_value(this._settings.get_value('trail-speed').deep_unpack());
this._setActiveEffect(effect);
}
_getGSettingsKeyFromWidgetName(widget) {
return widget.get_name().replace(/_/g, '-');
}
_onEffectChanged(widget) {
let effect = widget.get_active();
// set the value in the settings
this._settings.set_int(this._getGSettingsKeyFromWidgetName(widget), effect);
this._setActiveEffect(effect)
}
_onLogLevelChanged(widget) {
let level = widget.get_active();
this._settings.set_int(this._getGSettingsKeyFromWidgetName(widget), level);
JLog.setLogLevel(level);
}
_onScaleFloatValueChanged(widget) {
this._settings.set_double(this._getGSettingsKeyFromWidgetName(widget), widget.get_value());
}
_onScaleIntValueChanged(widget) {
this._settings.set_int(this._getGSettingsKeyFromWidgetName(widget), widget.get_value());
}
_onSwitchStateSet(widget, state) {
this._settings.set_boolean(this._getGSettingsKeyFromWidgetName(widget), state);
widget.set_active(state);
}
_setActiveEffect(effect) {
let child = "cursor_scaling";
switch (effect) {
case Effects.FIREWORKS:
child = "fireworks";
break;
case Effects.SPOTLIGHT:
child = "spotlight";
break;
case Effects.TRAIL:
child = "trail";
break;
}
this._effect_stack.set_visible_child(this["_jiggle_opts_"+child]);
}
});
// Like `extension.js` this is used for any one-time setup like translations.
function init() {
}
// This function is called when the preferences window is first created to build and return a Gtk widget.
function buildPrefsWidget() {
return new PrefsWidget();
}