app: Testing split type of surfaces sandbox/mvlad/agl-compositor-split
authorMarius Vlad <marius.vlad@collabora.com>
Wed, 13 May 2020 21:35:24 +0000 (00:35 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Wed, 13 May 2020 21:50:27 +0000 (00:50 +0300)
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
app/MediaPlayer.qml
app/app.pro
app/main.cpp

index 4138759..b153a18 100644 (file)
@@ -100,6 +100,7 @@ ApplicationWindow {
 
     ColumnLayout {
         anchors.fill: parent
+
         Item {
             Layout.fillWidth: true
             Layout.fillHeight: true
@@ -235,6 +236,15 @@ ApplicationWindow {
                             }
                         }
 
+                       // added button to simulate a close
+                        ImageButton {
+                            id: nforward
+                            offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
+                            onClicked: {
+                               Qt.quit()
+                            }
+                        }
+
                         Item { Layout.fillWidth: true }
  
                         ToggleButton {
@@ -312,4 +322,5 @@ ApplicationWindow {
         }
     }
 }
+
 }
index 95493ff..7423b9a 100644 (file)
@@ -1,13 +1,16 @@
 TARGET = mediaplayer
-QT = quickcontrols2 websockets
+QT = quickcontrols2 websockets gui-private
 
 SOURCES = main.cpp
 
-CONFIG += link_pkgconfig
-PKGCONFIG += qtappfw
+CONFIG += link_pkgconfig wayland-scanner
+PKGCONFIG += qtappfw wayland-client
 
 RESOURCES += \
     mediaplayer.qrc \
     images/images.qrc
 
+WAYLANDCLIENTSOURCES += \
+    protocol/agl-shell-desktop.xml
+
 include(app.pri)
index d72c492..b1b800b 100644 (file)
 
 #include <mediaplayer.h>
 
+#include <qpa/qplatformnativeinterface.h>
+#include <wayland-client.h>
+#include "wayland-agl-shell-desktop-client-protocol.h"
+
 #include <unistd.h>
 
+static struct wl_output *
+getWlOutput(QScreen *screen)
+{
+       QPlatformNativeInterface *native = qApp->platformNativeInterface();
+       void *output = native->nativeResourceForScreen("output", screen);
+       return static_cast<struct ::wl_output*>(output);
+}
+
+static void
+global_add(void *data, struct wl_registry *reg, uint32_t name,
+          const char *interface, uint32_t version)
+{
+       struct agl_shell_desktop **shell =
+               static_cast<struct agl_shell_desktop **>(data);
+
+       if (strcmp(interface, agl_shell_desktop_interface.name) == 0) {
+               *shell = static_cast<struct agl_shell_desktop *>(
+                       wl_registry_bind(reg, name, &agl_shell_desktop_interface, version)
+               );
+       }
+}
+
+static void global_remove(void *data, struct wl_registry *reg, uint32_t id)
+{
+       (void) data;
+       (void) reg;
+       (void) id;
+}
+
+static const struct wl_registry_listener registry_listener = {
+       global_add,
+       global_remove,
+};
+
+static void
+application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
+               const char *app_id)
+{
+       (void) data;
+       (void) app_id;
+       (void) agl_shell_desktop;
+}
+
+static void
+application_state_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
+                       const char *app_id, const char *app_data,
+                       uint32_t app_state, uint32_t app_role)
+{
+       (void) data;
+       (void) app_role;
+       (void) app_state;
+       (void) app_data;
+       (void) app_id;
+       (void) agl_shell_desktop;
+}
+
+static const struct agl_shell_desktop_listener agl_shell_desk_listener = {
+       application_id_event,
+       application_state_event,
+};
+
+static struct agl_shell_desktop *
+register_agl_shell_desktop(void)
+{
+       struct wl_display *wl;
+       struct wl_registry *registry;
+       struct agl_shell_desktop *shell = nullptr;
+
+       QPlatformNativeInterface *native = qApp->platformNativeInterface();
+
+       wl = static_cast<struct wl_display *>(native->nativeResourceForIntegration("display"));
+       registry = wl_display_get_registry(wl);
+
+       wl_registry_add_listener(registry, &registry_listener, &shell);
+       // Roundtrip to get all globals advertised by the compositor
+       wl_display_roundtrip(wl);
+       wl_registry_destroy(registry);
+
+       return shell;
+}
+
+static void
+setup_window_vertical(int type, const QString &myname)
+{
+       struct agl_shell_desktop *shell_desktop = nullptr;
+       struct wl_output *output;
+
+       if (type == 0)
+               return;
+
+       shell_desktop = register_agl_shell_desktop();
+       output = getWlOutput(qApp->screens().first());
+
+       // not necessary
+       if (shell_desktop)
+               agl_shell_desktop_add_listener(shell_desktop,
+                                              &agl_shell_desk_listener,
+                                              NULL);
+
+       if (type == 1) {
+               agl_shell_desktop_set_app_property(shell_desktop,
+                               myname.toStdString().c_str(),
+                               AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL,
+                               0, 0, output);
+               qDebug() << "setting vertical";
+       } else {
+               agl_shell_desktop_set_app_property(shell_desktop,
+                               myname.toStdString().c_str(),
+                               AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL,
+                               0, 0, output);
+               qDebug() << "setting horizontal";
+       }
+}
+
 int main(int argc, char *argv[])
 {
     QString graphic_role = QString("music");
+    QString myname = QString("mediaplayer");
 
     QGuiApplication app(argc, argv);
 
@@ -45,14 +164,23 @@ int main(int argc, char *argv[])
     QCommandLineParser parser;
     parser.addPositionalArgument("port", app.translate("main", "port for binding"));
     parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
+    parser.addPositionalArgument("split", app.translate("main", "split type"));
     parser.addHelpOption();
     parser.addVersionOption();
     parser.process(app);
     QStringList positionalArguments = parser.positionalArguments();
 
-    if (positionalArguments.length() == 2) {
+    if (positionalArguments.length() >= 2) {
         int port = positionalArguments.takeFirst().toInt();
         QString secret = positionalArguments.takeFirst();
+
+       // 0, no split, 1 splitv, 2 splith
+       if (positionalArguments.length() == 1) {
+               int split_type = positionalArguments.takeFirst().toInt();
+               setup_window_vertical(split_type, myname);
+       }
+
+
         QUrl bindingAddress;
         bindingAddress.setScheme(QStringLiteral("ws"));
         bindingAddress.setHost(QStringLiteral("localhost"));
@@ -68,5 +196,6 @@ int main(int argc, char *argv[])
 
         engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));
     }
+
     return app.exec();
 }