forked from dail8859/NotepadNext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (74 loc) · 3.01 KB
/
main.cpp
File metadata and controls
91 lines (74 loc) · 3.01 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
/*
* This file is part of Notepad Next.
* Copyright 2019 Justin Dailey
*
* Notepad Next is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Notepad Next is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Notepad Next. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QSettings>
#include <QSysInfo>
#include <QApplication>
#include <QDataStream>
#include "NotepadNextApplication.h"
int main(int argc, char *argv[])
{
qSetMessagePattern("[%{time process}] %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}: %{message}");
#ifdef Q_OS_LINUX
// Qt Advanced Docking System positions its drop-indicator overlays as
// top-level Qt::Tool windows using mapToGlobal() + move() to absolute
// coordinates. Wayland does not let clients position top-level windows,
// so during a tab drag the indicators appear at wrong locations. Run
// through XWayland where the positioning works correctly. Honor an
// explicit QT_QPA_PLATFORM and an opt-out escape hatch.
if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORM")
&& !qEnvironmentVariableIsSet("NOTEPADNEXT_FORCE_NATIVE_WAYLAND"))
{
const QByteArray sessionType = qgetenv("XDG_SESSION_TYPE");
const bool isWayland = (sessionType == "wayland")
|| qEnvironmentVariableIsSet("WAYLAND_DISPLAY");
if (isWayland) {
qputenv("QT_QPA_PLATFORM", "xcb;wayland");
}
}
#endif
// Set these since other parts of the app references these
QApplication::setOrganizationName("NotepadNext");
QApplication::setApplicationName("NotepadNext");
QGuiApplication::setApplicationDisplayName("Notepad Next");
QGuiApplication::setApplicationVersion(APP_VERSION);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
// Default settings format
QSettings::setDefaultFormat(QSettings::IniFormat);
NotepadNextApplication app(argc, argv);
// Log some debug info
qInfo("=============================");
for(const auto &d : app.debugInfo()){
qInfo("%s", qUtf8Printable(d));
}
qInfo("=============================");
if(app.isPrimary()) {
app.init();
return app.exec();
}
else {
qInfo() << "Primary instance already running. PID:" << app.primaryPid();
app.sendInfoToPrimaryInstance();
qInfo() << "Secondary instance closing...";
app.exit(0);
return 0;
}
}