[modules/xrandr] Sort display widgets by position

Show display widgets from left to right according to their relative
xrandr position.

see #19
This commit is contained in:
Tobi-wan Kenobi 2016-11-26 08:46:16 +01:00
parent 4ea0cfae1e
commit c095b89022

View file

@ -1,5 +1,6 @@
import bumblebee.module import bumblebee.module
import re import re
import sys
import subprocess import subprocess
def description(): def description():
@ -25,9 +26,19 @@ class Module(bumblebee.module.Module):
if not " connected" in line: if not " connected" in line:
continue continue
screen = line.split(" ", 2)[0] screen = line.split(" ", 2)[0]
m = re.search(r'\d+x\d+\+\d+\+\d+', line) m = re.search(r'\d+x\d+\+(\d+)\+\d+', line)
self._state = "on" if m else "off"
widgets.append(bumblebee.output.Widget(self, screen)) widget = bumblebee.output.Widget(self, screen)
if m:
self._state = "on"
widget.set("pos", int(m.group(1)))
else:
self._state = "off"
widget.set("pos", sys.maxint());
widgets.append(widget)
widgets.sort(key=lambda widget : widget.get("pos"))
return widgets return widgets