Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/session-widgets/auth_password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,34 @@ void AuthPassword::initConnections()
if (focus && !blockEditSig()) {
emit lineEditTextChanged(m_lineEdit->text());
}

if (focus) {
QString kbLayout = getCurrentKBLayout();
if (!kbLayout.isEmpty() && !kbLayout.toLower().startsWith("us")) {
m_originalKBLayout = kbLayout;
qCInfo(DDE_SHELL) << "Original keyboard layout:" << m_originalKBLayout;
// 如果键盘布局有特殊设置,则切换到英文键盘布局,认证成功后恢复
setKBLayout("us");
}
} else {
if (!m_originalKBLayout.isEmpty()) {
// 切换回原来的键盘布局
setKBLayout(m_originalKBLayout);
m_originalKBLayout.clear();
}
}
});

connect(this, &AuthPassword::authFinished, this, [this](const AuthState state) {
if (state == AS_Success) {
if (!m_originalKBLayout.isEmpty()) {
// 切换回原来的键盘布局
setKBLayout(m_originalKBLayout);
m_originalKBLayout.clear();
}
}
});

connect(m_lineEdit, &DLineEditEx::textChanged, this, [this, blockEditSig](const QString &text) {
m_lineEdit->hideAlertMessage();
hidePasswordHintWidget();
Expand Down Expand Up @@ -1038,3 +1065,27 @@ void AuthPassword::onReadyToAuthChanged(bool ready)
{
ready ? emit lineEditTextChanged(m_lineEdit->text()) : emit lineEditTextChanged("");
}


QString AuthPassword::getCurrentKBLayout() const
{
QProcess p;
p.start("/usr/bin/setxkbmap", {"-query"});
p.waitForFinished();

const QString output = QString::fromUtf8(p.readAllStandardOutput());
for (const QString &line : output.split('\n')) {
if (line.startsWith("layout:")) {
QString layout = line.section(':', 1).trimmed();
return layout;
}
}

return {};
}

void AuthPassword::setKBLayout(const QString &layout)
{
qCDebug(DDE_SHELL) << "Set keyboard layout: " << layout;
QProcess::execute("/usr/bin/setxkbmap", { layout});
}
3 changes: 3 additions & 0 deletions src/session-widgets/auth_password.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public slots:
void showAlertMessage(const QString &text);
void hidePasswordHintWidget();
void updatePasswordTextMargins();
QString getCurrentKBLayout() const;
void setKBLayout(const QString &layout);

private:
bool m_passwordLineEditEnabled;
Expand All @@ -126,6 +128,7 @@ public slots:
AssistLoginWidget *m_assistLoginWidget;
DConfig *m_authenticationDconfig;
bool m_canShowPasswordErrorTips;
QString m_originalKBLayout;
};

#endif // AUTHPASSWORD_H
Loading