forked from ukui/ukui-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
154 lines (137 loc) · 5.18 KB
/
main.cpp
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
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program 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, or (at your option)
* any later version.
*
* This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "src/MainWindow/mainwindow.h"
#include <QtSingleApplication>
#include <QDesktopWidget>
#include <QFile>
#include <QScreen>
#include <QTranslator>
#include <QLocale>
#include <KWindowEffects>
#include <X11/Xlib.h>
#include <syslog.h>
int getScreenWidth() {
Display *disp = XOpenDisplay(NULL);
Screen *scrn = DefaultScreenOfDisplay(disp);
if (NULL == scrn) {
return 0;
}
int width = scrn->width;
if (NULL != disp) {
XCloseDisplay(disp);
}
return width;
}
int main(int argc, char *argv[])
{
qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");
if (getScreenWidth() > 2560) {
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
}
QtSingleApplication app("ukui-menu", argc, argv);
app.setQuitOnLastWindowClosed(false);
if(app.isRunning())
{
app.sendMessage("raise_window_noop");
return EXIT_SUCCESS;
}
QTranslator translator;
if (translator.load(QLocale(), "ukui-menu", "_", QM_FILES_INSTALL_PATH))
app.installTranslator(&translator);
else
qDebug() << "Load translations file" << QLocale() << "failed!";
MainWindow w;
int position=0;
int panelSize=0;
if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit()))
{
QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit());
if(gsetting->keys().contains(QString("panelposition")))
position=gsetting->get("panelposition").toInt();
else
position=0;
if(gsetting->keys().contains(QString("panelsize")))
panelSize=gsetting->get("panelsize").toInt();
else
panelSize=46;
}
else
{
position=0;
panelSize=46;
}
int x=QApplication::primaryScreen()->geometry().x();
int y=QApplication::primaryScreen()->geometry().y();
if(position==0)
w.setGeometry(QRect(x,y+QApplication::primaryScreen()->geometry().height()-panelSize-Style::minh,Style::minw,Style::minh));
else if(position==1)
w.setGeometry(QRect(x,y+panelSize,Style::minw,Style::minh));
else if(position==2)
w.setGeometry(QRect(x+panelSize,y,Style::minw,Style::minh));
else
w.setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-Style::minw,y,Style::minw,Style::minh));
app.setActivationWindow(&w);
// QRectF rect;
// rect.setX(w.rect().x()+1);
// rect.setY(w.rect().y()+1);
// rect.setWidth(w.rect().width()-2);
// rect.setHeight(w.rect().height()-2);
// //QPainterPath画圆角矩形
// const qreal radius = 6;
// QPainterPath path;
// path.moveTo(rect.topRight() - QPointF(radius, 0));
// path.lineTo(rect.topLeft() + QPointF(radius, 0));
// path.quadTo(rect.topLeft(), rect.topLeft() + QPointF(0, radius));
// path.lineTo(rect.bottomLeft() + QPointF(0, -radius));
// path.quadTo(rect.bottomLeft(), rect.bottomLeft() + QPointF(radius, 0));
// path.lineTo(rect.bottomRight() - QPointF(radius, 0));
// path.quadTo(rect.bottomRight(), rect.bottomRight() + QPointF(0, -radius));
// path.lineTo(rect.topRight() + QPointF(0, radius));
// path.quadTo(rect.topRight(), rect.topRight() + QPointF(-radius, -0));
//右上角
// path.moveTo(rect.topRight() - QPointF(radius, 0));
// path.lineTo(rect.topLeft());
// path.lineTo(rect.bottomLeft());
// path.lineTo(rect.bottomRight());
// path.lineTo(rect.topRight() + QPointF(0, radius));
// path.quadTo(rect.topRight(), rect.topRight() + QPointF(-radius, -0));
//右下角
// path.moveTo(rect.topRight());
// path.lineTo(rect.topLeft());
// path.lineTo(rect.bottomLeft());
// path.lineTo(rect.bottomRight() - QPointF(radius, 0));
// path.quadTo(rect.bottomRight(), rect.bottomRight() + QPointF(0, -radius));
// path.lineTo(rect.topRight());
//左下角
// path.moveTo(rect.topRight());
// path.lineTo(rect.topLeft());
// path.lineTo(rect.bottomLeft() + QPointF(0, -radius));
// path.quadTo(rect.bottomLeft(), rect.bottomLeft() + QPointF(radius, 0));
// path.lineTo(rect.bottomRight());
// path.lineTo(rect.topRight());
// w.setFrameStyle();
// w.setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
//注释掉,以保证自启动时不显示界面
// w.show();
// w.raise();
// w.activateWindow();
// w.hide();
KWindowEffects::enableBlurBehind(w.winId(),true);
return app.exec();
}