Qt Wayland 6.3中的Shell扩展

Shell Extensions in Qt Wayland 6.3

Qt Wayland 6.3中的Shell扩展

Friday April 01, 2022 by Eskil Abrahamsen Blomfeldt | Comments

​2022年4月1日,星期五

The Qt 6.3.0 release is just around the corner, and I wanted to share some updates we have made for the Qt Wayland integration and its companion module Qt Wayland Compositor. I will also use this as an opportunity to introduce some basic concepts to those who are not already familiar with Wayland, and give some background/justification for how things currently work.

Qt 6.3.0即将发布,我想分享我们为Qt Wayland集成及其配套模块Qt Wayland合成器所做的一些更新。我还将借此机会向那些还不熟悉Wayland的人介绍一些基本概念,并为当前的工作方式提供一些背景/理由。

Basic introduction

基本简介

For those who don't know, Wayland is a display server protocol that can be used as an alternative to X11 on Linux systems. The Qt Wayland Client module provides a way for a Qt application to run on such systems, and Qt Wayland Compositor provides a powerful API to write custom display servers from scratch.

​对于那些不知道的人来说,Wayland是一种显示服务器协议,可以在Linux系统上用作X11的替代方案。Qt Wayland客户端模块为Qt应用程序提供了在此类系统上运行的方法,而Qt Wayland Compositor提供了一个强大的API,可以从头开始编写定制的显示服务器。

The two modules together are what you need when you are creating a system based on Qt.

这两个模块合在一起就是创建基于Qt的系统时所需要的。

For context: Many Qt users are creating embedded devices where Qt is at the core of all user interaction. When such a system is sufficiently complex, it will often be to advisable to split it into multiple, separate processes. Isolating parts of the system in this way can make it both more secure and easier to maintain. But in order to make the conversion into a multi-process system, you need a way to share resources between the clients. Qt Wayland manages this for Qt-based systems.

上下文:许多Qt用户正在创建嵌入式设备,其中Qt是所有用户交互的核心。当这样一个系统足够复杂时,通常建议将其拆分为多个独立的流程。以这种方式隔离系统的各个部分可以使其更安全,也更易于维护。但为了将其转换为多进程系统,您需要一种在客户端之间共享资源的方法。Qt Wayland为基于Qt的系统管理此功能。

 

Qt Wayland Compositor can also be used to create servers for desktop systems, of course. But the most common use case at the moment is for embedded systems, and some of the features described in this blog are things that may primarily be convenient in an embedded system where all applications are pre-defined and trusted.

当然,Qt Wayland合成器也可以用于为桌面系统创建服务器。但目前最常见的用例是嵌入式系统,本博客中描述的一些功能主要是在所有应用程序都是预定义和可信的嵌入式系统中方便使用的。

For a more detailed introduction, check out the documentation.

​有关更详细的介绍,请查看文档。

Custom shell protocols

自定义shell协议

Shells are Wayland protocols which provide ways the client and server can communicate about surfaces (aka "windows" in a typical desktop context). This can be used for the "window manager" part of the server: Resizing surfaces, minimizing/maximizing them, defining their role in the system (is it a popup menu or an application window?) , et cetera.

​Shell是Wayland协议,它提供了客户端和服务器就表面进行通信的方式(在典型的桌面环境中称为“窗口”)。这可以用于服务器的“窗口管理器”部分:调整曲面大小、最小化/最大化曲面、定义它们在系统中的角色(是弹出菜单还是应用程序窗口?)等等。

Qt 6.2 (and earlier versions) supports three such protocols by default: WlShell, XdgShell and IviApplication. XdgShell is a "desktop-grade" shell, and provides the features you would expect on such a system. IviApplication is intended for IVI systems and is much simpler. (WlShell is a legacy protocol and exists for compatibility with older applications.)

​Qt 6.2(以及更早的版本)默认支持三种这样的协议:WlShell、XdgShell和IviApplication。XdgShell是一个“桌面级”shell,它提供了您在这样一个系统上所期望的功能。IviApplication适用于IVI系统,而且更简单。(WlShell是一种遗留协议,其存在是为了与较旧的应用程序兼容。)

When you are building a platform based on Qt, Wayland comes with some additional powerful tools: When both clients and server are running on the same framework, you can extend Wayland with your own protocols. This is a way to further customize how an application is integrated in the system. Qt Wayland and Qt Wayland Compositor are designed with this in mind, so adding extensions is both easy and convenient.

在基于Qt构建平台时,Wayland附带了一些额外的强大工具:当客户端和服务器都在同一个框架上运行时,您可以使用自己的协议扩展Wayland。这是一种进一步定制应用程序在系统中集成方式的方法。Qt Wayland和Qt Wayland Compositor的设计都考虑到了这一点,因此添加扩展既简单又方便。

Before Qt 6.3, however, there was no public API for customizing the shell protocol of the application. Some users would still do it by hooking into the private API, but at the penalty of maintaining patches on top of Qt Wayland that had to be rebased when new versions were released.

