2020-01-17 13:56:30 +08:00
|
|
|
/*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 2, 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, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301, USA.
|
|
|
|
|
**/
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "./ui_mainwindow.h"
|
|
|
|
|
#include "powerprovider.h"
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QException>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QScreen>
|
2020-04-14 16:15:11 +08:00
|
|
|
#include <QCloseEvent>
|
2020-01-17 13:56:30 +08:00
|
|
|
#include <QMouseEvent>
|
2020-04-14 16:15:11 +08:00
|
|
|
#include <QX11Info>
|
|
|
|
|
#include <X11/extensions/XTest.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
#include "grab-x11.h"
|
|
|
|
|
#include "xeventmonitor.h"
|
2020-07-24 13:55:32 +08:00
|
|
|
#include <QFileInfo>
|
2020-08-31 20:28:22 +08:00
|
|
|
#include <QDBusInterface>
|
|
|
|
|
#include<QGSettings/QGSettings>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
|
2020-07-20 12:06:53 +08:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
extern void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
#define BLUR_RADIUS 300
|
|
|
|
|
#define BACKGROUND_SETTINGS "org.mate.background"
|
2020-08-31 20:28:22 +08:00
|
|
|
#define TABLED_SCHEMA "org.ukui.SettingsDaemon.plugins.tablet-mode"
|
|
|
|
|
|
2020-01-17 13:56:30 +08:00
|
|
|
|
2020-07-03 14:32:25 +08:00
|
|
|
void getUserNum(){
|
|
|
|
|
QStringList args;
|
|
|
|
|
QString cmd = "/bin/sh -c \"cat file | grep string\"";
|
|
|
|
|
//args<<"-l";
|
|
|
|
|
// QString command = "cat /etc/passwd | grep string";
|
|
|
|
|
// qDebug() << "Start ukui module: " << command << "args: " << args;
|
|
|
|
|
QProcess *process;
|
|
|
|
|
process->start(cmd,args);
|
|
|
|
|
process->waitForFinished();
|
|
|
|
|
process->waitForReadyRead();
|
|
|
|
|
QString s = process->readAll();
|
|
|
|
|
//process->close();
|
|
|
|
|
qDebug()<<s;
|
|
|
|
|
//return s.toInt();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 12:06:53 +08:00
|
|
|
QPixmap blurPixmap(QPixmap pixmap)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(&pixmap);
|
|
|
|
|
QImage srcImg = pixmap.toImage();
|
|
|
|
|
qt_blurImage(&painter, srcImg, BLUR_RADIUS, false, false);
|
|
|
|
|
painter.end();
|
|
|
|
|
return pixmap;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 13:56:30 +08:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2020-04-14 16:15:11 +08:00
|
|
|
: QMainWindow(parent),
|
|
|
|
|
ui(new Ui::MainWindow),
|
|
|
|
|
m_power(new UkuiPower(this)),
|
|
|
|
|
timer(new QTimer()),
|
|
|
|
|
xEventMonitor(new XEventMonitor(this))
|
2020-01-17 13:56:30 +08:00
|
|
|
{
|
2020-07-20 14:41:18 +08:00
|
|
|
const QByteArray id(BACKGROUND_SETTINGS);
|
|
|
|
|
if (QGSettings::isSchemaInstalled(id)) {
|
2020-08-31 20:28:22 +08:00
|
|
|
QGSettings *gset = new QGSettings(BACKGROUND_SETTINGS,"",this);
|
|
|
|
|
QString fullstr = gset->get("picture-filename").toString();
|
2020-07-24 13:55:32 +08:00
|
|
|
QFileInfo fileInfo(fullstr);
|
|
|
|
|
if(fileInfo.isFile()){
|
|
|
|
|
pix.load(fullstr);
|
|
|
|
|
pix = blurPixmap(pix);
|
2020-08-31 20:28:22 +08:00
|
|
|
gset->deleteLater();
|
2020-07-24 13:55:32 +08:00
|
|
|
}else
|
|
|
|
|
pix.load(":/images/background-ukui.png");
|
2020-07-20 14:41:18 +08:00
|
|
|
}else
|
|
|
|
|
pix.load(":/images/background-ukui.png");
|
|
|
|
|
|
2020-08-31 20:28:22 +08:00
|
|
|
|
2020-01-17 13:56:30 +08:00
|
|
|
ui->setupUi(this);
|
2020-07-03 14:32:25 +08:00
|
|
|
ui->switchuser->installEventFilter(this);
|
|
|
|
|
ui->hibernate->installEventFilter(this);
|
2020-07-22 16:59:58 +08:00
|
|
|
ui->suspend->installEventFilter(this);
|
2020-05-19 10:12:06 +08:00
|
|
|
ui->lockscreen->installEventFilter(this);
|
2020-01-17 13:56:30 +08:00
|
|
|
ui->logout->installEventFilter(this);
|
|
|
|
|
ui->reboot->installEventFilter(this);
|
|
|
|
|
ui->shutdown->installEventFilter(this);
|
|
|
|
|
|
2020-08-31 20:28:22 +08:00
|
|
|
ui->lockscreen_t->installEventFilter(this);
|
|
|
|
|
ui->lockscreen_t->setStyleSheet("background-color:white;opacity:10%,border-radius:16px");
|
|
|
|
|
ui->logout_t->installEventFilter(this);
|
|
|
|
|
ui->shutdown_t->installEventFilter(this);
|
|
|
|
|
ui->reboot_t->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
ui->lockscreen_t_label->installEventFilter(this);
|
|
|
|
|
ui->logout_t_label->installEventFilter(this);
|
|
|
|
|
ui->shutdown_t_label->installEventFilter(this);
|
|
|
|
|
ui->reboot_t_label->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
ui->lockscreen_t->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->logout_t->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->shutdown_t->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->reboot_t->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->lockscreen_t_icon->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->logout_t_icon->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->shutdown_t_icon->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
ui->reboot_t_icon->setStyleSheet("background-color: rgb(255,255,255,15)");
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
//Make a hash-map to store tableNum-to-lastWidget
|
2020-07-03 14:32:25 +08:00
|
|
|
map.insert(0,ui->switchuser);
|
|
|
|
|
map.insert(1,ui->hibernate);
|
2020-07-22 16:59:58 +08:00
|
|
|
map.insert(2,ui->suspend);
|
2020-07-03 14:32:25 +08:00
|
|
|
map.insert(3,ui->lockscreen);
|
|
|
|
|
map.insert(4,ui->logout);
|
|
|
|
|
map.insert(5,ui->reboot);
|
|
|
|
|
map.insert(6,ui->shutdown);
|
|
|
|
|
|
2020-08-31 20:28:22 +08:00
|
|
|
map.insert(7,ui->lockscreen_t);
|
|
|
|
|
map.insert(8,ui->logout_t);
|
|
|
|
|
map.insert(9,ui->reboot_t);
|
|
|
|
|
map.insert(10,ui->shutdown_t);
|
|
|
|
|
map.insert(11,ui->lockscreen_t_label);
|
|
|
|
|
map.insert(12,ui->logout_t_label);
|
|
|
|
|
map.insert(13,ui->reboot_t_label);
|
|
|
|
|
map.insert(14,ui->shutdown_t_label);
|
|
|
|
|
|
|
|
|
|
|
2020-08-05 13:54:55 +08:00
|
|
|
if(false){//m_power->canAction(UkuiPower::PowerHibernate)
|
2020-07-03 14:32:25 +08:00
|
|
|
isHibernateHide = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(true){
|
|
|
|
|
isSwitchuserHide = false;
|
|
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
|
2020-08-31 20:28:22 +08:00
|
|
|
gs = new QGSettings("org.ukui.session","/org/ukui/desktop/session/");
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
//Set the default value
|
2020-07-03 14:32:25 +08:00
|
|
|
lastWidget = ui->lockscreen;
|
|
|
|
|
tableNum = 3;
|
2020-08-14 14:43:03 +08:00
|
|
|
ui->lockscreen->setStyleSheet("QWidget#lockscreen{background-color: rgb(255,255,255,100);border-radius: 6px;}");
|
2020-06-18 13:21:41 +08:00
|
|
|
|
2020-01-17 13:56:30 +08:00
|
|
|
QDateTime current_date_time =QDateTime::currentDateTime();
|
|
|
|
|
QString current_date =current_date_time.toString("yyyy-MM-dd ddd");
|
|
|
|
|
QString current_time =current_date_time.toString("hh:mm");
|
|
|
|
|
ui->time_lable->setText(current_time);
|
|
|
|
|
ui->date_label->setText(current_date);
|
|
|
|
|
|
|
|
|
|
//根据屏幕分辨率与鼠标位置重设界面
|
|
|
|
|
m_screen = QApplication::desktop()->screenGeometry(QCursor::pos());
|
|
|
|
|
setFixedSize(QApplication::primaryScreen()->virtualSize());
|
|
|
|
|
move(0,0);//设置初始位置的值
|
|
|
|
|
ResizeEvent();
|
|
|
|
|
|
2020-04-18 17:43:12 +08:00
|
|
|
//设置窗体无边框,不可拖动拖拽拉伸;为顶层窗口,无法被切屏;不使用窗口管理器
|
|
|
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
2020-04-14 16:15:11 +08:00
|
|
|
//setAttribute(Qt::WA_TranslucentBackground, true);//设定该窗口透明显示
|
|
|
|
|
|
|
|
|
|
/*捕获键盘,如果捕获失败,那么模拟一次esc按键来退出菜单,如果仍捕获失败,则放弃捕获*/
|
2020-04-18 20:36:34 +08:00
|
|
|
if (establishGrab()) {
|
2020-04-14 16:15:11 +08:00
|
|
|
qDebug()<<"establishGrab : true";
|
2020-04-18 20:36:34 +08:00
|
|
|
} else {
|
2020-04-14 16:15:11 +08:00
|
|
|
qDebug()<<"establishGrab : false";
|
|
|
|
|
XTestFakeKeyEvent(QX11Info::display(), XKeysymToKeycode(QX11Info::display(),XK_Escape), True, 1);
|
|
|
|
|
XTestFakeKeyEvent(QX11Info::display(), XKeysymToKeycode(QX11Info::display(),XK_Escape), False, 1);
|
|
|
|
|
XFlush(QX11Info::display());
|
|
|
|
|
sleep(1);
|
2020-04-18 20:36:34 +08:00
|
|
|
if (!establishGrab()) {
|
2020-04-14 16:15:11 +08:00
|
|
|
qDebug()<<"establishGrab : false again!";
|
|
|
|
|
//exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
//KeyPress, KeyRelease, ButtonPress, ButtonRelease and MotionNotify events has been redirected
|
2020-07-29 11:45:23 +08:00
|
|
|
connect(xEventMonitor, SIGNAL(keyPress(const QString &)),this, SLOT(onGlobalKeyPress(const QString &)));
|
|
|
|
|
connect(xEventMonitor, SIGNAL(keyRelease(const QString &)),this, SLOT(onGlobalkeyRelease(const QString &)));
|
2020-06-18 13:21:41 +08:00
|
|
|
|
2020-04-14 16:15:11 +08:00
|
|
|
xEventMonitor->start();
|
|
|
|
|
|
2020-01-17 13:56:30 +08:00
|
|
|
this->show();
|
2020-04-18 17:43:12 +08:00
|
|
|
|
2020-04-14 16:15:11 +08:00
|
|
|
//qApp->installNativeEventFilter(this);
|
2020-01-17 13:56:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
2020-04-14 16:15:11 +08:00
|
|
|
delete m_power;
|
|
|
|
|
delete xEventMonitor;
|
2020-01-17 13:56:30 +08:00
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::ResizeEvent(){
|
|
|
|
|
int xx = m_screen.x();
|
|
|
|
|
int yy = m_screen.y();//取得当前鼠标所在屏幕的最左,上坐标
|
2020-05-19 10:12:06 +08:00
|
|
|
|
2020-07-03 14:32:25 +08:00
|
|
|
int hideNum = 0;
|
|
|
|
|
if(isHibernateHide){
|
|
|
|
|
hideNum = hideNum + 1;
|
|
|
|
|
}
|
|
|
|
|
if(isSwitchuserHide){
|
|
|
|
|
hideNum = hideNum + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
//Move the widget to the direction where they should be
|
2020-07-06 10:42:57 +08:00
|
|
|
int spaceW,spaceH;
|
2020-07-03 14:32:25 +08:00
|
|
|
int sum = 0;
|
|
|
|
|
int maxXX = 1000*1000;
|
2020-07-06 10:42:57 +08:00
|
|
|
int k = 0;
|
2020-08-31 20:28:22 +08:00
|
|
|
const QByteArray tabletId(TABLED_SCHEMA);
|
|
|
|
|
if (QGSettings::isSchemaInstalled(tabletId)){
|
|
|
|
|
QGSettings *tabletMode = new QGSettings(TABLED_SCHEMA);
|
|
|
|
|
res=tabletMode->get("tablet-mode").toBool();
|
|
|
|
|
}
|
2020-07-06 10:42:57 +08:00
|
|
|
if(m_screen.width()>1088){
|
2020-08-31 20:28:22 +08:00
|
|
|
if(res)
|
|
|
|
|
{
|
|
|
|
|
ui->time_lable->hide();
|
|
|
|
|
ui->date_label->hide();
|
|
|
|
|
spaceW = (m_screen.width() - 200*(5-hideNum)+18) / 2;
|
|
|
|
|
spaceH = (m_screen.height() - 140) / 2 -20;
|
|
|
|
|
for(int i=0;i<=6;i++){
|
|
|
|
|
map[i]->move(maxXX,maxXX);
|
2020-07-06 10:42:57 +08:00
|
|
|
}
|
2020-08-31 20:28:22 +08:00
|
|
|
for(int i=7;i<=10;i++){
|
|
|
|
|
map[i]->move(xx+spaceW + 200*sum,yy+spaceH);
|
|
|
|
|
map[i+4]->move(xx+spaceW+200*sum+48,yy+spaceH+144);
|
|
|
|
|
sum = sum+1;
|
2020-07-06 10:42:57 +08:00
|
|
|
}
|
2020-07-03 14:32:25 +08:00
|
|
|
}
|
2020-08-31 20:28:22 +08:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
spaceW = (m_screen.width() - 158*(7-hideNum)+18) / 2;
|
|
|
|
|
spaceH = (m_screen.height() - 140) / 2 -20;
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<=6;i++){
|
2020-07-06 10:42:57 +08:00
|
|
|
if(isHibernateHide && i == 1){
|
|
|
|
|
map[i]->move(maxXX , maxXX);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(isSwitchuserHide && i == 0){
|
|
|
|
|
map[i]->move(maxXX , maxXX);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-08-31 20:28:22 +08:00
|
|
|
map[i]->move(xx+spaceW + 158*sum,yy+spaceH);
|
|
|
|
|
sum = sum+1;
|
|
|
|
|
}
|
|
|
|
|
for(int i=7;i<=10;i++){
|
|
|
|
|
map[i]->move(maxXX,maxXX);
|
|
|
|
|
map[i+4]->move(maxXX,maxXX);
|
2020-07-06 10:42:57 +08:00
|
|
|
}
|
2020-08-31 20:28:22 +08:00
|
|
|
|
2020-07-03 14:32:25 +08:00
|
|
|
}
|
2020-07-06 10:42:57 +08:00
|
|
|
ui->widget->move(xx+(m_screen.width()-130)/2,yy+40);
|
2020-08-31 20:28:22 +08:00
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
if(res)
|
|
|
|
|
{
|
|
|
|
|
ui->time_lable->hide();
|
|
|
|
|
ui->date_label->hide();
|
|
|
|
|
int spaceWw = (m_screen.width() - 200*(5-hideNum)+18) / 2;
|
|
|
|
|
spaceW = (m_screen.width() - 200*4+18) / 2;
|
|
|
|
|
spaceH = (m_screen.height() - 80) / 2;
|
|
|
|
|
for(int i=0;i<=6;i++){
|
|
|
|
|
map[i]->move(maxXX,maxXX);
|
|
|
|
|
}
|
|
|
|
|
for(int i=7;i<=10;i++){
|
|
|
|
|
map[i]->move(xx+spaceW + 200*k,yy+spaceH+38);
|
|
|
|
|
map[i]->move(xx+spaceW+200*k+48,yy+spaceH+38+144);
|
|
|
|
|
k++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int spaceWw = (m_screen.width() - 158*(7-hideNum)+18) / 2;
|
|
|
|
|
spaceW = (m_screen.width() - 158*4+18) / 2;
|
|
|
|
|
spaceH = (m_screen.height() - 80) / 2;
|
|
|
|
|
for(int i=7;i<=10;i++){
|
|
|
|
|
map[i]->move(xx+spaceW + 158*k,yy+spaceH+38);
|
|
|
|
|
map[i]->move(xx+spaceW+158*k+48,yy+spaceH+38+144);
|
|
|
|
|
k++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for(int i=7;i<=10;i++){
|
|
|
|
|
map[i]->move(maxXX,maxXX);
|
|
|
|
|
map[i+4]->move(maxXX,maxXX);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->widget->move(xx+(m_screen.width()-130)/2,yy+40);
|
|
|
|
|
|
2020-07-03 14:32:25 +08:00
|
|
|
}
|
2020-01-17 13:56:30 +08:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 20:28:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
//Paint the background picture
|
2020-01-17 13:56:30 +08:00
|
|
|
void MainWindow::paintEvent(QPaintEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(this);
|
2020-07-20 12:06:53 +08:00
|
|
|
painter.setPen(Qt::transparent);
|
2020-04-18 20:36:34 +08:00
|
|
|
for(QScreen *screen : QApplication::screens()) {
|
2020-04-18 17:43:12 +08:00
|
|
|
//draw picture to every screen
|
2020-01-17 13:56:30 +08:00
|
|
|
QRect rect = screen->geometry();
|
|
|
|
|
painter.drawPixmap(rect,pix);
|
|
|
|
|
painter.drawRect(rect);
|
|
|
|
|
}
|
|
|
|
|
QWidget::paintEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
//lock screen
|
|
|
|
|
void doLockscreen(){
|
2020-08-31 20:28:22 +08:00
|
|
|
QDBusInterface *interface = new QDBusInterface("org.ukui.ScreenSaver",
|
|
|
|
|
"/",
|
|
|
|
|
"org.ukui.ScreenSaver"
|
|
|
|
|
);
|
|
|
|
|
QDBusMessage msg = interface->call("Lock");
|
|
|
|
|
exit(0);
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//handle mouse-clicked event
|
2020-01-17 13:56:30 +08:00
|
|
|
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
2020-07-03 14:32:25 +08:00
|
|
|
if (obj->objectName() == "switchuser") {
|
|
|
|
|
changePoint(ui->switchuser,event,0);
|
2020-05-19 10:12:06 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("switchuser",0);
|
|
|
|
|
}
|
|
|
|
|
}else if (obj->objectName() == "hibernate") {
|
|
|
|
|
changePoint(ui->hibernate,event,1);
|
|
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
doevent("hibernate",1);
|
|
|
|
|
}
|
2020-07-22 16:59:58 +08:00
|
|
|
}else if (obj->objectName() == "suspend") {
|
|
|
|
|
changePoint(ui->suspend,event,2);
|
2020-07-03 14:32:25 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2020-07-22 16:59:58 +08:00
|
|
|
doevent("suspend",2);
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
2020-08-31 20:28:22 +08:00
|
|
|
}else if (obj->objectName() == "lockscreen_t") {
|
|
|
|
|
changePoint(ui->lockscreen_t,event,3);
|
|
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
doevent("screensaver",3);
|
|
|
|
|
}
|
|
|
|
|
}else if (obj->objectName() == "logout_t") {
|
|
|
|
|
changePoint(ui->logout_t,event,4);
|
|
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
doevent("logout",4);
|
|
|
|
|
}
|
|
|
|
|
}else if (obj->objectName() == "reboot_t") {
|
|
|
|
|
changePoint(ui->reboot_t,event,5);
|
|
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
doevent("reboot",5);
|
|
|
|
|
}
|
|
|
|
|
}else if(obj->objectName() == "shutdown_t") {
|
|
|
|
|
changePoint(ui->shutdown_t,event,6);
|
|
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
doevent("shutdown",6);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (obj->objectName() == "lockscreen") {
|
2020-07-03 14:32:25 +08:00
|
|
|
changePoint(ui->lockscreen,event,3);
|
2020-06-18 13:21:41 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2020-08-31 20:28:22 +08:00
|
|
|
doevent("screensaver",3);
|
2020-05-19 10:12:06 +08:00
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
}else if (obj->objectName() == "logout") {
|
2020-07-03 14:32:25 +08:00
|
|
|
changePoint(ui->logout,event,4);
|
2020-06-18 13:21:41 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("logout",4);
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
}else if (obj->objectName() == "reboot") {
|
2020-07-03 14:32:25 +08:00
|
|
|
changePoint(ui->reboot,event,5);
|
2020-06-18 13:21:41 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("reboot",5);
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
} else if(obj->objectName() == "shutdown") {
|
2020-07-03 14:32:25 +08:00
|
|
|
changePoint(ui->shutdown,event,6);
|
2020-06-18 13:21:41 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("shutdown",6);
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
2020-01-17 13:56:30 +08:00
|
|
|
}
|
|
|
|
|
return QWidget::eventFilter(obj, event);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
void MainWindow::changePoint(QWidget *widget, QEvent *event, int i){
|
|
|
|
|
if(event->type() == QEvent::Enter){
|
|
|
|
|
tableNum = i;
|
|
|
|
|
flag = true;
|
|
|
|
|
refreshBlur(lastWidget,widget);
|
|
|
|
|
}
|
|
|
|
|
if(event->type() == QEvent::Leave){
|
|
|
|
|
flag = false;
|
|
|
|
|
lastWidget = widget;
|
2020-01-17 13:56:30 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
void MainWindow::doevent(QString test, int i){
|
|
|
|
|
try {
|
2020-08-31 20:28:22 +08:00
|
|
|
gs->set("win-key-release",false);
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
defaultnum = i;
|
|
|
|
|
qDebug()<<"Start do action"<<test<<defaultnum;
|
2020-08-04 13:56:56 +08:00
|
|
|
if (closeGrab()) {
|
|
|
|
|
qDebug()<<"success to close Grab";
|
|
|
|
|
} else {
|
|
|
|
|
qDebug()<<"failure to close Grab";
|
|
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
this->hide();
|
2020-08-31 20:28:22 +08:00
|
|
|
if(i == 3){
|
|
|
|
|
doLockscreen();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
emit signalTostart();
|
|
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
} catch (QException &e) {
|
|
|
|
|
qWarning() << e.what();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//handle the blank-area mousePressEvent
|
2020-01-17 13:56:30 +08:00
|
|
|
void MainWindow::mousePressEvent(QMouseEvent *event){
|
2020-07-22 16:59:58 +08:00
|
|
|
if (!ui->suspend->geometry().contains(event->pos()) &&
|
2020-07-22 17:30:14 +08:00
|
|
|
!ui->hibernate->geometry().contains(event->pos()) &&
|
2020-05-19 10:12:06 +08:00
|
|
|
!ui->lockscreen->geometry().contains(event->pos()) &&
|
2020-08-31 20:28:22 +08:00
|
|
|
!ui->lockscreen_t->geometry().contains(event->pos()) &&
|
2020-04-14 16:15:11 +08:00
|
|
|
!ui->switchuser->geometry().contains(event->pos()) &&
|
|
|
|
|
!ui->logout->geometry().contains(event->pos()) &&
|
2020-08-31 20:28:22 +08:00
|
|
|
!ui->logout_t->geometry().contains(event->pos()) &&
|
2020-04-14 16:15:11 +08:00
|
|
|
!ui->reboot->geometry().contains(event->pos()) &&
|
2020-08-31 20:28:22 +08:00
|
|
|
!ui->reboot_t->geometry().contains(event->pos()) &&
|
|
|
|
|
!ui->shutdown_t->geometry().contains(event->pos()) &&
|
2020-04-18 20:36:34 +08:00
|
|
|
!ui->shutdown->geometry().contains(event->pos())) {
|
2020-07-29 11:45:23 +08:00
|
|
|
exitt();
|
2020-04-14 16:15:11 +08:00
|
|
|
}
|
2020-01-17 13:56:30 +08:00
|
|
|
}
|
|
|
|
|
|
2020-07-29 11:45:23 +08:00
|
|
|
bool MainWindow::exitt(){
|
|
|
|
|
gs->set("win-key-release",false);
|
2020-08-04 13:56:56 +08:00
|
|
|
if (closeGrab()) {
|
|
|
|
|
qDebug()<<"success to close Grab";
|
|
|
|
|
} else {
|
|
|
|
|
qDebug()<<"failure to close Grab";
|
|
|
|
|
}
|
2020-07-29 11:45:23 +08:00
|
|
|
close();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onGlobalKeyPress(const QString &key){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 13:21:41 +08:00
|
|
|
//handle "Esc","Left","Right","Enter" keyPress event
|
2020-07-29 11:45:23 +08:00
|
|
|
void MainWindow::onGlobalkeyRelease(const QString &key)
|
2020-04-18 20:36:34 +08:00
|
|
|
{
|
2020-07-29 11:45:23 +08:00
|
|
|
qDebug()<<"key: "<<key;
|
2020-04-18 20:36:34 +08:00
|
|
|
if (key == "Escape") {
|
2020-07-29 11:45:23 +08:00
|
|
|
exitt();
|
2020-04-14 16:15:11 +08:00
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
if (key == "Left"){
|
|
|
|
|
if (flag == false){
|
|
|
|
|
if(tableNum == 0){
|
2020-07-03 14:32:25 +08:00
|
|
|
tableNum = 6;
|
2020-06-18 13:21:41 +08:00
|
|
|
}else{
|
2020-07-03 14:32:25 +08:00
|
|
|
if(isHibernateHide && tableNum == 2){
|
|
|
|
|
if(isSwitchuserHide){
|
|
|
|
|
tableNum = 6;
|
|
|
|
|
}else
|
|
|
|
|
tableNum = 0;
|
|
|
|
|
}else{
|
|
|
|
|
if(isSwitchuserHide && tableNum == 1){
|
|
|
|
|
tableNum = 6;
|
|
|
|
|
}else
|
|
|
|
|
tableNum = tableNum-1;
|
|
|
|
|
}
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-03 14:32:25 +08:00
|
|
|
refreshBlur(lastWidget,map[tableNum]);
|
|
|
|
|
lastWidget = map[tableNum];
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
if (key == "Right"){
|
|
|
|
|
if(flag == false){
|
2020-07-03 14:32:25 +08:00
|
|
|
if(!isSwitchuserHide && tableNum == 6){
|
2020-06-18 13:21:41 +08:00
|
|
|
tableNum = 0;
|
2020-07-03 14:32:25 +08:00
|
|
|
}else if(isSwitchuserHide && tableNum == 6){
|
|
|
|
|
if(isHibernateHide)
|
|
|
|
|
tableNum = 2;
|
|
|
|
|
else
|
|
|
|
|
tableNum = 1;
|
2020-06-18 13:21:41 +08:00
|
|
|
}else{
|
2020-07-03 14:32:25 +08:00
|
|
|
if(isHibernateHide && tableNum == 0)
|
|
|
|
|
tableNum = 2;
|
|
|
|
|
else
|
|
|
|
|
tableNum = tableNum+1;
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-03 14:32:25 +08:00
|
|
|
refreshBlur(lastWidget,map[tableNum]);
|
|
|
|
|
lastWidget = map[tableNum];
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
2020-06-19 14:05:46 +08:00
|
|
|
if (key == "Return"){//space,KP_Enter
|
2020-06-18 13:21:41 +08:00
|
|
|
qDebug()<<map[tableNum]->objectName()<<"";
|
|
|
|
|
switch (tableNum) {
|
|
|
|
|
case 0:
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("switchuser",0);
|
2020-06-18 13:21:41 +08:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("hibernate",1);
|
2020-06-18 13:21:41 +08:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2020-07-22 16:59:58 +08:00
|
|
|
doevent("suspend",2);
|
2020-06-18 13:21:41 +08:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2020-08-31 20:28:22 +08:00
|
|
|
doevent("screensaver",3);
|
2020-06-18 13:21:41 +08:00
|
|
|
break;
|
|
|
|
|
case 4:
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("logout",4);
|
2020-06-18 13:21:41 +08:00
|
|
|
break;
|
|
|
|
|
case 5:
|
2020-07-03 14:32:25 +08:00
|
|
|
doevent("reboot",5);
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
doevent("shutdown",6);
|
2020-06-18 13:21:41 +08:00
|
|
|
break;
|
|
|
|
|
}
|
2020-06-19 14:05:46 +08:00
|
|
|
this->hide();
|
2020-06-18 13:21:41 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::refreshBlur(QWidget *last, QWidget *now){
|
|
|
|
|
QString pastName = last->objectName();
|
|
|
|
|
QString name = now->objectName();
|
|
|
|
|
QString strlast = "QWidget#" + pastName + "{background-color: rgb(0,0,0,0)}";
|
2020-08-31 20:28:22 +08:00
|
|
|
if(res)
|
|
|
|
|
QString strlast = "QWidget#" + pastName + "{background-color: rgb(255,255,255,15)}";
|
2020-07-20 12:06:53 +08:00
|
|
|
QString str = "QWidget#" + name + "{background-color: rgb(255,255,255,100);border-radius: 6px;}";
|
2020-06-18 13:21:41 +08:00
|
|
|
last->setStyleSheet(strlast);
|
|
|
|
|
now->setStyleSheet(str);
|
2020-04-14 16:15:11 +08:00
|
|
|
}
|
|
|
|
|
|
2020-08-04 13:56:56 +08:00
|
|
|
//void MainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
|
//{
|
|
|
|
|
// qDebug()<<"MainWindow:: CloseEvent";
|
|
|
|
|
// if (closeGrab()) {
|
|
|
|
|
// qDebug()<<"success to close Grab";
|
|
|
|
|
// } else {
|
|
|
|
|
// qDebug()<<"failure to close Grab";
|
|
|
|
|
// }
|
|
|
|
|
// return QWidget::closeEvent(event);
|
|
|
|
|
//}
|
2020-04-14 16:15:11 +08:00
|
|
|
|
2020-04-18 20:36:34 +08:00
|
|
|
/*
|
|
|
|
|
bool MainWindow::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
|
|
|
|
|
{
|
|
|
|
|
if (qstrcmp(eventType, "xcb_generic_event_t") != 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
xcb_generic_event_t *event = reinterpret_cast<xcb_generic_event_t*>(message);
|
|
|
|
|
const uint8_t responseType = event->response_type & ~0x80;
|
|
|
|
|
if (responseType == XCB_CONFIGURE_NOTIFY) {
|
|
|
|
|
xcb_configure_notify_event_t *xc = reinterpret_cast<xcb_configure_notify_event_t*>(event);
|
|
|
|
|
if (xc->event == QX11Info::appRootWindow())
|
|
|
|
|
{
|
|
|
|
|
XRaiseWindow(QX11Info::display(), this->winId());
|
|
|
|
|
XFlush(QX11Info::display());
|
|
|
|
|
//raise();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if(responseType == XCB_PROPERTY_NOTIFY)
|
|
|
|
|
{
|
|
|
|
|
//raise();
|
|
|
|
|
XRaiseWindow(QX11Info::display(), this->winId());
|
|
|
|
|
XFlush(QX11Info::display());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
*/
|