QtWayland

什么是QtWayland?

QtWayland是封装了Wayland功能的Qt 5模块。QtWayland被分为一个客户端(client)和一个服务端(server)。客户端是wayland平台插件,提供了运行Wayland客户端Qt程序的方法。服务端是QtCompositor应用程序接口(API),允许用户编写自己的compositors。

什么是Wayland

Wayland是一个用C库实现的为了使Compositor和Client沟通的协议。要获得更多详细信息,请访问 Wayland项目主页

从哪里找到QtWayland代码?

Gitorious仓库

怎样构建QtWayland?

桌面构建指令

设置构建环境

第一步,选择一个合适的新的Linux发行版。我使用Ubuntu 12.04,比这个新的更好。

下面的指南基于 http://wayland.freedesktop.org/building.html 上的提示

我做的第一件事是创建一个Wayland安装目录和一个设置环境的文件:

~/Apps/Wayland/wayland.sourceme

#wayland.sourceme
WLD=$HOME/Apps/Wayland # change this to another location if you prefer
LD_LIBRARY_PATH=$WLD/lib
PKG_CONFIG_PATH=$WLD/lib/pkgconfig/:$WLD/share/pkgconfig/
ACLOCAL="aclocal -I $WLD/share/aclocal"
PATH=$WLD/bin:$PATH
XDG_RUNTIME_DIR=/tmp
 
export WLD LD_LIBRARY_PATH PKG_CONFIG_PATH ACLOCAL PATH XDG_RUNTIME_DIR

之后用这个文件设置您的工作环境:_source~/Apps/Wayland/wayland.sourceme_

编译依赖的库

您需要的大部分依赖库都已经发布了。但是仍然没有包含在最新的Linux发行版中。所以您需要编译它们。这里是编译它们的指南:

wayland
git clone git://anongit.freedesktop.org/wayland/wayland
cd wayland
git checkout -b branch-1.0.3 1.0.3
#this prevents autogen.sh to fail while testing for exiting folders
mkdir -p $WLD/share/aclocal
./autogen.sh —prefix=$WLD
make
make install
drm
git clone git://anongit.freedesktop.org/git/mesa/drm
cd drm
git checkout -b branch-2.4.40 2.4.40
./autogen.sh —prefix=$WLD
make && make install
mesa
git clone git://anongit.freedesktop.org/mesa/mesa
cd mesa
git checkout 9.0
./autogen.sh —prefix=$WLD —enable-gles2 —disable-gallium-egl —with-egl-platforms=x11,wayland,drm —enable-gbm —enable-shared-glapi —with-gallium-drivers=r300,r600,swrast,nouveau
make && make install
libxkbcommon
git clone git://people.freedesktop.org/xorg/lib/libxkbcommon.git
cd libxkbcommon/
git checkout -b branch-0.2.0 xkbcommon-0.2.0
./autogen.sh —prefix=$WLD —with-xkb-config-root=/usr/share/X11/xkb
make && make install
weston(可选)
git clone git://anongit.freedesktop.org/wayland/weston
cd weston
git checkout -b branch-1.0.3 1.0.3
./autogen.sh —prefix=$WLD
make
make install -k

Qt 5.0.0依赖

对于Qt,您可以使用于预编译的5.0.0二进制文件,或者从最新的Qt 5.0.0(stable分支)构建,这里不使用wayland.source环境。您至少需要的Qt 5.0.0模块有:qtbaseqtjsbackendqtdeclarative

如果您遇到了关于libGL和undefined references链接错误,可能是需要编译Qt5并且链接自己编译的mesa库,可能是由于编译和安装mesa的方式,配置脚本需要明确的定义openGL的版本,使用: ./configure -opengl es2

构建QtWayland模块

一旦您构建好了Qt 5,之后获取最新的QtWayland模块代码,使用qmake配置,这次是用wanyland.source环境。确定您使用的qmake是刚构建好的Qt 5中的。这将确定您使用了特别的OpenGL和Wayland版本来构建Wayland平台插件和QtCompositor API。

source ~/Apps/Wayland/wayland.sourceme
git clone git://gitorious.org/qt/qtwayland.git
cd qtwayland
qmake
make
make install


Raspberry Pi编译指南

敬请期待。


怎样使用QtWayland?

作为Wayland客户端运行Qt程序

