forked from Fmstrat/wintile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
219 lines (195 loc) · 6.66 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
'use strict';
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Gettext = imports.gettext;
const _ = Gettext.domain('wintile').gettext;
let gschema = Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_child('schemas').get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);
const gsettings = new Gio.Settings({
settings_schema: gschema.lookup('org.gnome.shell.extensions.wintile', true)
});
function init() {
}
function createColOptions(){
let options = [
{ name: _("2") },
{ name: _("3") },
{ name: _("4"),}
];
let liststore = new Gtk.ListStore();
liststore.set_column_types([GObject.TYPE_STRING])
for (let i = 0; i < options.length; i++ ) {
let option = options[i];
let iter = liststore.append();
liststore.set (iter, [0], [option.name]);
}
return liststore;
}
function buildPrefsWidget() {
let rendererText = new Gtk.CellRendererText();
// Create a parent widget that we'll return from this function
let layout = new Gtk.Grid({
margin: 18,
column_spacing: 12,
row_spacing: 12,
visible: true
});
let row = 0;
// Add a simple title and add it to the layout
let title = new Gtk.Label({
label: `<b>${Me.metadata.name} Extension Preferences</b>`,
halign: Gtk.Align.CENTER,
use_markup: true,
visible: true
});
layout.attach(title, 0, row++, 2, 1);
// Column setting
let colsLabel = new Gtk.Label({
label: _("Number of columns"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let colsInput = new Gtk.ComboBox({
model: createColOptions(),
visible: true
});
colsInput.pack_start (rendererText, false);
colsInput.add_attribute (rendererText, "text", 0);
layout.attach(colsLabel, 0, row, 1, 1);
layout.attach(colsInput, 1, row++, 1, 1);
// Maximize setting
let maximizeLabel = new Gtk.Label({
label: _("Use true maximizing of windows"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let maximizeInput = new Gtk.Switch({
active: gsettings.get_boolean ('use-maximize'),
halign: Gtk.Align.END,
visible: true
});
layout.attach(maximizeLabel, 0, row, 1, 1);
layout.attach(maximizeInput, 1, row++, 1, 1);
// Preview settings
let previewEnabled = gsettings.get_boolean ('preview');
let previewLabel = new Gtk.Label({
label: _("Enable preview and snapping when dragging windows"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let previewInput = new Gtk.Switch({
active: previewEnabled,
halign: Gtk.Align.END,
visible: true
});
layout.attach(previewLabel, 0, row, 1, 1);
layout.attach(previewInput, 1, row++, 1, 1);
// Double width previews
let doubleWidthLabel = new Gtk.Label({
label: _(" Use double width previews on sides in 4 column mode"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let doubleWidthInput = new Gtk.Switch({
active: gsettings.get_boolean ('double-width'),
halign: Gtk.Align.END,
visible: true
});
layout.attach(doubleWidthLabel, 0, row, 1, 1);
layout.attach(doubleWidthInput, 1, row++, 1, 1);
// Preview distance
let previewDistanceLabel = new Gtk.Label({
label: _(" Pixels from edge to start preview"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let previewDistanceInput = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
visible: true
});
let previewDistanceAdjustment = new Gtk.Adjustment({
lower: 0,
upper: 150,
step_increment: 1
});
let previewDistanceSettingInt = new Gtk.SpinButton({
adjustment: previewDistanceAdjustment,
snap_to_ticks: true,
visible: true
});
previewDistanceSettingInt.set_value(gsettings.get_int('distance'));
previewDistanceInput.add(previewDistanceSettingInt);
layout.attach(previewDistanceLabel, 0, row, 1, 1);
layout.attach(previewDistanceInput, 1, row++, 1, 1);
// Delay
let previewDelayLabel = new Gtk.Label({
label: _(" Delay in ms before preview dislpays"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let previewDelayInput = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
visible: true
});
let previewDelayAdjustment = new Gtk.Adjustment({
lower: 100,
upper: 1000,
step_increment: 1
});
let previewDelaySettingInt = new Gtk.SpinButton({
adjustment: previewDelayAdjustment,
snap_to_ticks: true,
visible: true
});
previewDelaySettingInt.set_value(gsettings.get_int('delay'));
previewDelayInput.add(previewDelaySettingInt);
layout.attach(previewDelayLabel, 0, row, 1, 1);
layout.attach(previewDelayInput, 1, row++, 1, 1);
// Debug setting
let debugLabel = new Gtk.Label({
label: _("Turn on debugging"),
visible: true,
hexpand: true,
halign: Gtk.Align.START
});
let debugInput = new Gtk.Switch({
active: gsettings.get_boolean ('debug'),
halign: Gtk.Align.END,
visible: true
});
layout.attach(debugLabel, 0, row, 1, 1);
layout.attach(debugInput, 1, row++, 1, 1);
gsettings.bind('cols', colsInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('use-maximize', maximizeInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('preview', previewInput, 'active', Gio.SettingsBindFlags.DEFAULT);
gsettings.bind('double-width', doubleWidthInput, 'active', Gio.SettingsBindFlags.DEFAULT);
previewDistanceSettingInt.connect('value-changed', function(entry) {
gsettings.set_int('distance', entry.value);
});
previewDelaySettingInt.connect('value-changed', function(entry) {
gsettings.set_int('delay', entry.value);
});
gsettings.bind('debug', debugInput, 'active', Gio.SettingsBindFlags.DEFAULT);
let setDoubleWidthWidgetsEnabled = function(enabled) {
doubleWidthLabel.set_sensitive(enabled);
doubleWidthInput.set_sensitive(enabled);
};
setDoubleWidthWidgetsEnabled(previewEnabled);
previewInput.connect('state-set', function(widget, state) {
setDoubleWidthWidgetsEnabled(state);
});
// Return our widget which will be added to the window
return layout;
}