bennypowers / gnome-shell-extension-firefox-pip

Make Firefox Picture-in-Picture window Always on Top
https://extensions.gnome.org/extension/5306/firefox-pip-always-on-top/
GNU General Public License v3.0
9 stars 3 forks source link

Add preferences #3

Closed Maickeli closed 12 months ago

Maickeli commented 1 year ago

Add preferences to adjust behavior, default settings keep the same behavior as before.

Add option to set initial position for PIP window.

bennypowers commented 1 year ago

Thanks for the issue! Great idea

Happy to review a PR. Please use dconf and latest adwaita widgets

Maickeli commented 1 year ago

Hey, I updated the widgets. First time fiddling around with a gnome extension, not sure how to use dconf and I'm yet to find any documentation about using it on gnome extension. I just looked up how some other extensions have made prefs and made these based on that.

If there is still some changes needed I would appreciate a link to some docs or examples.

bennypowers commented 12 months ago

i've seen a few git blow ups over the years but every so often i'm still surprised :) No clue why this pr was closed or why i can't open it again

In any event I was trying to push a commit onto your branch. Please apply the attached patches and continue work, replacing the GTK widgets with adwaita ones. Take a look at Blur My Shell (ui and js) for inspiration.

Please open a new PR, but please create a new branch, not main, in order to make it easier to work with.

patch ```diff diff --git a/extension.js b/extension.js index 2996295..862ecfe 100644 --- a/extension.js +++ b/extension.js @@ -28,7 +28,7 @@ class Extension { listenerId = 0; enable() { - this.settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.firefox-pip'); + this.settings = ExtensionUtils.getSettings(); this.listenerId = global.display.connect('window-created', (_, window) => window.get_compositor_private().connect('realize', () => diff --git a/prefs.js b/prefs.js index 05c795b..8d6b113 100644 --- a/prefs.js +++ b/prefs.js @@ -1,62 +1,42 @@ -const { Gio, Gtk, GObject } = imports.gi; +const { Adw, Gio, Gtk, GObject } = imports.gi; const Me = imports.misc.extensionUtils.getCurrentExtension(); const ExtensionUtils = imports.misc.extensionUtils; -const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']); -const _ = Gettext.gettext; - -const Settings = new GObject.Class({ - Name: 'FirefoxPIP.Settings', - - _init: function (params) { - this.parent(params); - - if (Me) { - this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.firefox-pip'); - } - else { - this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell.extensions.firefox-pip' }); - } - - this.builder = new Gtk.Builder(); - this.builder.set_translation_domain(Me.metadata['gettext-domain']); - this.builder.add_from_file(Me.path + '/prefs.ui'); - this.widget = this.builder.get_object('prefs-container'); - - this._bind_settings(); - }, - +const _ = imports.gettext.domain(Me.metadata.uuid).gettext; + +const FirefoxPIPSettings = new GObject.registerClass({ + GTypeName: 'FirefoxPIPSettings', + Template: `file://${GLib.build_filenamev([Me.path, 'prefs.ui'])}` +}, +class FirefoxPIPSettings extends Adw.PreferencesPage { + /** @private */ settings; + /** @private */ builder; + + _init({ settings }) { + super._init({ title: _("Settings"), icon_name: "settings-symbolic" }); + this.settings = settings; // Bind the gtk window to the schema settings - _bind_settings: function () { - let widget; - - // process toggles - let toggles = ['always-on-top', 'always-on-visible-workspace', - 'use-custom-position', - ]; - - for (let key in toggles) { - let toggle = toggles[key]; - - widget = this.builder.get_object(toggle); - widget.set_active(this._settings.get_boolean(toggle)); - widget.connect('state-set', (_, val) => { - this._settings.set_boolean(toggle, val); - }); - } - - this._settings.bind('position-x', this.builder.get_object('position-x'), 'value', Gio.SettingsBindFlags.DEFAULT); - this._settings.bind('position-y', this.builder.get_object('position-y'), 'value', Gio.SettingsBindFlags.DEFAULT); + for (const toggle of [ + 'always-on-top', + 'always-on-visible-workspace', + 'use-custom-position', + ]) { + const widget = this.builder.get_object(toggle); + widget.set_active(this.settings.get_boolean(toggle)); + widget.connect('state-set', (__, val) => { + this.settings.set_boolean(toggle, val); + }); } + + this.settings.bind('position-x', this.builder.get_object('position-x'), 'value', Gio.SettingsBindFlags.DEFAULT); + this.settings.bind('position-y', this.builder.get_object('position-y'), 'value', Gio.SettingsBindFlags.DEFAULT); + } }); function init() { ExtensionUtils.initTranslations(); } -function buildPrefsWidget() { - let settings = new Settings(); - let widget = settings.widget; - - widget.show(); - return widget; +function fillPreferencesWindow(window) { + const settings = ExtensionUtils.getSettings(); + window.add(new FirefoxPIPSettings({ settings })); } ```