Skip to content

Commit

Permalink
Merge pull request #8 from andr3slelouch/development
Browse files Browse the repository at this point in the history
Gnome 40 compability
  • Loading branch information
andr3slelouch authored Apr 12, 2021
2 parents b769610 + 36824b3 commit 089c170
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 30 deletions.
55 changes: 29 additions & 26 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/**
Optimus Manager Indicator for GNOME Shell
Copyright (C) 2020 Andrés Andrade <https://github.com/andr3slelouch>
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 <http://www.gnu.org/licenses/>.
**/
Expand Down Expand Up @@ -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;
Expand All @@ -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.
*/
Expand All @@ -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.
Expand All @@ -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"
)
);
/**
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -428,4 +431,4 @@ function getSettings() {
throw new Error("Cannot find schemas");
}
return new Gio.Settings({ settings_schema: schemaObj });
}
}
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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"
}
69 changes: 69 additions & 0 deletions prefs.glade
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<!-- n-columns=2 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="show_temp_lbl">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Always show GPU Temperature</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="change_temp_swc">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="restart_gnome_shell_lbl">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="save_prefs_btn">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="cancel_btn">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</interface>
2 changes: 0 additions & 2 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function buildPrefsWidget() {
);

let grid = new Gtk.Grid({
margin: 12,
column_spacing: 12,
row_spacing: 12,
halign: Gtk.Align.CENTER,
Expand Down Expand Up @@ -45,6 +44,5 @@ function buildPrefsWidget() {
settings.set_boolean("always-show-gpu-temperature", field.get_state());
});

grid.show_all();
return grid;
}
58 changes: 58 additions & 0 deletions prefs.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="PrefsWidget" parent="GtkGrid">
<property name="can-focus">0</property>
<child>
<object class="GtkLabel" id="show_temp_lbl">
<property name="can-focus">0</property>
<property name="label" translatable="yes">Always show GPU Temperature</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkSwitch" id="change_temp_swc">
<layout>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="restart_gnome_shell_lbl">
<property name="can-focus">0</property>
<property name="label" translatable="yes">Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes</property>
<layout>
<property name="column">0</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="save_prefs_btn">
<property name="label" translatable="yes">Save</property>
<property name="receives-default">1</property>
<layout>
<property name="column">0</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="cancel_btn">
<property name="label" translatable="yes">Cancel</property>
<property name="receives-default">1</property>
<layout>
<property name="column">1</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<placeholder/>
</child>
</template>
</interface>
58 changes: 58 additions & 0 deletions prefs_gtk4.glade
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkGrid">
<property name="can-focus">0</property>
<child>
<object class="GtkLabel" id="show_temp_lbl">
<property name="can-focus">0</property>
<property name="label" translatable="yes">Always show GPU Temperature</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkSwitch" id="change_temp_swc">
<layout>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="restart_gnome_shell_lbl">
<property name="can-focus">0</property>
<property name="label" translatable="yes">Restart Gnome Shell (alt + F2, type r and hit ENTER) to see the changes</property>
<layout>
<property name="column">0</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="save_prefs_btn">
<property name="label" translatable="yes">Save</property>
<property name="receives-default">1</property>
<layout>
<property name="column">0</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="cancel_btn">
<property name="label" translatable="yes">Cancel</property>
<property name="receives-default">1</property>
<layout>
<property name="column">1</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<placeholder/>
</child>
</object>
</interface>
Loading

0 comments on commit 089c170

Please sign in to comment.