42cc6d1f761f23900a58aa0de4bfaa85e16c17fa
[apps/launcher.git] / launcher / src / shell-desktop.cpp
1 /*
2  * Copyright (c) 2020 Collabora Ltd.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <QGuiApplication>
18 #include <QDebug>
19 #include "shell-desktop.h"
20 #include <qpa/qplatformnativeinterface.h>
21 #include <stdio.h>
22
23 static struct wl_output *
24 getWlOutput(QScreen *screen)
25 {
26         QPlatformNativeInterface *native = qApp->platformNativeInterface();
27         void *output = native->nativeResourceForScreen("output", screen);
28         return static_cast<struct ::wl_output*>(output);
29 }
30
31 void
32 Shell::activate_app(QWindow *win, const QString &app_id,
33                     const QString &app_data)
34 {
35         QScreen *screen = nullptr;
36         struct wl_output *output;
37
38         if (!win || !win->screen()) {
39                 screen = qApp->screens().first();
40         } else {
41                 screen = win->screen();
42         }
43
44         if (!screen)
45                 return;
46
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);
52 }
53
54 void
55 Shell::deactivate_app(const QString &app_id)
56 {
57         agl_shell_desktop_deactivate_app(this->shell.get(), 
58                                          app_id.toStdString().c_str());
59 }
60
61 void
62 Shell::set_window_props(QWindow *win, const QString &app_id,
63                         uint32_t props, int x, int y)
64 {
65         QScreen *screen = nullptr;
66         struct wl_output *output;
67
68         if (!win || !win->screen()) {
69                 screen = qApp->screens().first();
70         } else {
71                 screen = win->screen();
72         }
73
74         if (!screen) {
75                 return;
76         }
77
78         output = getWlOutput(screen);
79         agl_shell_desktop_set_app_property(this->shell.get(),
80                                            app_id.toStdString().c_str(),
81                                            props, x, y, output);
82 }