Repository navigation
Expand file tree
/
Copy pathstartup.cpp
More file actions
179 lines (157 loc) · 6.96 KB
/
Copy pathstartup.cpp
File metadata and controls
179 lines (157 loc) · 6.96 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*---------------------------------------------------------*\
| startup.cpp |
| |
| Startup for the OpenRGB application |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "cli.h"
#include "ResourceManager.h"
#include "NetworkServer.h"
#include "startup.h"
#include <QApplication>
#include <QSessionManager>
#include "OpenRGBDialog.h"
#ifdef __APPLE__
#include "macutils.h"
#endif
#ifdef __linux__
#include <csignal>
#endif
/******************************************************************************************\
* *
* Linux signal handler *
* *
\******************************************************************************************/
#ifdef __linux__
void sigHandler(int s)
{
std::signal(s, SIG_DFL);
qApp->quit();
}
#endif
/******************************************************************************************\
* *
* startup *
* *
* Opens the main windows or starts the server *
* *
\******************************************************************************************/
int startup(int argc, char* argv[], unsigned int ret_flags)
{
/*-----------------------------------------------------*\
| Initialize exit value, which will be returned on exit |
| in main() |
\*-----------------------------------------------------*/
int exitval = EXIT_SUCCESS;
/*-----------------------------------------------------*\
| Before opening GUI, wait for automatic connection so |
| that settings and profiles can be updated from server |
\*-----------------------------------------------------*/
ResourceManager::get()->WaitForInitialization();
/*-----------------------------------------------------*\
| If the command line parser indicates that the GUI |
| should run, or if there were no command line |
| arguments, start the GUI. |
\*-----------------------------------------------------*/
if(ret_flags & RET_FLAG_START_GUI)
{
LOG_TRACE("[main] initializing GUI");
/*-------------------------------------------------*\
| Enable high DPI scaling support (Qt5 only) |
\*-------------------------------------------------*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
#endif
/*-------------------------------------------------*\
| Enable high DPI fractional scaling support on |
| Windows |
\*-------------------------------------------------*/
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && defined(Q_OS_WIN)
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
/*-------------------------------------------------*\
| Create Qt application |
\*-------------------------------------------------*/
QApplication a(argc, argv);
QGuiApplication::setDesktopFileName("org.openrgb.OpenRGB");
LOG_TRACE("[startup] QApplication created");
#ifndef QT_NO_SESSIONMANAGER
/*-------------------------------------------------*\
| OpenRGB has its own Start at Login setting. A |
| session manager restoring it on top of that |
| starts a second instance that probes the same |
| devices concurrently with the first one |
\*-------------------------------------------------*/
QObject::connect(&a, &QGuiApplication::saveStateRequest, [](QSessionManager& manager)
{
manager.setRestartHint(QSessionManager::RestartNever);
});
#endif
/*-------------------------------------------------*\
| Main UI widget |
\*-------------------------------------------------*/
OpenRGBDialog dlg;
LOG_TRACE("[startup] Dialog created");
if(ret_flags & RET_FLAG_I2C_TOOLS)
{
dlg.AddI2CToolsPage();
}
dlg.AddClientTab();
if(ret_flags & RET_FLAG_START_MINIMIZED)
{
#ifdef _WIN32
/*---------------------------------------------*\
| Show the window always, even if it will |
| immediately be hidden. On Windows, events |
| are not delivered to nativeEventFilter (for |
| SuspendResume) until the window has been |
| shown once. |
| |
| TODO Try using |
| RegisterSuspendResumeNotification instead, |
| that should work in headless mode too |
\*---------------------------------------------*/
dlg.showMinimized();
#endif
#ifdef __APPLE__
MacUtils::ToggleApplicationDocklessState(false);
#endif
dlg.hide();
}
else
{
dlg.show();
}
LOG_TRACE("[main] Ready to exec() the dialog");
#ifdef __linux__
std::signal(SIGINT, sigHandler);
std::signal(SIGTERM, sigHandler);
#endif
exitval = a.exec();
}
else
{
/*-------------------------------------------------*\
| If no GUI is needed, we let the background |
| threads run as long as they need, but we need to |
| AT LEAST wait for initialization to finish |
\*-------------------------------------------------*/
ResourceManager::get()->WaitForInitialization();
if(ret_flags & RET_FLAG_START_SERVER)
{
NetworkServer* server = ResourceManager::get()->GetServer();
if(server)
{
exitval = !server->GetOnline();
}
else
{
exitval = EXIT_FAILURE;
}
}
}
return(exitval);
}