What is Linux’s native GUI API?
Asked Answered
B

11

487

Both Windows (Win32 API) and OS X (Cocoa) have their own APIs to handle windows, events and other OS stuff. I have never really got a clear answer as to what Linux’s equivalent is?

I have heard some people say GTK+, but GTK+ being cross platform. How can it be native?

Brahmana answered 3/10, 2012 at 21:23 Comment(9)
Joni is correct: "In Linux the graphical user interface is not a part of the operating system... X Window System defines a network protocol for [GUI capabilities]. Toolkit libraries such as Gtk+ (used by Gnome) and QT (used by KDE), built on top of Xlib."Calefactory
on the contrary, David, this is an excellent inquiryKamin
I agree - I've read "The Linux Programming API" and "Systems Programming... Unix" which are the two bibles on the kernel & API, and this question never occurred to me :) The answers are interesting.Teryn
The Win32 API is also cross-platform if you include Wine..Giselegisella
BTW Windows has WIN32/WIN64 subsystems which implement a lot of the same for the 'Windows Look and Feel - aka WIN32' amongst other things. These subsystems operate above the NT kernel. The APIs for these are different. For example C: is a WIN32 abstraction, not an NT kernel thing. Same for some of the windowing functionality. Windows also had Unix subsystems that are available (that support X11 to some degree).Came
So in effect Windows does this in a similar (possibly more complete way), as Linux (see @joni's answer) except that we just call the package Windows and tend to forget about the separation. However WIN32 is the one we tend to use so it's 'the defacto API.Came
Can someone please s/Linux/Unix to generalize this?Infatuated
@BrendanLong Actually that does not make it "crossplatform", since wine reimplemented windows API for use in linux.Situation
since in windows GUI is part of the OS and in linux it's not the case, shouldn't that make using GUI faster is windows than in linux? at least theoretically if not in practicePurusha
S
650

In Linux the graphical user interface is not a part of the operating system. The graphical user interface found on most Linux desktops is provided by software called the X Window System, which defines a device independent way of dealing with screens, keyboards and pointer devices.

X Window defines a network protocol for communication, and any program that knows how to "speak" this protocol can use it. There is a C library called Xlib that makes it easier to use this protocol, so Xlib is kind of the native GUI API. Xlib is not the only way to access an X Window server; there is also XCB.

Toolkit libraries such as GTK+ (used by GNOME) and Qt (used by KDE), built on top of Xlib, are used because they are easier to program with. For example they give you a consistent look and feel across applications, make it easier to use drag-and-drop, provide components standard to a modern desktop environment, and so on.

How X draws on the screen internally depends on the implementation. X.org has a device independent part and a device dependent part. The former manages screen resources such as windows, while the latter communicates with the graphics card driver, usually a kernel module. The communication may happen over direct memory access or through system calls to the kernel. The driver translates the commands into a form that the hardware on the card understands.

As of 2013, a new window system called Wayland is starting to become usable, and many distributions have said they will at some point migrate to it, though there is still no clear schedule. This system is based on OpenGL/ES API, which means that in the future OpenGL will be the "native GUI API" in Linux. Work is being done to port GTK+ and QT to Wayland, so that current popular applications and desktop systems would need minimal changes. The applications that cannot be ported will be supported through an X11 server, much like OS X supports X11 apps through Xquartz. The GTK+ port is expected to be finished within a year, while Qt 5 already has complete Wayland support.

To further complicate matters, Ubuntu has announced they are developing a new system called Mir because of problems they perceive with Wayland. This window system is also based on the OpenGL/ES API.

Stagger answered 3/10, 2012 at 21:38 Comment(17)
Even Windows was originally just a program that ran on top of DOS.Gilmour
+1 @DavidHammen I'm not sure if that was directed at me or not, but you're 100% correct. My terminology was not exactly accurate. What I should have said was that it's not a full operating system in the way you might commonly think of a OS with all of the additional components that make it easy to use, but rather a conglomeration of components from different vendors, etc.Stipendiary
@ChrisThompson - hmm... maybe I'm too old but I've never thought of a GUI as a core part of an OS. And I've never thought of an OS without a GUI as simply being "a conglomeration of components from different vendors, etc." But hey maybe things have moved on since I formed my opinion of what constituted an OS :)Lesser
@GeorgeHawkins I'm not doing a good job of explaining. A GUI is definitely not a core part of an OS, and frankly neither is a UI. When you look at Ubuntu Linux, most people typically think that entire software image as the OS including every feature that is present at installation. So that includes GNOME, the Linux kernel, bash, an X11 server, various software libraries (libc, pthread, etc), etc etc etc which can all come from different vendors. I'm not sure if that makes sense, but that's the idea I'm trying to get at.Stipendiary
Not in the context of this question, anyway. But you'd be surprised at how many people believe that to be the case...Teniers
+1 for the level of detail that you went into while keeping it easy for the less experienced to understand.Stab
@Stagger One remark: X-Window is the historical standard display protocol. New display protocol, Wayland, is already there and could be its successor. Read more at en.wikipedia.org/wiki/Wayland_%28display_server_protocol%29Carberry
+1 - have a look at freebsd.org/doc/en_US.ISO8859-1/books/handbook/x11-wm.html, quote: A “desktop environment” can mean anything ranging from a simple window manager to a complete suite of desktop applications, such as KDE or GNOME. In many cases we could probably simplify that to something which is a window manager using Xclients (see en.wikipedia.org/w/…). Also see this diagram describing where Xwindows sits in the OS csit.parkland.edu/~smauney/csc128/x-windows_diagram.htmlVanny
Are you sure X windows is using system calls to talk to driver that talks for GPU? I have a seriously strong feeling that X server communicates with a graphics card directly through DMA buffers mapped into user space.Brown
@VladLazarenko So you think there are no graphics device drivers? I suggest that you read blog.mecheye.net/2012/06/the-linux-graphics-stackCaning
@JimBalter: Did I say there are no drivers? I said that X server is most likely communicating through user-mapped DMA.Brown
@VladLazarenko You questioned whether X talks to the driver rather than directly to the graphics card. If it only did the latter, there would no need for nvidia and ATI drivers. DMA is for data, not control.Caning
since in windows GUI is part of the OS and in linux it's not the case, shouldn't that make using GUI faster is windows than in linux? at least theoretically if not in practicePurusha
"To meet the needs of today's users Mir avoids the X11 protocol and uses Wayland for a more modern and secure approach to graphics." ... "Mir uses Wayland as the primary protocol for connecting to applications." mir-server.ioSavill
Mir is a "Wayland compositor" like "Mutter". GNOME, and therefore ubuntu, uses Mutter. en.wikipedia.org/wiki/Mir_(software)Savill
Yes @HonestAbe the plans for Mir as a competitor/replacement for Wayland have changed since 2013, you're welcome to update the answer for 2019 if you're familiar with the current status of the display servers.Stagger
Unless an answer is a community wiki, I won't change any content, aside from improving grammar / formatting or adding links. If content needs to be corrected or updated, that's the responsibility of the person whose reputation is bound to the content. I will however do them the favor of commenting, so that they become aware that I think something needs to be corrected or updated.Savill
S
92

Linux is a kernel, not a full operating system. There are different windowing systems and gui's that run on top of Linux to provide windowing. Typically X11 is the windowing system used by Linux distros.

Stipendiary answered 3/10, 2012 at 21:26 Comment(13)
question: what do KDE Plasma and GNOME graphical environment relate to X11? are they in the same level, i.e. alternatives or are they built on top of X11? thanksKamin
They are built on top of it. X11 is the server, while KDE, Gnome etc. are desktop managers, providing higher level APIs, common window layouts etc.Effable
X11 is the actual low level layer that handles all of this stuff and handles drawing to screen etc (and communicates with graphics drivers). Gnome/KDE then control X11. That's about it at a high level and ignoring a billion and one details.Iinden
thanks. one more question: wikipedia explains that X11 "creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X." my question is: why does X11 provide hardware interaction (HAL), should the Linux Kernel provide that and X11 operate on top of the Kernel? In other words, why is X11 reaching to hardware devices when the Kernel should be its proxy?Kamin
I think in this case HAL is an incorrectly used term. Really what they're saying is X11 provides a system-independent means to display windows. There are versions of X11 for Darwin (Mac OS - that's actually more complicated now with Mountain Lion...), MS Windows and Linux.Stipendiary
so in this case, X11 would not really be a HAL but more like something like the JVM (OS abstraction layer), correct?Kamin
@foampile sort of if you want to take a really, really, really high-level view of what the JVM is and categorize it by the functionality it provides rather than how it provides it. I don't mean to be pedantic but X11 and the JVM are two very different things. X11 is closer to something like Qt where you have a standard set of function calls and libraries but your code must be compiled specifically for each system you want to run it on.Stipendiary
that is what i meant -- an analogy rather than a side-by-side comparisonKamin
@foampile then yes, I'd say that's a reasonable way to look at it!Stipendiary
X11 is a network protocol. Abstraction involves writing programs on platform A that can display X11 clients (windows, apps, etc) on platform B over some networking equipment. Your app can run locally, remotely, in a nested server, in a virtual server that just does VNC, etc. Hardware abstraction (on the local platform) is a side-effect of this feature, but it also blurs the line between X11 and the kernel (which is what does hardware abstraction on an average Unix system).Geriatric
@foampile HAL is the correct term, and it doesn't mean "hardware interaction", it means "hardware abstraction" -- an abstract view of graphics and user interface hardware. Neither X11 clients nor X11 servers need run on Linux, so Linux can't possibly do what X11 does. Linux itself provides an abstraction layer, to hardware and other services, and so does a JVM (which is an abstraction of a machine, not just an OS).Caning
" a really, really, really high-level view of what the JVM is and categorize it by the functionality it provides rather than how it provides it" -- The JVM has a formal specification that details the functionality that it provides and is agnostic about how it is provided.Caning
@JimBalter The JVM specification is indeed a specification. "The JVM" is an implementation of the JVM specification. ("The JVM" usually means either the Oracle JVM, or whichever JVM happens to be installed on your computer)Weaner
B
64

