-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (92 loc) · 3.08 KB
/
Copy pathmain.cpp
File metadata and controls
107 lines (92 loc) · 3.08 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
#include <QDesktopWidget>
#include "threads.h"
#include "qquickimage.h"
#include <cstring>
#include <stdio.h>
#include <X11/Xlib.h>
#include <toml++/toml.hpp>
#include <csignal>
#include <iostream>
#include <stdlib.h>
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickImageProvider>
#include <QStyle>
class StandardIconProvider : public QQuickImageProvider
{
public:
StandardIconProvider(QStyle *style)
: QQuickImageProvider(Pixmap)
, m_style(style)
{}
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
{
Q_UNUSED(size)
static const auto metaobject = QMetaEnum::fromType<QStyle::StandardPixmap>();
const int value = metaobject.keyToValue(id.toLatin1());
QIcon icon = m_style->standardIcon(static_cast<QStyle::StandardPixmap>(value));
return icon.pixmap(requestedSize);
}
QStyle *m_style;
};
auto config = toml::parse_file("config.toml");
int getConfigHeight()
{
int h;
try {
h = config["dimensions"]["height"].value_or(0);
} catch (const toml::parse_error& err) {
h = 40;
}
return h;
}
bool getOnTopConfig(QWindow *window, QRect screenGeometry)
{
std::optional<std::string> position = config["dimensions"]["panelPosition"].value<std::string>();
int height = getConfigHeight();
if(position == "top"){
window->setGeometry(screenGeometry.x(), 0,screenGeometry.width(), height);
return true;
} else if(position == "bottom") {
window->setGeometry(screenGeometry.x(), screenGeometry.height() + screenGeometry.y() - height,screenGeometry.width(), height);
return false;
}
}
void ifDisplayIsOpened()
{
Display *display;
// Open a connection to the X server
display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
XCloseDisplay(display);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDesktopWidget desktop;
Context context;
context.basepath = app.applicationDirPath();
QQuickImage image;
image.ctx = &context;
ifDisplayIsOpened();
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("Context", &context);
engine.addImageProvider(QLatin1String("standardicons"), new StandardIconProvider(app.style()));
engine.addImageProvider("pixmap", &image);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *main = engine.rootObjects().first();
QWindow *window = qobject_cast<QWindow *>(main); // (QWindow *)main
QRect screenGeometry = context.primaryDisplayDimensions();
window->setProperty("mainId", window->winId());
window->xChanged(Qt::WA_X11DoNotAcceptFocus | Qt::WA_X11NetWmWindowTypeDock);
app.setAttribute(Qt::AA_X11InitThreads);
Threads *threads = new Threads();
threads->main = window;
threads->start();
context.xchange(window->winId(), "_NET_WM_WINDOW_TYPE_DOCK");
context.xreservedSpace(window->winId(), window->height(), getOnTopConfig(window, screenGeometry));
return app.exec();
}