0

What exactly makes a graphical applications runable from terminal environment? In terms of X11, what do you have to do to make the application runable from tty?

How come programs like omxplayer, minecraft or gedit can't be ran from tty, but for instance "angry drunken dwarves" (a python game) or retroarch emulator can ?

Of course these are just examples, I don't want you to explain why these specifically do or don't run. But I suspect there is some common denominator. If you can, please go into details, but just links to the right literature/articles are welcome too. Thanks.

--EDIT--

Ok there has been some misunderstanding. To clarify: let's assume there is Xorg running in tty7 and we are trying to execute graphical programs in a different terminal (let's say tty1) that has no running instance of Xorg.

  • This is not a Linux only question. – Rob Feb 3 '18 at 14:15
  • 3
    @Rob so? This site is not a Linux only site, we deal with all *nix systems. – terdon Feb 3 '18 at 14:43
  • 2
    @Pyjong please read the answers here: What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? and edit your question to clarify the terminology you are using. It is very hard to understand as it is written. No graphical programs can be run from tty without several workarounds, they need a running X server, so your examples are also confusing. – terdon Feb 3 '18 at 14:45
  • @terdon I agree my edit isn't exactly straight forward explanation. I will try to update/clarify again with proper terminology. – Pyjong Feb 3 '18 at 18:00
  • @terdon My point was that the issue is not only on Linux but x11 runs on many other Unix and Unix-like sytems though, after re-reading the question, I realize his issue might only be with Linux. I'm not sure but it doesn't matter. – Rob Feb 3 '18 at 20:57
3

Whether a terminal is able to display a graphic application or not depends on two factors, the terminal capability and the graphic application design.

In the ancient time where terminals were real device connected to computers through serial lines, most terminals, especially the ones actually printing text on paper, a.k.a. teletypes were only able to display text.

There was already some kind of graphic "applications" able to print things similar to that one:

From: pk6811s_acad_drake_edu (Paul Kline)
[Here bingle and boobie.]
"They're 'just' pixellated art, but they're original and not overly long.
Best when viewed with light characters on dark background."

 Frank Sinatra

