From 31ffb35e2dbae7ed5d40dac9932f9a538a782749 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 8 Mar 2014 23:54:13 +0100 Subject: fix xdisplay bug for the case where DISPLAY is not set + xdisplay demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/plugins/xdisplay | 38 ++++++++++++++++++++++++++++++++++++++ src/plugins/xdisplay.py | 25 +++++++++++++++++-------- 2 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 examples/plugins/xdisplay diff --git a/examples/plugins/xdisplay b/examples/plugins/xdisplay new file mode 100644 index 0000000..4c90d90 --- /dev/null +++ b/examples/plugins/xdisplay @@ -0,0 +1,38 @@ +# -*- python -*- + +# A xpybar configuration example testing the features of plugins.xdisplay + +import time +import threading + +from plugins.xdisplay import XDisplay +from plugins.clock import Clock + + +OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True + + +clock = Clock(sync_to = 30 * Clock.MINUTES) + +start_ = start +def start(): + start_() + async(lambda : clock.continuous_sync(lambda : bar.invalidate())) + + +def redraw(): + x = XDisplay() + + text = 'No DISPLAY environment variable set' + if x.connection is not None: + text = 'Connection: %s │ %s │ Display: %i │ %s' + text %= (x.connection, + 'Default host' if x.host is None else ('Host: %s' % x.host), + x.display, + 'Default screen' if x.screen is None else ('Screen: %i' % x.screen)) + + text += ' │ VT: %i' % x.vt + + bar.clear() + bar.draw_coloured_text(0, 10, 0, 2, text) + diff --git a/src/plugins/xdisplay.py b/src/plugins/xdisplay.py index cba245a..907b6bf 100644 --- a/src/plugins/xdisplay.py +++ b/src/plugins/xdisplay.py @@ -26,13 +26,17 @@ from x import * class XDisplay: ''' - Retrieve information about the used X display + Retrieve information about the used X display as specified by the DISPLAY environment variable @variable connection:str? The full X display information, `None` if X is not running @variable host:str? The host, often `None` one local conncetions and "localhost" on remote oonnection - @variable display:int The display number - @variable screen:int? The screen number, often `None` + @variable display:int? The display number + @variable screen:int? The screen number, often `None` (default screen) @varaible vt:int The VT the X display is allocated to + + host, dispay and screen is None if connectiopn is None, which means that you + have started xpybar's DISPLAY environment variable is not set, and that a display + was configured in the settings. ''' @@ -41,12 +45,17 @@ class XDisplay: Constructor ''' self.connection = os.environ['DISPLAY'] if 'DISPLAY' in os.environ else None - self.host = self.connection.split(':')[0] - if self.host == '': + if self.connection is None: self.host = None - self.display, self.screen = (self.connection.split(':')[1] + '.').split('.')[:2] - self.display = int(self.display) - self.screen = None if self.screen == '' else int(self.screen) + self.display = None + self.screen = None + else: + self.host = self.connection.split(':')[0] + if self.host == '': + self.host = None + self.display, self.screen = (self.connection.split(':')[1] + '.').split('.')[:2] + self.display = int(self.display) + self.screen = None if self.screen == '' else int(self.screen) r = get_screen().root d = get_display() self.vt = r.get_full_property(d.get_atom('XFree86_VT'), Xlib.Xatom.INTEGER).value[0] -- cgit v1.2.3-70-g09d2