Skip to content

Commit

Permalink
power applet: remove auto-dimming controls, add idle inhibitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwebster committed Apr 19, 2015
1 parent 8b67304 commit c4ca771
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 33 deletions.
137 changes: 104 additions & 33 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}
};

Expand Down
15 changes: 15 additions & 0 deletions js/misc/gnomeSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ const SessionManagerIface = '\
<method name="CanShutdown"> \
<arg type="b" direction="out" /> \
</method> \
<method name="Inhibit"> \
<arg type="s" direction="in" /> \
<arg type="u" direction="in" /> \
<arg type="s" direction="in" /> \
<arg type="u" direction="in" /> \
<arg type="u" direction="out" /> \
</method> \
<method name="Uninhibit"> \
<arg type="u" direction="in" /> \
</method> \
<method name="IsInhibited"> \
<arg type="u" name="flags" direction="in"/> \
<arg type="b" name="is_inhibited" direction="out"/> \
</method> \
<property name="InhibitedActions" type="u" access="read"/> \
</interface> \
</node>';

Expand Down

0 comments on commit c4ca771

Please sign in to comment.