Skip to content

Commit

Permalink
[email protected]: Add unique applet icons for notification toggles
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Nocera Zanette <[email protected]>
  • Loading branch information
rcalixte and BrunoNZ committed Sep 1, 2023
1 parent b6744f1 commit 012db07
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 5 deletions.
47 changes: 42 additions & 5 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@ const Util = imports.misc.util;
const INHIBIT_IDLE_FLAG = 8;
const INHIBIT_SLEEP_FLAG = 4;

class InhibitAppletIcon {
constructor(applet, notificationStatus, inhibitStatus) {
this._applet = applet;
this.icon_name = 'inhibit';
this.notificationStatus = notificationStatus;
this.inhibitStatus = inhibitStatus;
}

setAppletIcon() {
this._applet.set_applet_icon_symbolic_name(this.getAppletIcon());
}

getAppletIcon() {
let appletIcon = this.icon_name;
if (this.inhibitStatus) {
appletIcon += '-active';
}
if (this.notificationStatus) {
appletIcon += '-notifications-disabled';
}
return appletIcon;
}

toggleNotificationStatus() {
this.notificationStatus = !this.notificationStatus;
this.setAppletIcon();
}

toggleInhibitStatus(status) {
this.inhibitStatus = status;
this.setAppletIcon();
}
}

class InhibitSwitch extends PopupMenu.PopupBaseMenuItem {
constructor(applet) {
super();
Expand Down Expand Up @@ -80,10 +114,10 @@ class InhibitSwitch extends PopupMenu.PopupBaseMenuItem {

if (current_state & INHIBIT_IDLE_FLAG ||
current_state & INHIBIT_SLEEP_FLAG) {
this._applet.set_applet_icon_symbolic_name('inhibit-active');
this._applet.icon.toggleInhibitStatus(true);
this._applet.set_applet_tooltip(_("Power management: inhibited"));
} else {
this._applet.set_applet_icon_symbolic_name('inhibit');
this._applet.icon.toggleInhibitStatus(false);
this._applet.set_applet_tooltip(_("Power management: active"));
}

Expand Down Expand Up @@ -214,7 +248,7 @@ class InhibitorMenuSection extends PopupMenu.PopupMenuSection {
}

resetInhibitors() {
// Abort any in-progress update or else it may continue to add menu items
// Abort any in-progress update or else it may continue to add menu items
// even after we've cleared them.
this._updateId++;

Expand All @@ -232,7 +266,7 @@ class InhibitorMenuSection extends PopupMenu.PopupMenuSection {
}

updateInhibitors(sessionProxy) {
// Grab a new ID for this update while at the same time aborting any other in-progress
// Grab a new ID for this update while at the same time aborting any other in-progress
// update. We don't want to end up with duplicate menu items!
let updateId = ++this._updateId;

Expand Down Expand Up @@ -358,17 +392,20 @@ class CinnamonInhibitApplet extends Applet.IconApplet {
this.inhibitSwitch = new InhibitSwitch(this);
this.menu.addMenuItem(this.inhibitSwitch);

this.set_applet_icon_symbolic_name('inhibit');
this.set_applet_tooltip(_("Inhibit applet"));

this.notif_settings = new Gio.Settings({ schema_id: "org.cinnamon.desktop.notifications" });
this.notificationsSwitch = new PopupMenu.PopupSwitchMenuItem(_("Notifications"), this.notif_settings.get_boolean("display-notifications"));

this.icon = new InhibitAppletIcon(this, !this.notificationsSwitch.state, !this.inhibitSwitch.state);
this.icon.setAppletIcon();

this.notif_settings.connect('changed::display-notifications', Lang.bind(this, function() {
this.notificationsSwitch.setToggleState(this.notif_settings.get_boolean("display-notifications"));
}));
this.notificationsSwitch.connect('toggled', Lang.bind(this, function() {
this.notif_settings.set_boolean("display-notifications", this.notificationsSwitch.state);
this.icon.toggleNotificationStatus();
}));

this.menu.addMenuItem(this.notificationsSwitch);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 012db07

Please sign in to comment.