launcher.pro: Use system() to figure out where to pull the protocol
[apps/launcher.git] / launcher / src / shell-desktop.h
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 #ifndef SHELLDESKTOP_H
18 #define SHELLDESKTOP_H
19
20 #include <QObject>
21 #include <QString>
22 #include <QScreen>
23 #include <QWindow>
24 #include <QDebug>
25 #include <memory>
26
27
28 #include "wayland-agl-shell-desktop-client-protocol.h"
29
30 static void
31 application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
32                      const char *app_id);
33 static void
34 application_state_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
35                         const char *app_id, const char *app_data,
36                         uint32_t app_state, uint32_t app_role);
37
38 static const struct agl_shell_desktop_listener agl_shell_desktop_listener = {
39         application_id_event,
40         application_state_event,
41 };
42
43 class Shell : public QObject
44 {
45 Q_OBJECT
46
47 public:
48         std::shared_ptr<struct agl_shell_desktop> shell;
49         Shell(std::shared_ptr<struct agl_shell_desktop> shell, QObject *parent = nullptr) :
50                 QObject(parent), shell(shell) 
51         {
52                 struct agl_shell_desktop *agl_shell_desktop = shell.get();
53                 agl_shell_desktop_add_listener(agl_shell_desktop, 
54                                                &agl_shell_desktop_listener, this);
55         }
56
57 public slots: // calls out of qml into CPP
58         void activate_app(QWindow *win, const QString &app_id, const QString &app_data);
59         void activate_app_by_screen(const QString &screen_name,
60                                     const QString &app_id,
61                                     const QString &app_data);
62         void deactivate_app(const QString &app_id);
63         void set_window_props(QWindow *win, const QString &app_id,
64                               uint32_t props, int x, int y, int bx, int by,
65                               int bwidth, int bheight);
66 };
67
68 static void
69 application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
70                      const char *app_id)
71 {
72         Shell *aglShell = static_cast<Shell *>(data);
73         (void) agl_shell_desktop;
74
75         qInfo() << "app_id: " << app_id;
76
77         // this ain't necessary in case the default policy API will activate
78         // applications by default (when they are started) but if that is not
79         // the case we can use this event handler to activate the application
80         // as this event is sent when the application is created (when the app
81         // surface is created that is); note this event is sent when launcher
82         // binds to the interface for each application present, besides being
83         // adevertised when the application surface is created; so the
84         // following will need some kind of filtering to avoid mass activation
85         //QString qstr_app_id = QString::fromUtf8(app_id, -1);
86         //aglShell->activate_app(nullptr, qstr_app_id, nullptr);
87 }
88
89 static void
90 application_state_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
91                         const char *app_id, const char *app_data,
92                         uint32_t app_state, uint32_t app_role)
93 {
94         (void) data;
95         (void) agl_shell_desktop;
96         (void) app_id;
97         (void) app_data;
98         (void) app_state;
99         (void) app_role;
100 }
101
102 #endif // SHELLDESKTOP_H