Wayland is also worth mentioning as it is mostly referred as a "future X11 killer".

Also note that Android and some other mobile operating systems don't include X11 although they have a Linux kernel, so in that sense X11 is not native to all Linux systems.

Being cross-platform has nothing to do with being native. Cocoa has also been ported to other platforms via GNUStep but it is still native to OS X / macOS.

Betook answered 3/10, 2012 at 21:49 Comment(7)
The high level architecture diagram for Wayland is the same as that of X, except that the "Compositor" and "Server" in the X diagram are merged in the Wayland diagram. What's lacking is a plausible explanation why this integration couldn't be worked into X.Margarethe
well, I would say it's not easy changing the fundamental design of a 20+ years old code base. Also note that another problem with X11 is that most of it's functionality such as font rendering is not being used today. Plus X11 will still be needed in servers and supercomputers, network transparency is just too good to be given up.Betook
@gokcehan wayland doesn't omit network transparency, it's a myth. It's not implemented yet, just as many other things in Wayland. wayland.freedesktop.org/faq.html#heading_toc_j_8 blog.martin-graesslin.com/blog/2011/08/… etc.Comyns
+! for mentioning Android's lack of X11. Android is probably the most convincing counter-example to the argument that "x11 is the native linux GUI". Demonstrating that Linux can have x11 or Android as it's "native" GUI shows beginners that Linux is really just a kernel and doesn't always have GUI.Engram
"Being cross-platform has nothing to do with being native" is an excellent point. I've used that pattern very frequently over my years of porting cross-platform. Most notably, in the 90's, I sold a framework which let you cross-compile code written to the Metrowerks PowerPlant framework using MFC under the hood. (Before anyone sneers, once you get below the macros, MFC is quite reasonable.) I've also had multiple porting jobs where either the Win32 or the Mac Toolbox API was the spec against which we compiled, reimplemented as necessary on the other platforms.Impi
@whitequark your link directly contradicts your claim. Is Wayland network transparent / does it support remote rendering? No, that is outside the scope of Wayland.Twitch
@Twitch Perhaps it should have been phrased as "Wayland does not preclude network transparency."Comyns
T
26

