@@ -112,6 +112,13 @@ void LockContent::init(SessionBaseModel *model)
112112 }
113113
114114 DConfigHelper::instance ()->bind (this , SHOW_MEDIA_WIDGET, &LockContent::OnDConfigPropertyChanged);
115+
116+ if (m_model->appType () == AuthCommon::Login && keyboardLayoutHasSpecialSetting ()) {
117+ m_originalKBLayout = getCurrentKBLayoutAndVariant ();
118+ qCInfo (DDE_SHELL) << " Original keyboard layout:" << m_originalKBLayout;
119+ // 如果是登录界面且键盘布局有特殊设置,则切换到英文键盘布局
120+ setKBLayoutAndVariant (" us" );
121+ }
115122}
116123
117124void LockContent::initUI ()
@@ -184,8 +191,13 @@ void LockContent::initConnections()
184191 connect (m_model, &SessionBaseModel::userListChanged, this , &LockContent::onUserListChanged);
185192 connect (m_model, &SessionBaseModel::userListLoginedChanged, this , &LockContent::onUserListChanged);
186193 connect (m_model, &SessionBaseModel::authFinished, this , [this ](bool successful) {
187- if (successful)
194+ if (successful) {
188195 setVisible (false );
196+ if (!m_originalKBLayout.isEmpty ()) {
197+ // 切换回原来的键盘布局
198+ setKBLayoutAndVariant (m_originalKBLayout);
199+ }
200+ }
189201 restoreMode ();
190202 });
191203 connect (m_model, &SessionBaseModel::MFAFlagChanged, this , [this ](const bool isMFA) {
@@ -985,3 +997,53 @@ void LockContent::showShutdown()
985997 m_model->setCurrentModeState (SessionBaseModel::ModeStatus::ShutDownMode);
986998 m_model->setVisible (true );
987999}
1000+
1001+ // 判断键盘布局是否有特殊设置,如XKBVARIANT=tib(藏文键盘布局),这个配置文件可通过安装器后配置键盘布局修改
1002+ // 如果设置特殊键盘布局,则在greeter阶段会导致无法输入的问题,密码输入框等设置过滤规则(如大小写,数字,符号等)
1003+ bool LockContent::keyboardLayoutHasSpecialSetting () const
1004+ {
1005+ QFile file (" /etc/default/keyboard" );
1006+ if (!file.open (QIODevice::ReadOnly | QIODevice::Text))
1007+ return false ;
1008+
1009+ QTextStream in (&file);
1010+ while (!in.atEnd ()) {
1011+ QString line = in.readLine ().trimmed ();
1012+ if (line.startsWith (" XKBVARIANT=" )) {
1013+ QString val = line.section (' =' , 1 ).trimmed ();
1014+ if (val.startsWith (' "' ) && val.endsWith (' "' ))
1015+ val = val.mid (1 , val.length () - 2 ); // Remove quotes
1016+ return !val.trimmed ().isEmpty ();
1017+ }
1018+ }
1019+
1020+ return false ;
1021+ }
1022+
1023+ QString LockContent::getCurrentKBLayoutAndVariant () const
1024+ {
1025+ QProcess p;
1026+ p.start (" /usr/bin/setxkbmap" , {" -query" });
1027+ p.waitForFinished ();
1028+ QString layout, variant;
1029+
1030+ const QString output = QString::fromUtf8 (p.readAllStandardOutput ());
1031+ for (const QString &line : output.split (' \n ' )) {
1032+ if (line.startsWith (" layout:" ))
1033+ layout = line.section (' :' , 1 ).trimmed ();
1034+ else if (line.startsWith (" variant:" ))
1035+ variant = line.section (' :' , 1 ).trimmed ();
1036+ }
1037+
1038+ return variant.isEmpty () ? layout : layout + " +" + variant;
1039+ }
1040+
1041+ void LockContent::setKBLayoutAndVariant (const QString &layoutVariant)
1042+ {
1043+ qCInfo (DDE_SHELL) << " Set keyboard layout and variant: " << layoutVariant;
1044+ const QStringList parts = layoutVariant.split (' +' );
1045+ if (parts.size () == 2 )
1046+ QProcess::execute (" /usr/bin/setxkbmap" , {parts[0 ], " -variant" , parts[1 ]});
1047+ else if (parts.size () == 1 )
1048+ QProcess::execute (" /usr/bin/setxkbmap" , {parts[0 ]});
1049+ }
0 commit comments