Merge pull request !65 from 杨敏/openkylin/nile
This commit is contained in:
杨敏 2024-01-26 01:04:22 +00:00 committed by Gitee
commit 728028aacf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 695 additions and 36 deletions

View File

@ -26,10 +26,13 @@
#include <QRegExp>
#include <QDebug>
#include <QScreen>
#include "definetypes.h"
#define CONFIG_FILE "/etc/lightdm/ukui-greeter.conf"
#define PROC_CPUINFO "/proc/cpuinfo"
Configuration* Configuration::m_instance = nullptr;
Configuration::Configuration(QObject *parent)
: QObject(parent)
{
@ -41,6 +44,13 @@ Configuration::Configuration(QObject *parent)
userSetting = new QSettings(configPath, QSettings::IniFormat, this);
}
Configuration* Configuration::instance(QObject *parent)
{
if(m_instance == nullptr)
m_instance = new Configuration(parent);
return m_instance;
}
QVariant Configuration::getValue(const QString &key)
{
configSettings->beginGroup("Greeter");
@ -127,24 +137,6 @@ void Configuration::saveLastNumLock(bool value)
recordSettings->sync();
}
int Configuration::getRootBackgroundOption(QString userName)
{
static QMap<QString, int> mapPicOptions = {{"scaled",0},{"stretched",1},{"centered",2},{"wallpaper",3},{"zoom",4},{"spanned",5}};
QString userConfigurePath = QString("/var/lib/lightdm-data/%1/ukui-greeter.conf").arg(userName);
QFile backgroundFile(userConfigurePath);
if(backgroundFile.exists()){
QSettings settings(userConfigurePath,QSettings::IniFormat);
settings.beginGroup("greeter");
if(settings.contains("picture-options")){
QString picOptions = settings.value("picture-options").toString();
if(!picOptions.isEmpty() && mapPicOptions.contains(picOptions)){
return mapPicOptions[picOptions];
}
}
}
return 0;
}
bool Configuration::getIs990()
{
if(hasCheck990){
@ -172,3 +164,53 @@ bool Configuration::getIs990()
return is990;
}
void Configuration::initShareConfig()
{
QString userName = getenv("USER");
QString configPath;
configPath = QString("/var/lib/lightdm-data/%1/ukui-greeter.conf").arg(userName);
QFile fileConf(configPath);
if (!fileConf.exists()) {
QFile file(configPath);
file.setPermissions(QFile::WriteUser | QFile::ReadUser | QFile::WriteOther | QFile::ReadOther);
}
m_shareSettings = new QSettings(configPath, QSettings::IniFormat, this);
}
void Configuration::setShareConfigValue(const QString &key, const QVariant &value)
{
if (!m_shareSettings)
return;
m_shareSettings->beginGroup("Greeter");
m_shareSettings->setValue(key, value);
m_shareSettings->endGroup();
m_shareSettings->sync();
}
QString Configuration::getDefaultBackgroundName()
{
return DEFAULT_BACKGROUND_PATH;
}
int Configuration::getRootBackgroundOption(QString userName)
{
static QMap<QString, int> mapPicOptions = {{"scaled",0},{"stretched",1},{"centered",2},{"wallpaper",3},{"zoom",4},{"spanned",5}};
QString userConfigurePath = QString("/var/lib/lightdm-data/%1/ukui-greeter.conf").arg(userName);
QFile backgroundFile(userConfigurePath);
if(backgroundFile.exists()){
QSettings settings(userConfigurePath,QSettings::IniFormat);
settings.beginGroup("greeter");
if(settings.contains("picture-options")){
QString picOptions = settings.value("picture-options").toString();
settings.endGroup();
if(!picOptions.isEmpty() && mapPicOptions.contains(picOptions)){
return mapPicOptions[picOptions];
}
} else {
settings.endGroup();
}
}
return 0;
}

View File

@ -27,10 +27,11 @@
class Configuration : public QObject
{
Q_OBJECT
public:
private:
explicit Configuration(QObject *parent = nullptr);
public:
static Configuration *instance(QObject *parent = nullptr);
QVariant getValue(const QString &);
QVariant getUserConfig(const QString &key);
void setValue(const QString&, const QVariant &);
@ -45,6 +46,12 @@ public:
int getRootBackgroundOption(QString userName);
bool getIs990();
void initShareConfig();
void setShareConfigValue(const QString &key, const QVariant &value);
QString getDefaultBackgroundName();
private:
QSettings *configSettings;
QSettings *recordSettings;
@ -53,7 +60,9 @@ private:
QGSettings *stylesettings = nullptr;
bool hasCheck990 = false;
bool is990 = false;
QSettings *m_shareSettings = nullptr;
static Configuration *m_instance;
};
#endif // CONFIGURATION_H

View File

@ -56,7 +56,7 @@ void DbusUpperInterface::initData()
{
m_bLockState = false;
m_bSlpState = false;
m_config = new Configuration(this);
m_config = Configuration::instance(this);
m_accountsHelper = new AccountsHelper(this);
m_lightDmHelper = new LightDMHelper(m_accountsHelper, m_config, this);
m_login1Helper = new Login1Helper(this);
@ -68,6 +68,12 @@ void DbusUpperInterface::initData()
m_sessionHelper = new SessionHelper(this);
m_sessionWatcher = new SessionWatcher(m_gsettingsHelper, this);
m_kglobalHelper = new KglobalAccelHelper(this);
m_config->initShareConfig();
m_config->setShareConfigValue("timeType", m_gsettingsHelper->GetUkccPluginsConf(KEY_HOUR_SYSTEM).toInt());
m_config->setShareConfigValue("dateType", m_gsettingsHelper->GetUkccPluginsConf(KEY_DATE).toString());
m_config->setShareConfigValue("fontSize", m_gsettingsHelper->GetThemeStyleConf(KEY_SYSTEM_FONT_SIZE).toDouble());
m_config->setShareConfigValue("themeColor", m_gsettingsHelper->GetThemeStyleConf(KEY_THEME_COLOR).toString());
}
void DbusUpperInterface::initConnections()
@ -710,7 +716,7 @@ QJsonArray DbusUpperInterface::GenerateUserInfoList()
{
if(!ptr->backgroundPath().isEmpty())
{
objUserInfo["backGround"] = ptr->backgroundPath();
objUserInfo["greeterBackGround"] = ptr->backgroundPath();
}
objUserInfo["dateType"] = ptr->dateType();
objUserInfo["fontSize"] = ptr->fontSize();
@ -720,7 +726,7 @@ QJsonArray DbusUpperInterface::GenerateUserInfoList()
if (isCurUserSelf(userInfo->name()) && m_gsettingsHelper) {
QString strBackground = m_gsettingsHelper->GetLockScreenConf(KEY_BACKGROUND).toString();
if (!strBackground.isEmpty() && QFile(strBackground).exists()) {
objUserInfo["backGround"] = strBackground;
objUserInfo["greeterBackGround"] = strBackground;
}
}
jsonArray.append(objUserInfo);
@ -1270,6 +1276,11 @@ void DbusUpperInterface::onUkccPluginsConfigChanged(QString strKey, QVariant val
default:
return;
}
if (strKey == KEY_DATE) {
m_config->setShareConfigValue("dateType", value.toString());
} else if (strKey == KEY_HOUR_SYSTEM) {
m_config->setShareConfigValue("timeType", value.toInt());
}
SendUpdateInfoSig(QString(QJsonDocument(retObj).toJson()));
}
@ -1298,7 +1309,11 @@ void DbusUpperInterface::onThemeStyleConfigChanged(QString strKey, QVariant valu
default:
return;
}
if (strKey == KEY_SYSTEM_FONT_SIZE) {
m_config->setShareConfigValue("fontSize", value.toDouble());
} else if (strKey == KEY_THEME_COLOR) {
m_config->setShareConfigValue("themeColor", value.toString());
}
SendUpdateInfoSig(QString(QJsonDocument(retObj).toJson()));
}

