diff options
author | Marius Vlad <marius.vlad@collabora.com> | 2020-05-29 14:01:54 +0300 |
---|---|---|
committer | Marius Vlad <marius.vlad@collabora.com> | 2020-05-31 15:38:26 +0300 |
commit | 7c1cdc5682a1e65d7110755003a1ef420edaebc9 (patch) | |
tree | d903b4e6a275e1dd7667f767075a8522e457d68a | |
parent | a44aaf342476a894aeb91edbc49b349aee93607b (diff) |
app: Allow to place the window on a different outputsandbox/mvlad/agl-compositor-on-other-output
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
-rw-r--r-- | app/app.pro | 14 | ||||
-rw-r--r-- | app/main.cpp | 91 | ||||
-rw-r--r-- | app/protocol/agl-shell-desktop.xml | 116 | ||||
-rw-r--r-- | app/shell-desktop.cpp | 50 | ||||
-rw-r--r-- | app/shell-desktop.h | 90 |
5 files changed, 356 insertions, 5 deletions
diff --git a/app/app.pro b/app/app.pro index d10f9c0..e041e42 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,15 +1,15 @@ TARGET = hvac -QT = quick qml websockets +QT = quick qml websockets gui-private -CONFIG += c++11 link_pkgconfig -PKGCONFIG += qtappfw afb-helpers-qt +CONFIG += c++11 link_pkgconfig wayland-scanner +PKGCONFIG += qtappfw afb-helpers-qt wayland-client #aglextras -HEADERS += \ +HEADERS += shell-desktop.h \ translator.h -SOURCES = main.cpp \ +SOURCES = main.cpp shell-desktop.cpp \ translator.cpp RESOURCES += \ @@ -20,3 +20,7 @@ include(app.pri) LANGUAGES = ja_JP fr_FR include(translations.pri) + +WAYLANDCLIENTSOURCES += \ + protocol/agl-shell-desktop.xml + diff --git a/app/main.cpp b/app/main.cpp index 6fe54a5..a34de35 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -20,17 +20,94 @@ #include <QCommandLineParser> #include <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlContext> +#include <QScreen> + +#include <qpa/qplatformnativeinterface.h> +#include <wayland-client.h> + +#include "shell-desktop.h" +#include "wayland-agl-shell-desktop-client-protocol.h" #include "translator.h" +/* this could be a combintion or some sort */ +#define OUTPUT_ID "Virtual-1" + +static void +global_add(void *data, struct wl_registry *reg, uint32_t name, + const char *interface, uint32_t) +{ + 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, 1) + ); + } +} + +static void +global_remove(void *data, struct wl_registry *reg, uint32_t id) +{ + /* Don't care */ + (void) data; + (void) reg; + (void) id; +} + +static const struct wl_registry_listener registry_listener = { + global_add, + global_remove, +}; + +static struct agl_shell_desktop * +register_agl_shell_desktop(QPlatformNativeInterface *native) +{ + struct wl_display *wl; + struct wl_registry *registry; + struct agl_shell_desktop *shell = nullptr; + + wl = static_cast<struct wl_display *>(native->nativeResourceForIntegration("display")); + registry = wl_display_get_registry(wl); + + wl_registry_add_listener(registry, ®istry_listener, &shell); + + /* Roundtrip to get all globals advertised by the compositor */ + wl_display_roundtrip(wl); + wl_registry_destroy(registry); + + return shell; +} + +static QScreen * +find_qscreen(const char *screen_name) +{ + QList<QScreen *> screens = qApp->screens(); + QScreen *found = nullptr; + QString qstr_name = QString::fromUtf8(screen_name, -1); + + for (QScreen *xscreen : screens) { + if (qstr_name == xscreen->name()) { + found = xscreen; + break; + } + } + + return found; +} + + int main(int argc, char *argv[]) { setenv("QT_QPA_PLATFORM", "wayland", 1); int port; QString token; + QString graphic_role = "hvac"; + struct agl_shell_desktop *agl_shell_desktop = nullptr; QCommandLineParser parser; QGuiApplication app(argc, argv); + app.setDesktopFileName(graphic_role); parser.addPositionalArgument("port", app.translate("main", "port for binding")); @@ -51,6 +128,20 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + agl_shell_desktop = register_agl_shell_desktop(native); + if (!agl_shell_desktop) { + qDebug() << "Could not find agl_shell_desktop extension. Is agl-compositor running?"; + exit(EXIT_FAILURE); + } + + std::shared_ptr<struct agl_shell_desktop> shell{agl_shell_desktop, agl_shell_desktop_destroy}; + Shell *aglShell = new Shell(shell, nullptr); + + QScreen *screen_to_put = find_qscreen(OUTPUT_ID); + if (screen_to_put) + aglShell->set_window_on_screen(screen_to_put, graphic_role); + QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); bindingAddress.setHost(QStringLiteral("localhost")); diff --git a/app/protocol/agl-shell-desktop.xml b/app/protocol/agl-shell-desktop.xml new file mode 100644 index 0000000..4f942f5 --- /dev/null +++ b/app/protocol/agl-shell-desktop.xml @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="agl_shell_desktop"> + <copyright> + Copyright © 2020 Collabora, Ltd. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + <interface name="agl_shell_desktop" version="1"> + <description summary="Private extension to allow applications activate other apps"> + This extension can be used by regular application to instruct to compositor + to activate or switch to other running (regular) applications. The client + is responsbile for filtering their own app_id when receiving application id. + + Note that other (regular) applications can bind to this interface and there is + no mechanism to place to restrict or limit that. + </description> + + <enum name="app_role"> + <entry name="popup" value="0"/> + <entry name="fullscreen" value="1"/> + <entry name="split_vertical" value="2"/> + <entry name="split_horizontal" value="3"/> + <entry name="remote" value="4"/> + </enum> + + <enum name="app_state"> + <entry name="activated" value="0"/> + <entry name="deactivated" value="1"/> + </enum> + + <event name="application"> + <description summary="advertise application id"> + The compositor may choose to advertise one or more application ids which + can be used to activate/switch to. + + When this global is bound, the compositor will send all application ids + available for activation, but may send additional application id at any + time (when they've been mapped in the compositor). + </description> + <arg name="app_id" type="string"/> + </event> + + <request name="activate_app"> + <description summary="make client current window"> + Ask the compositor to make a toplevel to become the current/focused + window for window management purposes. + + See xdg_toplevel.set_app_id from the xdg-shell protocol for a + description of app_id. + </description> + <arg name="app_id" type="string"/> + <arg name="app_data" type="string" allow-null="true"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + + <request name="set_app_property"> + <description summary="set properties for a client identified by app_id"> + Ask the compositor to make a toplevel obey the app_role and, depending + on the role, to use the the x and y values as initial positional values. + The x and y values would only make sense for certain roles. + + See xdg_toplevel.set_app_id from the xdg-shell protocol for a + description of app_id. + </description> + <arg name="app_id" type="string"/> + <arg name="role" type="uint" enum="app_role"/> + <arg name="x" type="int"/> + <arg name="y" type="int"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + + <request name="deactivate_app"> + <description summary="de-activate/hide window identified by app_id"> + Ask the compositor to hide the toplevel window for window + management purposes. Depending on the window role, this request + will either display the previously active window (or the background + in case there's no previously activate surface) or temporarly (or + until a 'activate_app' is called upon) hide the surface. All + the surfaces are identifiable by using the app_id, and no actions are + taken in case the app_id is not/was not present. + + See xdg_toplevel.set_app_id from the xdg-shell protocol for a + description of app_id. + </description> + <arg name="app_id" type="string"/> + </request> + + <event name="state_app"> + <description summary="event sent when application has suffered state modification"> + Notifies application(s) when other application have suffered state modifications. + </description> + <arg name="app_id" type="string"/> + <arg name="app_data" type="string" allow-null="true"/> + <arg name="state" type="uint" enum="app_state"/> + <arg name="role" type="uint" enum="app_role"/> + </event> + + </interface> +</protocol> diff --git a/app/shell-desktop.cpp b/app/shell-desktop.cpp new file mode 100644 index 0000000..f0a54e5 --- /dev/null +++ b/app/shell-desktop.cpp @@ -0,0 +1,50 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include <QGuiApplication> +#include <QDebug> +#include "shell-desktop.h" +#include <qpa/qplatformnativeinterface.h> +#include <stdio.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); +} + +void +Shell::set_window_on_screen(QScreen *screen, const QString &app_id) +{ + struct wl_output *output; + output = getWlOutput(screen); + agl_shell_desktop_set_app_property(this->shell.get(), + app_id.toStdString().c_str(), + AGL_SHELL_DESKTOP_APP_ROLE_REMOTE, + 0, 0, output); + +} diff --git a/app/shell-desktop.h b/app/shell-desktop.h new file mode 100644 index 0000000..7c3c36b --- /dev/null +++ b/app/shell-desktop.h @@ -0,0 +1,90 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef SHELLDESKTOP_H +#define SHELLDESKTOP_H + +#include <QObject> +#include <QString> +#include <QScreen> +#include <QWindow> +#include <QDebug> +#include <memory> + +#include "wayland-agl-shell-desktop-client-protocol.h" + +static void +application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop, + const char *app_id); +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); + +static const struct agl_shell_desktop_listener agl_shell_desktop_listener = { + application_id_event, + application_state_event, +}; + +class Shell : public QObject +{ +Q_OBJECT + +public: + std::shared_ptr<struct agl_shell_desktop> shell; + Shell(std::shared_ptr<struct agl_shell_desktop> shell, QObject *parent = nullptr) : + QObject(parent), shell(shell) + { + struct agl_shell_desktop *agl_shell_desktop = shell.get(); + agl_shell_desktop_add_listener(agl_shell_desktop, + &agl_shell_desktop_listener, this); + } + +public slots: // calls out of qml into CPP + void set_window_on_screen(QScreen *screen, const QString &app_id); +}; + +static void +application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop, + const char *app_id) +{ + Shell *aglShell = static_cast<Shell *>(data); + (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) agl_shell_desktop; + (void) app_id; + (void) app_data; + (void) app_state; + (void) app_role; +} + +#endif // SHELLDESKTOP_H |