From 82962542fa5d993a28791efc3b72e009c9f45f38 Mon Sep 17 00:00:00 2001 From: andr3slelouch Date: Mon, 12 Apr 2021 14:25:44 -0500 Subject: [PATCH 1/2] Updated for compatibility with Gnome 40 Preferences are not working, but the main extension is --- extension.js | 55 ++++++++++++++++++++------------------ metadata.json | 4 +-- prefs.glade | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ prefs.js | 61 ++++++++++++------------------------------ prefs.ui | 58 ++++++++++++++++++++++++++++++++++++++++ prefs_gtk4.glade | 58 ++++++++++++++++++++++++++++++++++++++++ prefs_old.js | 50 +++++++++++++++++++++++++++++++++++ 7 files changed, 283 insertions(+), 72 deletions(-) create mode 100644 prefs.glade create mode 100644 prefs.ui create mode 100644 prefs_gtk4.glade create mode 100644 prefs_old.js diff --git a/extension.js b/extension.js index af60d02..e640e9e 100644 --- a/extension.js +++ b/extension.js @@ -1,17 +1,14 @@ /** Optimus Manager Indicator for GNOME Shell Copyright (C) 2020 Andrés Andrade - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . **/ @@ -51,10 +48,12 @@ let notifySwitch = let nvidiaSettings = "nvidia-settings -p 'PRIME Profiles'"; let panelTempText, timeout; -var OptimusManagerDialog = GObject.registerClass( - class OptimusManagerDialog extends ModalDialog.ModalDialog { - _init(mode) { - super._init({ +const OptimusManagerDialog = new Lang.Class({ + Name: "OptimusManagerDialog", + Extends: ModalDialog.ModalDialog, + + _init: function(mode) { + this.parent({ styleClass: "extension-dialog", }); this._mode = mode; @@ -77,27 +76,29 @@ var OptimusManagerDialog = GObject.registerClass( }); this.contentLayout.add(content); - } + }, - _onNoButtonPressed() { + _onNoButtonPressed: function() { this.close(); this._invocation.return_value(GLib.Variant.new("(s)", ["cancelled"])); - } + }, - _onYesButtonPressed() { + _onYesButtonPressed: function() { var switching = { Intel: intelSwitch, Hybrid: hybridSwitch, Nvidia: nvidiaSwitch, }; // var [ok, out, err, exit] = GLib.spawn_command_line_sync(notifySwitch); + var [ok, out, err, exit] = GLib.spawn_command_line_sync( + "prime-offload" + ); var [ok, out, err, exit] = GLib.spawn_command_line_sync( switching[this._mode] ); this.close(); - } - } -); + }, + }); /** * Behold the Optimus Manager Indicator Indicator class. */ @@ -119,14 +120,15 @@ const OptimusManagerIndicator = new Lang.Class({ this._detectPrimeState(); - let topBox = new St.BoxLayout(); + let topBox = new St.BoxLayout({ vertical: false, style_class: 'panel-status-menu-box' }); panelTempText = new St.Label({ + y_expand: true, y_align: Clutter.ActorAlign.CENTER, text: "", }); - topBox.add_actor(this.statusIcon); - topBox.add_actor(panelTempText); - this.add_actor(topBox); + topBox.add_child(this.statusIcon); + topBox.add_child(panelTempText); + this.add_child(topBox); /** * Create all menu items. @@ -135,25 +137,25 @@ const OptimusManagerIndicator = new Lang.Class({ this.nvidiaProfiles = new PopupMenu.PopupImageMenuItem( "NVIDIA PRIME Profiles", Gio.icon_new_for_string( - Me.path + "/icons/primeindicatornvidiasymbolic.svg" + Me.dir.get_child('icons').get_path() + "/primeindicatornvidiasymbolic.svg" ) ); this.switchIntel = new PopupMenu.PopupImageMenuItem( "Switch to INTEL", Gio.icon_new_for_string( - Me.path + "/icons/primeindicatorintelsymbolic.svg" + Me.dir.get_child('icons').get_path() + "/primeindicatorintelsymbolic.svg" ) ); this.switchHybrid = new PopupMenu.PopupImageMenuItem( "Switch to HYBRID", Gio.icon_new_for_string( - Me.path + "/icons/primeindicatorhybridsymbolic.svg" + Me.dir.get_child('icons').get_path() + "/primeindicatorhybridsymbolic.svg" ) ); this.switchNvidia = new PopupMenu.PopupImageMenuItem( "Switch to NVIDIA", Gio.icon_new_for_string( - Me.path + "/icons/primeindicatornvidiasymbolic.svg" + Me.dir.get_child('icons').get_path() + "/primeindicatornvidiasymbolic.svg" ) ); /** @@ -216,8 +218,9 @@ const OptimusManagerIndicator = new Lang.Class({ * This function would check the optimus manager status */ _detectPrimeState: function () { - let settings = getSettings(); - let forcedMode = settings.get_boolean("always-show-gpu-temperature"); + //let settings = getSettings(); + //let forcedMode = settings.get_boolean("always-show-gpu-temperature"); + let forcedMode = false; if (forcedMode) { this.gpu_mode = "forced"; this._setIcon("nvidia"); @@ -376,7 +379,7 @@ const OptimusManagerIndicator = new Lang.Class({ } this.iconName = iconName; this.statusIcon.gicon = Gio.icon_new_for_string( - Me.path + "/icons/primeindicator" + iconName + "symbolic.svg" + Me.dir.get_child('icons').get_path() + "/primeindicator" + iconName + "symbolic.svg" ); }, _setTemp: function () { @@ -428,4 +431,4 @@ function getSettings() { throw new Error("Cannot find schemas"); } return new Gio.Settings({ settings_schema: schemaObj }); -} +} \ No newline at end of file diff --git a/metadata.json b/metadata.json index ce7bb70..a2afa1c 100644 --- a/metadata.json +++ b/metadata.json @@ -2,7 +2,7 @@ "name": "Optimus Manager Indicator", "description": "Intel/Hybrid/NVIDIA GPU Switch Note: The GPU mode activated doesn't show up in the options, by example: When you turn on the PC you are gonna be in Intel mode so Intel option is not gonna be shown. Note: Optimus Manager Indicator is made(for the moment) for Arch based distributions with optimus-manager.", "uuid": "optimus-manager-indicator@andr3slelouch.github.com", - "shell-version": ["3.36", "3.38"], - "version": 4, + "shell-version": ["3.36", "3.38", "40.0"], + "version": 5, "url": "https://github.com/andr3slelouch/Optimus-Manager-Indicator" } diff --git a/prefs.glade b/prefs.glade new file mode 100644 index 0000000..ada45ac --- /dev/null +++ b/prefs.glade @@ -0,0 +1,69 @@ + + + + + + + True + False + + + True + False + Always show GPU Temperature + + + 0 + 0 + + + + + True + True + + + 1 + 0 + + + + + True + False + Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes + + + 0 + 1 + + + + + Save + True + True + True + + + 0 + 2 + + + + + Cancel + True + True + True + + + 1 + 2 + + + + + + + diff --git a/prefs.js b/prefs.js index 0dd3501..6b0a128 100644 --- a/prefs.js +++ b/prefs.js @@ -1,50 +1,23 @@ -const GObject = imports.gi.GObject; -const Gtk = imports.gi.Gtk; +const {GObject, Gtk} = imports.gi; const ExtensionUtils = imports.misc.extensionUtils; -const Me = imports.misc.extensionUtils.getCurrentExtension(); +const Me = ExtensionUtils.getCurrentExtension(); + +const PrefsWidget = GObject.registerClass({ + GTypeName: 'PrefsWidget', + Template: Me.dir.get_child('prefs.ui').get_uri(), +}, class PrefsWidget extends Gtk.Grid { + + _init(params = {}) { + super._init(params); + } + + _onButtonClicked(button) { + button.set_label('Clicked!'); + } +}); function init() {} function buildPrefsWidget() { - let settings = ExtensionUtils.getSettings( - "org.gnome.shell.extensions.optimus-manager-indicator" - ); - - let grid = new Gtk.Grid({ - margin: 12, - column_spacing: 12, - row_spacing: 12, - halign: Gtk.Align.CENTER, - }); - - let label = new Gtk.Label({ - label: "Always show GPU Temperature", - halign: Gtk.Align.START, - }); - grid.attach(label, 0, 0, 1, 1); - - let noteLabel = new Gtk.Label({ - label: "Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes", - halign: Gtk.Align.START, - }); - grid.attach(noteLabel, 0, 0, 1, 4); - - let field = new Gtk.Switch(); - grid.attach(field, 1, 0, 1, 1); - - // Save Button - let saveButton = new Gtk.Button({ - label: " Save Changes ", - visible: true, - }); - grid.attach(saveButton, 1, 50, 1, 1); - - field.set_state(settings.get_boolean("always-show-gpu-temperature")); - - saveButton.connect("clicked", (button) => { - settings.set_boolean("always-show-gpu-temperature", field.get_state()); - }); - - grid.show_all(); - return grid; + return new PrefsWidget(); } diff --git a/prefs.ui b/prefs.ui new file mode 100644 index 0000000..37d0d24 --- /dev/null +++ b/prefs.ui @@ -0,0 +1,58 @@ + + + + + \ No newline at end of file diff --git a/prefs_gtk4.glade b/prefs_gtk4.glade new file mode 100644 index 0000000..7b667c8 --- /dev/null +++ b/prefs_gtk4.glade @@ -0,0 +1,58 @@ + + + + + 0 + + + 0 + Always show GPU Temperature + + 0 + 0 + + + + + + + 1 + 0 + + + + + + 0 + Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes + + 0 + 1 + + + + + + Save + 1 + + 0 + 2 + + + + + + Cancel + 1 + + 1 + 2 + + + + + + + + diff --git a/prefs_old.js b/prefs_old.js new file mode 100644 index 0000000..0dd3501 --- /dev/null +++ b/prefs_old.js @@ -0,0 +1,50 @@ +const GObject = imports.gi.GObject; +const Gtk = imports.gi.Gtk; +const ExtensionUtils = imports.misc.extensionUtils; +const Me = imports.misc.extensionUtils.getCurrentExtension(); + +function init() {} + +function buildPrefsWidget() { + let settings = ExtensionUtils.getSettings( + "org.gnome.shell.extensions.optimus-manager-indicator" + ); + + let grid = new Gtk.Grid({ + margin: 12, + column_spacing: 12, + row_spacing: 12, + halign: Gtk.Align.CENTER, + }); + + let label = new Gtk.Label({ + label: "Always show GPU Temperature", + halign: Gtk.Align.START, + }); + grid.attach(label, 0, 0, 1, 1); + + let noteLabel = new Gtk.Label({ + label: "Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes", + halign: Gtk.Align.START, + }); + grid.attach(noteLabel, 0, 0, 1, 4); + + let field = new Gtk.Switch(); + grid.attach(field, 1, 0, 1, 1); + + // Save Button + let saveButton = new Gtk.Button({ + label: " Save Changes ", + visible: true, + }); + grid.attach(saveButton, 1, 50, 1, 1); + + field.set_state(settings.get_boolean("always-show-gpu-temperature")); + + saveButton.connect("clicked", (button) => { + settings.set_boolean("always-show-gpu-temperature", field.get_state()); + }); + + grid.show_all(); + return grid; +} From 36824b3c6b02336e02d8b40c72b8fd237de12fda Mon Sep 17 00:00:00 2001 From: andr3slelouch Date: Mon, 12 Apr 2021 14:49:38 -0500 Subject: [PATCH 2/2] Updated prefs.js for gnome 40 --- prefs.js | 59 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/prefs.js b/prefs.js index 6b0a128..fd14a44 100644 --- a/prefs.js +++ b/prefs.js @@ -1,23 +1,48 @@ -const {GObject, Gtk} = imports.gi; +const GObject = imports.gi.GObject; +const Gtk = imports.gi.Gtk; const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); - -const PrefsWidget = GObject.registerClass({ - GTypeName: 'PrefsWidget', - Template: Me.dir.get_child('prefs.ui').get_uri(), -}, class PrefsWidget extends Gtk.Grid { - - _init(params = {}) { - super._init(params); - } - - _onButtonClicked(button) { - button.set_label('Clicked!'); - } -}); +const Me = imports.misc.extensionUtils.getCurrentExtension(); function init() {} function buildPrefsWidget() { - return new PrefsWidget(); + let settings = ExtensionUtils.getSettings( + "org.gnome.shell.extensions.optimus-manager-indicator" + ); + + let grid = new Gtk.Grid({ + column_spacing: 12, + row_spacing: 12, + halign: Gtk.Align.CENTER, + }); + + let label = new Gtk.Label({ + label: "Always show GPU Temperature", + halign: Gtk.Align.START, + }); + grid.attach(label, 0, 0, 1, 1); + + let noteLabel = new Gtk.Label({ + label: "Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes", + halign: Gtk.Align.START, + }); + grid.attach(noteLabel, 0, 0, 1, 4); + + let field = new Gtk.Switch(); + grid.attach(field, 1, 0, 1, 1); + + // Save Button + let saveButton = new Gtk.Button({ + label: " Save Changes ", + visible: true, + }); + grid.attach(saveButton, 1, 50, 1, 1); + + field.set_state(settings.get_boolean("always-show-gpu-temperature")); + + saveButton.connect("clicked", (button) => { + settings.set_boolean("always-show-gpu-temperature", field.get_state()); + }); + + return grid; }