From 4ea0cfae1e9b10605144b703dd6797fb11a5034a Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sat, 26 Nov 2016 08:28:19 +0100 Subject: [PATCH] [modules/xrandr] Add module to show attached displays This modules shows attached displays and their states (on or off). Future versions of this module will order the icons by the relative order of the screens (left-to-right) and will allow switching monitors on and off. see #19 --- bumblebee/modules/xrandr.py | 43 +++++++++++++++++++++++++++++++++ themes/default.json | 5 +++- themes/gruvbox-powerline.json | 3 +++ themes/powerline.json | 3 +++ themes/solarized-powerline.json | 3 +++ themes/solarized.json | 3 +++ 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 bumblebee/modules/xrandr.py 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 "} } } }