-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch VT using dbus to fix #72 #75
Open
guillaumezin
wants to merge
5
commits into
OpenRoberta:develop
Choose a base branch
from
guillaumezin:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cde0bbb
Use dbus to switch VT, should help with https://github.com/OpenRobert…
guillaumezin 649f184
Keep ioctl to VT when correcting https://github.com/OpenRoberta/rober…
guillaumezin 037591c
Getting current vt number from fgconsole, for https://github.com/Open…
guillaumezin bec9494
Switch only if vt number from stdin different than current vt, for ht…
guillaumezin 5ade723
Add log message if not switching VT
guillaumezin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,20 +153,55 @@ def status(self, status): | |
class GfxMode(object): | ||
|
||
def __init__(self): | ||
# get target vt from stdin, if vt number given by stdin is different than active vt number, we will have to switch then switch back | ||
self.tty_name = os.ttyname(sys.stdin.fileno()) | ||
# get digit from string | ||
self.tty_num = int(list(filter(str.isdigit, self.tty_name))[0]) | ||
try: | ||
# ugly hack to get current vt number, I didn't find any dbus properties to get it properly | ||
stream = os.popen('fgconsole') | ||
self.previous_tty_num = int(stream.readline()) | ||
logger.info('current virtual terminal number is: %d', self.previous_tty_num) | ||
except: | ||
self.previous_tty_num = self.tty_num | ||
logger.exception('cannot read current virtual terminal number from fgconsole command, setting to %d', self.previous_tty_num) | ||
self.previous_tty_name = '/dev/tty' + str(self.previous_tty_num) | ||
try: | ||
bus = dbus.SystemBus() | ||
seat_obj = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1/seat/seat0') | ||
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) | ||
# change vt if not already done by caller | ||
if self.tty_name != self.previous_tty_num: | ||
logger.info('switching to tty: %s', self.tty_name) | ||
try: | ||
self.seat_methods.SwitchTo(self.tty_num) | ||
except: | ||
logger.exception('cannot switch to: %s', self.tty_name) | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd probaby just print this in init() and remove the ekese part here. |
||
logger.info('running on tty: %s', self.tty_name) | ||
|
||
def __exit__(self, type, value, traceback): | ||
# 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') | ||
# change vt if not managed by caller | ||
if self.tty_name != self.previous_tty_num: | ||
logger.info('switching back to tty: %s', self.previous_tty_name) | ||
try: | ||
self.seat_methods.SwitchTo(self.previous_tty_num) | ||
except: | ||
logger.exception('cannot switch back to: %s', self.previous_tty_name) | ||
|
||
|
||
class AbortHandler(threading.Thread): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I recall, we need to enable graphics. It is not enabled by default.