From be6559a251183ab2b16769e6f150d9024c26f25e Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Wed, 23 Nov 2016 13:57:29 +0100 Subject: [PATCH 1/3] [modules/caffeine] Add caffeine module to prevent sleep --- bumblebee/modules/caffeine.py | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bumblebee/modules/caffeine.py diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py new file mode 100644 index 0000000..bf67b2b --- /dev/null +++ b/bumblebee/modules/caffeine.py @@ -0,0 +1,40 @@ +import subprocess +import shlex + +import bumblebee.module + +def description(): + return "Enable/disable auto screen lock." + +class Module(bumblebee.module.Module): + def __init__(self, output, config, alias): + super(Module, self).__init__(output, config, alias) + self._activated = 0 + # output.add_callback(module="caffeine.activate", button=1, cmd='notify-send "Consuming caffeine"; xset s off') + # output.add_callback(module="caffeine.deactivate", button=1, cmd='notify-send "Out of coffee"; xset s 600 600') + output.add_callback(module="caffeine.activate", button=1, cmd='xset s off') + output.add_callback(module="caffeine.deactivate", button=1, cmd='xset s 600 600') + + def widgets(self): + output = subprocess.check_output(shlex.split("xset q")) + xset_out = output.decode().split("\n") + for line in xset_out: + if line.startswith(" timeout"): + timeout = int(line.split(" ")[4]) + if timeout == 0: + self._activated = 1; + else: + self._activated = 0; + break + + if self._activated == 0: + return bumblebee.output.Widget(self, "", instance="caffeine.activate") + elif self._activated == 1: + return bumblebee.output.Widget(self, "", instance="caffeine.deactivate") + + def state(self, widget): + if self._activated == 1: + return "activated" + else: + return "deactivated" + From 5faba39643409ab471c9522c0e701895b4f52a1e Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Wed, 23 Nov 2016 14:04:33 +0100 Subject: [PATCH 2/3] [themes] Add caffeine module support --- bumblebee/themes/default.json | 3 +++ bumblebee/themes/gruvbox-powerline.json | 3 +++ bumblebee/themes/powerline.json | 3 +++ bumblebee/themes/solarized-powerline.json | 3 +++ bumblebee/themes/solarized.json | 3 +++ 5 files changed, 15 insertions(+) diff --git a/bumblebee/themes/default.json b/bumblebee/themes/default.json index fe3af8b..32a23ea 100644 --- a/bumblebee/themes/default.json +++ b/bumblebee/themes/default.json @@ -121,5 +121,8 @@ "suffix": " dis " } } + }, + "caffeine": { + "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/bumblebee/themes/gruvbox-powerline.json b/bumblebee/themes/gruvbox-powerline.json index bb43b68..1f3271b 100644 --- a/bumblebee/themes/gruvbox-powerline.json +++ b/bumblebee/themes/gruvbox-powerline.json @@ -153,5 +153,8 @@ }, "brightness": { "prefix": "  " + }, + "caffeine": { + "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/bumblebee/themes/powerline.json b/bumblebee/themes/powerline.json index b3c98f5..84fb73a 100644 --- a/bumblebee/themes/powerline.json +++ b/bumblebee/themes/powerline.json @@ -152,5 +152,8 @@ "suffix": "  " } } + }, + "caffeine": { + "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/bumblebee/themes/solarized-powerline.json b/bumblebee/themes/solarized-powerline.json index 6e0e13d..5cbd561 100644 --- a/bumblebee/themes/solarized-powerline.json +++ b/bumblebee/themes/solarized-powerline.json @@ -153,5 +153,8 @@ "suffix": "  " } } + }, + "caffeine": { + "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/bumblebee/themes/solarized.json b/bumblebee/themes/solarized.json index 2b3908c..af6d876 100644 --- a/bumblebee/themes/solarized.json +++ b/bumblebee/themes/solarized.json @@ -146,5 +146,8 @@ "suffix": " dis " } } + }, + "caffeine": { + "states": { "activated": {"prefix": " caf on " }, "deactivated": { "prefix": " caf off " } } } } From d2e3a192696efe436996ea943480c9b36de4cbeb Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Wed, 23 Nov 2016 14:08:34 +0100 Subject: [PATCH 3/3] [modules/caffeine] Fix times for screen on time --- bumblebee/modules/caffeine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index bf67b2b..5d0dbaf 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -13,7 +13,7 @@ class Module(bumblebee.module.Module): # output.add_callback(module="caffeine.activate", button=1, cmd='notify-send "Consuming caffeine"; xset s off') # output.add_callback(module="caffeine.deactivate", button=1, cmd='notify-send "Out of coffee"; xset s 600 600') output.add_callback(module="caffeine.activate", button=1, cmd='xset s off') - output.add_callback(module="caffeine.deactivate", button=1, cmd='xset s 600 600') + output.add_callback(module="caffeine.deactivate", button=1, cmd='xset s default') def widgets(self): output = subprocess.check_output(shlex.split("xset q"))