Skip to content

Commit 0df8574

Browse files
committed
feat: integrate keyboard management with dsg configuration
Added functionality to manage keyboard settings through the dsg configuration system. This includes initializing the configuration manager, updating keyboard states based on user settings, and handling device changes effectively. The keyboardEnabled key is now part of the configuration, allowing for user-level control over keyboard activation. Log: integrate keyboard management with dsg configuration pms: BUG-315763
1 parent a6d4043 commit 0df8574

6 files changed

Lines changed: 128 additions & 9 deletions

File tree

inputdevices1/keyboard.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/godbus/dbus/v5"
1919
"github.com/linuxdeepin/dde-api/dxinput"
2020
ddbus "github.com/linuxdeepin/dde-daemon/dbus"
21+
configManager "github.com/linuxdeepin/go-dbus-factory/org.desktopspec.ConfigManager"
2122
accounts "github.com/linuxdeepin/go-dbus-factory/system/org.deepin.dde.accounts1"
2223
"github.com/linuxdeepin/go-gir/gio-2.0"
2324
"github.com/linuxdeepin/go-lib/dbusutil"
@@ -52,6 +53,8 @@ const (
5253
qtDefaultConfig = ".config/Trolltech.conf"
5354

5455
cmdSetKbd = "/usr/bin/setxkbmap"
56+
57+
dsettingsKeyboardEnabledKey = "keyboardEnabled"
5558
)
5659

5760
type Keyboard struct {
@@ -82,7 +85,9 @@ type Keyboard struct {
8285
user accounts.User
8386
layoutMap layoutMap
8487

85-
devNumber int
88+
devNumber int
89+
devInfos Keyboards
90+
dsgInputConfig configManager.Manager
8691
}
8792

8893
func newKeyboard(service *dbusutil.Service) *Keyboard {
@@ -158,6 +163,8 @@ func newKeyboard(service *dbusutil.Service) *Keyboard {
158163
kbd.listenSettingsChanged()
159164
kbd.listenRootWindowXEvent()
160165
kbd.startXEventLoop()
166+
kbd.initDsgConfig()
167+
kbd.updateDXKeyboards()
161168
return kbd
162169
}
163170

@@ -275,6 +282,8 @@ func (kbd *Keyboard) handleDeviceChanged() {
275282
kbd.applySettings()
276283
}
277284
kbd.devNumber = num
285+
286+
kbd.updateDXKeyboards()
278287
}
279288

280289
func (kbd *Keyboard) applyLayout() {
@@ -742,3 +751,59 @@ func (kbd *Keyboard) toggleNextLayout() {
742751
}
743752
}
744753
}
754+
755+
func (kbd *Keyboard) updateDXKeyboards() {
756+
logger.Debug("updateDXKeyboards")
757+
kbd.devInfos = Keyboards{}
758+
for _, info := range getKeyboardInfos(false) {
759+
tmp := kbd.devInfos.get(info.Id)
760+
if tmp != nil {
761+
continue
762+
}
763+
kbd.devInfos = append(kbd.devInfos, info)
764+
}
765+
766+
value, err := kbd.dsgInputConfig.Value(0, dsettingsKeyboardEnabledKey)
767+
if err != nil {
768+
logger.Warningf("getDsgData key : %s. err : %s", dsettingsKeyboardEnabledKey, err)
769+
return
770+
}
771+
772+
if enableKeyboard, ok := value.Value().(bool); ok {
773+
for _, dev := range kbd.devInfos {
774+
dev.Enable(enableKeyboard)
775+
}
776+
}
777+
}
778+
779+
func (kbd *Keyboard) initDsgConfig() error {
780+
logger.Debug("initDsgConfig")
781+
systemBus, err := dbus.SystemBus()
782+
if err != nil {
783+
logger.Warning(err)
784+
return nil
785+
}
786+
// 加载dsg配置
787+
dsg := configManager.NewConfigManager(systemBus)
788+
789+
inputDevicesPath, err := dsg.AcquireManager(0, dsettingsAppID, dsettingsInputdevices, "")
790+
if err != nil {
791+
logger.Warning(err)
792+
return err
793+
}
794+
795+
kbd.dsgInputConfig, err = configManager.NewManager(systemBus, inputDevicesPath)
796+
if err != nil {
797+
logger.Warning(err)
798+
return err
799+
}
800+
801+
kbd.dsgInputConfig.InitSignalExt(kbd.sysSigLoop, true)
802+
kbd.dsgInputConfig.ConnectValueChanged(func(key string) {
803+
logger.Infof("key: %v", key)
804+
if key == dsettingsKeyboardEnabledKey {
805+
kbd.updateDXKeyboards()
806+
}
807+
})
808+
return nil
809+
}

