什么是 Linux 的原生 GUI API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12717138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is Linux’s native GUI API?
提问by DavidColson
I hope this doesn't come across as a stupid question but it's always something I have wondered. 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.
我希望这不会被认为是一个愚蠢的问题,但它总是我一直想知道的。Windows (Win32 API) 和 OS X (Cocoa) 都有自己的 API 来处理窗口、事件和其他操作系统的东西。对于 Linux 的等价物是什么,我从来没有真正得到明确的答案。
I have heard some people say GTK+, but GTK+ being cross platform, how can it be native?
我听有人说GTK+,但是GTK+是跨平台的,怎么可能是原生的?
采纳答案by Joni
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.
在 Linux 中,图形用户界面不是操作系统的一部分。大多数 Linux 桌面上的图形用户界面是由称为X Window System的软件提供的,它定义了一种处理屏幕、键盘和指针设备的独立于设备的方式。
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 Xlibthat makes it easier to use this protocol, so Xlib is kind of thenative GUI API. Xlib is not the only way to access an X Window server; there is also XCB.
X Window 定义了一个用于通信的网络协议,任何知道如何“说”这个协议的程序都可以使用它。有一个叫C库的Xlib,使得它更容易使用这个协议,所以×程序库是一种对本地的GUI API。Xlib 不是访问 X Window 服务器的唯一方法;还有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.
使用工具包库,例如GTK+(由GNOME 使用)和Qt(由KDE 使用),它们构建在 Xlib 之上,因为它们更易于编程。例如,它们为您提供跨应用程序一致的外观和感觉,使拖放操作更容易,为现代桌面环境提供组件标准,等等。
How X draws on the screen internally depends on the implementation. X.orghas 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 accessor through system callsto the kernel. The driver translates the commands into a form that the hardware on the card understands.
X 在屏幕上的内部绘制方式取决于实现。X.org有一个设备独立部分和一个设备相关部分。前者管理windows等屏幕资源,而后者与显卡驱动通信,通常是一个内核模块。通信可以通过直接内存访问或通过对内核的系统调用进行。驱动程序将命令转换为卡上的硬件可以理解的形式。
As of 2013, a new window system called Waylandis 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.
到 2013 年,一个名为Wayland的新窗口系统开始可用,许多发行版都表示他们将在某个时候迁移到它,尽管仍然没有明确的时间表。该系统基于 OpenGL/ES API,这意味着未来 OpenGL 将成为 Linux 中的“原生 GUI API”。正在完成将 GTK+ 和 QT 移植到 Wayland 的工作,以便当前流行的应用程序和桌面系统需要最少的更改。无法移植的应用程序将通过 X11 服务器得到支持,就像 OS X 通过 Xquartz 支持 X11 应用程序一样。GTK+ 移植预计将在一年内完成,而 Qt 5 已经完全支持 Wayland。
To further complicate matters, Ubuntu has announced they are developing a new system called Mirbecause of problems they perceive with Wayland. This window system is also based on the OpenGL/ES API.
更复杂的是,Ubuntu 宣布他们正在开发一个名为Mir的新系统,因为他们认为 Wayland 存在问题。这个窗口系统也是基于 OpenGL/ES API。
回答by Chris Thompson
回答by Sergey Sirotkin
XWindows is probably the closest to what could be called 'native' :)
XWindows 可能最接近于所谓的“本机”:)
回答by Mark
I suppose the question is more like "What is linux's native GUI API".
我想这个问题更像是“什么是 linux 的原生 GUI API”。
In most cases X (aka X11) will be used for that: http://en.wikipedia.org/wiki/X_Window_System.
在大多数情况下,X(又名 X11)将用于:http: //en.wikipedia.org/wiki/X_Window_System。
You can find the API documentation here
您可以在此处找到 API 文档
回答by nibot
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_callfor a general introduction.
严格来说,Linux 的 API 由它的系统调用组成。这些是用户模式(非内核)程序可以调用的所有内核函数。这是一个非常低级的接口,允许程序执行诸如打开和读取文件之类的操作。有关一般介绍,请参阅http://en.wikipedia.org/wiki/System_call。
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.
一个真正的 Linux 系统还会有一个完整的“堆栈”,上面运行着其他软件,以提供图形用户界面和其他功能。此堆栈的每个元素都将提供自己的 API。
回答by none
Waylandis also worth mentioning as it is mostly referred as a "future X11 killer".
Wayland也值得一提,因为它通常被称为“未来的 X11 杀手”。
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.
另请注意,虽然 Android 和其他一些移动操作系统具有 Linux 内核,但它们并不包含 X11,因此从这个意义上说,X11 并非所有 Linux 系统都自带。
Being cross-platform has nothing to do with being native. Cocoa has also been ported to other platforms via GNUStepbut it is still native to OS X / macOS.
跨平台与本机无关。Cocoa 也已通过GNUStep移植到其他平台,但它仍然是 OS X / macOS 原生的。
回答by Midhat
The closest thing to Win32 in linux would be the libc, as you mention not only the UI but events and "other os stuff"
linux 中最接近 Win32 的是 libc,你不仅提到了 UI,还提到了事件和“其他操作系统的东西”
回答by Matt
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/
为了帮助已经提到的内容,此博客中对 Linux 图形堆栈进行了很好的概述: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:
这解释了 X11/Wayland 等以及它们如何组合在一起。除了已经提到的内容之外,我认为值得添加一些有关以下 API 的信息,这些 API 可用于 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."
Mesa- “Mesa 有很多东西,但它提供的最有名的主要东西之一是它的 OpenGL 实现。它是 OpenGL API 的开源实现。”
Cairo- "cairo is a drawing library used either by applications like Firefox directly, or through libraries like GTK+, to draw vector shapes."
Cairo- “cairo 是一个绘图库,可以由 Firefox 等应用程序直接使用,也可以通过 GTK+ 等库使用,用于绘制矢量形状。”
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
DRM(直接渲染管理器)-我对此至少了解,但它基本上是内核驱动程序,可让您将图形直接写入帧缓冲区而无需通过 X
回答by Chawathe Vipul S
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".
GUI 是功能的高级抽象,因此几乎从 XOrg 服务器到 OpenGL 的所有内容都是跨平台移植的,包括 Windows 平台。但是,如果 GUI API 是指 *nix 图形 API,那么您可能会在“直接渲染基础架构”中徘徊。
回答by M. Ziegast
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.
linux 内核图形操作在 /include/linux/fb.h 中作为 struct fb_ops。最终,这就是 X11、Wayland 或 DRM 等附加组件所参考的内容。由于这些操作仅适用于视频卡,而不适用于矢量或光栅硬拷贝或面向 tty 的终端设备,因此它们作为 GUI 的用途有限;如果您不介意使用某些汇编程序在必要时绕过系统调用,则并非完全正确,您需要这些附加组件来获得图形输出。