Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gnome-shell 42 and Libadwaita #54

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@
"ngettext": false
},
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
}
}
2 changes: 1 addition & 1 deletion metadata.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
147 changes: 141 additions & 6 deletions prefs.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
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();

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) {
Expand Down Expand Up @@ -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();

Expand All @@ -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);
}