-
Notifications
You must be signed in to change notification settings - Fork 22
/
prefs.js
128 lines (101 loc) · 3.58 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
/**
* These preferences menu for the Desktop Scroller are made by Bruuno Orlandi,
* brorlandi@gmail.com.
* Most of the code is borrowed from js/ui/altTab.js of the gnome-shell source
* code.
*/
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
const Gettext = imports.gettext.domain('desktop-scroller');
const _ = Gettext.gettext;
const N_ = function(e) { return e };
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const SCROLL_EDGES = 'scroll-edges';
const DESKTOP_SCROLL = 'desktop-scroll';
const EDGES = {
left: { flag: 1 << 0, name: N_("Left") },
right: { flag: 1 << 1, name: N_("Right") },
top: { flag: 1 << 2, name: N_("Top") },
bottom: { flag: 1 << 3, name: N_("Bottom") },
};
const DesktopScrollerSettingsWidget = new GObject.Class({
Name: 'DesktopScroller.Prefs.DesktopScrollerSettingsWidget',
GTypeName: 'DesktopScrollerSettingsWidget',
Extends: Gtk.Grid,
_init: function(params) {
this.parent(params);
this.margin = this.row_spacing = this.column_spacing = 10;
this._settings = Convenience.getSettings();
// Wallpaper scrolling
let label = new Gtk.Label({
label: _("Wallpaper Scrolling"),
wrap: true,
xalign: 0.0
});
let wallpaperSwitch = new Gtk.Switch({ halign: Gtk.Align.START });
wallpaperSwitch.active = this._settings.get_boolean(DESKTOP_SCROLL);
this._settings.bind(DESKTOP_SCROLL, wallpaperSwitch, 'active',
Gio.SettingsBindFlags.DEFAULT);
this.attach(label, 0, 0, 1, 1);
this.attach(wallpaperSwitch, 1, 0, 1, 1);
// Enabled edges
label = new Gtk.Label({
label: _("Enabled Edges"),
wrap: true,
xalign: 0.0
});
this.attach(label, 0, 1, 1, 1);
let left = 0;
let check = null;
let checkGrid = new Gtk.Grid({ halign: Gtk.Align.START });
checkGrid.margin = checkGrid.row_spacing = checkGrid.column_spacing = 10;
for (let edge_key in EDGES) {
let edge = EDGES[edge_key];
check = new Gtk.CheckButton({
label: _(edge.name),
halign: Gtk.Align.START
});
checkGrid.attach(check, left, 1, 1, 1);
check.connect('toggled', Lang.bind(this, function(widget) {
if (widget.active) {
enableEdge(this._settings, edge);
} else {
disableEdge(this._settings, edge);
}
}));
check.active = isEdgeEnabled(this._settings, edge);
left += 1;
}
this.attach(checkGrid, 1, 1, 1, 1);
},
});
function getEnabledEdges(settings) {
return settings.get_flags(SCROLL_EDGES);
}
function isEdgeEnabled(settings, edge) {
let edges = getEnabledEdges(settings);
return edges & edge.flag;
}
function disableEdge(settings, edge) {
let edges = getEnabledEdges(settings);
edges = edges & ~edge.flag;
settings.set_flags(SCROLL_EDGES, edges);
}
function enableEdge(settings, edge) {
let edges = getEnabledEdges(settings);
edges = edges | edge.flag;
settings.set_flags(SCROLL_EDGES, edges);
}
function init() {
Convenience.initTranslations();
}
function buildPrefsWidget() {
let widget = new DesktopScrollerSettingsWidget();
return widget;
}