Skip to content

Commit

Permalink
Merge pull request #14 from paxy97/master
Browse files Browse the repository at this point in the history
Add caffeine module
  • Loading branch information
tobi-wan-kenobi authored Nov 23, 2016
2 parents c1123fa + d2e3a19 commit f967eaf
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bumblebee/modules/caffeine.py
Original file line number Diff line number Diff line change
@@ -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 default')

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"

3 changes: 3 additions & 0 deletions bumblebee/themes/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,8 @@
"suffix": " dis "
}
}
},
"caffeine": {
"states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } }
}
}
3 changes: 3 additions & 0 deletions bumblebee/themes/gruvbox-powerline.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,8 @@
},
"brightness": {
"prefix": ""
},
"caffeine": {
"states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } }
}
}
3 changes: 3 additions & 0 deletions bumblebee/themes/powerline.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,8 @@
"suffix": ""
}
}
},
"caffeine": {
"states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } }
}
}
3 changes: 3 additions & 0 deletions bumblebee/themes/solarized-powerline.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,8 @@
"suffix": ""
}
}
},
"caffeine": {
"states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } }
}
}
3 changes: 3 additions & 0 deletions bumblebee/themes/solarized.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,8 @@
"suffix": " dis "
}
}
},
"caffeine": {
"states": { "activated": {"prefix": " caf on " }, "deactivated": { "prefix": " caf off " } }
}
}

0 comments on commit f967eaf

Please sign in to comment.