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

Added the possibility to rearrange the graphs #700

Merged
merged 1 commit into from
Jan 22, 2023
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
37 changes: 26 additions & 11 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2439,20 +2439,35 @@ function enable() {
};

// Items to Monitor
Main.__sm.elts = createCpus();
Main.__sm.elts.push(new Freq());
Main.__sm.elts.push(new Mem());
Main.__sm.elts.push(new Swap());
Main.__sm.elts.push(new Net());
Main.__sm.elts.push(new Disk());
Main.__sm.elts.push(new Gpu());
Main.__sm.elts.push(new Thermal());
Main.__sm.elts.push(new Fan());
Main.__sm.elts.push(new Battery());

let tray = Main.__sm.tray;
let elts = Main.__sm.elts;

// Load the preferred position of the displays and insert them in said order.
const positionList = {};
// CPUs are inserted differently, so cpu-position is stored apart
const cpuPosition = Schema.get_int('cpu-position');
positionList[cpuPosition] = createCpus();
positionList[Schema.get_int('freq-position')] = new Freq();
positionList[Schema.get_int('memory-position')] = new Mem();
positionList[Schema.get_int('swap-position')] = new Swap();
positionList[Schema.get_int('net-position')] = new Net();
positionList[Schema.get_int('disk-position')] = new Disk();
positionList[Schema.get_int('gpu-position')] = new Gpu();
positionList[Schema.get_int('thermal-position')] = new Thermal();
positionList[Schema.get_int('fan-position')] = new Fan();
positionList[Schema.get_int('battery-position')] = new Battery();

for (let i = 0; i < Object.keys(positionList).length; i++) {
if (i === cpuPosition) {
// CPUs are in an array, store them one by one
for (let cpu of positionList[cpuPosition]) {
elts.push(cpu);
}
} else {
elts.push(positionList[i]);
}
}

if (Schema.get_boolean('move-clock')) {
let dateMenu = Main.panel.statusArea.dateMenu;
Main.panel._centerBox.remove_actor(dateMenu.container);
Expand Down
27 changes: 25 additions & 2 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,26 @@ const SettingFrame = class SystemMonitor {

const App = class SystemMonitor_App {
constructor() {
let setting_items = ['cpu', 'memory', 'swap', 'net', 'disk', 'gpu', 'thermal', 'fan', 'freq', 'battery'];
let setting_names = ['cpu', 'memory', 'swap', 'net', 'disk', 'gpu', 'thermal', 'fan', 'freq', 'battery'];
let ordered_items = {};
let setting_items = [];
// Get preferred position of the tabs
for (let item of setting_names) {
ordered_items[Schema.get_int(item + '-position')] = item;
}
// Populate setting_items with the names in order of preference
for (let i = 0; i < Object.keys(ordered_items).length; i++) {
setting_items.push(ordered_items[i]);
}
let keys = Schema.list_keys();

this.items = [];
this.settings = [];
this.frameToLabel = {}; // Maps Gtk.Widget to the English name of the setting

setting_items.forEach((setting) => {
this.settings[setting] = new SettingFrame(_(setting.capitalize()), Schema);
this.frameToLabel[this.settings[setting].frame] = setting;
});

this.main_vbox = box({
Expand Down Expand Up @@ -531,9 +543,20 @@ const App = class SystemMonitor_App {
}
}
});
this.notebook = new Gtk.Notebook()

this.notebook = new Gtk.Notebook();
this.notebook.connect('page-reordered', (widget_, pageNum_) => {
// After a page has been moved, update the order preferences
for (let i = 0; i < this.notebook.get_n_pages(); i++) {
let frame = this.notebook.get_nth_page(i);
let name = this.frameToLabel[frame];
Schema.set_int(name + '-position', i);
}
});

setting_items.forEach((setting) => {
this.notebook.append_page(this.settings[setting].frame, this.settings[setting].label)
this.notebook.set_tab_reorderable(this.settings[setting].frame, true);
if (shellMajorVersion < 40) {
this.main_vbox.show_all();
this.main_vbox.pack_start(this.notebook, true, true, 0)
Expand Down
Binary file modified [email protected]/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,46 @@
<default>false</default>
<summary>Hide system battery icon</summary>
</key>
<key name="cpu-position" type="i">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon change the indentation of these new settings to match the others. Might as well fix up the indentation of the other elements too while we're at it.

<default>0</default>
<summary>Position in which to display the CPU display</summary>
</key>
<key name="freq-position" type="i">
<default>1</default>
<summary>Position in which to display the frequency display</summary>
</key>
<key name="memory-position" type="i">
<default>2</default>
<summary>Position in which to display the memory display</summary>
</key>
<key name="swap-position" type="i">
<default>3</default>
<summary>Position in which to display the swap display</summary>
</key>
<key name="net-position" type="i">
<default>4</default>
<summary>Position in which to display the net display</summary>
</key>
<key name="disk-position" type="i">
<default>5</default>
<summary>Position in which to display the disk display</summary>
</key>
<key name="gpu-position" type="i">
<default>6</default>
<summary>Position in which to display the GPU display</summary>
</key>
<key name="thermal-position" type="i">
<default>7</default>
<summary>Position in which to display the thermal display</summary>
</key>
<key name="fan-position" type="i">
<default>8</default>
<summary>Position in which to display the fan display</summary>
</key>
<key name="battery-position" type="i">
<default>9</default>
<summary>Position in which to display the battery display</summary>
</key>

</schema>
</schemalist>