Skip to content

Commit e4d2293

Browse files
sync: from linuxdeepin/dde-session-shell (#456)
Synchronize source files from linuxdeepin/dde-session-shell. Source-pull-request: linuxdeepin/dde-session-shell#34 Co-authored-by: zyz <zhaoyingzhen@uniontech.com>
1 parent 4aaf06f commit e4d2293

15 files changed

Lines changed: 928 additions & 472 deletions

docs/development-guide.md

Lines changed: 659 additions & 353 deletions
Large diffs are not rendered by default.

src/app/dde-lock.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ int main(int argc, char *argv[])
8686
});
8787

8888
DLogManager::setLogFormat("%{time}{yyyy-MM-dd, HH:mm:ss.zzz} [%{type:-7}] [ %{function:-35} %{line}] %{message}\n");
89+
#ifdef QT_DEBUG
8990
DLogManager::registerConsoleAppender();
90-
DLogManager::registerFileAppender();
91+
#endif
9192
DLogManager::registerJournalAppender();
9293

9394
QCommandLineParser cmdParser;
@@ -203,6 +204,7 @@ int main(int argc, char *argv[])
203204
QObject::connect(WarningContent::instance(), &WarningContent::requestLockFrameHide, [model] {
204205
model->setVisible(false);
205206
});
207+
QObject::connect(LockContent::instance(), &LockContent::requestLockStateChange, worker, &LockWorker::setLocked);
206208

