diff --git a/.eslintrc.json b/.eslintrc.json index e6cf1f4..98f05ea 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -114,6 +114,6 @@ "ngettext": false }, "parserOptions": { - "ecmaVersion": 2017 + "ecmaVersion": 2018 } } diff --git a/metadata.json.in b/metadata.json.in index 5b8b705..8a9d005 100644 --- a/metadata.json.in +++ b/metadata.json.in @@ -3,7 +3,7 @@ "name": "GameMode", "description": "Status indicator for GameMode", "uuid": "@UUID@", - "shell-version": ["3.38", "40", "41"], + "shell-version": ["3.38", "40", "41", "42"], "version": "@VERSION@", "url": "@URL@", "original-author": "ckellner@redhat.com", diff --git a/prefs.js b/prefs.js index ae3410f..7b7e3c1 100644 --- a/prefs.js +++ b/prefs.js @@ -1,9 +1,3 @@ -const GObject = imports.gi.GObject; -const Gtk = imports.gi.Gtk; -const Gdk = imports.gi.Gdk; -const Lang = imports.lang; -const Gio = imports.gi.Gio; - const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); @@ -11,6 +5,10 @@ const Config = imports.misc.config; const [major] = Config.PACKAGE_VERSION.split('.'); const shellVersion = Number.parseInt(major); +const {Gdk, Gio, GObject, Gtk} = imports.gi; +const Adw = shellVersion >= 42 ? imports.gi.Adw : null; + + var GameModeSettings = GObject.registerClass(class GameModePrefWidget extends Gtk.ListBox { _init(params) { @@ -148,10 +146,132 @@ var GameModeSettings = GObject.registerClass(class GameModePrefWidget extends Gt } }); + +/*Gnome 42 - libadwaita implementation*/ + +const RowColorButton = shellVersion < 42 ? null : GObject.registerClass( + { + GTypeName: 'RowColorButton', + Properties: { + 'css-color': GObject.ParamSpec.string( + 'css-color', 'css color', + 'The currently selected color, as a valid css color spec.', + GObject.ParamFlags.READWRITE, '' + ) + } + }, + class RowColorButton extends Gtk.ColorButton { + + constructor(params) { + super(params); + this.bind_property_full( + 'css-color', this, 'rgba', + GObject.BindingFlags.SYNC_CREATE | + GObject.BindingFlags.BIDIRECTIONAL, + (_, target)=> { + let rgba = new Gdk.RGBA(); + rgba.parse(target); + return [true, rgba]; + }, + (_, target)=>[true, target.to_string()] + ); + } + }); + + +const SwitchActionRow = shellVersion < 42 ? null : GObject.registerClass( + { + GTypeName: 'SwitchActionRow', + Properties: { + 'active-key': GObject.ParamSpec.string( + 'active-key', 'Active key', + 'Key name in settings that stores the switch active property.', + GObject.ParamFlags.READWRITE, '' + ), + }, + }, + class SwitchActionRow extends Adw.ActionRow { + + constructor({active_key, ...args}) { + super(args); + this._settings = ExtensionUtils.getSettings(); + this._suffix_container = new Gtk.Box( + {orientation: Gtk.Orientation.HORIZONTAL} + ); + this._switch = new Gtk.Switch({valign: Gtk.Align.CENTER}); + + this.add_suffix(this._suffix_container); + this.add_suffix(this._switch); + this.set_activatable_widget(this._switch); + this.activeKey = active_key; + } + + get active_key() { + return this._active_key; + } + + set active_key(key) { + if (this.active_key === key) + return; + if (this._settings.settings_schema.get_key(key)) { + let schema_key = this._settings.settings_schema.get_key(key); + this.title = schema_key.get_summary(); + this.subtitle = schema_key.get_description(); + this._settings.bind(key, this._switch, 'active', + Gio.SettingsBindFlags.DEFAULT); + this._active_key = key; + this.notify('active-key'); + } + } + }); + + +const ColorActionRow = shellVersion < 42 ? null : GObject.registerClass( + { + GTypeName: 'ColorActionRow', + InternalChilds: ['color_btn'], + Properties: { + 'color-key': GObject.ParamSpec.string( + 'color-key', 'Color key', + 'Key name in settings that stores the selected color.', + GObject.ParamFlags.READWRITE, '' + ), + }, + }, + class ColorActionRow extends SwitchActionRow { + + constructor({color_key, ...args}) { + super(args); + this._color_btn = new RowColorButton({valign: Gtk.Align.CENTER}); + this._suffix_container.append(this._color_btn); + this.colorKey = color_key; + } + + get color_key() { + return this._color_key; + } + + set color_key(key) { + if (this.color_key === key) + return; + if (this._settings.settings_schema.get_key(key)) { + let schema_key = this._settings.settings_schema.get_key(key); + this._color_btn.set_tooltip_markup(schema_key.get_description()); + this._settings.bind(key, this._color_btn, 'css-color', + Gio.SettingsBindFlags.DEFAULT | + Gio.SettingsBindFlags.NO_SENSITIVITY); + this._color_key = key; + this.notify('color-key'); + } + } + }); + + function init() { ExtensionUtils.initTranslations(); } +// Gnome Shell < 42 function buildPrefsWidget() { let widget = new GameModeSettings(); @@ -161,3 +281,18 @@ function buildPrefsWidget() { return widget; } + +// Gnome Shell >= 42 +function fillPreferencesWindow(window) { + let settings_page = Adw.PreferencesPage.new(); + let main_group = Adw.PreferencesGroup.new(); + + main_group.add(new SwitchActionRow({active_key: 'emit-notifications'})); + main_group.add(new SwitchActionRow({active_key: 'always-show-icon'})); + main_group.add(new ColorActionRow( + {active_key: 'active-tint', color_key: 'active-color'})); + + settings_page.add(main_group); + window.add(settings_page); +} +