diff --git a/laptop-suspend-inhibitor@carsongfromjpt/applet.js b/laptop-suspend-inhibitor@carsongfromjpt/applet.js new file mode 100644 index 00000000000..b456feee7ff --- /dev/null +++ b/laptop-suspend-inhibitor@carsongfromjpt/applet.js @@ -0,0 +1,41 @@ +const Applet = imports.ui.applet; +const GLib = imports.gi.GLib; +const Gio = imports.gi.Gio; + +class MyTrayApplet extends Applet.IconApplet { + constructor(metadata, orientation, panelHeight, instanceId) { + super(orientation, panelHeight, instanceId); + + this.appletPath = metadata.path + "/"; + + this.set_applet_tooltip("Laptop Suspend Inhibitor: Click to disable suspension when the laptop lid is closed, click again to re-enable. Useful for playing music with the laptop closed."); + + // dconf schema and key + this.dconfKey = "/org/cinnamon/settings-daemon/plugins/power/"; + this.dconfClient = new Gio.Settings({ schema_id: "org.cinnamon.settings-daemon.plugins.power" }); + + // Watch dconf for changes + this.dconfClient.connect("changed", () => this.updateIcon()); + + this.updateIcon(); + } + + updateIcon() { + let value = this.dconfClient.get_string("lid-close-battery-action"); + if (value === "suspend") { + this.set_applet_icon_symbolic_name("suspend"); + } else { + this.set_applet_icon_symbolic_name("lock-screen"); + } + } + + on_applet_clicked(event) { + // Run your script when clicked + GLib.spawn_command_line_async(this.appletPath + "switch-mode.sh"); + } +} + +function main(metadata, orientation, panelHeight, instanceId) { + return new MyTrayApplet(metadata, orientation, panelHeight, instanceId); +} + diff --git a/laptop-suspend-inhibitor@carsongfromjpt/icon.png b/laptop-suspend-inhibitor@carsongfromjpt/icon.png new file mode 100644 index 00000000000..9bad96d76ba Binary files /dev/null and b/laptop-suspend-inhibitor@carsongfromjpt/icon.png differ diff --git a/laptop-suspend-inhibitor@carsongfromjpt/icons/lock-screen-symbolic.svg b/laptop-suspend-inhibitor@carsongfromjpt/icons/lock-screen-symbolic.svg new file mode 100644 index 00000000000..1b575b02d1b --- /dev/null +++ b/laptop-suspend-inhibitor@carsongfromjpt/icons/lock-screen-symbolic.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/laptop-suspend-inhibitor@carsongfromjpt/icons/suspend-symbolic.svg b/laptop-suspend-inhibitor@carsongfromjpt/icons/suspend-symbolic.svg new file mode 100644 index 00000000000..e93fdb2fbde --- /dev/null +++ b/laptop-suspend-inhibitor@carsongfromjpt/icons/suspend-symbolic.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/laptop-suspend-inhibitor@carsongfromjpt/metadata.json b/laptop-suspend-inhibitor@carsongfromjpt/metadata.json new file mode 100644 index 00000000000..e80ec5495bb --- /dev/null +++ b/laptop-suspend-inhibitor@carsongfromjpt/metadata.json @@ -0,0 +1,7 @@ +{ + "uuid": "laptop-suspend-inhibitor@carsongfromjpt", + "name": "Laptop Suspend Inhibitor", + "description": "Click to disable suspension when the laptop lid is closed. Click again to re-enable suspension. Useful for playing music with the lid closed.", + "icon": "icon.png" +} + diff --git a/laptop-suspend-inhibitor@carsongfromjpt/switch-mode.sh b/laptop-suspend-inhibitor@carsongfromjpt/switch-mode.sh new file mode 100755 index 00000000000..552e070f131 --- /dev/null +++ b/laptop-suspend-inhibitor@carsongfromjpt/switch-mode.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [[ "$(gsettings get org.cinnamon.settings-daemon.plugins.power lid-close-battery-action)" == "'suspend'" ]] +then + action="blank" +else + action="suspend" +fi +gsettings set org.cinnamon.settings-daemon.plugins.power lid-close-ac-action "$action" +gsettings set org.cinnamon.settings-daemon.plugins.power lid-close-battery-action "$action" +