We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5311 - [rfe] implement console switching
Summary: [rfe] implement console switching
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.12
Hardware: x86_64 Linux
: P2 enhancement
Assignee: Manuel Alfayate Corchete
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-09 16:15 UTC by Stas Sergeev
Modified: 2020-10-16 10:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stas Sergeev 2020-10-09 16:15:28 UTC
SDL2 seems to support drm rendering without X.
But in this mode console switching doesn't work.
Neither Alt-fN not Ctrl-Alt-fN (where N is a
console number) produce any switch.
Comment 1 Manuel Alfayate Corchete 2020-10-15 15:32:47 UTC
Isn't this happening because SDL2 is getting the input instead of TTY?
In other words, I guess that non-working TTY switching while a program is running is the intended behaviour, if I am not mistaken.
I don't even start to guess how to do this, if possible at all.
Comment 2 Stas Sergeev 2020-10-15 16:25:30 UTC
> Isn't this happening because SDL2 is getting the input instead of TTY?

Yes, this is the reason why native switching is disabled.
But it won't work anyway. It just doesn't look like DRM
console can switch the rendered content on its own. I
tried to enable the native switching, but it never restores
the graphical content when I switch back.

> I don't even start to guess how to do this, if possible at all.

Classic gfx console switching works as follows.

ioctl(0, VT_GETSTATE, &vts);
our_vt_num = vts.v_active; // get our console num
ioctl(0, VT_SETMODE, VT_PROCESS); // enter manual console switching
ioctl(0, KDSKBMODE, KD_GRAPHICS); // switch console to gfx mode
/* do some gfx rendering here */
/* detect Ctrl-Alt-fN presses */
ioctl(0, VT_ACTIVATE, N); // activate console N
usleep(10000);      /* some kernel bug, hangs without this */
ioctl(0, VT_RELDISP, 1); // confirm console release
ioctl(0, VT_WAITACTIVE, N); // wait activation of console N
ioctl(0, VT_WAITACTIVE, our_vt_num); // wait until our console is switched on again when user hits Ctrl-Alt-f<our_vt_num>
/* restore the gfx image here, as it gets destroyed */
/* return back to client code */

I hope DRM console have some better techniques
than all that crap. In particular, it would be
cool if it could at least save/restore image itself.
But my experiment shows its not the case, so perhaps
you'll have to execute the entire sequence above. :(
Comment 3 Stas Sergeev 2020-10-16 10:01:02 UTC
Even after googling for the whole day, I can't
find any docs on drm VT switching, other than
that you need to "drop master" via drmDropMaster().
But you do not seem to be doing drmSetMaster()
anyway.
Maybe you just need to do drmDropMaster()
before ioctl(0, VT_RELDISP, 1), and do the
classical switching? Or should it be something
entirely different?
Is this drm stuff that much undocumented...