From 7c1cdc5682a1e65d7110755003a1ef420edaebc9 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Fri, 29 May 2020 14:01:54 +0300 Subject: app: Allow to place the window on a different output Signed-off-by: Marius Vlad --- app/app.pro | 14 +++-- app/main.cpp | 91 +++++++++++++++++++++++++++++ app/protocol/agl-shell-desktop.xml | 116 +++++++++++++++++++++++++++++++++++++ app/shell-desktop.cpp | 50 ++++++++++++++++ app/shell-desktop.h | 90 ++++++++++++++++++++++++++++ 5 files changed, 356 insertions(+), 5 deletions(-) create mode 100644 app/protocol/agl-shell-desktop.xml create mode 100644 app/shell-desktop.cpp create mode 100644 app/shell-desktop.h 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 #include #include +#include + +#include +#include + +#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(data); + + if (strcmp(interface, agl_shell_desktop_interface.name) == 0) { + *shell = static_cast( + 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(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 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 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 @@ + + + + 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. + + + + 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. + + + + + + + + + + + + + + + + + + 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). + + + + + + + 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. + + + + + + + + + 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. + + + + + + + + + + + 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. + + + + + + + Notifies application(s) when other application have suffered state modifications. + + + + + + + + + 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 +#include +#include "shell-desktop.h" +#include +#include + +static struct wl_output * +getWlOutput(QScreen *screen) +{ + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + void *output = native->nativeResourceForScreen("output", screen); + return static_cast(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 +#include +#include +#include +#include +#include + +#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 shell; + Shell(std::shared_ptr 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(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 -- cgit 1.2.3-korg