From c095b890224aaf1e5f684c2d0b9f9770ece381ce Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sat, 26 Nov 2016 08:46:16 +0100 Subject: [PATCH] [modules/xrandr] Sort display widgets by position Show display widgets from left to right according to their relative xrandr position. see #19 --- bumblebee/modules/xrandr.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/xrandr.py b/bumblebee/modules/xrandr.py index 06bf3fa..d5e438b 100644 --- a/bumblebee/modules/xrandr.py +++ b/bumblebee/modules/xrandr.py @@ -1,5 +1,6 @@ import bumblebee.module import re +import sys import subprocess def description(): @@ -25,9 +26,19 @@ class Module(bumblebee.module.Module): 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)) + m = re.search(r'\d+x\d+\+(\d+)\+\d+', line) + + 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