Skip to content

Commit e8817de

Browse files
committed
fix: greeter could not enter the password after setting a special keyboard layout
无法输入是因为密码输入限制输入字符。而密码输入需要字母,数字,符号等,禁止其他字符,如藏文。 1.检测到设置特殊键盘布局后,修改称us键盘布局 2.认证成功后,恢复原先键盘布局。 Log: as title Pms: BUG-317167,BUG-329229
1 parent e10e61a commit e8817de

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/session-widgets/lockcontent.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ void LockContent::init(SessionBaseModel *model)
112112
}
113113

114114
DConfigHelper::instance()->bind(this, SHOW_MEDIA_WIDGET, &LockContent::OnDConfigPropertyChanged);
115+
116+
QString kbLayout = getCurrentKBLayout();
117+
if (!kbLayout.isEmpty() && !kbLayout.toLower().startsWith("us")) {
118+
m_originalKBLayout = kbLayout;
119+
qCInfo(DDE_SHELL) << "Original keyboard layout:" << m_originalKBLayout;
120+
// 如果键盘布局有特殊设置,则切换到英文键盘布局,认证成功后恢复
121+
setKBLayout("us");
122+
}
115123
}
116124

117125
void LockContent::initUI()
@@ -184,8 +192,13 @@ void LockContent::initConnections()
184192
connect(m_model, &SessionBaseModel::userListChanged, this, &LockContent::onUserListChanged);
185193
connect(m_model, &SessionBaseModel::userListLoginedChanged, this, &LockContent::onUserListChanged);
186194
connect(m_model, &SessionBaseModel::authFinished, this, [this](bool successful) {
187-
if (successful)
195+
if (successful) {
188196
setVisible(false);
197+
if (!m_originalKBLayout.isEmpty()) {
198+
// 切换回原来的键盘布局
199+
setKBLayout(m_originalKBLayout);
200+
}
201+
}
189202
restoreMode();
190203
});
191204
connect(m_model, &SessionBaseModel::MFAFlagChanged, this, [this](const bool isMFA) {
@@ -985,3 +998,26 @@ void LockContent::showShutdown()
985998
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::ShutDownMode);
986999
m_model->setVisible(true);
9871000
}
1001+
1002+
QString LockContent::getCurrentKBLayout() const
1003+
{
1004+
QProcess p;
1005+
p.start("/usr/bin/setxkbmap", {"-query"});
1006+
p.waitForFinished();
1007+
1008+
const QString output = QString::fromUtf8(p.readAllStandardOutput());
1009+
for (const QString &line : output.split('\n')) {
1010+
if (line.startsWith("layout:")) {
1011+
QString layout = line.section(':', 1).trimmed();
1012+
return layout;
1013+
}
1014+
}
1015+
1016+
return {};
1017+
}
1018+
1019+
void LockContent::setKBLayout(const QString &layout)
1020+
{
1021+
qCDebug(DDE_SHELL) << "Set keyboard layout: " << layout;
1022+
QProcess::execute("/usr/bin/setxkbmap", { layout});
1023+
}

src/session-widgets/lockcontent.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public slots:
101101
void initFMAWidget();
102102
void initUserListWidget();
103103
void enableSystemShortcut(const QStringList &shortcuts, bool enabled, bool isPersistent);
104+
QString getCurrentKBLayout() const;
105+
void setKBLayout(const QString &layout);
104106

105107
protected:
106108
SessionBaseModel *m_model = nullptr;
@@ -133,6 +135,8 @@ public slots:
133135
bool m_MPRISEnable = false;
134136
bool m_showMediaWidget = false;
135137
bool m_hasResetPasswordDialog = false;
138+
139+
QString m_originalKBLayout;
136140
};
137141

138142
#endif // LOCKCONTENT_H

0 commit comments

Comments
 (0)