View File

@ -1157,6 +1157,8 @@ QList<UserInfoPtr> BackendDbusHelper::ParseUsersInfo(const QJsonObject &objRes)
userPtr->updateLoggedIn(objUser.value("loggedIn").toBool(false));
userPtr->updateBackground(objUser.value("backGround").toString());
userPtr->updateLang(objUser.value("lang").toString());
userPtr->updateGreeterBackground(objUser.value("greeterBackGround").toString());
userPtr->updateBackgroundColor(objUser.value("color").toString());
listUser.append(userPtr);
}
Q_EMIT usersInfoChanged(listUser);

View File

@ -188,6 +188,8 @@ void LockDialogModel::updateUsersInfo(QList<UserInfoPtr> list)
changedUserInfo->updateLang(userinfo->lang());
changedUserInfo->updateLoggedIn(userinfo->isLoggedIn());
changedUserInfo->updateBackground(userinfo->backGround());
changedUserInfo->updateGreeterBackground(userinfo->greeterBackGround());
changedUserInfo->updateBackgroundColor(userinfo->backGroundColor());
}
} else {
m_listUsersInfo.append(userinfo);
@ -219,6 +221,8 @@ void LockDialogModel::onUsersInfoChanged(QList<UserInfoPtr> list)
changedUserInfo->updateLang(userinfo->lang());
changedUserInfo->updateLoggedIn(userinfo->isLoggedIn());
changedUserInfo->updateBackground(userinfo->backGround());
changedUserInfo->updateGreeterBackground(userinfo->greeterBackGround());
changedUserInfo->updateBackgroundColor(userinfo->backGroundColor());
}
} else {
m_listUsersInfo.append(userinfo);

View File

@ -0,0 +1,426 @@
/* rootWindowBackground.cpp
* Copyright (C) 2018 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 <QScreen>
#include <QX11Info>
#include <QRect>
#include <QApplication>
#include <QDesktopWidget>
#include <QDebug>
#include <stdio.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <qmath.h>
#include <QStringList>
#include "rootWindowBackground.h"
static const XID INVAL_ID = ~0UL;
Pixmap pix = INVAL_ID;
Display *dpy = NULL;
Window root = 0;
Screen *scn = NULL;
struct RootWindowBGInfo {
bool isValid = false;
int nType;
int nColor;
QString strFileName;
int nOption;
QList<QRect> listScreen;
};
static RootWindowBGInfo g_lastRootWndInfo;
typedef enum WNDBG_OPTION_e{
WNDBG_OPTION_SCALED, // 填充
WNDBG_OPTION_STRETCHED, // 拉伸
WNDBG_OPTION_CENTERED, // 居中
WNDBG_OPTION_WALLPAPER, // 平铺
WNDBG_OPTION_ZOOM, // 适应
WNDBG_OPTION_SPANNED // 跨区
}WNDBG_OPTION;
static QRect getSourceRect(const QRect &destination, const QRect &source)
{
qreal screenScale = qreal(destination.width()) / qreal(destination.height());
qreal width = source.width();
qreal height = source.height();
if ((width / height) == screenScale) {
return source;
}
bool isShortX = (width <= height);
if (isShortX) {
screenScale = qreal(destination.height()) / qreal(destination.width());
}
qreal shortEdge = isShortX ? width : height;
qreal longEdge = isShortX ? height : width;
while (shortEdge > 1) {
qint32 temp = qFloor(shortEdge * screenScale);
if (temp <= longEdge) {
longEdge = temp;
break;
}
qint32 spacing = qRound(shortEdge / 20);
if (spacing <= 0) {
spacing = 1;
}
shortEdge -= spacing;
}
QSize sourceSize = source.size();
if (shortEdge > 1 && longEdge > 1) {
sourceSize.setWidth(isShortX ? shortEdge : longEdge);
sourceSize.setHeight(isShortX ? longEdge : shortEdge);
}
qint32 offsetX = 0;
qint32 offsetY = 0;
if (source.width() > sourceSize.width()) {
offsetX = (source.width() - sourceSize.width()) / 2;
}
if (source.height() > sourceSize.height()) {
offsetY = (source.height() - sourceSize.height()) / 2;
}
QPoint offsetPoint = source.topLeft();
offsetPoint += QPoint(offsetX, offsetY);
return QRect(offsetPoint, sourceSize);
}
static QRect getDestRect(const QRect &destination, const QRect &source)
{
qreal screenScale = qreal(destination.width()) / qreal(destination.height());
qreal pixmapScale = qreal(source.width() / source.height());
qreal width = source.width();
qreal height = source.height();
if (pixmapScale == screenScale) {
return destination;
}
qreal scaleWidth = destination.width() / width;
qreal scaleHeight = destination.height() / height;
qreal realPixmapWidth = 0;
qreal realPixmapHeight = 0;
if(pixmapScale < screenScale){
//图片比例小于屏幕比例时,按照图片和屏幕高度比进行缩放
realPixmapWidth = width * scaleHeight;
realPixmapHeight = destination.height();
}else{
//图片比例大于屏幕比例时,按照图片与屏幕宽度比进行缩放
realPixmapWidth = destination.width();
realPixmapHeight = height * scaleWidth;
}
QSize sourceSize = destination.size();
qint32 offsetX = 0;
qint32 offsetY = 0;
if (destination.width() == realPixmapWidth) {
offsetY = (destination.height() - realPixmapHeight) / 2;
sourceSize.setHeight(realPixmapHeight);
} else if (destination.height() == realPixmapHeight) {
offsetX = (destination.width() - realPixmapWidth) / 2;
sourceSize.setWidth(realPixmapWidth);
}
qDebug() << "=========getDestRect sourceSize:" << sourceSize;
QPoint offsetPoint = destination.topLeft();
offsetPoint += QPoint(offsetX, offsetY);
return QRect(offsetPoint, sourceSize);
}
static QRect getSourceRect(const QRect &source, const QRect &screenGeometry, const QRect &screenVirtualGeometry)
{
qreal pixWidth = source.width();
qreal pixHeight = source.height();
QSize sourceSize = source.size();
sourceSize.setWidth(screenGeometry.width() * 1.0 / screenVirtualGeometry.width() * pixWidth);
sourceSize.setHeight(screenGeometry.height() * 1.0 / screenVirtualGeometry.height() * pixHeight);
qint32 offsetX = 0;
qint32 offsetY = 0;
if (screenGeometry.x() > 0) {
offsetX = (screenGeometry.x() * 1.0 / screenVirtualGeometry.width() * pixWidth);
}
if (screenGeometry.y() > 0) {
offsetY = (screenGeometry.y() * 1.0 / screenVirtualGeometry.height() * pixHeight);
}
QPoint offsetPoint = source.topLeft();
offsetPoint += QPoint(offsetX, offsetY);
return QRect(offsetPoint, sourceSize);
}
void setRootWindowBackground(bool type,unsigned int color,char *filename, const QList<QPair<QRect,QRect>> screenRectList, int nOption)
{
Imlib_Image img;
if (!dpy){
dpy = XOpenDisplay(NULL);
if(!dpy)
return;
}
int width = 0,height = 0;
width = QApplication::desktop()->geometry().width()*qApp->devicePixelRatio();
height = QApplication::desktop()->geometry().height()*qApp->devicePixelRatio();
if(!scn)
scn = DefaultScreenOfDisplay(dpy);
if(!root)
root = DefaultRootWindow(dpy);
if (pix != INVAL_ID) {
XFreePixmap(dpy, pix);
pix = INVAL_ID;
}
pix = XCreatePixmap(dpy, root, width, height,
DefaultDepthOfScreen(scn));
imlib_context_set_display(dpy);
imlib_context_set_visual(DefaultVisualOfScreen(scn));
imlib_context_set_colormap(DefaultColormapOfScreen(scn));
imlib_context_set_drawable(pix);
if(type == 0){
img = imlib_load_image(filename);
if (!img) {
fprintf(stderr, "%s:Unable to load image\n", filename);
return ;
}
imlib_context_set_image(img);
}else if(type == 1){
img = imlib_create_image(width, height);
imlib_context_set_image(img);
int blue = color & 0xFF;
int green = color >> 8 & 0xFF;
int red = color >> 16 & 0xFF;
qDebug()<<"red = "<<red<<" green = "<<green<<" blue = "<<blue;
imlib_context_set_color(red, green,blue, 255);
imlib_image_fill_rectangle(0, 0, width, height);
}
g_lastRootWndInfo.isValid = true;
g_lastRootWndInfo.nType = type;
g_lastRootWndInfo.nColor = color;
g_lastRootWndInfo.strFileName = filename;
g_lastRootWndInfo.nOption = nOption;
g_lastRootWndInfo.listScreen.clear();
imlib_context_set_image(img);
QRect rectImg(0, 0, imlib_image_get_width(), imlib_image_get_height());
for(QPair<QRect,QRect> pair : screenRectList){
QRect rect = pair.first;
//在每个屏幕上绘制背景
rect.setRect(rect.x()*qApp->devicePixelRatio(),
rect.y()*qApp->devicePixelRatio(),
rect.width()*qApp->devicePixelRatio(),
rect.height()*qApp->devicePixelRatio());
QRect newSrcRect = rectImg;
g_lastRootWndInfo.listScreen.append(rect);
switch (nOption) {
case WNDBG_OPTION_CENTERED: //居中
{
if (newSrcRect.width() > rect.width()) {
int nHDiff = (newSrcRect.width()-rect.width())/2;
newSrcRect.setX(newSrcRect.x()+nHDiff);
newSrcRect.setWidth(newSrcRect.width()-nHDiff);
} else {
int nHDiff = (rect.width()-newSrcRect.width())/2;
rect.setX(rect.x()+nHDiff);
rect.setWidth(rect.width()-nHDiff);
}
if (newSrcRect.height() > rect.height()) {
int nVDiff = (newSrcRect.height()-rect.height())/2;
newSrcRect.setY(newSrcRect.y()+nVDiff);
newSrcRect.setHeight(newSrcRect.height()-nVDiff);
} else {
int nVDiff = (rect.height()-newSrcRect.height())/2;
rect.setY(rect.y()+nVDiff);
rect.setHeight(rect.height()-nVDiff);
}
qDebug()<<"Centered:"<<rect<<newSrcRect<<rectImg;
imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(),
newSrcRect.width(), newSrcRect.height(),
rect.x(), rect.y(),
rect.width(),rect.height());
}
break;
case WNDBG_OPTION_STRETCHED: //拉伸
{
qDebug()<<"Stretched:"<<rect<<newSrcRect<<rectImg;
imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(),
newSrcRect.width(), newSrcRect.height(),
rect.x(), rect.y(),
rect.width(),rect.height());
}
break;
case WNDBG_OPTION_SCALED: //填充
{
newSrcRect = getSourceRect(rect, newSrcRect);
qDebug()<<"Scaled:"<<rect<<newSrcRect<<rectImg;
imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(),
newSrcRect.width(), newSrcRect.height(),
rect.x(), rect.y(),
rect.width(),rect.height());
}
break;
case WNDBG_OPTION_WALLPAPER: // 平铺
{
int drawedWidth = 0;
int drawedHeight = 0;
while (1) {
drawedWidth = 0;
while (1) {
imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(),
newSrcRect.width(), newSrcRect.height(),
drawedWidth, drawedHeight,
newSrcRect.width(), newSrcRect.height());
drawedWidth += newSrcRect.width();
if (drawedWidth >= rect.width()) {
break;
}
}
drawedHeight += newSrcRect.height();
if (drawedHeight >= rect.height()) {
break;
}
}
}
break;
case WNDBG_OPTION_ZOOM: // 适应
{
rect = getDestRect(rect, newSrcRect);
qDebug()<<"Zoom:"<<rect<<newSrcRect<<rectImg;
imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(),
newSrcRect.width(), newSrcRect.height(),
rect.x(), rect.y(),
rect.width(),rect.height());
}
break;
case WNDBG_OPTION_SPANNED: // 跨区
{
//for(auto sscreen : qApp->screens()){
// if (screen->name() == sscreen->name()) {
QRect srcRect = getSourceRect(newSrcRect, pair.first, pair.second);
imlib_render_image_part_on_drawable_at_size(srcRect.x(), srcRect.y(),
srcRect.width(), srcRect.height(),
rect.x(), rect.y(),
rect.width(),rect.height());
break;
// }
//}
}
break;
default:
{
imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(),
newSrcRect.width(), newSrcRect.height(),
rect.x(), rect.y(),
rect.width(),rect.height());
}
break;
}
}
imlib_free_image();
}
void updateRootWindowBackground()
{
// 对比新的屏幕尺寸是否有变化
if (g_lastRootWndInfo.isValid) {
bool isSame = true;
QList<QRect> listScreen;
for(QScreen *screen : QApplication::screens()){
//在每个屏幕上绘制背景
QRect rect = screen->geometry();
rect.setX(rect.x()*screen->devicePixelRatio());
rect.setY(rect.y()*screen->devicePixelRatio());
rect.setWidth(rect.width()*screen->devicePixelRatio());
rect.setHeight(rect.height()*screen->devicePixelRatio());
listScreen.append(rect);
}
qDebug()<<"ScreenRects:"<<listScreen<<"||"<<g_lastRootWndInfo.listScreen;
if (listScreen.size() > g_lastRootWndInfo.listScreen.size()) {
isSame = false;
} else {
for (int n = 0; n < listScreen.size(); n++) {
if (n < g_lastRootWndInfo.listScreen.size()) {
if (g_lastRootWndInfo.listScreen[n] != listScreen[n]) {
isSame = false;
break;
}
}
}
}
if (!isSame) {
QList<QPair<QRect,QRect>> screenRectList;
for(QScreen *screen : QApplication::screens()){
QRect rect1 = screen->geometry();
QRect rect2 = screen->virtualGeometry();
screenRectList.append(qMakePair(rect1,rect2));
}
setRootWindowBackground(g_lastRootWndInfo.nType, g_lastRootWndInfo.nColor,
g_lastRootWndInfo.strFileName.toLatin1().data(), screenRectList, g_lastRootWndInfo.nOption);
}
}
}
void drawBackground(bool isDraw)
{
if (!dpy) {
return ;
}
if (isDraw) {
if (pix != INVAL_ID)
XSetWindowBackgroundPixmap(dpy, root, pix);
XClearWindow(dpy, root);
}
while (XPending(dpy)) {
XEvent ev;
XNextEvent(dpy, &ev);
}
if (pix != INVAL_ID) {
XFreePixmap(dpy, pix);
pix = INVAL_ID;
}
XCloseDisplay(dpy);
dpy = NULL;
}

View File

@ -0,0 +1,22 @@
/* rootWindowBackground.h
* Copyright (C) 2018 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.
**/
void setRootWindowBackground(bool type,unsigned int color,char *filename, const QList<QPair<QRect,QRect>> screenRectList, int nOption = 0);
void updateRootWindowBackground();
void drawBackground(bool isDraw);

View File

@ -31,6 +31,7 @@ UserInfo::UserInfo(QObject *parent)
, m_strBackground(DEFAULT_BACKGROUND_PATH)
, m_strLang(qgetenv("LANG"))
, m_strName("")
, m_strGreeterBackground("")
{
m_strHeadImage = getDefaultFace();
}
@ -44,6 +45,7 @@ UserInfo::UserInfo(const UserInfo &userInfo)
, m_strBackground(userInfo.m_strBackground)
, m_strLang(userInfo.m_strLang)
, m_strName(userInfo.m_strName)
, m_strGreeterBackground(userInfo.m_strGreeterBackground)
{
}
@ -96,6 +98,16 @@ void UserInfo::updateName(const QString &name)
m_strName = name;
}
void UserInfo::updateGreeterBackground(const QString &background)
{
m_strGreeterBackground = background;
}
void UserInfo::updateBackgroundColor(const QString &color)
{
m_strBackgroundColor = color;
}
QDebug operator <<(QDebug stream, const UserInfo &userInfo)
{
stream << "["

View File

@ -40,6 +40,8 @@ public:
inline QString backGround() const { return m_strBackground; }
inline QString lang() const { return m_strLang; }
inline QString name() const { return m_strName; }
inline QString greeterBackGround() const { return m_strGreeterBackground; }
inline QString backGroundColor() const { return m_strBackgroundColor; }
virtual inline QString path() const { return QString(); }
@ -51,6 +53,8 @@ public:
void updateBackground(const QString &backGround);
void updateLang(const QString &lang);
void updateName(const QString &name);
void updateGreeterBackground(const QString &background);
void updateBackgroundColor(const QString &color);
Q_SIGNALS:
void userPropChanged(const QString &userName);
@ -63,6 +67,8 @@ protected:
QString m_strBackground; // 用户界面背景
QString m_strLang; // 用户语言
QString m_strName; // 用户名
QString m_strGreeterBackground; // 登录界面背景
QString m_strBackgroundColor; // 桌面背景颜色
};
typedef std::shared_ptr<UserInfo> UserInfoPtr;