Strictly speaking, the API of Linux consists of its system calls. These are all of the kernel functions that can be called by a user-mode (non-kernel) program. This is a very low-level interface that allows programs to do things like open and read files. See http://en.wikipedia.org/wiki/System_call for a general introduction.

A real Linux system will also have an entire "stack" of other software running on it, in order to provide a graphical user interface and other features. Each element of this stack will offer its own API.

Tayyebeb answered 3/10, 2012 at 21:37 Comment(2)
This answer was written when the question was "What is linux's native API?" (since then, "GUI" has been inserted into the question).Tayyebeb
It's still the right answer to what is now an incoherent question because none of the systems that sit on top of Linux, including GNU and X11, are "native" in any meaningful sense.Caning
F
21

To aid in what has already been mentioned there is a very good overview of the Linux graphics stack at this blog: http://blog.mecheye.net/2012/06/the-linux-graphics-stack/

This explains X11/Wayland etc and how it all fits together. In addition to what has already been mentioned I think it's worth adding a bit about the following API's you can use for graphics in Linux:

Mesa - "Mesa is many things, but one of the major things it provides that it is most famous for is its OpenGL implementation. It is an open-source implementation of the OpenGL API."

Cairo - "cairo is a drawing library used either by applications like Firefox directly, or through libraries like GTK+, to draw vector shapes."

