commit
45aa44cb9a
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
void checkPassword();
|
||||
int getBioNum();
|
||||
bool getLineeditStatus();
|
||||
QString getCurAuthUserName();
|
||||
private:
|
||||
void initUI();
|
||||
void startWaiting();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -75,6 +75,7 @@ public Q_SLOTS:
|
|||
void propertiesChangedSlot(QString, QMap<QString, QVariant>, QStringList);
|
||||
void onShowBlackBackGround();
|
||||
#endif
|
||||
void onSessionActiveChanged(bool isActive);
|
||||
|
||||
Q_SIGNALS:
|
||||
void StartupModeChanged(bool isStartup);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<void> m_futureLoadDeskBg;
|
||||
|
||||
QTimer *m_timerChkActive = nullptr;
|
||||
};
|
||||
|
||||
#endif // LOCKWIDGET_H
|
||||
|
|
|
@ -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<QDBusObjectPath> sessionPath = loginInterface.call("GetSessionByPID",(quint32) QCoreApplication::applicationPid());
|
||||
QDBusReply<QDBusObjectPath> 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<QVariant> reply = iface.call("Get", login1SessionInterface, "Active");
|
||||
if (reply.isValid()) {
|
||||
m_isSessionActive = reply.value().toBool();
|
||||
qDebug()<<"Session is active:"<<m_isSessionActive;
|
||||
} else {
|
||||
qDebug() << "Failed to get session active state!";
|
||||
}
|
||||
|
||||
// 监听属性变化
|
||||
QDBusConnection::systemBus().connect(login1Service,
|
||||
session,
|
||||
propertiesInterface,
|
||||
"PropertiesChanged",
|
||||
this,
|
||||
SLOT(onSessionPropChanged(QString, QVariantMap, QStringList)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LogindIntegration::~LogindIntegration() = default;
|
||||
LogindIntegration::~LogindIntegration()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LogindIntegration::onSessionPropChanged(QString strInterface, QVariantMap mapVar, QStringList listValue)
|
||||
{
|
||||
if (login1SessionInterface == strInterface) {
|
||||
qDebug()<<"onSessionPropChanged:"<<strInterface<<mapVar<<listValue;
|
||||
QVariantMap::iterator itVar = mapVar.begin();
|
||||
for ( ; itVar != mapVar.end(); itVar++) {
|
||||
if (itVar.key() == "Active") {
|
||||
QVariant varValue = itVar.value();
|
||||
m_isSessionActive = varValue.toBool();
|
||||
if (!m_isSessionActive) {
|
||||
Q_EMIT requestLock();
|
||||
}
|
||||
Q_EMIT sessionActiveChanged(m_isSessionActive);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LogindIntegration::isSessionActive()
|
||||
{
|
||||
return m_isSessionActive;
|
||||
}
|
||||
|
|
12
src/logind.h
12
src/logind.h
|
@ -19,6 +19,7 @@
|
|||
#define LOGIND_H
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QVariantMap>
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <QX11Info>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDBusInterface>
|
||||
#include <QEventLoop>
|
||||
#include "plasma-shell-manager.h"
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
@ -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:"<<isActive;
|
||||
if (isActive && loopTemp->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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue