2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2017 Konsulko Group
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <QtCore/QCommandLineParser>
19 #include <QtCore/QDebug>
20 #include <QtCore/QDir>
21 #include <QtCore/QStandardPaths>
22 #include <QtCore/QUrlQuery>
23 #include <QtGui/QGuiApplication>
24 #include <QtQml/QQmlApplicationEngine>
25 #include <QtQml/QQmlContext>
26 #include <QtQml/qqml.h>
27 #include <QtQuickControls2/QQuickStyle>
28 #include <QQuickWindow>
30 #include <mediaplayer.h>
32 #include <qpa/qplatformnativeinterface.h>
33 #include <wayland-client.h>
34 #include "wayland-agl-shell-desktop-client-protocol.h"
38 static struct wl_output *
39 getWlOutput(QScreen *screen)
41 QPlatformNativeInterface *native = qApp->platformNativeInterface();
42 void *output = native->nativeResourceForScreen("output", screen);
43 return static_cast<struct ::wl_output*>(output);
47 global_add(void *data, struct wl_registry *reg, uint32_t name,
48 const char *interface, uint32_t version)
50 struct agl_shell_desktop **shell =
51 static_cast<struct agl_shell_desktop **>(data);
53 if (strcmp(interface, agl_shell_desktop_interface.name) == 0) {
54 *shell = static_cast<struct agl_shell_desktop *>(
55 wl_registry_bind(reg, name, &agl_shell_desktop_interface, version)
60 static void global_remove(void *data, struct wl_registry *reg, uint32_t id)
67 static const struct wl_registry_listener registry_listener = {
73 application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
78 (void) agl_shell_desktop;
82 application_state_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
83 const char *app_id, const char *app_data,
84 uint32_t app_state, uint32_t app_role)
91 (void) agl_shell_desktop;
94 static const struct agl_shell_desktop_listener agl_shell_desk_listener = {
96 application_state_event,
99 static struct agl_shell_desktop *
100 register_agl_shell_desktop(void)
102 struct wl_display *wl;
103 struct wl_registry *registry;
104 struct agl_shell_desktop *shell = nullptr;
106 QPlatformNativeInterface *native = qApp->platformNativeInterface();
108 wl = static_cast<struct wl_display *>(native->nativeResourceForIntegration("display"));
109 registry = wl_display_get_registry(wl);
111 wl_registry_add_listener(registry, ®istry_listener, &shell);
112 // Roundtrip to get all globals advertised by the compositor
113 wl_display_roundtrip(wl);
114 wl_registry_destroy(registry);
120 setup_window_vertical(int type, const QString &myname)
122 struct agl_shell_desktop *shell_desktop = nullptr;
123 struct wl_output *output;
128 shell_desktop = register_agl_shell_desktop();
129 output = getWlOutput(qApp->screens().first());
133 agl_shell_desktop_add_listener(shell_desktop,
134 &agl_shell_desk_listener,
138 agl_shell_desktop_set_app_property(shell_desktop,
139 myname.toStdString().c_str(),
140 AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL,
142 qDebug() << "setting vertical";
144 agl_shell_desktop_set_app_property(shell_desktop,
145 myname.toStdString().c_str(),
146 AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL,
148 qDebug() << "setting horizontal";
152 int main(int argc, char *argv[])
154 QString graphic_role = QString("music");
155 QString myname = QString("mediaplayer");
157 QGuiApplication app(argc, argv);
159 QQuickStyle::setStyle("AGL");
161 QQmlApplicationEngine engine;
162 QQmlContext *context = engine.rootContext();
164 QCommandLineParser parser;
165 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
166 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
167 parser.addPositionalArgument("split", app.translate("main", "split type"));
168 parser.addHelpOption();
169 parser.addVersionOption();
171 QStringList positionalArguments = parser.positionalArguments();
173 if (positionalArguments.length() >= 2) {
174 int port = positionalArguments.takeFirst().toInt();
175 QString secret = positionalArguments.takeFirst();
177 // 0, no split, 1 splitv, 2 splith
178 if (positionalArguments.length() == 1) {
179 int split_type = positionalArguments.takeFirst().toInt();
180 setup_window_vertical(split_type, myname);
185 bindingAddress.setScheme(QStringLiteral("ws"));
186 bindingAddress.setHost(QStringLiteral("localhost"));
187 bindingAddress.setPort(port);
188 bindingAddress.setPath(QStringLiteral("/api"));
190 query.addQueryItem(QStringLiteral("token"), secret);
191 bindingAddress.setQuery(query);
192 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
194 context->setContextProperty("AlbumArt", "");
195 context->setContextProperty("mediaplayer", new Mediaplayer(bindingAddress, context));
197 engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));