DRM (Direct Rendering Manager) - I understand this the least but its basically the kernel drivers that let you write graphics directly to framebuffer without going through X

Foss answered 4/10, 2012 at 3:40 Comment(1)
habrahabr.ru/post/148954 - (in russian) translation of that post if anyone needsSalespeople
E
11

I suppose the question is more like "What is linux's native GUI API".

In most cases X (aka X11) will be used for that: http://en.wikipedia.org/wiki/X_Window_System.

You can find the API documentation here

Effable answered 3/10, 2012 at 21:33 Comment(0)
K
6

XWindows is probably the closest to what could be called 'native' :)

Kirakiran answered 3/10, 2012 at 21:26 Comment(2)
is that the same thing as x11?Brahmana
But if you use it directly, you will see it's not quite a GUI api... Linux just doesn't have 1 native GUI api. But nearly all those GUI APIs (at least those common on desktop linux today) run on top of X. If you start writing an application using plain old X today, it will look totally out of place on any modern distro, so I'd say the native GUI is distribution dependent - gtk/gnome for ubuntu, kde for others.Sussi
I
1

The linux kernel graphical operations are in /include/linux/fb.h as struct fb_ops. Eventually this is what add-ons like X11, Wayland, or DRM appear to reference. As these operations are only for video cards, not vector or raster hardcopy or tty oriented terminal devices, their usefulness as a GUI is limited; it's just not entirely true you need those add-ons to get graphical output if you don't mind using some assembler to bypass syscall as necessary.

Irrawaddy answered 27/2, 2018 at 1:49 Comment(0)
K
1

Wayland

As you might hear, wayland is the featured choice of many distros these days, because of its protocol is simpler than the X.

Toolkits of wayland

Toolkits or gui libraries that wayland suggests are:

  • QT 5
  • GTK+
  • LSD
  • Clutter
  • EFL
Kiloliter answered 4/10, 2018 at 7:39 Comment(0)
M
0

The closest thing to Win32 in linux would be the libc, as you mention not only the UI but events and "other os stuff"

Maggiemaggio answered 4/10, 2012 at 0:54 Comment(4)
libc (the C standard library) is an interface to the OS system calls. It's the latter (OS system calls) on Linux that roughly translates to Win32 on Windows. You can't really (or at all?) program for current versions of Windows without at some level using the Win32 API, but you can program for both Windows and Linux without using the respective compiler's standard C library, simply by duplicating the direct-to-syscalls code. It isn't recommended, and it makes your code completely nonportable to other OSes, but it's possible to do.Carminecarmita
UI isn't part of libc - as long as you don't think of printf/scanf and the like as being a UI... libc is just the C standard library. And it's not really an interface to the OS system calls either. It provides functions for file i/o, memory management, string processing etc. and internally uses system calls. For making system calls like ioctl yourself, you'd have to include something from sys/.Sussi
The question didn't always specify "GUI".Healthful
Maybe you talk about Xlib not libc.Claimant
S
0

GUI is a high level abstraction of capability, so almost everything from XOrg server to OpenGL is ported cross-platform, including for Windows platform. But if by GUI API you mean *nix graphics API then you might be wandering around "Direct Rendering Infrastructure".

Smooth answered 29/11, 2015 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.