Skip to content

Commit 4a921f4

Browse files
rcalixtemtwebster
authored andcommitted
Add support for key bindings to Inhibit Applet
1 parent be4ed16 commit 4a921f4

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const Applet = imports.ui.applet;
22
const Gio = imports.gi.Gio;
33
const Lang = imports.lang;
4+
const Main = imports.ui.main;
45
const St = imports.gi.St;
56
const Tooltips = imports.ui.tooltips;
67
const PopupMenu = imports.ui.popupMenu;
78
const GnomeSession = imports.misc.gnomeSession;
9+
const Settings = imports.ui.settings;
10+
const Util = imports.misc.util;
811

912
const INHIBIT_IDLE_FLAG = 8;
1013
const INHIBIT_SLEEP_FLAG = 4;
@@ -368,6 +371,11 @@ class CinnamonInhibitApplet extends Applet.IconApplet {
368371

369372
this.menu.addMenuItem(this.notificationsSwitch);
370373

374+
this.settings = new Settings.AppletSettings(this, metadata.uuid, instanceId);
375+
this.settings.bind("keyPower", "keyPower", this._setKeybinding);
376+
this.settings.bind("keyNotifications", "keyNotifications", this._setKeybinding);
377+
this._setKeybinding();
378+
371379
this._createInhibitorMenuSection(orientation);
372380
}
373381

@@ -386,11 +394,30 @@ class CinnamonInhibitApplet extends Applet.IconApplet {
386394
}
387395
}
388396

397+
_setKeybinding() {
398+
Main.keybindingManager.addHotKey("inhibit-power-" + this.instance_id,
399+
this.keyPower,
400+
Lang.bind(this, this.toggle_inhibit_power));
401+
Main.keybindingManager.addHotKey("inhibit-notifications-" + this.instance_id,
402+
this.keyNotifications,
403+
Lang.bind(this, this.toggle_inhibit_notifications));
404+
}
405+
389406
on_applet_clicked(event) {
390407
this.menu.toggle();
391408
}
392409

410+
on_btn_open_system_power_settings_clicked() {
411+
Util.spawnCommandLine("cinnamon-settings power");
412+
}
413+
414+
on_btn_open_system_notification_settings_clicked() {
415+
Util.spawnCommandLine("cinnamon-settings notifications");
416+
}
417+
393418
on_applet_removed_from_panel() {
419+
Main.keybindingManager.removeHotKey("inhibit-power-" + this.instance_id);
420+
Main.keybindingManager.removeHotKey("inhibit-notifications-" + this.instance_id);
394421
this.inhibitSwitch.kill();
395422
}
396423

@@ -404,6 +431,27 @@ class CinnamonInhibitApplet extends Applet.IconApplet {
404431
this.inhibitSwitch.updateStatus();
405432
}
406433

434+
toggle_inhibit_power() {
435+
this.inhibitSwitch._switch.toggle();
436+
this.inhibitSwitch.toggled(this.inhibitSwitch._switch.state);
437+
438+
let _symbol = this.inhibitSwitch._switch.state ?
439+
"inhibit-symbolic" :
440+
"inhibit-active-symbolic";
441+
442+
Main.osdWindowManager.show(-1, Gio.ThemedIcon.new(_symbol));
443+
}
444+
445+
toggle_inhibit_notifications() {
446+
this.notificationsSwitch.toggle();
447+
448+
let _symbol = this.notificationsSwitch._switch.state ?
449+
"inhibit-notification-symbolic" :
450+
"inhibit-notification-active-symbolic";
451+
452+
Main.osdWindowManager.show(-1, Gio.ThemedIcon.new(_symbol));
453+
}
454+
407455
get inhibitors() {
408456
return this._inhibitorMenuSection;
409457
}
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"section1": {
3+
"type": "section",
4+
"description": "Keyboard shortcuts"
5+
},
6+
"keyPower": {
7+
"type": "keybinding",
8+
"description": "Inhibit power management",
9+
"default": "",
10+
"tooltip": "Set keybinding(s) to inhibit power management."
11+
},
12+
"keyNotifications": {
13+
"type": "keybinding",
14+
"description": "Inhibit notifications",
15+
"default": "",
16+
"tooltip": "Set keybinding(s) to inhibit notifications."
17+
},
18+
"section2": {
19+
"type": "section",
20+
"description": ""
21+
},
22+
"btnSystemPowerSettings": {
23+
"type": "button",
24+
"description": "Open power settings",
25+
"callback": "on_btn_open_system_power_settings_clicked"
26+
},
27+
"btnSystemNotificationSettings": {
28+
"type": "button",
29+
"description": "Open notification settings",
30+
"callback": "on_btn_open_system_notification_settings_clicked"
31+
}
32+
}

0 commit comments

Comments
 (0)