207209
auto createFrame = [&](QPointer<QScreen> screen, int count) -> QWidget* {
208210
LockFrame *lockFrame = new LockFrame(model);

src/app/greeter-display-setting.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,65 @@ static double calcMaxScaleFactor(unsigned int width, unsigned int height) {
108108
return maxScale;
109109
}
110110

111+
static QStringList getScaleList()
112+
{
113+
qDebug() << "Get scale list";
114+
Display *display = XOpenDisplay(nullptr);
115+
if (!display) {
116+
qWarning() << "Display is null";
117+
return QStringList{};
118+
}
119+
120+
XRRScreenResources *resources = XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
121+
if (!resources) {
122+
resources = XRRGetScreenResources(display, DefaultRootWindow(display));
123+
qCWarning(DDE_SHELL) << "Get current XRR screen resources failed, instead of getting XRR screen resources, resources: " << resources;
124+
}
125+
126+
static const float MinScreenWidth = 1024.0f;
127+
static const float MinScreenHeight = 768.0f;
128+
static const QStringList tvstring = {"1.0", "1.25", "1.5", "1.75", "2.0", "2.25", "2.5", "2.75", "3.0"};
129+
QStringList fscaleList;
130+
131+
if (resources) {
132+
for (int i = 0; i < resources->noutput; i++) {
133+
XRROutputInfo* outputInfo = XRRGetOutputInfo(display, resources, resources->outputs[i]);
134+
if (outputInfo->crtc == 0 || outputInfo->mm_width == 0)
135+
continue;
136+
137+
XRRCrtcInfo *crtInfo = XRRGetCrtcInfo(display, resources, outputInfo->crtc);
138+
if (crtInfo == nullptr)
139+
continue;
140+
141+
auto maxWScale = crtInfo->width / MinScreenWidth;
142+
auto maxHScale = crtInfo->height / MinScreenHeight;
143+
auto maxScale = maxWScale < maxHScale ? maxWScale : maxHScale;
144+
maxScale = maxScale < 3.0f ? maxScale : 3.0f;
145+
if (fscaleList.isEmpty()) {
146+
for (int idx = 0; idx * 0.25f + 1.0f <= maxScale; ++idx) {
147+
fscaleList << tvstring[idx];
148+
}
149+
qDebug() << "First screen scale list:" << fscaleList;
150+
} else {
151+
QStringList tmpList;
152+
for (int idx = 0; idx * 0.25f + 1.0f <= maxScale; ++idx) {
153+
tmpList << tvstring[idx];
154+
}
155+
qDebug() << "Current screen scale list:" << tmpList;
156+
// fscaleList、tmpList两者取交集
157+
for (const auto &scale : fscaleList) {
158+
if (!tmpList.contains(scale))
159+
fscaleList.removeAll(scale);
160+
}
161+
}
162+
}
163+
} else {
164+
qCWarning(DDE_SHELL) << "Get scale factor failed, please check X11 Extension";
165+
}
166+
167+
return fscaleList;
168+
}
169+
111170
static double getScaleFactor() {
112171
Display *display = XOpenDisplay(nullptr);
113172
double scaleFactor = 0.0;
@@ -199,6 +258,14 @@ double getScaleFormConfig()
199258
qDebug() << "Scale factor from system display config: " << scaleFactor;
200259
if(scaleFactor == 0.0) {
201260
scaleFactor = defaultScaleFactor;
261+
} else {
262+
// 处理关机期间从高分屏换到低分屏的场景
263+
const auto &scales = getScaleList();
264+
qDebug() << "Scales:" << scales;
265+
if (!scales.isEmpty() && !scales.contains(QString::number(scaleFactor, 'f', 2).replace("00", "0"))) {
266+
qInfo() << "Scale factor is not in scales, use default scale factor";
267+
scaleFactor = defaultScaleFactor;
268+
}
202269
}
203270
return scaleFactor;
204271
} else {

src/dde-lock/lockworker.cpp

Lines changed: 99 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,39 @@ void LockWorker::initConnections()
190190
const bool sleepLock = isSleepLock();
191191
#endif
192192
qCInfo(DDE_SHELL) << "Lock screen when system wakes up: " << sleepLock << ", is visible:" << m_model->visible();
193+
194+
FullScreenBackground::setContent(LockContent::instance());
195+
m_model->setCurrentContentType(SessionBaseModel::LockContent);
196+
193197
if (isSleep) {
194-
endAuthentication(m_account, AT_All);
195-
destroyAuthentication(m_account);
196198
checkSystemWakeupTimer->start();
197199
doSuspendTime = QDateTime::currentDateTime();
198-
} else {
199-
// 非黑屏mode
200-
m_model->setIsBlackMode(isSleep);
201-
202-
// 如果待机唤醒后需要密码则创建验证
203-
if(m_login1SessionSelf->active() && sleepLock)
204-
createAuthentication(m_model->currentUser()->name());
205-
}
206-
if (!m_model->visible() && sleepLock) {
207-
m_model->setIsBlackMode(isSleep);
208-
m_model->setVisible(true);
209-
}
200+
m_model->setIsBlackMode(true);
201+
// 休眠时按需拉起锁屏,注意此时是被动响应休眠
202+
if (sleepLock && m_login1SessionSelf->active()) {
203+
// 仅sleepLock配置开启时执行
204+
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::PasswordMode);
205+
setLocked(true);
206+
m_model->setVisible(true);
210207

211-
if (!isSleep && !sleepLock) {
212-
//待机唤醒后检查是否需要密码,若不需要密码直接隐藏锁定界面
213-
m_model->setVisible(false);
208+
qCInfo(DDE_SHELL) << "locked for sleepLock config";
209+
}
210+
} else {
211+
SessionBaseModel::ModeStatus status = m_model->currentModeState();
212+
if (isLocked() || (m_model->isNoPasswordLogin() && (status == SessionBaseModel::ModeStatus::PowerMode || status == SessionBaseModel::ModeStatus::PasswordMode))) {
213+
// 唤醒时如果处于lock状态,重置认证
214+
if (m_login1SessionSelf->active()) {
215+
endAuthentication(m_account, AT_All);
216+
destroyAuthentication(m_account);
217+
createAuthentication(m_model->currentUser()->name());
218+
}
219+
} else {
220+
// 处理其他流程设置的可见状态
221+
m_model->setVisible(false);
222+
}
223+
// 避免在电源选项处理中设置密码模式,会导致唤醒后闪锁屏
224+
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::PasswordMode);
225+
m_model->setIsBlackMode(false);
214226
}
215227
emit m_model->prepareForSleep(isSleep);
216228
});
@@ -286,40 +298,50 @@ void LockWorker::initConnections()
286298

