2 * Copyright 2023 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include <QGuiApplication>
26 #include <QCommandLineParser>
27 #include <QtCore/QUrlQuery>
28 #include <QtCore/QObject>
31 #include <QtGui/QGuiApplication>
32 #include <QtQml/QQmlApplicationEngine>
33 #include <QtQml/QQmlContext>
34 #include <QtQml/QQmlComponent>
35 #include <QtQml/qqml.h>
36 #include <QQuickWindow>
39 #include "AglShellGrpcClient.h"
41 const QString myname = QString("window-management-client-rpc");
47 FULLSCREEN_QT = 3, // rather than use rpc, use Qt API
55 create_window(QQmlComponent *comp)
57 QObject *obj = comp->create();
58 obj->setParent(nullptr);
60 QWindow *win = qobject_cast<QWindow *>(obj);
65 int main(int argc, char *argv[])
67 enum mode mmode = NONE;
69 QGuiApplication app(argc, argv);
70 QQmlApplicationEngine engine;
72 // necessary to identify correctly by app_id
73 app.setDesktopFileName(myname);
75 QQmlComponent main_comp(&engine, QUrl("qrc:/Main.qml"));
78 const char *output_name = nullptr;
79 if (strcmp(argv[1], "float") == 0)
81 else if (strcmp(argv[1], "full") == 0)
83 else if (strcmp(argv[1], "on_output") == 0)
84 mmode = ON_OTHER_OUTPUTS;
85 else if (strcmp(argv[1], "full_qt") == 0)
86 mmode = FULLSCREEN_QT;
87 else if (strcmp(argv[1], "position") == 0)
88 mmode = SET_FLOAT_POS;
89 else if (strcmp(argv[1], "scale") == 0)
91 else if (strcmp(argv[1], "split") == 0)
94 assert(!"Invalid mode");
96 if (mmode != FLOAT && mmode != FULLSCREEN &&
97 mmode != ON_OTHER_OUTPUTS && mmode != SET_FLOAT_POS &&
98 mmode != SCALE && mmode != SPLIT) {
99 fprintf(stderr, "Will not use rpc\n");
103 if (mmode == ON_OTHER_OUTPUTS)
104 output_name = argv[2];
107 output_name = argv[2];
109 // start grpc connection
110 GrpcClient *client = new GrpcClient();
112 // note that these are setting up the window state by using
113 // another communication channel (rpc), and need to happen
114 // before the client does the initial commit (without a buffer
118 fprintf(stderr, "Setting the application as float\n");
119 client->SetAppFloat(myname.toStdString(), 40, 300);
122 fprintf(stderr, "Setting the application as fullscreen\n");
123 client->SetAppFullscreen(myname.toStdString());
125 case ON_OTHER_OUTPUTS:
126 fprintf(stderr, "Setting application '%s' on output '%s'\n",
127 myname.toStdString().c_str(), output_name);
129 fprintf(stderr, "Output name is not set!\n");
132 client->SetAppOnOutput(myname.toStdString(),
133 std::string(output_name));
136 // this assumes the window is already running and
137 // floating; uses the same application so this needs
138 // to be first started as float.
139 client->SetAppPosition(myname.toStdString(), 550, 550);
143 // this assumes the window is already running and
144 // floating; uses the same application so this needs
145 // to be first started as float.
146 client->SetAppScale(myname.toStdString(), 200, 200);
150 // put it on the bottom
151 client->SetAppSplit(myname.toStdString(), 4, 0, 0,
152 std::string(output_name));
160 // this would allow call any of the QWindow methods
161 QWindow *win = create_window(&main_comp);
163 // alternatively do the load directly
164 //engine.load(QUrl(QStringLiteral("qrc:/Main.qml")));