Skip to content

Commit d1aca82

Browse files
authored
fix: lock window just show background widget (#400)
as title Log: as title Pms: bug-307701
1 parent c2029e2 commit d1aca82

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed

src/dde-lock/lockframe.cpp

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,6 @@ LockFrame::LockFrame(SessionBaseModel *const model, QWidget *parent)
9191
m_enablePowerOffKey = true;
9292
});
9393
}
94-
95-
//待机时由锁屏提供假黑屏,唤醒时显示正常界面
96-
model->setIsBlackMode(isSleep);
97-
model->setVisible(true);
98-
99-
if (!isSleep) {
100-
//待机唤醒后检查是否需要密码,若不需要密码直接隐藏锁定界面
101-
if (!isSleepLock()) {
102-
qDebug() << "sleep-lock is off, prepare unlock";
103-
// 待机唤醒的一瞬间,会延迟收到DBusLogin1Manager::PrepareForSleep(true), 进而最终传入到dde-session的locked状态也是延迟的
104-
// dde-session 延迟收到locked后会重新发送锁定信号,导致这里unlock后又被重新lock
105-
// 设置一个100ms的延时,等待dde-session的locked状态和dde-lock的locked状态完全同步后再进行隐藏锁屏的动作
106-
model->setIsBlackMode(true);
107-
QTimer::singleShot(100, this, [this, model](){
108-
model->setIsBlackMode(false);
109-
hide();
110-
});
111-
}
112-
}
11394
} );
11495

11596
connect(model, &SessionBaseModel::authFinished, this, [this](bool success) {
@@ -263,16 +244,18 @@ void LockFrame::shutdownInhibit(const SessionBaseModel::PowerAction action, bool
263244
m_warningContent->setPowerAction(action);
264245
}
265246
m_warningContent->resize(size());
266-
setContent(m_warningContent);
267-
268-
//多屏状态下,当前界面显示内容时才显示提示界面
269-
if (old_visible) {
270-
setContentVisible(true);
271-
m_lockContent->hide();
247+
//检查是有阻塞
248+
if (const bool inhibit = m_warningContent->beforeInvokeAction(needConfirm)) {
249+
setContent(m_warningContent);
250+
251+
//多屏状态下,当前界面显示内容时才显示提示界面
252+
if (old_visible) {
253+
m_lockContent->hide();
254+
setContentVisible(true);
255+
}
256+
} else {
257+
m_warningContent->doAccecpShutdownInhibit();
272258
}
273-
274-
//检查是否允许关机
275-
m_warningContent->beforeInvokeAction(needConfirm);
276259
}
277260

278261
void LockFrame::cancelShutdownInhibit(bool hideFrame)

src/dde-lock/lockworker.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,35 @@ void LockWorker::initConnections()
132132
/* org.freedesktop.login1.Manager */
133133
connect(m_login1Inter, &DBusLogin1Manager::PrepareForSleep, this, [ = ](bool isSleep) {
134134
qInfo() << "DBusLogin1Manager::PrepareForSleep:" << isSleep;
135+
136+
const auto sleepLock = isSleepLock();
135137
if (isSleep) {
136138
endAuthentication(m_account, AT_All);
137139
destroyAuthentication(m_account);
138140
} else {
139-
createAuthentication(m_model->currentUser()->name());
141+
// 非黑屏mode
142+
m_model->setIsBlackMode(false);
143+
144+
// 如果待机唤醒后需要密码则创建验证
145+
if(m_login1SessionSelf->active() && sleepLock)
146+
createAuthentication(m_model->currentUser()->name());
140147
}
148+
if (!m_model->visible() && sleepLock) {
149+
m_model->setIsBlackMode(isSleep);
150+
m_model->setVisible(true);
151+
}
152+
153+
if (!isSleep && !sleepLock) {
154+
// 待机唤醒后检查是否需要密码,若不需要密码直接隐藏锁定界面
155+
// 待机唤醒的一瞬间,会延迟收到DBusLogin1Manager::PrepareForSleep(true), 进而最终传入到dde-session的locked状态也是延迟的
156+
// dde-session 延迟收到locked后会重新发送锁定信号,导致这里unlock后又被重新lock
157+
// 设置一个100ms的延时,等待dde-session的locked状态和dde-lock的locked状态完全同步后再进行隐藏锁屏的动作
158+
QTimer::singleShot(100, this, [this]() {
159+
m_model->setVisible(false);
160+
m_model->setCurrentModeState(SessionBaseModel::PasswordMode);
161+
});
162+
}
163+
141164
emit m_model->prepareForSleep(isSleep);
142165
});
143166

src/widgets/fullscreenbackground.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ void FullscreenBackground::setContentVisible(bool visible)
184184

185185
void FullscreenBackground::setContent(QWidget *const w)
186186
{
187+
if (m_content) {
188+
m_content->setVisible(false);
189+
}
190+
187191
m_content = w;
188192
m_content->setParent(this);
189193
m_content->move(0, 0);

src/widgets/warningcontent.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void WarningContent::doAccecpShutdownInhibit()
138138
emit m_model->cancelShutdownInhibit(false);
139139
}
140140

141-
void WarningContent::beforeInvokeAction(bool needConfirm)
141+
bool WarningContent::beforeInvokeAction(bool needConfirm)
142142
{
143143
const QList<InhibitWarnView::InhibitorData> inhibitors = listInhibitors(m_powerAction);
144144
const QList<std::shared_ptr<User>> &loginUsers = m_model->loginedUserList();
@@ -178,7 +178,7 @@ void WarningContent::beforeInvokeAction(bool needConfirm)
178178
tr("To close the program, click Cancel, and then close the program."));
179179
break;
180180
default:
181-
return;
181+
return true;
182182
}
183183

184184
// 如果有阻止关机、重启、待机或休眠的进程,则不允许手动强制执行
@@ -209,7 +209,7 @@ void WarningContent::beforeInvokeAction(bool needConfirm)
209209
connect(view, &InhibitWarnView::cancelled, this, &WarningContent::doCancelShutdownInhibit);
210210
connect(view, &InhibitWarnView::actionInvoked, this, &WarningContent::doAccecpShutdownInhibit);
211211

212-
return;
212+
return true;
213213
}
214214

