From ce46bc880844a186d43c605362a6673322b0b104 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Sat, 11 Apr 2020 18:52:21 +0300 Subject: protocol: Allow to activate windows Signed-off-by: Marius Vlad --- launcher/launcher.pro | 10 +++- launcher/protocol/agl-shell-desktop.xml | 96 +++++++++++++++++++++++++++++++++ launcher/src/main.cpp | 63 ++++++++++++++++++++++ launcher/src/shell-desktop.cpp | 53 ++++++++++++++++++ launcher/src/shell-desktop.h | 45 ++++++++++++++++ 5 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 launcher/protocol/agl-shell-desktop.xml create mode 100644 launcher/src/shell-desktop.cpp create mode 100644 launcher/src/shell-desktop.h diff --git a/launcher/launcher.pro b/launcher/launcher.pro index 513dd6d..f08b26e 100644 --- a/launcher/launcher.pro +++ b/launcher/launcher.pro @@ -15,15 +15,17 @@ TEMPLATE = app TARGET = launcher -QT = qml quick dbus websockets -CONFIG += c++11 link_pkgconfig +QT = qml quick dbus websockets gui-private +CONFIG += c++11 link_pkgconfig wayland-scanner pkgdatadir DESTDIR = $${OUT_PWD}/../package/root/bin +PKGCONFIG += wayland-client include(../pws/pws.pri) SOURCES += \ src/main.cpp \ src/applicationmodel.cpp \ + src/shell-desktop.cpp \ src/appinfo.cpp \ src/applicationlauncher.cpp \ src/applicationhandler.cpp @@ -31,6 +33,7 @@ SOURCES += \ HEADERS += \ src/applicationlauncher.h \ src/applicationmodel.h \ + src/shell-desktop.h \ src/appinfo.h \ src/applicationhandler.h @@ -40,3 +43,6 @@ OTHER_FILES += \ RESOURCES += \ qml/images/images.qrc \ qml/qml.qrc + +WAYLANDCLIENTSOURCES += \ + protocol/agl-shell-desktop.xml diff --git a/launcher/protocol/agl-shell-desktop.xml b/launcher/protocol/agl-shell-desktop.xml new file mode 100644 index 0000000..6d53f92 --- /dev/null +++ b/launcher/protocol/agl-shell-desktop.xml @@ -0,0 +1,96 @@ + + + + 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. + + + + + diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index 6d20ec8..2355022 100644 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -24,20 +24,75 @@ #include #include #include +#include #include #include +#include +#include "wayland-agl-shell-desktop-client-protocol.h" + #include "applicationlauncher.h" #include "applicationmodel.h" #include "applicationhandler.h" +#include "shell-desktop.h" #include "appinfo.h" #define CONNECT_STR "unix:/run/platform/apis/ws/afm-main" +// this and the agl-shell extension should be added in some kind of a wrapper +// for easy usage +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(data); + + if (strcmp(interface, agl_shell_desktop_interface.name) == 0) { + *shell = static_cast( + 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 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(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; +} + + + int main(int argc, char *argv[]) { QString myname = QString("launcher"); + struct agl_shell_desktop *ashell = nullptr; QGuiApplication a(argc, argv); QCommandLineParser parser; @@ -67,6 +122,7 @@ int main(int argc, char *argv[]) new ApplicationLauncher(CONNECT_STR, &a); ApplicationHandler *homescreenHandler = new ApplicationHandler(nullptr, launcher->get_launcher()); + ashell = register_agl_shell_desktop(); QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); @@ -83,6 +139,13 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler); engine.rootContext()->setContextProperty(QStringLiteral("launcher"), launcher); + + if (ashell) { + std::shared_ptr shell{ashell, agl_shell_desktop_destroy}; + Shell *agl_shell = new Shell(shell, &a); + engine.rootContext()->setContextProperty("shell", agl_shell); + } + engine.load(QUrl(QStringLiteral("qrc:/Launcher.qml"))); homescreenHandler->getRunnables(); diff --git a/launcher/src/shell-desktop.cpp b/launcher/src/shell-desktop.cpp new file mode 100644 index 0000000..8503c01 --- /dev/null +++ b/launcher/src/shell-desktop.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 Collabora Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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::activate_app(QWindow *win, const QString &app_id) +{ + QScreen *screen = nullptr; + struct wl_output *output; + + if (!win || !win->screen()) { + qDebug() << "window or screen, not available, using the first one available"; + screen = qApp->screens().first(); + } else { + screen = win->screen(); + } + + if (!screen) { + qDebug() << "screen not available?"; + return; + } + + output = getWlOutput(screen); + qDebug() << "will activate app: " << app_id; + agl_shell_desktop_activate_app(this->shell.get(), + app_id.toStdString().c_str(), output); +} diff --git a/launcher/src/shell-desktop.h b/launcher/src/shell-desktop.h new file mode 100644 index 0000000..eb6f8c5 --- /dev/null +++ b/launcher/src/shell-desktop.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Collabora Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SHELLHANDLER_H +#define SHELLHANDLER_H + +#include +#include +#include +#include +#include +#include "wayland-agl-shell-desktop-client-protocol.h" + +/* + * Basic type to wrap the agl_shell wayland object into a QObject, so that it + * can be used in callbacks from QML. + */ + +class Shell : public QObject +{ +Q_OBJECT + std::shared_ptr shell; + +public: + Shell(std::shared_ptr shell, QObject *parent = nullptr) : + QObject(parent), shell(shell) + {} +public slots: + void activate_app(QWindow *win, const QString &app_id); +}; + +#endif // SHELLHANDLER_H -- cgit 1.2.3-korg