diff --git a/bumblebee/modules/xrandr.py b/bumblebee/modules/xrandr.py new file mode 100644 index 0000000..06bf3fa --- /dev/null +++ b/bumblebee/modules/xrandr.py @@ -0,0 +1,43 @@ +import bumblebee.module +import re +import subprocess + +def description(): + return "Shows all connected screens" + +def parameters(): + return [ + ] + +class Module(bumblebee.module.Module): + def __init__(self, output, config, alias): + super(Module, self).__init__(output, config, alias) + self._state = "off" + + def widgets(self): + process = subprocess.Popen([ "xrandr", "-q" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, error = process.communicate() + + widgets = [] + + # TODO: sort by position + for line in output.split("\n"): + if not " connected" in line: + continue + screen = line.split(" ", 2)[0] + m = re.search(r'\d+x\d+\+\d+\+\d+', line) + self._state = "on" if m else "off" + widgets.append(bumblebee.output.Widget(self, screen)) + + return widgets + + def state(self, widget): + return self._state + + def warning(self, widget): + return False + + def critical(self, widget): + return False + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/default.json b/themes/default.json index 5c9498a..76d3b1f 100644 --- a/themes/default.json +++ b/themes/default.json @@ -126,6 +126,9 @@ } }, "caffeine": { - "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } + "states": { "activated": {"prefix": " caf on " }, "deactivated": { "prefix": " caf off " } } + }, + "xrandr": { + "states": { "on": { "prefix": " off "}, "off": { "prefix": " on "} } } } diff --git a/themes/gruvbox-powerline.json b/themes/gruvbox-powerline.json index ba155e0..0d9f63c 100644 --- a/themes/gruvbox-powerline.json +++ b/themes/gruvbox-powerline.json @@ -159,5 +159,8 @@ }, "caffeine": { "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } + }, + "xrandr": { + "states": { "on": { "prefix": "   "}, "off": { "prefix": "   "} } } } diff --git a/themes/powerline.json b/themes/powerline.json index d74c461..7846814 100644 --- a/themes/powerline.json +++ b/themes/powerline.json @@ -158,5 +158,8 @@ }, "caffeine": { "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } + }, + "xrandr": { + "states": { "on": { "prefix": "   "}, "off": { "prefix": "   "} } } } diff --git a/themes/solarized-powerline.json b/themes/solarized-powerline.json index 206e030..4a72def 100644 --- a/themes/solarized-powerline.json +++ b/themes/solarized-powerline.json @@ -159,5 +159,8 @@ }, "caffeine": { "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } + }, + "xrandr": { + "states": { "on": { "prefix": "   "}, "off": { "prefix": "   "} } } } diff --git a/themes/solarized.json b/themes/solarized.json index 8a3fc8f..e195ad9 100644 --- a/themes/solarized.json +++ b/themes/solarized.json @@ -152,5 +152,8 @@ }, "caffeine": { "states": { "activated": {"prefix": " caf on " }, "deactivated": { "prefix": " caf off " } } + }, + "xrandr": { + "states": { "on": { "prefix": " off "}, "off": { "prefix": " on "} } } }