[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
This commit is contained in:
parent
3dd595477f
commit
4ea0cfae1e
6 changed files with 59 additions and 1 deletions
43
bumblebee/modules/xrandr.py
Normal file
43
bumblebee/modules/xrandr.py
Normal file
|
@ -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
|
|
@ -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 "} }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,5 +159,8 @@
|
|||
},
|
||||
"caffeine": {
|
||||
"states": { "activated": {"prefix": " " }, "deactivated": { "prefix": " " } }
|
||||
},
|
||||
"xrandr": {
|
||||
"states": { "on": { "prefix": " "}, "off": { "prefix": " "} }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,5 +158,8 @@
|
|||
},
|
||||
"caffeine": {
|
||||
"states": { "activated": {"prefix": " " }, "deactivated": { "prefix": " " } }
|
||||
},
|
||||
"xrandr": {
|
||||
"states": { "on": { "prefix": " "}, "off": { "prefix": " "} }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,5 +159,8 @@
|
|||
},
|
||||
"caffeine": {
|
||||
"states": { "activated": {"prefix": " " }, "deactivated": { "prefix": " " } }
|
||||
},
|
||||
"xrandr": {
|
||||
"states": { "on": { "prefix": " "}, "off": { "prefix": " "} }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,5 +152,8 @@
|
|||
},
|
||||
"caffeine": {
|
||||
"states": { "activated": {"prefix": " caf on " }, "deactivated": { "prefix": " caf off " } }
|
||||
},
|
||||
"xrandr": {
|
||||
"states": { "on": { "prefix": " off "}, "off": { "prefix": " on "} }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue