forked from linuxmint/cinnamon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
power applet: remove auto-dimming controls, add idle inhibitor.
- Loading branch information
Showing
2 changed files
with
119 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const PopupMenu = imports.ui.popupMenu; | |
const Pango = imports.gi.Pango; | ||
const Main = imports.ui.main; | ||
const Settings = imports.ui.settings; | ||
const GnomeSession = imports.misc.gnomeSession; | ||
|
||
const DimSettingsSchema = "org.cinnamon.settings-daemon.plugins.power"; | ||
const DimSettingsAc = "idle-dim-ac"; | ||
|
@@ -183,6 +184,106 @@ BrightnessSlider.prototype = { | |
} | ||
}; | ||
|
||
const INHIBIT_IDLE_FLAG = 8; /* idle inhibit only */ | ||
|
||
function InhibitSwitch() { | ||
this._init.apply(this); | ||
} | ||
|
||
InhibitSwitch.prototype = { | ||
__proto__: PopupMenu.PopupBaseMenuItem.prototype, | ||
|
||
_init: function(params) { | ||
PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params); | ||
|
||
this.label = new St.Label({ text: _("Prevent system idling") }); | ||
|
||
this._statusIcon = new St.Icon({ style_class: 'popup-menu-icon', | ||
icon_type: St.IconType.SYMBOLIC, | ||
icon_name: "dialog-warning-symbolic", | ||
reactive: true}); | ||
|
||
this._switch = new PopupMenu.Switch(false); | ||
|
||
this.addActor(this.label); | ||
this.addActor(this._statusIcon); | ||
|
||
this._statusBin = new St.Bin({ x_align: St.Align.END }); | ||
this.addActor(this._statusBin, { expand: true, span: -1, align: St.Align.END }); | ||
this._statusBin.child = this._switch.actor; | ||
|
||
this.actor.hide(); | ||
this.tooltip = new Tooltips.Tooltip(this._statusIcon, ""); | ||
|
||
this.sessionProxy = null; | ||
this.sessionCookie = null; | ||
this.sigAddedId = 0 | ||
this.sigRemovedId = 0 | ||
|
||
GnomeSession.SessionManager(Lang.bind(this, function(proxy, error) { | ||
if (error) | ||
return; | ||
|
||
this.sessionProxy = proxy; | ||
this.actor.show(); | ||
this.updateStatus(); | ||
this.propId = this.sessionProxy.connect("g-properties-changed", | ||
Lang.bind(this, this.updateStatus)); | ||
})); | ||
}, | ||
|
||
activate: function(event) { | ||
if (this._switch.actor.mapped) { | ||
this._switch.toggle(); | ||
} | ||
|
||
this.toggled(this._switch.state); | ||
|
||
PopupMenu.PopupBaseMenuItem.prototype.activate.call(this, event, true); | ||
}, | ||
|
||
updateStatus: function(o) { | ||
this.sessionProxy.IsInhibitedRemote(INHIBIT_IDLE_FLAG, Lang.bind(this, function(is_inhibited) { | ||
if (is_inhibited[0] && !this.sessionCookie) { | ||
this.tooltip.set_text(_("Another program is already inhibiting idle")); | ||
this._statusIcon.show(); | ||
} else { | ||
this.tooltip.set_text(""); | ||
this._statusIcon.hide(); | ||
} | ||
})); | ||
}, | ||
|
||
toggled: function(active) { | ||
if (active && !this.sessionCookie) { | ||
this.sessionProxy.InhibitRemote("[email protected]", | ||
0, | ||
"prevent idle functions like screen blanking and dimming", | ||
INHIBIT_IDLE_FLAG, | ||
Lang.bind(this, function(cookie) { | ||
this.sessionCookie = cookie; | ||
this.updateStatus(); | ||
})); | ||
} else if (!active && this.sessionCookie) { | ||
this.sessionProxy.UninhibitRemote(this.sessionCookie); | ||
this.sessionCookie = null; | ||
this.updateStatus(); | ||
} | ||
}, | ||
|
||
kill: function() { | ||
if (!this.sessionProxy) | ||
return; | ||
|
||
if (this.sessionCookie) { | ||
this.sessionProxy.UninhibitRemote(this.sessionCookie); | ||
this.sessionCookie = null; | ||
} | ||
|
||
this.sessionProxy.disconnect(this.propId); | ||
} | ||
}; | ||
|
||
function MyApplet(metadata, orientation, panel_height, instanceId) { | ||
this._init(metadata, orientation, panel_height, instanceId); | ||
} | ||
|
@@ -225,14 +326,9 @@ MyApplet.prototype = { | |
|
||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); | ||
|
||
let settingsMenu = new PopupMenu.PopupSubMenuMenuItem(_("Dimming settings")); | ||
this.inhibitSwitch = new InhibitSwitch(); | ||
this.menu.addMenuItem(this.inhibitSwitch); | ||
|
||
let dimSwitchAc = this._buildItem(_("Dim screen on AC power"), DimSettingsSchema, DimSettingsAc); | ||
settingsMenu.menu.addMenuItem(dimSwitchAc); | ||
let dimSwitchBattery = this._buildItem(_("Dim screen on battery"), DimSettingsSchema, DimSettingsBattery); | ||
settingsMenu.menu.addMenuItem(dimSwitchBattery); | ||
|
||
this.menu.addMenuItem(settingsMenu); | ||
this.menu.addSettingsAction(_("Power Settings"), 'power'); | ||
|
||
this.actor.connect("scroll-event", Lang.bind(this, this._onScrollEvent)); | ||
|
@@ -431,32 +527,7 @@ MyApplet.prototype = { | |
|
||
on_applet_removed_from_panel: function() { | ||
Main.systrayManager.unregisterId(this.metadata.uuid); | ||
}, | ||
|
||
/* both methods are taken from [email protected] */ | ||
_buildItem: function(string, schema, key) { | ||
let settings = new Gio.Settings({ schema: schema }); | ||
let widget = this._buildItemExtended(string, | ||
settings.get_boolean(key), | ||
settings.is_writable(key), | ||
function(enabled) { | ||
return settings.set_boolean(key, enabled); | ||
}); | ||
settings.connect('changed::'+key, function() { | ||
widget.setToggleState(settings.get_boolean(key)); | ||
}); | ||
return widget; | ||
}, | ||
|
||
_buildItemExtended: function(string, initial_value, writable, on_set) { | ||
let widget = new PopupMenu.PopupSwitchMenuItem(string, initial_value); | ||
if (!writable) | ||
widget.actor.reactive = false; | ||
else | ||
widget.connect('toggled', function(item) { | ||
on_set(item.state); | ||
}); | ||
return widget; | ||
this.inhibitSwitch.kill(); | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters