summaryrefslogtreecommitdiffstats
path: root/examples/wayland/custom-extension/compositor
diff options
context:
space:
mode:
Diffstat (limited to 'examples/wayland/custom-extension/compositor')
-rw-r--r--examples/wayland/custom-extension/compositor/customextension.cpp55
-rw-r--r--examples/wayland/custom-extension/compositor/customextension.h24
-rw-r--r--examples/wayland/custom-extension/compositor/main.cpp2
-rw-r--r--examples/wayland/custom-extension/compositor/qml/Screen.qml77
-rw-r--r--examples/wayland/custom-extension/compositor/qml/main.qml106
5 files changed, 224 insertions, 40 deletions
diff --git a/examples/wayland/custom-extension/compositor/customextension.cpp b/examples/wayland/custom-extension/compositor/customextension.cpp
index 6c1f05977..7a292a9e6 100644
--- a/examples/wayland/custom-extension/compositor/customextension.cpp
+++ b/examples/wayland/custom-extension/compositor/customextension.cpp
@@ -44,9 +44,8 @@
#include <QDebug>
-namespace QtWayland {
-
-CustomExtension::CustomExtension()
+CustomExtension::CustomExtension(QWaylandCompositor *compositor)
+ :QWaylandCompositorExtensionTemplate(compositor)
{
}
@@ -57,22 +56,60 @@ void CustomExtension::initialize()
init(compositor->display(), 1);
}
-void CustomExtension::sendEvent(QWaylandSurface *surface, uint time, const QString &text, uint value)
+void CustomExtension::setFontSize(QWaylandSurface *surface, uint pixelSize)
+{
+ if (surface) {
+ Resource *target = resourceMap().value(surface->waylandClient());
+ if (target) {
+ qDebug() << "Server-side extension sending setFontSize:" << pixelSize;
+ send_set_font_size(target->handle, surface->resource(), pixelSize);
+ }
+ }
+}
+
+void CustomExtension::showDecorations(QWaylandClient *client, bool shown)
+{
+ if (client) {
+ Resource *target = resourceMap().value(client->client());
+ if (target) {
+ qDebug() << "Server-side extension sending showDecorations:" << shown;
+ send_set_window_decoration(target->handle, shown);
+ }
+ }
+
+}
+
+void CustomExtension::close(QWaylandSurface *surface)
{
if (surface) {
Resource *target = resourceMap().value(surface->waylandClient());
if (target) {
- qDebug() << "Server-side extension sending an event:" << text << value;
- send_qtevent(target->handle, surface->resource(), time, text, value);
+ qDebug() << "Server-side extension sending close for" << surface;
+ send_close(target->handle, surface->resource());
}
}
}
-void CustomExtension::example_extension_qtrequest(QtWaylandServer::qt_example_extension::Resource *resource, const QString &text, int32_t value)
+void CustomExtension::example_extension_bounce(QtWaylandServer::qt_example_extension::Resource *resource, wl_resource *wl_surface, uint32_t duration)
{
Q_UNUSED(resource);
- qDebug() << "Server-side extension received a request:" << text << value;
- emit requestReceived(text, value);
+ auto surface = QWaylandSurface::fromResource(wl_surface);
+ qDebug() << "server received bounce" << surface << duration;
+ emit bounce(surface, duration);
}
+void CustomExtension::example_extension_spin(QtWaylandServer::qt_example_extension::Resource *resource, wl_resource *wl_surface, uint32_t duration)
+{
+ Q_UNUSED(resource);
+ auto surface = QWaylandSurface::fromResource(wl_surface);
+ qDebug() << "server received spin" << surface << duration;
+ emit spin(surface, duration);
+}
+
+void CustomExtension::example_extension_register_surface(QtWaylandServer::qt_example_extension::Resource *resource, wl_resource *wl_surface)
+{
+ Q_UNUSED(resource);
+ auto surface = QWaylandSurface::fromResource(wl_surface);
+ qDebug() << "server received new surface" << surface;
+ emit surfaceAdded(surface);
}
diff --git a/examples/wayland/custom-extension/compositor/customextension.h b/examples/wayland/custom-extension/compositor/customextension.h
index 8419eeea3..b1b00408b 100644
--- a/examples/wayland/custom-extension/compositor/customextension.h
+++ b/examples/wayland/custom-extension/compositor/customextension.h
@@ -48,24 +48,30 @@
#include <QtWaylandCompositor/QWaylandCompositor>
#include "qwayland-server-custom.h"
-namespace QtWayland {
-
-class CustomExtension : public QWaylandCompositorExtensionTemplate<CustomExtension>, public QtWaylandServer::qt_example_extension
+class CustomExtension : public QWaylandCompositorExtensionTemplate<CustomExtension>
+ , public QtWaylandServer::qt_example_extension
{
Q_OBJECT
public:
- CustomExtension();
+ CustomExtension(QWaylandCompositor *compositor = 0);
void initialize() Q_DECL_OVERRIDE;
- Q_INVOKABLE void sendEvent(QWaylandSurface *surface, uint time, const QString &text, uint value);
signals:
- void requestReceived(const QString &text, uint value);
+ void surfaceAdded(QWaylandSurface *surface);
+ void bounce(QWaylandSurface *surface, uint ms);
+ void spin(QWaylandSurface *surface, uint ms);
+
+public slots:
+ void setFontSize(QWaylandSurface *surface, uint pixelSize);
+ void showDecorations(QWaylandClient *client, bool);
+ void close(QWaylandSurface *surface);
+
protected:
- virtual void example_extension_qtrequest(Resource *resource, const QString &text, int32_t value) Q_DECL_OVERRIDE;
+ void example_extension_bounce(Resource *resource, wl_resource *surface, uint32_t duration) Q_DECL_OVERRIDE;
+ void example_extension_spin(Resource *resource, wl_resource *surface, uint32_t duration) Q_DECL_OVERRIDE;
+ void example_extension_register_surface(Resource *resource, wl_resource *surface) Q_DECL_OVERRIDE;
};
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(CustomExtension)
-}
-
#endif // CUSTOMEXTENSION_H
diff --git a/examples/wayland/custom-extension/compositor/main.cpp b/examples/wayland/custom-extension/compositor/main.cpp
index 867e4c0de..7ece7bd0e 100644
--- a/examples/wayland/custom-extension/compositor/main.cpp
+++ b/examples/wayland/custom-extension/compositor/main.cpp
@@ -50,7 +50,7 @@
static void registerTypes()
{
- qmlRegisterType<QtWayland::CustomExtensionQuickExtension>("com.theqtcompany.customextension", 1, 0, "CustomExtension");
+ qmlRegisterType<CustomExtensionQuickExtension>("com.theqtcompany.customextension", 1, 0, "CustomExtension");
}
int main(int argc, char *argv[])
diff --git a/examples/wayland/custom-extension/compositor/qml/Screen.qml b/examples/wayland/custom-extension/compositor/qml/Screen.qml
index b6e4e12d0..a6d5fbc7c 100644
--- a/examples/wayland/custom-extension/compositor/qml/Screen.qml
+++ b/examples/wayland/custom-extension/compositor/qml/Screen.qml
@@ -50,13 +50,65 @@ WaylandOutput {
property QtObject output
- width: 1024
- height: 768
+ width: 1600
+ height: 900
visible: true
+ Rectangle {
+ id: sidebar
+ width: 150
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ color: "lightgray"
+ Column {
+ anchors.top: parent.top
+ anchors.left: parent.left
+ anchors.right: parent.right
+ spacing: 5
+
+ Repeater {
+ model: comp.itemList
+ Rectangle {
+ height: 36
+ width: sidebar.width - 5
+ color: "white"
+ radius: 5
+ Text {
+ text: "window: " + modelData.shellSurface.title + "[" + modelData.shellSurface.className
+ + (modelData.isCustom ? "]\nfont size: " + modelData.fontSize :"]\n No extension")
+ color: modelData.isCustom ? "black" : "darkgray"
+ }
+ MouseArea {
+ enabled: modelData.isCustom
+ anchors.fill: parent
+ onWheel: {
+ if (wheel.angleDelta.y > 0)
+ modelData.fontSize++
+ else if (wheel.angleDelta.y < 0 && modelData.fontSize > 3)
+ modelData.fontSize--
+ }
+ onDoubleClicked: {
+ output.compositor.customExtension.close(modelData.surface)
+ }
+ }
+ }
+ }
+ Text {
+ visible: comp.itemList.length > 0
+ width: sidebar.width - 5
+ text: "Mouse wheel to change font size. Double click to close"
+ wrapMode: Text.Wrap
+ }
+ }
+ }
+
WaylandMouseTracker {
id: mouseTracker
- anchors.fill: parent
+ anchors.left: sidebar.right
+ anchors.right: parent.right
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
windowSystemCursorEnabled: true
Image {
@@ -74,16 +126,25 @@ WaylandOutput {
seat: output.compositor.defaultSeat
}
+
Rectangle {
- anchors.bottom: parent.bottom
+ anchors.top: parent.top
anchors.right: parent.right
- width: 75
- height: 75
- color: "#BADA55"
+ width: 100
+ height: 100
+ property bool on : true
+ color: on ? "#DEC0DE" : "#FACADE"
+ Text {
+ anchors.fill: parent
+ text: "Toggle window decorations"
+ wrapMode: Text.WordWrap
+ }
+
MouseArea {
anchors.fill: parent
onClicked: {
- comp.sendEvent();
+ parent.on = !parent.on
+ comp.setDecorations(parent.on);
}
}
}
diff --git a/examples/wayland/custom-extension/compositor/qml/main.qml b/examples/wayland/custom-extension/compositor/qml/main.qml
index a7ca56e03..b5d90bd11 100644
--- a/examples/wayland/custom-extension/compositor/qml/main.qml
+++ b/examples/wayland/custom-extension/compositor/qml/main.qml
@@ -46,15 +46,14 @@ import com.theqtcompany.customextension 1.0
WaylandCompositor {
id: comp
- property var lastItem: null
+ property alias customExtension: custom
+ property var itemList: []
- property int counter : 0
-
- function sendEvent() {
- if (lastItem != null) {
- console.log("Compositor sending event: " + counter);
- custom.sendEvent(lastItem.shellSurface.surface, 0, "test", counter);
- counter++;
+ function itemForSurface(surface) {
+ var n = itemList.length
+ for (var i = 0; i < n; i++) {
+ if (itemList[i].surface === surface)
+ return itemList[i]
}
}
@@ -66,11 +65,67 @@ WaylandCompositor {
id: chromeComponent
ShellSurfaceItem {
id: chrome
+
+ property bool isCustom
+ property int fontSize: 12
+
onSurfaceDestroyed: {
- if (chrome === lastItem)
- lastItem = null;
+ var index = itemList.indexOf(chrome);
+ if (index > -1) {
+ var listCopy = itemList
+ listCopy.splice(index, 1);
+ itemList = listCopy
+ }
chrome.destroy()
}
+ transform: [
+ Rotation {
+ id: xRot
+ origin.x: chrome.width/2; origin.y: chrome.height/2;
+ angle: 0
+ axis { x: 1; y: 0; z: 0 }
+ },
+ Rotation {
+ id: yRot
+ origin.x: chrome.width/2; origin.y: chrome.height/2;
+ angle: 0
+ axis { x: 0; y: 1; z: 0 }
+ }
+ ]
+ NumberAnimation {
+ id: spinAnimation
+ running: false
+ loops: 2
+ target: yRot;
+ property: "angle";
+ from: 0; to: 360;
+ duration: 400;
+ }
+
+ function doSpin(ms) {
+ console.log("spin " + ms)
+ // using the 'ms' argument is left as an exercise for the reader...
+ spinAnimation.start()
+ }
+
+ NumberAnimation {
+ id: bounceAnimation
+ running: false
+ target: chrome
+ property: "y"
+ from: 0
+ to: output.window.height - chrome.height
+ easing.type: Easing.OutBounce
+ duration: 1000
+ }
+ function doBounce(ms) {
+ console.log("bounce " + ms)
+ // using the 'ms' argument is left as an exercise for the reader...
+ bounceAnimation.start()
+ }
+ onFontSizeChanged: {
+ custom.setFontSize(surface, fontSize)
+ }
}
}
@@ -78,14 +133,39 @@ WaylandCompositor {
id: defaultShell
onWlShellSurfaceCreated: {
var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": shellSurface } );
- lastItem = item;
+ var w = defaultOutput.surfaceArea.width/2
+ var h = defaultOutput.surfaceArea.height/2
+ item.x = Math.random()*w
+ item.y = Math.random()*h
+ var listCopy = itemList // List properties cannot be modified through Javascript operations
+ listCopy.push(item)
+ itemList = listCopy
}
}
CustomExtension {
id: custom
- onRequestReceived: {
- console.log("Compositor received a request: \"" + text + "\", " + value)
+
+ onSurfaceAdded: {
+ var item = itemForSurface(surface)
+ item.isCustom = true
+ }
+ onBounce: {
+ var item = itemForSurface(surface)
+ item.doBounce(ms)
+ }
+ onSpin: {
+ var item = itemForSurface(surface)
+ item.doSpin(ms)
+ }
+ }
+
+ function setDecorations(shown) {
+ var n = itemList.length
+ for (var i = 0; i < n; i++) {
+ // TODO: we only need to do it once for each client
+ if (itemList[i].isCustom)
+ custom.showDecorations(itemList[i].surface.client, shown)
}
}
}