rework ignore screen detection; detect user of current TTY

This commit is contained in:
chrys
2017-02-22 23:48:37 +01:00
parent ef006fb423
commit abb3823606
9 changed files with 135 additions and 52 deletions

View File

@ -0,0 +1,56 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
import subprocess, os
from subprocess import Popen, PIPE
import _thread
class command():
def __init__(self):
pass
def initialize(self, environment, scriptPath=''):
self.env = environment
self.scriptPath = scriptPath
def shutdown(self):
pass
def getDescription(self):
return 'export the current fenrir clipboard to X clipboard'
def run(self):
_thread.start_new_thread(self._threadRun , ())
def _threadRun(self):
try:
currClipboard = self.env['commandBuffer']['currClipboard']
if currClipboard < 0:
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
if not self.env['commandBuffer']['clipboard']:
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
if not self.env['commandBuffer']['clipboard'][currClipboard]:
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
if self.env['commandBuffer']['clipboard'][currClipboard] == '':
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
p = Popen('su -c "echo -n \"' + self.env['commandBuffer']['clipboard'][currClipboard] +'\" | xclip -selection c' + self.env['generalInformation']['currUser'] , stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = p.communicate()
self.env['runtime']['outputManager'].interruptOutput()
screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding')
stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
if stderr != '':
self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False)
else:
self.env['runtime']['outputManager'].presentText('export clipboard', soundIcon='PasteClipboardOnScreen', interrupt=True)
except Exception as e:
print(e)
self.env['runtime']['outputManager'].presentText(e , soundIcon='', interrupt=False)
def setCallback(self, callback):
pass

View File

@ -9,4 +9,6 @@ from core import debug
generalInformation = {
'running': True,
'tutorialMode': False,
'currUser':'',
'prevUser':'',
}

View File

@ -32,5 +32,6 @@ screenData = {
'newContentAttrib': b'',
'newTTY':'0',
'newApplication': '',
'lastScreenUpdate': time.time()
'lastScreenUpdate': time.time(),
'autoIgnoreScreens':[],
}

View File

@ -9,22 +9,22 @@ import time
class screenManager():
def __init__(self):
self.autoIgnoreScreens = []
pass
def initialize(self, environment):
self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\
self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver')
self.updateAutoIgnoreScreens()
self.env['runtime']['screenDriver'].getCurrScreen()
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.updateAutoIgnoreScreens()
if self.isScreenChange():
self.changeBrailleScreen()
if not self.isSuspendingScreen(self.env['screenData']['newTTY']):
self.env['runtime']['screenDriver'].update(trigger)
@ -36,12 +36,14 @@ 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))
def updateAutoIgnoreScreens(self):
ignoreScreens = []
fixIgnoreScreens = self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreen')
if fixIgnoreScreens != '':
ignoreScreens.append(fixIgnoreScreens.split(','))
if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'):
self.autoIgnoreScreens = self.env['runtime']['screenDriver'].getIgnoreScreens()
ignoreScreens.append(self.env['screenData']['autoIgnoreScreens'])
return (screen in ignoreScreens)
def isScreenChange(self):
if not self.env['screenData']['oldTTY']:
return False

View File

@ -57,14 +57,13 @@ class fenrir():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \
self.environment['runtime']['applicationManager'].getPrevApplication(), \
self.environment['runtime']['applicationManager'].getCurrentApplication())
self.environment['runtime']['screenManager'].updateAutoIgnoreScreens()
self.environment['runtime']['applicationManager'].getCurrentApplication())
if self.environment['runtime']['screenManager'].isScreenChange():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged')
else:
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
self.environment['runtime']['outputManager'].brailleText(flush=False)
#self.environment['runtime']['outputManager'].brailleText(flush=False)
self.handleCommands()
#print(time.time()-startTime)

View File

@ -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,34 @@ 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):
sta = time.time()
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)
if screen == self.env['screenData']['newTTY'] :
if self.env['generalInformation']['currUser'] != session[2]:
self.env['generalInformation']['prevUser'] = self.env['generalInformation']['currUser']
self.env['generalInformation']['currUser'] = session[2]
def update(self, trigger='onUpdate'):
newContentBytes = b''