diff --git a/VirtualKeyboard/src/kbtitle.cpp b/VirtualKeyboard/src/kbtitle.cpp index 1d270cc..f5aa6b7 100644 --- a/VirtualKeyboard/src/kbtitle.cpp +++ b/VirtualKeyboard/src/kbtitle.cpp @@ -37,13 +37,14 @@ KBTitle::~KBTitle() void KBTitle::initUI() { setFixedHeight(KEYBOARD_TITLE_DEFAULT_HEIGHT); - QString strBtnStyle = "QPushButton{ text-align:center; color: rgb(255, 255, 255, 255); border: none; border-radius: 4px; outline: none;}" - "QPushButton:hover{ background-color: rgb(255,255,255,15%); }" + QString strBtnStyle = "QPushButton{ text-align:center; color: rgba(255, 255, 255, 255); border: none; border-radius: 4px; outline: none;}" + "QPushButton:hover{ background-color: rgba(255,255,255,15%); }" "QPushButton::pressed { background-color: rgba(255,255,255,40%); }" "QPushButton::checked { background-color: rgba(255,255,255,40%); }"; m_btnFloat = new QPushButton(this); m_btnFloat->setFlat(true); + m_btnFloat->setFocusPolicy(Qt::NoFocus); m_btnFloat->setIcon(QIcon(":/images/images/float.svg")); m_btnFloat->setObjectName("btn_float"); m_btnFloat->setIconSize(KEYBOARD_FIXED_DEFAULT_ICONSIZE); @@ -53,6 +54,7 @@ void KBTitle::initUI() m_btnClose = new QPushButton(this); m_btnClose->setFlat(true); + m_btnClose->setFocusPolicy(Qt::NoFocus); m_btnClose->setIcon(QIcon(":/images/images/close.svg")); m_btnClose->setIconSize(KEYBOARD_FIXED_DEFAULT_ICONSIZE); m_btnClose->setObjectName("btn_close"); diff --git a/src/authdialog.cpp b/src/authdialog.cpp index b351202..e68e6ed 100644 --- a/src/authdialog.cpp +++ b/src/authdialog.cpp @@ -1639,6 +1639,11 @@ void AuthDialog::onBiometricDbusChanged(bool bActive) } } +QString AuthDialog::getCurAuthUserName() +{ + return user.name; +} + QPixmap AuthDialog::makeRoundLogo(QString logo, int wsize, int hsize, int radius) { QPixmap rectPixmap; diff --git a/src/authdialog.h b/src/authdialog.h index b3602e3..9288545 100644 --- a/src/authdialog.h +++ b/src/authdialog.h @@ -71,6 +71,7 @@ public: void checkPassword(); int getBioNum(); bool getLineeditStatus(); + QString getCurAuthUserName(); private: void initUI(); void startWaiting(); diff --git a/src/fullbackgroundwidget.cpp b/src/fullbackgroundwidget.cpp index 5ab2976..23b3d13 100644 --- a/src/fullbackgroundwidget.cpp +++ b/src/fullbackgroundwidget.cpp @@ -260,15 +260,6 @@ FullBackgroundWidget::FullBackgroundWidget(QWidget *parent) qApp->installNativeEventFilter(this); installEventFilter(this); QTimer::singleShot(500,this,SLOT(switchToLinux())); - - LogindIntegration *m_logind = new LogindIntegration(this); - - - connect(m_logind, &LogindIntegration::requestUnlock, this, - [this]() { - closeScreensaver(); - }); - } #ifdef USE_INTEL @@ -438,6 +429,16 @@ void FullBackgroundWidget::paintEvent(QPaintEvent *event) void FullBackgroundWidget::closeEvent(QCloseEvent *event) { qDebug() << "FullBackgroundWidget::closeEvent"; + // 处理认证完成后收到屏幕变化信号,调用lockWidget指针崩溃问题 + QDesktopWidget *desktop = QApplication::desktop(); + disconnect(desktop, &QDesktopWidget::resized, + this, &FullBackgroundWidget::onDesktopResized); + disconnect(desktop, &QDesktopWidget::workAreaResized, + this, &FullBackgroundWidget::onDesktopResized); + disconnect(desktop, &QDesktopWidget::primaryScreenChanged, + this, &FullBackgroundWidget::onDesktopResized); + disconnect(desktop, &QDesktopWidget::screenCountChanged, + this, &FullBackgroundWidget::onDesktopResized); if (isStartup) setIsStartup(false); if(future.isRunning()){ @@ -466,7 +467,6 @@ void FullBackgroundWidget::closeEvent(QCloseEvent *event) if(widget) widget->close(); } - if(QX11Info::isPlatformX11()){ closeGrab(); } @@ -930,6 +930,13 @@ int FullBackgroundWidget::onSessionStatusChanged(uint status) return 0; } +void FullBackgroundWidget::onSessionActiveChanged(bool isActive) +{ + if (lockWidget) { + lockWidget->onSessionActiveChanged(isActive); + } +} + void FullBackgroundWidget::delayLockScreen() { if (!m_timerLock) { diff --git a/src/fullbackgroundwidget.h b/src/fullbackgroundwidget.h index 92f1e06..e960415 100644 --- a/src/fullbackgroundwidget.h +++ b/src/fullbackgroundwidget.h @@ -75,6 +75,7 @@ public Q_SLOTS: void propertiesChangedSlot(QString, QMap, QStringList); void onShowBlackBackGround(); #endif + void onSessionActiveChanged(bool isActive); Q_SIGNALS: void StartupModeChanged(bool isStartup); diff --git a/src/lockwidget.cpp b/src/lockwidget.cpp index 43eefb6..c106c2b 100644 --- a/src/lockwidget.cpp +++ b/src/lockwidget.cpp @@ -216,24 +216,7 @@ void LockWidget::key_enter_release(int key) break; case SWITCHBTN: if(scrollArea && scrollArea->isVisible()) { - if(authDialog) - { - if(list.at(nowAt)->objectName() != getenv("USER")) - authDialog->stopAuth(); - } - if(list.at(nowAt)->objectName() == "Guest") - { - displayManager->switchToGuest(); - } - else if(list.at(nowAt)->objectName() == "SwitchUser") - { - displayManager->switchToGreeter(); - } - else - { - if(list.at(nowAt)->objectName() != getenv("USER")) - displayManager->switchToUser(list.at(nowAt)->objectName()); - } + SwitchToUser(list.at(nowAt)->objectName()); } else { ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); showUserMenu(); @@ -1422,6 +1405,67 @@ void LockWidget::setVirkeyboardPos() } } +void LockWidget::SwitchToUser(QString strUserName) +{ + bool isSwitchSelf = false; + if(authDialog) { + if (strUserName == authDialog->getCurAuthUserName()) { + isSwitchSelf = true; + } else { + authDialog->stopAuth(); + } + } + if (!isSwitchSelf) { + this->hide(); + if (!m_timerChkActive) { + m_timerChkActive = new QTimer(this); + m_timerChkActive->setInterval(10*1000); + connect(m_timerChkActive, &QTimer::timeout, this, [&,this](){ + if (this->isHidden()) { + this->show(); + } + m_timerChkActive->stop(); + }); + } else { + if (m_timerChkActive->isActive()) { + m_timerChkActive->stop(); + } + } + m_timerChkActive->start(); + } + QTimer::singleShot(10,this, [&,this, isSwitchSelf, strUserName](){ + if(strUserName == "*Guest") + { + this->displayManager->switchToGuest(); + } + else if(strUserName == "*SwitchUser") + { + this->displayManager->switchToGreeter(); + } + else + { + if (!isSwitchSelf) { + this->displayManager->switchToUser(strUserName); + } + } + }); +} + +void LockWidget::onSessionActiveChanged(bool isActive) +{ + if (isActive) { + if (m_timerChkActive && m_timerChkActive->isActive()) { + m_timerChkActive->stop(); + } + if (this->isHidden()) { + this->show(); + } + } else { + if (m_timerChkActive && m_timerChkActive->isActive()) { + m_timerChkActive->stop(); + } + } +} void LockWidget::initUserMenu() { @@ -1787,11 +1831,6 @@ void LockWidget::onUserMenuTrigged(QAction *action) { qDebug() << action->data().toString() << "selected"; - if(authDialog) - { - authDialog->stopAuth(); - } - QString userName = action->data().toString(); for (int i =0; i < list.count(); i++) { @@ -1803,18 +1842,7 @@ void LockWidget::onUserMenuTrigged(QAction *action) "HoverWidget:hover:!pressed{background-color:rgb(255,255,255,15%);border-radius: 6px;}"); } } - if(userName == "Guest") - { - displayManager->switchToGuest(); - } - else if(userName == "SwitchUser") - { - displayManager->switchToGreeter(); - } - else - { - displayManager->switchToUser(userName); - } + SwitchToUser(userName); } bool LockWidget::exitSubWidget() diff --git a/src/lockwidget.h b/src/lockwidget.h index da89db0..47f8b28 100644 --- a/src/lockwidget.h +++ b/src/lockwidget.h @@ -95,6 +95,7 @@ public: void onActiveLineedit(); QString getBatteryIconName(); void key_enter_release(int key); + void onSessionActiveChanged(bool isActive); Q_SIGNALS: void closed(); @@ -128,6 +129,8 @@ private: */ void setRootWindow(); + void SwitchToUser(QString strUserName); + private Q_SLOTS: void onUserAdded(const UserItem &user); void onUserDeleted(const UserItem &user); @@ -208,6 +211,8 @@ private: double curFontSize = 0; QFuture m_futureLoadDeskBg; + + QTimer *m_timerChkActive = nullptr; }; #endif // LOCKWIDGET_H diff --git a/src/logind.cpp b/src/logind.cpp index 34c00ed..e8817ac 100644 --- a/src/logind.cpp +++ b/src/logind.cpp @@ -24,6 +24,7 @@ const static QString login1Service = QStringLiteral("org.freedesktop.login1"); const static QString login1Path = QStringLiteral("/org/freedesktop/login1"); +const static QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); const static QString login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager"); const static QString login1SessionInterface = QStringLiteral("org.freedesktop.login1.Session"); @@ -34,12 +35,11 @@ LogindIntegration::LogindIntegration(QObject *parent) login1Path, login1ManagerInterface, QDBusConnection::systemBus()); - QDBusReply sessionPath = loginInterface.call("GetSessionByPID",(quint32) QCoreApplication::applicationPid()); + QDBusReply sessionPath = loginInterface.call("GetSession", "auto"); if(!sessionPath.isValid()){ qWarning()<< "Get session error:" << sessionPath.error(); } else{ - QString session = sessionPath.value().path(); QDBusConnection::systemBus().connect(login1Service, session, @@ -53,9 +53,56 @@ LogindIntegration::LogindIntegration(QObject *parent) QStringLiteral("Unlock"), this, SIGNAL(requestUnlock())); + + // 获取会话激活状态 + QDBusInterface iface(login1Service, + session, + propertiesInterface, + QDBusConnection::systemBus()); + QDBusReply reply = iface.call("Get", login1SessionInterface, "Active"); + if (reply.isValid()) { + m_isSessionActive = reply.value().toBool(); + qDebug()<<"Session is active:"< +#include #include class QDBusServiceWatcher; @@ -28,15 +29,20 @@ class LogindIntegration : public QObject Q_OBJECT public: explicit LogindIntegration(QObject *parent = nullptr); - ~LogindIntegration() override; + virtual ~LogindIntegration(); + + bool isSessionActive(); + +public Q_SLOTS: + void onSessionPropChanged(QString, QVariantMap, QStringList); Q_SIGNALS: void requestLock(); void requestUnlock(); - void connectedChanged(); + void sessionActiveChanged(bool isActive); private: - + bool m_isSessionActive = false; }; #endif diff --git a/src/ukui-screensaver-dialog.cpp b/src/ukui-screensaver-dialog.cpp index 8626b4c..009fd8b 100644 --- a/src/ukui-screensaver-dialog.cpp +++ b/src/ukui-screensaver-dialog.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "plasma-shell-manager.h" #include #include @@ -158,6 +159,30 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QApplication::setSetuidAllowed(true); + LogindIntegration *m_logind = new LogindIntegration(&a); + QObject::connect(m_logind, &LogindIntegration::requestUnlock, [=]() { + if (window) { + window->closeScreensaver(); + } else { + exit(0); + } + }); + if (!m_logind->isSessionActive()) { + QEventLoop *loopTemp = new QEventLoop(&a); + QObject::connect(m_logind, &LogindIntegration::sessionActiveChanged, [loopTemp](bool isActive) { + qDebug()<<"sessionActiveChanged:"<isRunning()) { + loopTemp->quit(); + } + }); + QObject::connect(m_logind, &LogindIntegration::requestLock, [loopTemp]() { + qDebug()<<"session requestLock!"; + if (loopTemp->isRunning()) { + loopTemp->quit(); + } + }); + loopTemp->exec(); + } //命令行参数解析 QCommandLineParser parser; @@ -214,6 +239,8 @@ int main(int argc, char *argv[]) // a.setStyleSheet(qssFile.readAll()); // } // qssFile.close(); + // 监听会话active状态 + QObject::connect(m_logind, &LogindIntegration::sessionActiveChanged, window, &FullBackgroundWidget::onSessionActiveChanged); // 注册DBus ScreenSaverWndAdaptor adaptorWnd(window);