fix(multiscreen): Multiple monitors cannot be extended or replicated properly

Description: 多显示器无法正常扩展或复制

Log: https://e.gitee.com/openkylin-enterprise/issues/list?issue=I8YHES
This commit is contained in:
Yang Min 2024-02-19 17:52:26 +08:00
parent 1b9bca3bc7
commit 0cdeef1023
2 changed files with 79 additions and 133 deletions

View File

@ -45,6 +45,7 @@
#include "screensavermode.h"
#include "screensaverwidget.h"
#include "displayservice.h"
#include "configuration.h"
FullBackgroundWidget::FullBackgroundWidget(LockDialogModel *model, QWidget *parent)
: QWidget(parent)
@ -57,33 +58,30 @@ FullBackgroundWidget::FullBackgroundWidget(LockDialogModel *model, QWidget *pare
FullBackgroundWidget::~FullBackgroundWidget()
{
if (m_backgrondGradationTimer)
{
if (m_backgrondGradationTimer) {
if (m_backgrondGradationTimer->isActive())
m_backgrondGradationTimer->stop();
m_backgrondGradationTimer->disconnect();
m_backgrondGradationTimer->deleteLater();
}
}
void FullBackgroundWidget::initUI()
{
if(QX11Info::isPlatformX11()){
if (QX11Info::isPlatformX11()) {
/*捕获键盘如果捕获失败则可能是由于弹出菜单项已经捕获那么模拟一次esc按键来退出菜单如果仍捕获失败则放弃锁屏避免密码无法输入*/
if(establishGrab())
if (establishGrab())
qDebug()<<"establishGrab : true";
else {
qDebug()<<"establishGrab : false";
/*检测当前是否存在弹出菜单只有存在弹出菜单时才模拟按键esc*/
if(checkHasPopupMenu()){
if (checkHasPopupMenu()) {
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);
}
if(!establishGrab())
{
if(!establishGrab()) {
exit(1);
}
}
@ -96,8 +94,7 @@ void FullBackgroundWidget::initUI()
if (!m_lockWidget) {
m_lockWidget = new LockWidget(m_modelLockDialog, this);
connect(m_lockWidget, &LockWidget::authSucceed, this, &FullBackgroundWidget::onAuthSucceed);
m_lockWidget->setGeometry(this->geometry());
m_lockWidget->show();
onCursorMoved(QCursor::pos());
}
if(m_modelLockDialog->getAgreementWindowShowLoginPrompt() && (/*IsStartupMode() || */(qgetenv("USER") == "lightdm"))){
@ -497,8 +494,7 @@ QList<quint64> FullBackgroundWidget::GetSubWndIds()
void FullBackgroundWidget::onCursorMoved(const QPoint &pos)
{
if(!m_lockWidget)
{
if(!m_lockWidget) {
return;
}
bool chkInOneScreen = false;
@ -519,7 +515,7 @@ void FullBackgroundWidget::onCursorMoved(const QPoint &pos)
}
if (!chkInOneScreen) {
for(auto screen : QGuiApplication::screens()) {
if(!screen){
if(screen){
/*避免切换时闪烁*/
qInfo()<<"LockWidget:"<<screen->geometry()<<m_lockWidget->geometry()<<","<<screen;
if(!m_lockWidget->isHidden()){
@ -769,11 +765,7 @@ void FullBackgroundWidget::loadingAllUserBackground()
void FullBackgroundWidget::paintEvent(QPaintEvent *event)
{
// qDebug() << __LINE__ << __FUNCTION__;
QPainter painter(this);
for(QScreen *screen : QApplication::screens()){
for (QScreen *screen : QApplication::screens()) {
//在每个屏幕上绘制背景
QRect rect = screen->geometry();
int width = rect.width();
@ -784,30 +776,21 @@ void FullBackgroundWidget::paintEvent(QPaintEvent *event)
QString oldPath = getUserBackgroundPath(m_oldUserName);
QPair<QString,QString> oldKey(oldPath, resolution);
//if (m_gradualChanging && m_allBackgroundsMap.contains(m_currentUserName))
if (m_gradualChanging && m_allBackgroundsDataMap.contains(cunrrentKey))
{
//drawBackground(m_allBackgroundsMap[m_currentUserName],m_allBackgroundsMap[m_oldUserName],rect,m_backgroundAlpha);
if (m_gradualChanging && m_allBackgroundsDataMap.contains(cunrrentKey)) {
drawBackground(m_allBackgroundsDataMap[cunrrentKey],m_allBackgroundsDataMap.contains(oldKey)?m_allBackgroundsDataMap[oldKey]:nullptr,rect,m_backgroundAlpha);
}
else
{
} else {
stopTransition();
// qWarning() << __LINE__<< __FUNCTION__ << "===============" << m_allBackgroundsMap.contains(m_currentUserName);
if (m_allBackgroundsDataMap.contains(cunrrentKey))
{
//drawPixmap(rect, *m_allBackgroundsMap[m_currentUserName]);
painter.drawPixmap(rect, *m_allBackgroundsDataMap[cunrrentKey]);
}
else
{
QString defaultPath = getDefaultBackgroundPath();
QPair<QString,QString> defaultKey(defaultPath, resolution);
if (m_allBackgroundsDataMap.contains(defaultKey))
painter.drawPixmap(rect, *m_allBackgroundsDataMap[defaultKey]);
if (m_allBackgroundsDataMap.contains(cunrrentKey)) {
drawBackground(m_allBackgroundsDataMap[cunrrentKey], m_allBackgroundsDataMap[cunrrentKey], rect);
} else {
QPainter painter(this);
QPixmap *pixmapBg = getBackground(currentPath, rect);
if (!pixmapBg) {
pixmapBg = getBackground(getDefaultBackgroundPath(), rect);
}
if (pixmapBg && !pixmapBg->isNull()) {
painter.drawPixmap(rect, *pixmapBg);
}
}
}
}
@ -816,7 +799,6 @@ void FullBackgroundWidget::paintEvent(QPaintEvent *event)
bool FullBackgroundWidget::isOpenGradation()
{
qDebug() << __LINE__ << __FUNCTION__;
bool isOpenGradation = false;
// return true;//test 一直触发渐变效果
if (m_currentUserName.isEmpty() || m_oldUserName.isEmpty())
@ -824,21 +806,8 @@ bool FullBackgroundWidget::isOpenGradation()
if (m_currentUserName == m_oldUserName)
return isOpenGradation;
if (m_allBackgroundsMap.contains(m_currentUserName))
{
int width = QApplication::primaryScreen()->geometry().width();
int height = QApplication::primaryScreen()->geometry().height();
QString currentPath = getUserBackgroundPath(m_currentUserName);
QString resolution = QString("%1x%2").arg(width).arg(height);
QPair<QString,QString> cunrrentKey(currentPath, resolution);
QString oldPath = getUserBackgroundPath(m_oldUserName);
QPair<QString,QString> oldKey(oldPath, resolution);
if (cunrrentKey != oldKey)
{
isOpenGradation = true;
}
if (getUserBackgroundPath(m_oldUserName) != getUserBackgroundPath(m_currentUserName)) {
isOpenGradation = true;
}
return isOpenGradation;
@ -846,23 +815,22 @@ bool FullBackgroundWidget::isOpenGradation()
void FullBackgroundWidget::onUpdateUserBackground(const QString &strUserName)
{
qWarning() << __LINE__ <<__FUNCTION__ << "==========" << strUserName ;
qDebug() << __LINE__ <<__FUNCTION__ << "==========" << strUserName ;
if (m_currentUserName == strUserName)
return;
m_oldUserName = m_currentUserName;
m_currentUserName = strUserName;
//是否需要开启渐变效果
m_gradualChanging = isOpenGradation();
qWarning() << __LINE__ <<__FUNCTION__ << "==========" << m_gradualChanging ;
bool gradualChangeEnable = isOpenGradation();
qDebug() << __LINE__ <<__FUNCTION__ << "==========" << gradualChangeEnable ;
if (m_gradualChanging)
if (gradualChangeEnable)
startTransition();
repaint();
}
void FullBackgroundWidget::onTransition()
{
qWarning() << __LINE__ << __FUNCTION__ ;
m_backgroundAlpha += 0.05;
if(m_backgroundAlpha >= 1.0)
@ -883,10 +851,9 @@ void FullBackgroundWidget::startTransition()
m_backgrondGradationTimer->start(10);
}
void FullBackgroundWidget::stopTransition()
{
// qDebug() << __LINE__ << __FUNCTION__;
if(m_backgrondGradationTimer && m_backgrondGradationTimer->isActive())
m_backgrondGradationTimer->stop();
m_backgroundAlpha = 1.0;
@ -896,34 +863,22 @@ void FullBackgroundWidget::stopTransition()
void FullBackgroundWidget::drawBackground(QPixmap * backgroundBack, QPixmap * backgroundFront,
const QRect &rect, float alpha)
{
// qDebug() << __LINE__ << __FUNCTION__;
if(backgroundBack->isNull())
{
if (!backgroundBack || backgroundBack->isNull()) {
stopTransition();
repaint();
return;
}
QPainter painter(this);
if(backgroundFront == nullptr)
{
if (!backgroundBack || backgroundBack->isNull() || !backgroundFront) {
painter.setOpacity(alpha);
//QString color = m_configuration->getValue("background-color").toString();
QString color = Configuration::instance(this)->getValue("background-color").toString();
QColor cor;
//if(!color.isEmpty())
// cor = color;
//else
if(!color.isEmpty())
cor = color;
else
cor = "#035290";
painter.setBrush(cor);
painter.drawRect(rect);
}
else
{
} else {
painter.drawPixmap(rect, *backgroundFront);
painter.setOpacity(alpha);
painter.drawPixmap(rect, *backgroundBack);
@ -939,23 +894,18 @@ void FullBackgroundWidget::drawBackground(QPixmap * backgroundBack, QPixmap * ba
painter1.setPen(Qt::transparent);
painter1.drawPath(path);
}
// qDebug() << __LINE__ << __FUNCTION__<< "===============2";
}
void FullBackgroundWidget::onRemoveUserBackground(const QString &strUserName)
{
qDebug() << __LINE__ << __FUNCTION__;
if (m_allBackgroundsMap.contains(strUserName))
m_allBackgroundsMap.remove(strUserName);
}
QString FullBackgroundWidget::getUserBackgroundPath(const QString &strUserName)
{
for (UserInfoPtr userInfo : m_modelLockDialog->usersInfo())
{
if (strUserName == userInfo->name())
{
for (UserInfoPtr userInfo : m_modelLockDialog->usersInfo()) {
if (strUserName == userInfo->name()) {
if (!userInfo->greeterBackGround().isEmpty() && QFile(userInfo->greeterBackGround()).exists()) {
return userInfo->greeterBackGround();
} else {
@ -968,49 +918,33 @@ QString FullBackgroundWidget::getUserBackgroundPath(const QString &strUserName)
void FullBackgroundWidget::addBackgroundData(const QString &bgPath)
{
qDebug() << __LINE__ << __FUNCTION__;
if (bgPath.isEmpty())
{
if (bgPath.isEmpty()) {
qDebug() << __LINE__ << __FUNCTION__ << bgPath << ":Path is Null";
return;
}
QFile file(bgPath);
if (!file.exists())
{
if (!file.exists()) {
qDebug() << __LINE__ << __FUNCTION__ << "Add background file isn't exists";
return;
}
int width = QApplication::primaryScreen()->geometry().width();
int height = QApplication::primaryScreen()->geometry().height();
for (QScreen *screen : QApplication::screens()) {
int width = screen->geometry().width();
int height = screen->geometry().height();
QString resolution = QString("%1x%2").arg(width).arg(height);
QPair<QString, QString> key(bgPath, resolution);
QPixmap *pixmap = new QPixmap(scaleBlurPixmap(width,height, bgPath));
m_allBackgroundsDataMap[key] = pixmap;
}
bool FullBackgroundWidget::existsBackgroundData(const QString &bgPath)
{
qDebug() << __LINE__ << __FUNCTION__;
int width = QApplication::primaryScreen()->geometry().width();
int height = QApplication::primaryScreen()->geometry().height();
QString resolution = QString("%1x%2").arg(width).arg(height);
QPair<QString, QString> key(bgPath, resolution);
return m_allBackgroundsDataMap.contains(key);
QString resolution = QString("%1x%2").arg(width).arg(height);
QPair<QString, QString> key(bgPath, resolution);
if (!m_allBackgroundsDataMap.contains(key)) {
QPixmap *pixmap = new QPixmap(scaleBlurPixmap(width,height, bgPath));
m_allBackgroundsDataMap[key] = pixmap;
}
}
}
void FullBackgroundWidget::onAddUserBackground(const QString &strUserName)
{
qDebug() << __LINE__ << __FUNCTION__;
FullBackgroundWidget::m_loadingOneBackgroundFuture = QtConcurrent::run([=](){
m_loadingOneBackgroundFuture = QtConcurrent::run([=](){
QString strBackground = getUserBackgroundPath(strUserName);
if (!existsBackgroundData(strBackground))
addBackgroundData(strBackground);
addBackgroundData(strBackground);
});
m_loadingOneBackgroundFuture.waitForFinished();
}
@ -1022,17 +956,29 @@ void FullBackgroundWidget::onUserBackgroundChanged(const QString &strUserName)
void FullBackgroundWidget::onCurrentUserBackground(const QString &strUserName)
{
qWarning() << __LINE__ << __FUNCTION__ << "===============" << strUserName;
//m_currentUserName = strUserName;
QString userPath = getUserBackgroundPath(strUserName);
int width = QApplication::primaryScreen()->geometry().width();
int height = QApplication::primaryScreen()->geometry().height();
QString resolution = QString("%1x%2").arg(width).arg(height);
QPair<QString,QString> UserKey(userPath, resolution);
if (!m_allBackgroundsDataMap.contains(UserKey))
{
onAddUserBackground(strUserName);
}
qDebug() << __LINE__ << __FUNCTION__ << "===============" << strUserName;
onAddUserBackground(strUserName);
repaint();
}
QPixmap* FullBackgroundWidget::getBackground(const QString &path, const QRect &rect)
{
if (path.isEmpty() || !QFile(path).exists())
return nullptr;
QString resolution = QString("%1x%2").arg(rect.width()).arg(rect.height());
QPair<QString, QString> key(path, resolution);
if (m_allBackgroundsDataMap.isEmpty()&& m_loadingOneBackgroundFuture.isRunning()) {
m_loadingOneBackgroundFuture.waitForFinished();
} else {
if (!m_loadingOneBackgroundFuture.isFinished() && m_loadingOneBackgroundFuture.isStarted()) {
m_loadingOneBackgroundFuture.waitForFinished();
}
}
if (!m_allBackgroundsDataMap.contains(key)) {
QPixmap *pixmap = new QPixmap(scaleBlurPixmap(width(), height(), path));
m_allBackgroundsDataMap[key] = pixmap;
}
return m_allBackgroundsDataMap[key];
}

View File

@ -111,7 +111,6 @@ private:
QString getDefaultBackgroundPath();
void loadingAllUserBackground();
QString getUserBackgroundPath(const QString &);
bool existsBackgroundData(const QString &);
void addBackgroundData(const QString &);
bool isOpenGradation();
@ -119,6 +118,7 @@ private:
void stopTransition();
void drawBackground(QPixmap * backgroundBack, QPixmap * backgroundFront,
const QRect &rect, float alpha);
QPixmap* getBackground(const QString &path, const QRect &rect);
void delayLockScreen();
void onLockScreenTimeout();