当您编译完QtWayland模块,您将得到一个新的wayland平台插件。要使用它,您首先需要有一个已经运行的Wayland compositor。这可以是一个Wayland项目提供的Weston reference compositor,或是QtWayland提供的Qt example compositor。不管怎样,作为一个应用程序开发者,您需要做的唯一一件事是把您的程序作为wayland客户端运行:

source~/Apps/Wayland/wayland.sourceme
./application -platform wayland

创建和运行您自己的Qt5 Wayland Compositor

运行例子中的compositor

QtWayland模块中提供了几个compositor样例,演示了QtCompositor是如何工作的。这些样例在QtWayland模块的example目录中,如果您使用qmake时添加了"wayland-compositor"到CONFIG变量。

qmake CONFIG+=wayland-compositor<code>
 
这些例子示范了服务器端(server side)的Wayland,所以您不需要使用wayland平台插件,不管您是在那个平台运行。通常这些平台是eglfs、 kms或者您想运行于X11 xcb。
 
如果您想在X11中运行qml-compositor: 您需要按下面的方式运行:
source ~/Apps/Wayland/wayland.sourceme

cd qtwayland/examples/qml-compositor

./qml-compositor -platform xcb
现在,您的Wayland compositor运行了,您可以连接和显示Wayland客户端了。
 
=== 创建您自己的compositor ===
 
创建Wayland compositor和控制相关事件的应用程序接口在QtWayland类的WaylandCompositor中。它的构造函数需要QWindow对象指针作为主参数。这使实现compositor更加灵活。
 
由于这种设计,实现compositor有3中不同的方法:
 
* 基于QWidow:实例将会用于配置WaylandCompositor对象。
* 基于QWidget:这种情况中,基础的widget窗体句柄将被使用。
* 基于QML:您的C+''程序将使用一个QQuickView对象类配置WaylandCompositor。直到些这篇文章的时候,还没有仅使用QML创建compositor的方法。
 
 
WaylandCompositor是纯抽象虚类,它不能用来创建实例。实现compositor的通用方法是继承自WaylandCompositor并实现这个方法*void surfaceCreated(WaylandSurface '''surface)'''。
 
这个方法会在每次新客户端连接的时候执行(例如程序启动请求compositor服务时)。作为一个WaylandSurface对象。这里有一些这个对象生成的信号,被compositor处理,叫做:
 
 
* mapped(): 当client连接到compositor时发射。
 
* damaged(): TODO
 
* destroyed(): 当client退出时发射(即应用程序退出时)
 
* unmapped(): TODO
 
* extendedSurfaceReady(): TODO
 
工程文件需要使用compositor模块(即在.pro文件中添加QT''= compositor)。有趣的是在写这篇文章的时候,需要注意的是有些QML相关的API只能在工程文件中添加宏定义(即DEFINES += QT_COMPOSITOR_QUICK)。
 
=== 独立运行compositor ===
 
TODO

https://wiki.qt.io/QtWayland/zh
  • 0
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Qt Wayland是一个Qt模块,它包含两个部分:Wayland平台插件和QtWaylandCompositor API。Wayland平台插件使得Qt应用程序可以作为Wayland客户端运行,而QtWaylandCompositor API则允许使用QtQtQuick创建Wayland合成器。\[1\]\[2\] 要使用Qt Wayland,您需要先编译QtWayland模块,并获得一个新的Wayland平台插件。然后,您需要有一个已经运行的Wayland合成器,可以是Weston参考合成器或QtWayland提供的Qt示例合成器。作为应用程序开发者,您只需要将您的程序作为Wayland客户端运行即可。\[1\] 如果您想创建和运行自己的Qt5 Wayland合成器,可以参考QtWayland提供的API和示例代码。\[1\] 关于如何运行QtWayland,您可以参考QtWayland官方网站提供的编译指南。在源码中,QtWayland还提供了一些合成器的示例,您只需要设置一些环境变量,如"QT_WAYLAND_HARDWARE_INTEGRATION"和"XDG_RUNTIME_DIR",然后即可运行这些示例。\[3\] 总之,Qt Wayland是一个允许Qt应用程序作为Wayland客户端运行,并提供创建Wayland合成器的API的模块。您可以根据需要编译和使用它。 #### 引用[.reference_title] - *1* [QtWayland](https://blog.csdn.net/qnnming/article/details/51881630)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [【WaylandQtWayland框架分析](https://blog.csdn.net/zxc024000/article/details/127953543)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值