287299
void LockWorker::initData()
288300
{
289-
/* com.deepin.daemon.Accounts */
290-
m_model->updateUserList(m_accountsInter->userList());
291-
m_model->updateLoginedUserList(m_loginedInter->userList());
292-
293-
m_model->setUserlistVisible(valueByQSettings<bool>("", "userlist", true));
294-
/* com.deepin.udcp.iam */
295-
QDBusInterface ifc(DSS_DBUS::udcpIamService, DSS_DBUS::udcpIamPath, DSS_DBUS::udcpIamService, QDBusConnection::systemBus(), this);
296-
const bool allowShowCustomUser = (!m_model->userlistVisible()) || valueByQSettings<bool>("", "loginPromptInput", false) ||
297-
ifc.property("Enable").toBool() || checkIsADDomain();
298-
m_model->setAllowShowCustomUser(allowShowCustomUser);
299-
300-
/* init server user or custom user */
301-
if (DSysInfo::deepinType() == DSysInfo::DeepinServer || m_model->allowShowCustomUser()) {
302-
std::shared_ptr<User> user(new User());
303-
m_model->setIsServerModel(DSysInfo::deepinType() == DSysInfo::DeepinServer);
304-
m_model->addUser(user);
305-
}
301+
auto list = m_accountsInter->userList();
302+
if (!list.isEmpty()) {
303+
/* com.deepin.daemon.Accounts */
304+
m_model->updateUserList(m_accountsInter->userList());
305+
m_model->updateLoginedUserList(m_loginedInter->userList());
306+
307+
m_model->setUserlistVisible(valueByQSettings<bool>("", "userlist", true));
308+
/* com.deepin.udcp.iam */
309+
QDBusInterface ifc(DSS_DBUS::udcpIamService, DSS_DBUS::udcpIamPath, DSS_DBUS::udcpIamService, QDBusConnection::systemBus(), this);
310+
const bool allowShowCustomUser = (!m_model->userlistVisible()) || valueByQSettings<bool>("", "loginPromptInput", false) ||
311+
ifc.property("Enable").toBool() || checkIsADDomain();
312+
m_model->setAllowShowCustomUser(allowShowCustomUser);
313+
314+
/* init server user or custom user */
315+
if (DSysInfo::deepinType() == DSysInfo::DeepinServer || m_model->allowShowCustomUser()) {
316+
std::shared_ptr<User> user(new User());
317+
m_model->setIsServerModel(DSysInfo::deepinType() == DSysInfo::DeepinServer);
318+
m_model->addUser(user);
319+
}
306320

307-
/* com.deepin.dde.LockService */
308-
std::shared_ptr<User> user_ptr = m_model->findUserByUid(getuid());
309-
if (user_ptr.get()) {
310-
m_model->updateCurrentUser(user_ptr);
311-
const QString &userJson = m_lockInter->CurrentUser();
312-
QJsonParseError jsonParseError;
313-
const QJsonDocument userDoc = QJsonDocument::fromJson(userJson.toUtf8(), &jsonParseError);
314-
if (jsonParseError.error != QJsonParseError::NoError || userDoc.isEmpty()) {
315-
qCWarning(DDE_SHELL) << "Failed to obtain current user information from lock service!";
321+
/* com.deepin.dde.LockService */
322+
std::shared_ptr<User> user_ptr = m_model->findUserByUid(getuid());
323+
if (user_ptr.get()) {
324+
m_model->updateCurrentUser(user_ptr);
325+
const QString &userJson = m_lockInter->CurrentUser();
326+
QJsonParseError jsonParseError;
327+
const QJsonDocument userDoc = QJsonDocument::fromJson(userJson.toUtf8(), &jsonParseError);
328+
if (jsonParseError.error != QJsonParseError::NoError || userDoc.isEmpty()) {
329+
qCWarning(DDE_SHELL) << "Failed to obtain current user information from lock service!";
330+
} else {
331+
const QJsonObject userObj = userDoc.object();
332+
m_model->currentUser()->setLastAuthType(AUTH_TYPE_CAST(userObj["AuthType"].toInt()));
333+
m_model->currentUser()->setLastCustomAuth(userObj["LastCustomAuth"].toString());
334+
}
316335
} else {
317-
const QJsonObject userObj = userDoc.object();
318-
m_model->currentUser()->setLastAuthType(AUTH_TYPE_CAST(userObj["AuthType"].toInt()));
319-
m_model->currentUser()->setLastCustomAuth(userObj["LastCustomAuth"].toString());
336+
m_model->updateCurrentUser(m_lockInter->CurrentUser());
320337
}
321338
} else {
322-
m_model->updateCurrentUser(m_lockInter->CurrentUser());
339+
qCWarning(DDE_SHELL) << "dbus com.deepin.daemon.Accounts userList is empty, use ...";
340+
341+
std::shared_ptr<User> user(new User());
342+
m_model->addUser(user);
343+
m_model->updateCurrentUser(user);
344+
m_model->setAllowShowCustomUser(true);
323345
}
324346

325347
/* com.deepin.daemon.Authenticate */
@@ -343,6 +365,8 @@ void LockWorker::initConfiguration()
343365
m_model->setAllowShowUserSwitchButton(getDconfigValue("switchUser", Ondemand).toInt() == AuthInterface::Ondemand);
344366
#endif
345367

368+
m_model->setGsCheckpwd(isCheckPwdBeforeRebootOrShut());
369+
346370
checkPowerInfo();
347371
}
348372

@@ -490,7 +514,6 @@ void LockWorker::doPowerAction(const SessionBaseModel::PowerAction action)
490514
case SessionBaseModel::PowerAction::RequireSuspend:
491515
{
492516
m_model->setIsBlackMode(true);
493-
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::PasswordMode);
494517

495518
int delayTime = 500;
496519
#ifndef ENABLE_DSS_SNIPE
@@ -520,7 +543,6 @@ void LockWorker::doPowerAction(const SessionBaseModel::PowerAction action)
520543
case SessionBaseModel::PowerAction::RequireHibernate:
521544
{
522545
m_model->setIsBlackMode(true);
523-
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::PasswordMode);
524546

525547
int delayTime = 500;
526548
#ifndef ENABLE_DSS_SNIPE
@@ -549,42 +571,44 @@ void LockWorker::doPowerAction(const SessionBaseModel::PowerAction action)
549571
}
550572
}
551573
break;
552-
case SessionBaseModel::PowerAction::RequireRestart:
574+
case SessionBaseModel::PowerAction::RequireRestart: {
553575
m_model->setShutdownMode(true);
576+
auto gsCheckPwd = m_model->gsCheckpwd();
577+
if (!isLocked() || m_model->currentModeState() == SessionBaseModel::ModeStatus::ShutDownMode || !gsCheckPwd) {
578+
m_sessionManagerInter->RequestReboot();
579+
} else {
580+
createAuthentication(m_account);
581+
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::ConfirmPasswordMode);
582+
}
554583