然而,在Qt6.3之前,没有用于定制应用程序外壳协议的公共API。一些用户仍然会通过连接到私有API来实现这一点,但代价是在Qt Wayland上维护补丁,新版本发布时,这些补丁必须重新设置。

In Qt 6.3, this gap has been filled, and writing custom shell extensions is now a supported use case. (It's worth noting that this is a rather advanced use case, and for most users the existing shells will probably be sufficient.)

在Qt6.3中,这个缺口已经被填补,编写定制的shell扩展现在是一个受支持的用例。(值得注意的是,这是一个相当高级的用例,对于大多数用户来说,现有的shell可能就足够了。)

In order to write a custom shell, you need to create an extension protocol, an implementation for the compositor, as well as a plugin that can be loaded by Qt applications. Together these pieces define how Qt application windows behave when running against your compositor, and you can run any unmodified Qt 6.3-based application with your shell extension as long as the compositor also supports it. For instance, in this screenshot, two instances of the particles3d example from Qt Quick 3D are running against the compositor. The code for the example has not been touched at all, and is the same that would be run on any other shell extension or platform.

​为了编写自定义shell,您需要创建一个扩展协议、一个合成器实现,以及一个可以由Qt应用程序加载的插件。这些部分共同定义了Qt应用程序窗口在针对合成器运行时的行为,只要合成器也支持,您就可以使用shell扩展运行任何未经修改的基于Qt 6.3的应用程序。例如,在这个屏幕截图中,来自Qt Quick 3D的Particle3D示例的两个实例正在与合成器运行。该示例的代码完全没有被涉及,与在任何其他shell扩展或平台上运行的代码相同。

For a full walk-through on how to do this, check out the Custom Shell Example.

​要全面了解如何实现这一点,请查看Custom Shell示例。

Qt Shell Extension

Qt Shell扩展

The standard shell extensions such as XdgShell have built-in limitations that are designed to enforce a consistent and non-intrusive behavior on part of the client applications. For instance, a client is not allowed to forcibly activate itself, since this will risk interrupting what the user is currently doing, and be both confusing and frustrating.

XdgShell等标准shell扩展具有内置的限制,旨在在部分客户端应用程序上强制执行一致且非侵入性的行为。例如,不允许客户端强制激活自身,因为这可能会中断用户当前正在做的事情,并且会让人困惑和沮丧。

The limitations exist for good reason, but they also limit the Qt APIs that can be supported. For instance, the QWindow::requestActivate() function is explicitly prohibited by this.

​存在这些限制是有充分理由的,但它们也限制了可以支持的Qt API。例如,QWindow::requestActivate()函数被明确禁止。

When building a custom platform consisting of trusted applications, the built-in limitations of XdgShell may be more in the way than they are useful. In some cases, it could be convenient to be able to use the existing APIs in Qt (such as QWindow::requestActivate()) rather than have to invent system-specific extensions for things like phone calls or warnings taking over the system.

在构建由受信任的应用程序组成的定制平台时,XdgShell的内置限制可能会带来更多不便。在某些情况下,可以方便地使用Qt中现有的API(例如QQWindow::requestActivate()),而不必为接管系统的电话或警告等事情发明特定于系统的扩展。

For this purpose, we have implemented a special QtShell which supports all the window management features in Qt's APIs. It is not intended as a replacement for XdgShell, but only as an alternative that can be used under the special circumstances where the limitations of XdgShell and interoperability with third-party applications are not required.

​为此,我们实现了一个特殊的QtShell,它支持Qt的api中的所有窗口管理功能。它不是XdgShell的替代品,而是在不需要XdgShell的限制和与第三方应用程序的互操作性的特殊情况下可以使用的替代品。

The Qt Shell also comes with a customizable "Chrome" (the packaging around the window surface). Here you can add your own decorations and behavior to client windows (the Qt Shell only supports server-side decorations). The example has a very simple style to illustrate how window decorations can be customized, but they can easily be expanded in the code.

​Qt Shell还带有可定制的“Chrome”(围绕窗户表面的包装)。在这里,您可以将自己的装饰和行为添加到客户端窗口(Qt外壳仅支持服务器端装饰)。这个例子有一个非常简单的样式来说明如何定制窗口装饰,但它们可以很容易地在代码中扩展。

See the QtShell Compositor Example for details on how to use this shell in your own compositor.

​有关如何在自己的合成器中使用此shell的详细信息,请参见QtShell合成器示例。

Conclusion

结论

Qt 6.3 introduces new ways of customizing the behavior and appearance of windows in your Qt Wayland-based systems. The standardized shells are still preferable - as long as they fulfill your requirements. But for some advanced use cases, it might be necessary to add features to the windowing system itself. Qt 6.3 adds two new ways of achieving this with Wayland.

Qt 6.3引入了在基于Qt Wayland的系统中自定义窗口行为和外观的新方法。标准化shell仍然更可取——只要它们满足您的要求。但对于某些高级用例,可能需要向窗口系统本身添加功能。Qt 6.3增加了两种通过Wayland实现这一点的新方法。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值