inputdevices1/kwayland.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ func doHandleKWinDeviceAdded(sysName string) {
129129
}
130130
}
131131
_manager.tpad.handleDeviceChanged()
132+
case common.DevTypeKeyboard:
133+
v, _ := dxinput.NewKeyboardDevInfo(info)
134+
if len(_keyboardnfos) == 0 {
135+
_keyboardnfos = append(_keyboardnfos, v)
136+
} else {
137+
for _, tmp := range _keyboardnfos {
138+
if tmp.Id == v.Id {
139+
continue
140+
}
141+
_keyboardnfos = append(_keyboardnfos, v)
142+
}
143+
}
144+
_manager.kbd.handleDeviceChanged()
132145
}
133146
}
134147

inputdevices1/manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const (
2323
gsSchemaInputDevices = "com.deepin.dde.inputdevices"
2424
gsKeyWheelSpeed = "wheel-speed"
2525
imWheelBin = "imwheel"
26+
27+
dsettingsAppID = "org.deepin.dde.daemon"
28+
dsettingsInputdevices = "org.deepin.dde.daemon.inputdevices"
2629
)
2730

2831
type devicePathInfo struct {

inputdevices1/touchpad.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ const (
4343
tpadKeyPalmMinWidth = "palm-min-width"
4444
tpadKeyPalmMinZ = "palm-min-pressure"
4545

46-
dsettingsAppID = "org.deepin.dde.daemon"
47-
dsettingsInputdevices = "org.deepin.dde.daemon.inputdevices"
48-
dsettingsData = "ps2MouseAsTouchPadEnabled"
46+
dsettingsData = "ps2MouseAsTouchPadEnabled"
4947
)
5048

5149
const (

inputdevices1/wrapper.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ type touchpadInfo struct {
3939
type Mouses []*mouseInfo
4040
type Touchpads []*touchpadInfo
4141
type dxWacoms []*dxinput.Wacom
42+
type Keyboards []*dxinput.Keyboard
4243

4344
var (
44-
_devInfos common.DeviceInfos
45-
_mouseInfos Mouses
46-
_tpadInfos Touchpads
47-
_wacomInfos dxWacoms
48-
_gudevClient = gudev.NewClient([]string{"input"})
45+
_devInfos common.DeviceInfos
46+
_mouseInfos Mouses
47+
_tpadInfos Touchpads
48+
_wacomInfos dxWacoms
49+
_keyboardnfos Keyboards
50+
_gudevClient = gudev.NewClient([]string{"input"})
4951
)
5052

5153
func startDeviceListener() {
@@ -69,6 +71,8 @@ func handleDeviceChanged() {
6971
getMouseInfos(false)
7072
_wacomInfos = dxWacoms{}
7173
getWacomInfos(false)
74+
_keyboardnfos = Keyboards{}
75+
getKeyboardInfos(false)
7276

7377
if _manager == nil {
7478
logger.Warning("_manager is nil")
@@ -310,3 +314,28 @@ func (info mouseInfo) isVirtual() bool {
310314
func (info touchpadInfo) isVirtual() bool {
311315
return strings.Contains(info.sysfsPath, "virtual")
312316
}
317+
318+
func getKeyboardInfos(force bool) Keyboards {
319+
if !force && len(_keyboardnfos) != 0 {
320+
return _keyboardnfos
321+
}
322+
323+
_keyboardnfos = Keyboards{}
324+
for _, info := range getDeviceInfos(false) {
325+
if info.Type == common.DevTypeKeyboard {
326+
tmp, _ := dxinput.NewKeyboardDevInfo(info)
327+
_keyboardnfos = append(_keyboardnfos, tmp)
328+
}
329+
}
330+
331+
return _keyboardnfos
332+
}
333+
334+
func (infos Keyboards) get(id int32) *dxinput.Keyboard {
335+
for _, info := range infos {
336+
if info.Id == id {
337+
return info
338+
}
339+
}
340+
return nil
341+
}

misc/dsg-configs/org.deepin.dde.daemon.inputdevices.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
"description": "",
3535
"permissions": "readwrite",
3636
"visibility": "private"
37+
},
38+
"keyboardEnabled": {
39+
"value": true,
40+
"serial": 0,
41+
"flags": [],
42+
"name": "keyboard_Enabled",
43+
"name[zh_CN]": "键盘启用状态",
44+
"description[zh_CN]": "用户级别键盘开关",
45+
"description": "",
46+
"permissions": "readwrite",
47+
"visibility": "public"
3748
}
3849
}
3950
}

0 commit comments

Comments
 (0)