@@ -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
117125void 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+ }
0 commit comments