QtWayland/zh

From Qt Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

English | 简体中文

什么是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模块有: qtbase qtjsbackend qtdeclarative

如果您遇到了关于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