2 * Copyright (c) 2020 Collabora Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <QGuiApplication>
19 #include "shell-desktop.h"
20 #include <qpa/qplatformnativeinterface.h>
23 static struct wl_output *
24 getWlOutput(QScreen *screen)
26 QPlatformNativeInterface *native = qApp->platformNativeInterface();
27 void *output = native->nativeResourceForScreen("output", screen);
28 return static_cast<struct ::wl_output*>(output);
32 Shell::activate_app(QWindow *win, const QString &app_id,
33 const QString &app_data)
35 QScreen *screen = nullptr;
36 struct wl_output *output;
38 if (!win || !win->screen()) {
39 screen = qApp->screens().first();
41 screen = win->screen();
47 output = getWlOutput(screen);
48 qDebug() << "will activate app: " << app_id;
49 agl_shell_desktop_activate_app(this->shell.get(),
50 app_id.toStdString().c_str(),
51 app_data.toStdString().c_str(), output);
55 Shell::activate_app_by_screen(const QString &screen_name, const QString &app_id,
56 const QString &app_data)
58 QScreen *qscreen_to_put = nullptr;
59 for (auto &ss: qApp->screens()) {
60 if (ss->name() == screen_name) {
66 /* use the primary one */
67 if (!qscreen_to_put) {
68 qscreen_to_put = qApp->screens().first();
71 struct wl_output *output = getWlOutput(qscreen_to_put);
72 qDebug() << "will activate app: " << app_id << " on output " <<
73 qscreen_to_put->name();
74 agl_shell_desktop_activate_app(this->shell.get(),
75 app_id.toStdString().c_str(),
76 app_data.toStdString().c_str(), output);
80 Shell::deactivate_app(const QString &app_id)
82 agl_shell_desktop_deactivate_app(this->shell.get(),
83 app_id.toStdString().c_str());
87 Shell::set_window_props(QWindow *win, const QString &app_id,
88 uint32_t props, int x, int y, int bx, int by,
89 int bwidth, int bheight)
91 QScreen *screen = nullptr;
92 struct wl_output *output;
94 if (!win || !win->screen()) {
95 screen = qApp->screens().first();
97 screen = win->screen();
104 output = getWlOutput(screen);
105 agl_shell_desktop_set_app_property(this->shell.get(),
106 app_id.toStdString().c_str(),
108 bwidth, bheight, output);