Skip to content

Commit

Permalink
Keep ioctl to VT when correcting OpenRoberta#72
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumezin committed Jul 26, 2020
1 parent cde0bbb commit 649f184
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions roberta/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,41 @@ def status(self, status):
class GfxMode(object):

def __init__(self):
self.tty_name = os.ttyname(sys.stdin.fileno())
# get digit from string
self.tty_num = int(list(filter(str.isdigit, self.tty_name))[0])
# TODO: get tty number from calling program as parameter
self.previous_tty_num = 3
self.previous_tty_name = "/dev/tty" + str(self.previous_tty_num)
self.tty_num = 5
self.tty_name = "/dev/tty" + str(self.tty_num)
self.previous_tty_name = '/dev/tty' + str(self.previous_tty_num)
try:
self.bus = dbus.SystemBus()
self.devobj = self.bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1/seat/seat0')
self.devprop = dbus.Interface(self.devobj, "org.freedesktop.DBus.Properties")
self.dev = dbus.Interface(self.devobj, 'org.freedesktop.login1.Seat')
bus = dbus.SystemBus()
seat_obj = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1/seat/seat0')
seat_props = dbus.Interface(seat_obj, 'org.freedesktop.DBus.Properties')
self.seat_methods = dbus.Interface(seat_obj, 'org.freedesktop.login1.Seat')
except:
logger.exception('cannot open dbus interface for org.freedesktop.login1.Seat')

def __enter__(self):
logger.info('running on tty: %s', self.tty_name)
# really useful ? Can block if permission is not set correctly on /dev/ttyx
with open(self.tty_name, 'r') as tty:
# KDSETMODE = 0x4B3A, GRAPHICS = 0x01
ioctl(tty, 0x4B3A, 0x01)
try:
self.dev.SwitchTo(self.tty_num)
logger.info('running on tty: %s', self.tty_name)
self.seat_methods.SwitchTo(self.tty_num)
except:
logger.exception('cannot switch to: %s', self.tty_name)

def __exit__(self, type, value, traceback):
logger.info('switching back to tty: %s', self.previous_tty_name)
# really useful ? Can block if permission is not set correctly on /dev/ttyx
with open(self.tty_name, 'w') as tty:
# KDSETMODE = 0x4B3A, TEXT = 0x00
ioctl(tty, 0x4B3A, 0x00)
# send Ctrl-L to tty to clear
tty.write('\033c')
try:
self.dev.SwitchTo(self.previous_tty_num)
logger.info('running on tty: %s', self.previous_tty_name)
self.seat_methods.SwitchTo(self.previous_tty_num)
except:
logger.exception('cannot switch back to: %s', self.previous_tty_name)

Expand Down

0 comments on commit 649f184

Please sign in to comment.