From 546b44febce8ac207556745dc437cecd385c4f48 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 25 Feb 2017 01:38:39 +0100 Subject: [PATCH] fix screen auto ignore --- src/fenrir/core/screenManager.py | 14 ++++++++----- src/fenrir/screenDriver/vcsa.py | 34 +++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/fenrir/core/screenManager.py b/src/fenrir/core/screenManager.py index e0fad83b..9ff7e738 100644 --- a/src/fenrir/core/screenManager.py +++ b/src/fenrir/core/screenManager.py @@ -15,14 +15,14 @@ class screenManager(): self.env = environment self.env['runtime']['settingsManager'].loadDriver(\ self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver') - if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'): - self.autoIgnoreScreens = self.env['runtime']['screenDriver'].getIgnoreScreens() + self.env['runtime']['screenDriver'].getSessionInformation() def shutdown(self): self.env['runtime']['settingsManager'].shutdownDriver('screenDriver') def update(self, trigger='onUpdate'): self.env['runtime']['screenDriver'].getCurrScreen() + self.env['runtime']['screenDriver'].getSessionInformation() self.env['screenData']['oldApplication'] = self.env['screenData']['newApplication'] if self.isScreenChange(): self.changeBrailleScreen() @@ -36,9 +36,13 @@ class screenManager(): def isSuspendingScreen(self, screen = None): if screen == None: screen = self.env['screenData']['newTTY'] - return ((screen in \ - self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreen').split(',')) or - (screen in self.autoIgnoreScreens)) + ignoreScreens = [] + fixIgnoreScreens = self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreen') + if fixIgnoreScreens != '': + ignoreScreens.append(fixIgnoreScreens.split(',')) + if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'): + ignoreScreens.extend(self.env['screenData']['autoIgnoreScreens']) + return (screen in ignoreScreens) def isScreenChange(self): if not self.env['screenData']['oldTTY']: diff --git a/src/fenrir/screenDriver/vcsa.py b/src/fenrir/screenDriver/vcsa.py index 7184af24..851a2df9 100644 --- a/src/fenrir/screenDriver/vcsa.py +++ b/src/fenrir/screenDriver/vcsa.py @@ -10,6 +10,7 @@ import subprocess import fcntl import termios import time +import dbus from core import debug from utils import screen_utils @@ -63,19 +64,28 @@ class driver(): self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) return - def getIgnoreScreens(self): - xlist = [] - try: - x = subprocess.Popen('ps a -o tty,comm | grep Xorg', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n') - except Exception as e: - return xlist - for i in x: - if not "grep" in i and \ - not "ps" in i: - if (i[:3].lower() == 'tty'): - xlist.append(i[3]) - return xlist + def getSessionInformation(self): + progname = 'org.freedesktop.login1' + objpath = '/org/freedesktop/login1' + intfname = 'org.freedesktop.login1.Manager' + methname = 'ListSessions' + bus = dbus.SystemBus() + + obj = bus.get_object(progname, objpath) + inf = dbus.Interface(obj, intfname) + meth = inf.get_dbus_method(methname) + + sessions = meth() + self.env['screenData']['autoIgnoreScreens'] = [] + for session in sessions: + obj = bus.get_object(progname, session[4]) + inf = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') + sessionType = inf.Get('org.freedesktop.login1.Session', 'Type') + screen = str(inf.Get('org.freedesktop.login1.Session', 'TTY')) + screen = screen[screen.upper().find('TTY') + 3:] + if sessionType.upper() == 'X11': + self.env['screenData']['autoIgnoreScreens'].append(screen) def update(self, trigger='onUpdate'): newContentBytes = b''