Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions inputdevices1/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ const (
kbdSystemConfig = "/etc/default/keyboard"
qtDefaultConfig = ".config/Trolltech.conf"
cmdSetKbd = "/usr/bin/setxkbmap"

// Treeland keyboard layout DConfig
treelandAppID = "org.deepin.dde.treeland"
treelandSeatName = "org.deepin.dde.treeland.user.seat"
treelandKeyXkbLayout = "xkbLayout"
treelandKeyXkbVariant = "xkbVariant"
)

type Keyboard struct {
Expand Down Expand Up @@ -89,6 +95,9 @@ type Keyboard struct {
devNumber int
devInfos Keyboards
dsgInputConfig *dconfig.DConfig

// treelandSeatConfig 用于在 Treeland 环境下跨 app 写入 user seat DConfig
treelandSeatConfig *dconfig.DConfig
}

func newKeyboard(service *dbusutil.Service) *Keyboard {
Expand Down Expand Up @@ -117,6 +126,11 @@ func newKeyboard(service *dbusutil.Service) *Keyboard {
logger.Error("failed to get X conn:", err)
return nil
}
} else {
kbd.treelandSeatConfig, err = dconfig.NewDConfig(treelandAppID, treelandSeatName, "")
if err != nil {
logger.Warning("failed to init treeland seat dconfig:", err)
}
}

kbd.layoutMap, err = getLayoutsFromFile(kbdLayoutsXml)
Expand Down Expand Up @@ -288,6 +302,11 @@ func (kbd *Keyboard) applyLayout() {
currentLayout := kbd.CurrentLayout.Get()
kbd.PropsMu.RUnlock()

if hasTreeLand {
kbd.applyLayoutTreeLand(currentLayout)
return
}
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

err := applyLayout(currentLayout)
if err != nil {
logger.Warningf("failed to set layout to %q: %v", currentLayout, err)
Expand All @@ -301,6 +320,10 @@ func (kbd *Keyboard) applyLayout() {
}

func (kbd *Keyboard) applyOptions() {
if hasTreeLand {
return
}

options := kbd.UserOptionList.Get()
if len(options) == 0 {
return
Expand Down Expand Up @@ -560,6 +583,39 @@ func applyLayout(value string) error {
return cmd.Run()
}

func (kbd *Keyboard) applyLayoutTreeLand(value string) {
if kbd.treelandSeatConfig == nil {
logger.Warning("treeland seat dconfig is nil, skip applying layout")
return
}

array := strings.Split(value, layoutDelim)
if len(array) != 2 {
logger.Warningf("invalid layout: %s", value)
return
}

layout, variant := array[0], array[1]
if layout != "us" {
layout += ",us"

if variant != "" {
variant += ","
}
}

err := kbd.treelandSeatConfig.SetValue(treelandKeyXkbLayout, layout)
if err != nil {
logger.Warning("failed to set treeland xkbLayout:", err)
return
}

err = kbd.treelandSeatConfig.SetValue(treelandKeyXkbVariant, variant)
if err != nil {
logger.Warning("failed to set treeland xkbVariant:", err)
}
}

func setQtCursorBlink(rate int32, file string) error {
ok := dutils.WriteKeyToKeyFile(file, "Qt", "cursorFlashTime", rate)
if !ok {
Expand Down
Loading