summaryrefslogtreecommitdiffstats
path: root/app/surface.cpp
blob: c0cd8ac6e45b552fd0cdc90655f44db6e52513ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * Copyright (c) 2017 Panasonic Corporation
 * Copyright (c) 2018 Konsulko Group
 *
 * 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 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 <cstdio>
#include <cstdarg>
#include "surface.hpp"
#include "hmi-debug.h"

#include <QGuiApplication>
#include <QtGui/QGuiApplication>
#include <qpa/qplatformnativeinterface.h>

#include <QObject>
#include <QString>
#include <QScreen>
#include <QWindow>

#include "agl-shell-desktop-client-protocol.h"

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<struct agl_shell_desktop **>(data);

	if (strcmp(interface, agl_shell_desktop_interface.name) == 0) {
		*shell = static_cast<struct agl_shell_desktop *>(
			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 void
application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
		const char *app_id)
{

}

static void
application_id_state(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) app_data;
	(void) agl_shell_desktop;
	(void) app_id;
	(void) app_state;
	(void) app_role;
}

static const struct agl_shell_desktop_listener agl_shell_desk_listener = {
	application_id_event,
	application_id_state,
};

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<struct wl_display *>(native->nativeResourceForIntegration("display"));
	registry = wl_display_get_registry(wl);

	wl_registry_add_listener(registry, &registry_listener, &shell);
	// Roundtrip to get all globals advertised by the compositor
	wl_display_roundtrip(wl);
	wl_registry_destroy(registry);

	return shell;
}

SurfaceHandler::SurfaceHandler(const int port, const std::string &token, const std::string &role)
{
	m_port = port;
	m_token = token;
	m_role = role;

	if (init_agl_shell()) {
		exit(1);
	}

	agl_shell_desktop_add_listener(shell, &agl_shell_desk_listener, this);
}

int
SurfaceHandler::init_agl_shell(void)
{
	QPlatformNativeInterface *native = qApp->platformNativeInterface();
	shell = register_agl_shell_desktop(native);
	if (!shell) {
		return -1;
	}

	std::shared_ptr<struct agl_shell_desktop>
		agl_shell{shell, agl_shell_desktop_destroy};

	aglShell = new Shell(agl_shell, nullptr);

	return 0;
}

void
SurfaceHandler::set_bounding_box(int x, int y, int bx, int by, int width, int height)
{
	QString app_id = QString::fromUtf8(m_role.c_str(), -1);
	aglShell->set_window_props(app_id, AGL_SHELL_DESKTOP_APP_ROLE_POPUP,
				   x, y, bx, by, width, height);
}