什么是 Linux 的原生 GUI API? [英] What is Linux’s native GUI API?

查看:30
本文介绍了什么是 Linux 的原生 GUI API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows (Win32 API) 和 OS X (Cocoa) 都有自己的 API 来处理窗口、事件和其他操作系统内容.对于 Linux 的等价物是什么,我从来没有真正得到明确的答案?

我听说有人说 GTK+,但 GTK+ 是跨平台的.怎么可能是原生的?

解决方案

在 Linux 中,图形用户界面不是操作系统的一部分.大多数 Linux 桌面上的图形用户界面由名为 X Window System 的软件提供,它定义了一种处理屏幕、键盘和指针设备的独立于设备的方式.

X Window 定义了一个用于通信的网络协议,任何知道如何说"这个协议的程序都可以使用它.有一个名为 Xlib 的 C 库可以更轻松地使用该协议,因此 Xlib 有点像 原生 GUI API.Xlib 不是访问 X Window 服务器的唯一方法;还有 XCB.

工具包库,例如 GTK+(由 GNOME) 和 Qt(由 KDE),建立在 Xlib 之上,因为它们更容易编程而被​​使用.例如,它们为您提供跨应用程序一致的外观和感觉、更易于使用拖放、为现代桌面环境提供组件标准等等.

X 在屏幕上的内部绘制方式取决于实现.X.org 有一个设备独立部分和一个设备相关部分.前者管理windows等屏幕资源,而后者与显卡驱动通信,通常是一个内核模块.通信可能通过直接内存访问或通过系统调用到内核.驱动程序将命令转换为卡上的硬件可以理解的形式.

截至 2013 年,一个名为 Wayland 的新窗口系统开始可用,许多发行版都表示他们将在某个时候迁移到它,尽管仍然没有明确的时间表.该系统基于 OpenGL/ES API,这意味着未来 OpenGL 将成为 Linux 中的原生 GUI API".正在完成将 GTK+ 和 QT 移植到 Wayland 的工作,以便当前流行的应用程序和桌面系统需要最少的更改.无法移植的应用程序将通过 X11 服务器得到支持,就像 OS X 通过 Xquartz 支持 X11 应用程序一样.GTK+ 移植预计在一年内完成,而 Qt 5 已经完全支持 Wayland.>

为了让事情更加复杂,Ubuntu 宣布他们正在开发一个名为 Mir 的新系统,因为他们遇到了一些问题.用 Wayland 感知.这个窗口系统也是基于OpenGL/ES API.

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?

解决方案

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.

这篇关于什么是 Linux 的原生 GUI API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