View File

@ -397,8 +397,10 @@ void FullBackgroundWidget::onDesktopResized()
qDebug() << "[FullBackgroundWidget] [onDesktopResized]";
QDesktopWidget *desktop = QApplication::desktop();
setGeometry(desktop->geometry());
if(m_lockWidget)
if(m_lockWidget) {
this->onCursorMoved(QCursor::pos());
m_lockWidget->reloadRootBackground();
}
update();
}
@ -677,6 +679,9 @@ void FullBackgroundWidget::onAuthSucceed(QString strUserName)
if (getenv("USER") == strUserName) {
onCloseScreensaver();
} else {
if (m_lockWidget) {
m_lockWidget->drawRootBackground();
}
if (m_modelLockDialog) {
Q_EMIT m_modelLockDialog->startSession();
}
@ -951,7 +956,11 @@ QString FullBackgroundWidget::getUserBackgroundPath(const QString &strUserName)
{
if (strUserName == userInfo->name())
{
return userInfo->backGround();
if (!userInfo->greeterBackGround().isEmpty() && QFile(userInfo->greeterBackGround()).exists()) {
return userInfo->greeterBackGround();
} else {
return userInfo->backGround();
}
}
}
return QString("");
@ -999,16 +1008,9 @@ void FullBackgroundWidget::onAddUserBackground(const QString &strUserName)
qDebug() << __LINE__ << __FUNCTION__;
FullBackgroundWidget::m_loadingOneBackgroundFuture = QtConcurrent::run([=](){
for (UserInfoPtr userInfo : m_modelLockDialog->usersInfo())
{
if (strUserName == userInfo->name())
{
if (!existsBackgroundData(userInfo->backGround()))
addBackgroundData(userInfo->backGround());
break;
}
}
QString strBackground = getUserBackgroundPath(strUserName);
if (!existsBackgroundData(strBackground))
addBackgroundData(strBackground);
});
m_loadingOneBackgroundFuture.waitForFinished();
}