555-
QTimer::singleShot(350, this, [=] {
556-
if (!isLocked() || m_model->currentModeState() == SessionBaseModel::ModeStatus::ShutDownMode || !isCheckPwdBeforeRebootOrShut()) {
557-
m_sessionManagerInter->RequestReboot();
558-
} else {
559-
createAuthentication(m_account);
560-
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::ConfirmPasswordMode);
561-
}
562-
563-
if (m_model->visibleShutdownWhenRebootOrShutdown()) {
564-
return;
565-
}
584+
if (m_model->visibleShutdownWhenRebootOrShutdown()) {
585+
return;
586+
}
566587

588+
if (!gsCheckPwd)
567589
m_model->setVisible(false);
568-
});
590+
569591
return;
570-
case SessionBaseModel::PowerAction::RequireShutdown:
592+
}
593+
case SessionBaseModel::PowerAction::RequireShutdown: {
571594
m_model->setShutdownMode(true);
595+
auto gsCheckPwd = m_model->gsCheckpwd();
596+
if (!isLocked() || m_model->currentModeState() == SessionBaseModel::ModeStatus::ShutDownMode || !gsCheckPwd) {
597+
m_sessionManagerInter->RequestShutdown();
598+
} else {
599+
createAuthentication(m_account);
600+
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::ConfirmPasswordMode);
601+
}
572602

573-
QTimer::singleShot(350, this, [=] {
574-
if (!isLocked() || m_model->currentModeState() == SessionBaseModel::ModeStatus::ShutDownMode || !isCheckPwdBeforeRebootOrShut()) {
575-
m_sessionManagerInter->RequestShutdown();
576-
} else {
577-
createAuthentication(m_account);
578-
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::ConfirmPasswordMode);
579-
}
580-
581-
if (m_model->visibleShutdownWhenRebootOrShutdown()) {
582-
return;
583-
}
603+
if (m_model->visibleShutdownWhenRebootOrShutdown()) {
604+
return;
605+
}
584606

607+
if (!gsCheckPwd)
585608
m_model->setVisible(false);
586-
});
609+
587610
return;
611+
}
588612
case SessionBaseModel::PowerAction::RequireLock:
589613
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::PasswordMode);
590614
createAuthentication(m_model->currentUser()->name());

src/dde-lock/lockworker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public slots:
6868

6969
void onNoPasswordLoginChanged(const QString &account, bool noPassword);
7070
void sendExtraInfo(const QString &account, AuthCommon::AuthType authType, const QString &info);
71+
void setLocked(const bool locked);
7172

7273
private:
7374
void initConnections();
@@ -76,7 +77,6 @@ public slots:
7677

7778
void doPowerAction(const SessionBaseModel::PowerAction action);
7879
void setCurrentUser(const std::shared_ptr<User> user);
79-
void setLocked(const bool locked);
8080

8181
// lock
8282
void lockServiceEvent(quint32 eventType, quint32 pid, const QString &username, const QString &message);

0 commit comments

Comments
 (0)