@@ -194,7 +194,34 @@ void AuthPassword::initConnections()
194194 if (focus && !blockEditSig ()) {
195195 emit lineEditTextChanged (m_lineEdit->text ());
196196 }
197+
198+ if (focus) {
199+ QString kbLayout = getCurrentKBLayout ();
200+ if (!kbLayout.isEmpty () && !kbLayout.toLower ().startsWith (" us" )) {
201+ m_originalKBLayout = kbLayout;
202+ qCInfo (DDE_SHELL) << " Original keyboard layout:" << m_originalKBLayout;
203+ // 如果键盘布局有特殊设置,则切换到英文键盘布局,认证成功后恢复
204+ setKBLayout (" us" );
205+ }
206+ } else {
207+ if (!m_originalKBLayout.isEmpty ()) {
208+ // 切换回原来的键盘布局
209+ setKBLayout (m_originalKBLayout);
210+ m_originalKBLayout.clear ();
211+ }
212+ }
197213 });
214+
215+ connect (this , &AuthPassword::authFinished, this , [this ](const AuthState state) {
216+ if (state == AS_Success) {
217+ if (!m_originalKBLayout.isEmpty ()) {
218+ // 切换回原来的键盘布局
219+ setKBLayout (m_originalKBLayout);
220+ m_originalKBLayout.clear ();
221+ }
222+ }
223+ });
224+
198225 connect (m_lineEdit, &DLineEditEx::textChanged, this , [this , blockEditSig](const QString &text) {
199226 m_lineEdit->hideAlertMessage ();
200227 hidePasswordHintWidget ();
@@ -1038,3 +1065,27 @@ void AuthPassword::onReadyToAuthChanged(bool ready)
10381065{
10391066 ready ? emit lineEditTextChanged (m_lineEdit->text ()) : emit lineEditTextChanged (" " );
10401067}
1068+
1069+
1070+ QString AuthPassword::getCurrentKBLayout () const
1071+ {
1072+ QProcess p;
1073+ p.start (" /usr/bin/setxkbmap" , {" -query" });
1074+ p.waitForFinished ();
1075+
1076+ const QString output = QString::fromUtf8 (p.readAllStandardOutput ());
1077+ for (const QString &line : output.split (' \n ' )) {
1078+ if (line.startsWith (" layout:" )) {
1079+ QString layout = line.section (' :' , 1 ).trimmed ();
1080+ return layout;
1081+ }
1082+ }
1083+
1084+ return {};
1085+ }
1086+
1087+ void AuthPassword::setKBLayout (const QString &layout)
1088+ {
1089+ qCDebug (DDE_SHELL) << " Set keyboard layout: " << layout;
1090+ QProcess::execute (" /usr/bin/setxkbmap" , { layout});
1091+ }
0 commit comments