215215
if (loginUsers.length() > 1 && (m_powerAction == SessionBaseModel::PowerAction::RequireShutdown || m_powerAction == SessionBaseModel::PowerAction::RequireRestart)) {
@@ -239,7 +239,7 @@ void WarningContent::beforeInvokeAction(bool needConfirm)
239239
connect(view, &MultiUsersWarningView::cancelled, this, &WarningContent::doCancelShutdownInhibit);
240240
connect(view, &MultiUsersWarningView::actionInvoked, this, &WarningContent::doAccecpShutdownInhibit);
241241

242-
return;
242+
return true;
243243
}
244244

245245
if (needConfirm && (m_powerAction == SessionBaseModel::PowerAction::RequireShutdown ||
@@ -266,10 +266,11 @@ void WarningContent::beforeInvokeAction(bool needConfirm)
266266
connect(view, &InhibitWarnView::cancelled, this, &WarningContent::doCancelShutdownInhibit);
267267
connect(view, &InhibitWarnView::actionInvoked, this, &WarningContent::doAccecpShutdownInhibit);
268268

269-
return;
269+
return true;
270270
}
271271

272-
doAccecpShutdownInhibit();
272+
//doAccecpShutdownInhibit();
273+
return false;
273274
}
274275

275276
void WarningContent::setPowerAction(const SessionBaseModel::PowerAction action)

src/widgets/warningcontent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class WarningContent : public SessionBaseWindow
2222
public:
2323
explicit WarningContent(SessionBaseModel *const model, const SessionBaseModel::PowerAction action, QWidget *parent = nullptr);
2424
~WarningContent() override;
25-
void beforeInvokeAction(bool needConfirm);
25+
bool beforeInvokeAction(bool needConfirm);
2626
void setPowerAction(const SessionBaseModel::PowerAction action);
27+
void doAccecpShutdownInhibit();
2728

2829
protected:
2930
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
3031
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
3132
QList<InhibitWarnView::InhibitorData> listInhibitors(const SessionBaseModel::PowerAction action);
3233
void doCancelShutdownInhibit();
33-
void doAccecpShutdownInhibit();
3434

3535
private:
3636
SessionBaseModel *m_model;

0 commit comments

Comments
 (0)