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

[email protected]: Add unique applet icons for notification toggles #11744

Merged
merged 1 commit into from
Apr 5, 2024
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
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.