0 | |
const GObject = imports.gi.GObject;
|
1 | |
const Gtk = imports.gi.Gtk;
|
2 | |
const Gdk = imports.gi.Gdk;
|
3 | |
const Lang = imports.lang;
|
4 | |
const Gio = imports.gi.Gio;
|
5 | |
|
6 | 0 |
const ExtensionUtils = imports.misc.extensionUtils;
|
7 | 1 |
const Me = ExtensionUtils.getCurrentExtension();
|
8 | 2 |
|
9 | 3 |
const Config = imports.misc.config;
|
10 | 4 |
const [major] = Config.PACKAGE_VERSION.split('.');
|
11 | 5 |
const shellVersion = Number.parseInt(major);
|
|
6 |
|
|
7 |
const {Gdk, Gio, GObject, Gtk} = imports.gi;
|
|
8 |
const Adw = shellVersion >= 42 ? imports.gi.Adw : null;
|
|
9 |
|
12 | 10 |
|
13 | 11 |
var GameModeSettings = GObject.registerClass(class GameModePrefWidget extends Gtk.ListBox {
|
14 | 12 |
|
|
147 | 145 |
}
|
148 | 146 |
});
|
149 | 147 |
|
|
148 |
|
|
149 |
/*Gnome 42 - libadwaita implementation*/
|
|
150 |
|
|
151 |
const RowColorButton = shellVersion < 42 ? null : GObject.registerClass(
|
|
152 |
{
|
|
153 |
GTypeName: 'RowColorButton',
|
|
154 |
Properties: {
|
|
155 |
'css-color': GObject.ParamSpec.string(
|
|
156 |
'css-color', 'css color',
|
|
157 |
'The currently selected color, as a valid css color spec.',
|
|
158 |
GObject.ParamFlags.READWRITE, ''
|
|
159 |
)
|
|
160 |
}
|
|
161 |
},
|
|
162 |
class RowColorButton extends Gtk.ColorButton {
|
|
163 |
|
|
164 |
constructor(params) {
|
|
165 |
super(params);
|
|
166 |
this.bind_property_full(
|
|
167 |
'css-color', this, 'rgba',
|
|
168 |
GObject.BindingFlags.SYNC_CREATE |
|
|
169 |
GObject.BindingFlags.BIDIRECTIONAL,
|
|
170 |
(_, target)=> {
|
|
171 |
let rgba = new Gdk.RGBA();
|
|
172 |
rgba.parse(target);
|
|
173 |
return [true, rgba];
|
|
174 |
},
|
|
175 |
(_, target)=>[true, target.to_string()]
|
|
176 |
);
|
|
177 |
}
|
|
178 |
});
|
|
179 |
|
|
180 |
|
|
181 |
const SwitchActionRow = shellVersion < 42 ? null : GObject.registerClass(
|
|
182 |
{
|
|
183 |
GTypeName: 'SwitchActionRow',
|
|
184 |
Properties: {
|
|
185 |
'active-key': GObject.ParamSpec.string(
|
|
186 |
'active-key', 'Active key',
|
|
187 |
'Key name in settings that stores the switch active property.',
|
|
188 |
GObject.ParamFlags.READWRITE, ''
|
|
189 |
),
|
|
190 |
},
|
|
191 |
},
|
|
192 |
class SwitchActionRow extends Adw.ActionRow {
|
|
193 |
|
|
194 |
constructor({active_key, ...args}) {
|
|
195 |
super(args);
|
|
196 |
this._settings = ExtensionUtils.getSettings();
|
|
197 |
this._suffix_container = new Gtk.Box(
|
|
198 |
{orientation: Gtk.Orientation.HORIZONTAL}
|
|
199 |
);
|
|
200 |
this._switch = new Gtk.Switch({valign: Gtk.Align.CENTER});
|
|
201 |
|
|
202 |
this.add_suffix(this._suffix_container);
|
|
203 |
this.add_suffix(this._switch);
|
|
204 |
this.set_activatable_widget(this._switch);
|
|
205 |
this.activeKey = active_key;
|
|
206 |
}
|
|
207 |
|
|
208 |
get active_key() {
|
|
209 |
return this._active_key;
|
|
210 |
}
|
|
211 |
|
|
212 |
set active_key(key) {
|
|
213 |
if (this.active_key === key)
|
|
214 |
return;
|
|
215 |
if (this._settings.settings_schema.get_key(key)) {
|
|
216 |
let schema_key = this._settings.settings_schema.get_key(key);
|
|
217 |
this.title = schema_key.get_summary();
|
|
218 |
this.subtitle = schema_key.get_description();
|
|
219 |
this._settings.bind(key, this._switch, 'active',
|
|
220 |
Gio.SettingsBindFlags.DEFAULT);
|
|
221 |
this._active_key = key;
|
|
222 |
this.notify('active-key');
|
|
223 |
}
|
|
224 |
}
|
|
225 |
});
|
|
226 |
|
|
227 |
|
|
228 |
const ColorActionRow = shellVersion < 42 ? null : GObject.registerClass(
|
|
229 |
{
|
|
230 |
GTypeName: 'ColorActionRow',
|
|
231 |
InternalChilds: ['color_btn'],
|
|
232 |
Properties: {
|
|
233 |
'color-key': GObject.ParamSpec.string(
|
|
234 |
'color-key', 'Color key',
|
|
235 |
'Key name in settings that stores the selected color.',
|
|
236 |
GObject.ParamFlags.READWRITE, ''
|
|
237 |
),
|
|
238 |
},
|
|
239 |
},
|
|
240 |
class ColorActionRow extends SwitchActionRow {
|
|
241 |
|
|
242 |
constructor({color_key, ...args}) {
|
|
243 |
super(args);
|
|
244 |
this._color_btn = new RowColorButton({valign: Gtk.Align.CENTER});
|
|
245 |
this._suffix_container.append(this._color_btn);
|
|
246 |
this.colorKey = color_key;
|
|
247 |
}
|
|
248 |
|
|
249 |
get color_key() {
|
|
250 |
return this._color_key;
|
|
251 |
}
|
|
252 |
|
|
253 |
set color_key(key) {
|
|
254 |
if (this.color_key === key)
|
|
255 |
return;
|
|
256 |
if (this._settings.settings_schema.get_key(key)) {
|
|
257 |
let schema_key = this._settings.settings_schema.get_key(key);
|
|
258 |
this._color_btn.set_tooltip_markup(schema_key.get_description());
|
|
259 |
this._settings.bind(key, this._color_btn, 'css-color',
|
|
260 |
Gio.SettingsBindFlags.DEFAULT |
|
|
261 |
Gio.SettingsBindFlags.NO_SENSITIVITY);
|
|
262 |
this._color_key = key;
|
|
263 |
this.notify('color-key');
|
|
264 |
}
|
|
265 |
}
|
|
266 |
});
|
|
267 |
|
|
268 |
|
150 | 269 |
function init() {
|
151 | 270 |
ExtensionUtils.initTranslations();
|
152 | 271 |
}
|
153 | 272 |
|
|
273 |
// Gnome Shell < 42
|
154 | 274 |
function buildPrefsWidget() {
|
155 | 275 |
let widget = new GameModeSettings();
|
156 | 276 |
|
|
160 | 280 |
|
161 | 281 |
return widget;
|
162 | 282 |
}
|
|
283 |
|
|
284 |
// Gnome Shell >= 42
|
|
285 |
function fillPreferencesWindow(window) {
|
|
286 |
let settings_page = Adw.PreferencesPage.new();
|
|
287 |
let main_group = Adw.PreferencesGroup.new();
|
|
288 |
|
|
289 |
main_group.add(new SwitchActionRow({active_key: 'emit-notifications'}));
|
|
290 |
main_group.add(new SwitchActionRow({active_key: 'always-show-icon'}));
|
|
291 |
main_group.add(new ColorActionRow(
|
|
292 |
{active_key: 'active-tint', color_key: 'active-color'}));
|
|
293 |
|
|
294 |
settings_page.add(main_group);
|
|
295 |
window.add(settings_page);
|
|
296 |
}
|
|
297 |
|