Skip to content

Commit 5753f0a

Browse files
deepin-ci-robotyixinshark
authored andcommitted
sync: from linuxdeepin/dde-session-shell
Synchronize source files from linuxdeepin/dde-session-shell. Source-pull-request: linuxdeepin/dde-session-shell#10
1 parent 42f5cba commit 5753f0a

File tree

4 files changed

+97
-5
lines changed

4 files changed

+97
-5
lines changed

files/wayland/lightdm-deepin-greeter-wayland

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,37 @@ if [ -x $display_daemon ]; then
1515
fi
1616

1717

18+
#在满足条件下,设置tapToClick=true
19+
#解析dbus信息输出
20+
dbus_values_get_strings(){
21+
local input="$1"
22+
echo "$input" | grep -oP 'string \K".*?"' | tr -d '"'
23+
}
24+
dbus_values_get_bool(){
25+
local input="$1"
26+
echo "$input" | grep -oP 'boolean \Ktrue|false' | awk '{print $1}'
27+
}
28+
29+
#判断并设置设备属性
30+
device_handle(){
31+
local input="$1"
32+
local dbus_touchpad=$(dbus-send --session --print-reply --dest=org.kde.KWin $input org.freedesktop.DBus.Properties.Get string:"org.kde.KWin.InputDevice" string:"touchpad")
33+
local touchpad=$(dbus_values_get_bool "$dbus_touchpad")
34+
35+
if [ "$touchpad" = "true" ]; then
36+
dbus-send --session --dest=org.kde.KWin "$input" org.freedesktop.DBus.Properties.Set string:"org.kde.KWin.InputDevice" string:"tapToClick" variant:boolean:true
37+
fi
38+
}
39+
40+
#获取设备列表
41+
dbus_devices=$(dbus-send --session --print-reply --dest=org.kde.KWin /org/kde/KWin/InputDevice org.freedesktop.DBus.Properties.Get string:"org.kde.KWin.InputDeviceManager" string:"devicesSysNames")
42+
devices_strings=$(dbus_values_get_strings "$dbus_devices")
43+
44+
#遍历设备列表
45+
device_path="/org/kde/KWin/InputDevice/"
46+
for dev in $devices_strings; do
47+
path="${device_path}${dev}"
48+
device_handle "$path"
49+
done
50+
1851
/usr/share/dde-session-shell/greeters.d/launch-binary

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

src/session-widgets/sessionbasemodel.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
#include "sessionbasemodel.h"
6+
#include "dconfig_helper.h"
7+
#include "dbus/dbusdisplaymanager.h"
68

79
#include <DSysInfo>
8-
910
#include <QDebug>
1011

1112
#include "dbusconstant.h"
12-
#include "dconfig_helper.h"
1313

1414
DCORE_USE_NAMESPACE
1515

@@ -462,6 +462,22 @@ void SessionBaseModel::updateUserList(const QStringList &list)
462462
void SessionBaseModel::updateLoginedUserList(const QString &list)
463463
{
464464
qCDebug(DDE_SHELL) << "Logined user list: " << list;
465+
// kwin崩溃时systemd中的sessions不会被remove掉,这里通过DisplayManager的session信息过滤一遍(临时解决方案)
466+
QStringList loggedUserNameList;
467+
DBusDisplayManager displayManager("org.freedesktop.DisplayManager", "/org/freedesktop/DisplayManager", QDBusConnection::systemBus());
468+
const auto &sessions = displayManager.sessions();
469+
for (const auto &session : sessions) {
470+
const QString &sessionPath = session.path();
471+
if (sessionPath.isEmpty())
472+
continue;
473+
QDBusInterface interface("org.freedesktop.DisplayManager", sessionPath, "org.freedesktop.DisplayManager.Session", QDBusConnection::systemBus());
474+
if (interface.isValid()) {
475+
const QString &userName = interface.property("UserName").toString();
476+
if (!userName.isEmpty())
477+
loggedUserNameList.append(userName);
478+
}
479+
}
480+
qInfo(DDE_SHELL) << "Logined users from display manager: " << loggedUserNameList;
465481

466482
QList<QString> loginedUsersTmp = m_loginedUsers->keys();
467483
QJsonParseError jsonParseError;
@@ -486,8 +502,11 @@ void SessionBaseModel::updateLoginedUserList(const QString &list)
486502
// 对于通过自定义窗口输入的账户(域账户), 此时账户还没添加进来,导致下面m_users->value(path)为空指针,调用会导致程序奔溃
487503
// 因此在登录时,对于新增的账户,调用addUser先将账户添加进来,然后再去更新对应账户的登录状态
488504
addUser(path);
489-
m_loginedUsers->insert(path, m_users->value(path));
490-
m_users->value(path)->updateLoginState(true);
505+
auto user = m_users->value(path);
506+
if (user->name().isEmpty() || loggedUserNameList.contains(user->name())) {
507+
m_loginedUsers->insert(path, user);
508+
user->updateLoginState(true);
509+
}
491510
} else {
492511
loginedUsersTmp.removeAll(path);
493512
}

0 commit comments

Comments
 (0)