"The old crooner himself:"
     QB"   .  . ....^FBQQBQBQ
     #^   ..../,, ,/yyBQBDBt`"B
   B"  ._L_yQ&Qy&&QQBQQDlL;S; (Q
  B^   /DQQQBQQQQQQBQBDQQD1:   "B
 Q~   ,GQBDQDQQQQQQBBQQDQ&EC    7B
 D    lQQQQQBQBQQQQQQQQBBID('    {
 E   .iDDBQQBQQQQBBBQBQQDQ1!:    (
 3   .(BQBBQBBQQQQBBQBBBDBS'     }                     I'm
 Q   '~~<MMBQQBBQBP"""<BD1EL.    Q                   dreaming
 Q    LuL `7QBBB?../LL;.!JDL     Q                    of a
"  ,  ,__&L.DBBEEL1L_,'EylEE!  ,U                     white
1 :s&yyQQQ6-DQBBQ&QQQQQQQQJY!  lyB1Q                Christmas.
S  ?DDQQBD'.QQBDQDBQBQQQDD1<  LIQDG
Q   j8BQE2 LQQBE9EBBEBQQES{! /BQSE
 Q_ 'TS7L  <#P~^,G1?TXC3({!  3PEy
  Q, ,_>'.,___yBD1DU;,'('''  yQ
   L "Qy,  'IIIZl',L/&;!;:  LQ
   Q; FD(  (`IE2L/QDB&lY!   6Q
    Q, (/. `!?"21iQDU&/~   L FB
     Q_ (EL/&&QDBQBDJ"   ,y^  `FB
      Qy 75EEBBQESf`   _yB^      "M
      Q7  `'^""~`   _yQQM'         `"FQ
      F;         _yQQQQF              Q

Then came CRT based terminals like the DEC VT100 which implemented a standard that most current terminals emulators do follow. These terminals were essentially text, although there was support for some graphic characters but they were unable to display (high resolution) graphics. A 80 columns 25 lines display can also be regarded as a low resolution 2000 pixel device (80x25) but the serial lines speed was preventing this approach to be very useful.

There used to be also terminals able to display graphics natively, for example that one:

enter image description here

Nowadays, most graphic applications running on Unix and Linux are based on the X11 protocol at the lower level. This protocol requires an X11 compatible server to run on the computer controlling the screen. This server is taking control of the underlying console, or of one of the virtual terminals on all implementations so to a certain extent, all graphic applications are running from a terminal environment, often tty7, but of course this terminal lose its original capabilities as soon as X11 takes control.

The console used by most Unix/Unix like OSes provide some support for graphic applications. On Linux, this support is available through the linux framebuffer (fbdev - /dev/fb0). It is used for example to display the Linux penguin, Tux, at boot time.

enter image description here

There used to be a few applications that directly used that device like doom but now, most graphic applications use X11, which is also a relying on fbdev. Some very versatile applications like vlc and mplayer are able to directly use the Linux frame buffer.

There are also libraries that implement a graphic layer presenting a graphic device to applications but that are actually displaying on text consoles, not unlike what was done in the sixties on teletypes and on the eighties on PC connected to BBS. A well known one is libcaca with which you might even watch a movie on a terminal with mplayer...

enter image description here

Finally, some terminal emulators support graphics too. A notable one is the venerable xterm which provides a Tektronix 4014 emulator window able to display vector graphics with gnuplot and other applications/libraries:

enter image description here

  • What about a program that direct uses the framebuffer? Many exist, probably that you yourself use, eg. vlc, w3m, feh. – user1404316 Feb 4 '18 at 5:41
  • @user1404316 Yes, you are right, vlc is very flexible by supporting both libcaca and the framebuffer. I already mentioned doom, but using the framebuffer isn't the trend outside perhaps with embedded Linux to avoid X11 overhead. – jlliagre Feb 4 '18 at 10:14
6

Actually, what you (or more correctly, the GUI apps you run) need is two things usually.

  • access to X11 server via xhost
  • provide DISPLAY environment variable.

Practical working example is one of my old answes where dad-OP requested to show message from terminal ( assuming ssh ) to kids logged in via GUI.

With some desktop environments that use DBUS you may need to provide environment variable for DBUS session as well. This type of suggestion is often seen in questions on running GUI apps/messages to users from /etc/rc.local.

  • What about a program that direct uses the framebuffer? Many exist, probably that you yourself use, eg. vlc, w3m, feh. – user1404316 Feb 4 '18 at 5:40
  • @user1404316 I don't know enough about framebuffer to comment on it, I only have used fbterm and an image viewer app in TTY. Apps like feh still needs an X11 server, though. But "in theory" you probably could make something similar to fbterm to redraw TTY directly. But then you'll need separate TTY for everything. And why build it from scratch, if X11 and Wayland have APIs already? I'll leave this with a "maybe", since there's a lot question to consider. – Sergiy Kolodyazhnyy Feb 4 '18 at 6:00
  • There's nothing to be "built from scratch", and feh does not need an X-server if access to the frame-buffer is enabled. – user1404316 Feb 4 '18 at 7:51
  • @user1404316 OK, so would you care to explain how one would enable framebuffer access for feh ? Would be interesting to learn. And feh actually does need X-server apparently, because it specifically gives an error feh: Can't open X display. Bigger problem now is that we're discussing a particular application - we're getting distracted here. There's tons of others, and OP asked about GUI apps in general with reference to X11. And when I said about building from scratch, I meant building an app that relies on framebuffer only and not X11. – Sergiy Kolodyazhnyy Feb 4 '18 at 8:04
  • Here: unix.stackexchange.com/questions/117936/… is an answer I posted to another question thats answer you, and also be of use to @Pyjong. – user1404316 Feb 4 '18 at 12:29
1

Graphical applications do not run in a terminal. They run in an X server. This X server need not be connected to a tty although it usually is.

Thus not the application is connected to a tty but only the X server is. You can start an X server on a tty only, not an application.

IIRC you can make an X server run a single application, though. But I cannot give details on that.

  • I see.. that is getting me closer. Does the connection of X server to tty matter? Can applications started in terminal run in X server that is connected to a different tty? – Pyjong Feb 3 '18 at 18:09
  • @Pyjong It doesn't have to be tty. Consider VNC or ssh -X - in such cases there's no local TTY connected,but you can still use X11 server. So, no it doesn't matter. But for app to run, X server has to run in whichever way. – Sergiy Kolodyazhnyy Feb 3 '18 at 18:18
  • @Fox Yes but that only is if you call XOpenDisplay(NULL) – Pyjong Feb 3 '18 at 18:27
  • What about a program that direct uses the framebuffer? Many exist, probably that you yourself use, eg. vlc, w3m, feh. – user1404316 Feb 4 '18 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.