轉自:https://wiki.qt.io/QtWayland/zh
QtWayland/zh
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 | 簡體中文
Contents
什么是QtWayland?
QtWayland是封裝了Wayland功能的Qt 5模塊。QtWayland被分為一個客戶端(client)和一個服務端(server)。客戶端是wayland平台插件,提供了運行Wayland客戶端Qt程序的方法。服務端是QtCompositor應用程序接口(API),允許用戶編寫自己的compositors。
什么是Wayland
Wayland是一個用C庫實現的為了使Compositor和Client溝通的協議。要獲得更多詳細信息,請訪問 Wayland項目主頁
從哪里找到QtWayland代碼?
怎樣構建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
這些例子示范了服務器端(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