View File

@ -30,7 +30,6 @@
#include <QGSettings>
#include <QPixmap>
class Configuration;
extern float scale;
class IconEdit : public QWidget
{

View File

@ -29,6 +29,9 @@
#include <QScrollBar>
#include <QLabel>
#include <QPushButton>
#include <QApplication>
#include <QScreen>
#include <QtConcurrent/QtConcurrentRun>
#include "poweritemwidget.h"
#include "useritemwidget.h"
#include "mylistwidget.h"
@ -50,6 +53,8 @@
#include "pluginsloader.h"
#include "global_utils.h"
#include "../lock-dialog/languagesetting.h"
#include "../lock-dialog/rootWindowBackground.h"
#include "configuration.h"
#define BLUR_RADIUS 300
#define RIGHT_MARGIN 24
@ -682,6 +687,22 @@ void LockWidget::onCurUserChanged(const QString &strUserName)
}
if (authDialog)
authDialog->onCurUserChanged(m_curUserInfo);
//登录后绘制桌面背景而不是登录背景
QString backgroundPath = m_curUserInfo->backGround();
QFile backgroundPathFile(backgroundPath);
if(backgroundPath.isEmpty() || !backgroundPathFile.exists()) {
backgroundPath = Configuration::instance(this)->getDefaultBackgroundName();
}
setRootWindowBgOptions(Configuration::instance(this)->getRootBackgroundOption(strUserName));
setrootWindowBackground(rootWinPicture,0,backgroundPath);
QString drawBackgroundColor = m_curUserInfo->backGroundColor();
if(drawBackgroundColor.length() == 7 && drawBackgroundColor.startsWith("#")){
drawBackgroundColor = drawBackgroundColor.remove(0,1);
bool ok;
int color = drawBackgroundColor.toUInt(&ok,16);
setrootWindowBackground(rootWinColor,color,NULL);
}
reloadRootBackground();
}
if (m_btnItemSession && m_curUserInfo->isLoggedIn()) {
buttonListWidget->setItemHidden(m_btnItemSession, true);
@ -1088,3 +1109,77 @@ void LockWidget::onLanguageChanged(bool isCompleted)
}
}
}
void LockWidget::setrootWindowBackground(int type,unsigned int color,QString filename)
{
drawBackgroundType = type;
if(drawBackgroundType == rootWinPicture)
m_rootWindowBackground = filename;
else if(drawBackgroundType == rootWinColor)
drawBackgroundColor = color;
}
void LockWidget::setRootWindowBgOptions(int nOption)
{
m_nPicOptions = nOption;
}
bool LockWidget::getdrawBackgroundIsStarted()
{
return drawBackgroundIsStarted;
}
void LockWidget::setrootWindow(QList<QPair<QRect,QRect>> screenRectList)
{
drawBackgroundIsStarted = true;
QString m_defaultBackgroundPath = DEFAULT_BACKGROUND_PATH;
if(m_rootWindowBackground.isEmpty())
m_rootWindowBackground = m_defaultBackgroundPath;
if(m_rootWindowBackground.isEmpty())
return;
char* path;
QByteArray ba = m_rootWindowBackground.toLatin1(); // must
path=ba.data();
if(drawBackgroundType == 0)
setRootWindowBackground(0, 0, path, screenRectList, m_nPicOptions);
else
setRootWindowBackground(1, drawBackgroundColor, NULL, screenRectList, m_nPicOptions);
drawBackgroundIsStarted = false;
}
void LockWidget::reloadRootBackground()
{
if (!isGreeterMode())
return ;
//记录当前的屏幕信息写入QList保存防止线程中在遍历屏幕信息时
//屏幕插拔而崩溃
m_screenRectList.clear();
for(QScreen *screen : QApplication::screens()){
QRect rect1 = screen->geometry();
QRect rect2 = screen->virtualGeometry();
m_screenRectList.append(qMakePair(rect1,rect2));
}
if(getdrawBackgroundIsStarted()){
if(m_futureDrawBg.isStarted()&& m_futureDrawBg.isRunning()){
m_futureDrawBg.waitForFinished();
m_futureDrawBg = QtConcurrent::run([=](){
setrootWindow(m_screenRectList);
});
}else{
m_futureDrawBg = QtConcurrent::run([=](){
setrootWindow(m_screenRectList);
});
}
}else{
m_futureDrawBg = QtConcurrent::run([=](){
setrootWindow(m_screenRectList);
});
}
}
void LockWidget::drawRootBackground()
{
drawBackground(true);
}

View File

@ -20,6 +20,7 @@
#include <QWidget>
#include <QObject>
#include <QFuture>
#include "userinfo.h"
class QListWidgetItem;
@ -39,6 +40,10 @@ class BlockWidget;
class StatusButton;
class NetWorkButton;
enum{
rootWinPicture,
rootWinColor
};
class LockWidget : public QWidget
{
Q_OBJECT
@ -47,6 +52,9 @@ public:
bool exitSubWidget();
void stopAuth();
void startAuth();
void reloadRootBackground();
void drawRootBackground();
protected:
void paintEvent(QPaintEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
@ -141,6 +149,15 @@ private Q_SLOTS:
Q_SIGNALS:
void authSucceed(QString strUserName);
private:
void setrootWindowBackground(int type,unsigned int color,QString filename);
void setRootWindowBgOptions(int nOption);
bool getdrawBackgroundIsStarted();
void setrootWindow(QList<QPair<QRect,QRect>> screenRectList);
private:
// 日期时间
TimeWidget *m_timeWidget = nullptr;
@ -191,6 +208,14 @@ private:
bool m_isCustomDefault = false; /** 是否默认使用第三方认证 */
bool m_isShowNetwork = true; /** 是否显示网络插件 */
bool m_isShowUserSwitch = true; /** 是否显示用户切换 */
QString m_rootWindowBackground;
int m_nPicOptions = 0;
int drawBackgroundType = 0;
unsigned int drawBackgroundColor = 0x0;
bool drawBackgroundIsStarted = false;
QFuture<void> m_futureDrawBg;
QList<QPair<QRect,QRect>> m_screenRectList;
};
#endif // LOCKWIDGET_H