From 026d46ed6b5ab2c44e640c411c5e0d28ea615b8a Mon Sep 17 00:00:00 2001 From: zhangkun Date: Wed, 2 Dec 2026 15:12:44 +0800 Subject: [PATCH] fix(inputdevices): set Treeland layout via Wayland MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Apply XKB layout and variant through the Treeland input manager protocol. 2. Preserve the X11 path and existing keyboard D-Bus interface. 3. Ship generated bindings and require dde-api-dev 6.2.2 for Debian builds. 4. Test accepted and rejected layout requests over a Unix socket. Log: Apply keyboard layouts through the Treeland Wayland protocol. Influence: Layout switching works in Treeland. fix(inputdevices): 通过 Wayland 设置 Treeland 键盘布局 1. 通过 Treeland 输入管理协议应用 XKB 布局和变体。 2. 保留 X11 路径和现有键盘 D-Bus 接口。 3. 提交生成的绑定,Debian 构建要求 dde-api-dev 6.2.2。 4. 通过 Unix socket 测试布局请求成功和被拒绝的情况。 Log: 通过 Treeland Wayland 协议应用键盘布局。 PMS: BUG-377251 Influence: Treeland 会话可切换键盘布局。 --- LICENSES/MIT.txt | 21 + Makefile | 10 + debian/control | 2 +- debian/copyright | 21 + inputdevices1/internal/inputmanager/layout.go | 130 +++++ .../internal/inputmanager/layout_test.go | 101 ++++ ...put-manager-unstable-v1-client-protocol.go | 470 ++++++++++++++++++ inputdevices1/keyboard.go | 48 +- 8 files changed, 769 insertions(+), 34 deletions(-) create mode 100644 LICENSES/MIT.txt create mode 100644 inputdevices1/internal/inputmanager/layout.go create mode 100644 inputdevices1/internal/inputmanager/layout_test.go create mode 100644 inputdevices1/internal/inputmanager/wayland-treeland-input-manager-unstable-v1-client-protocol.go diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 000000000..90a002459 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 UnionTech Software Technology Co., Ltd. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile index ba695df49..0b161d321 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,7 @@ TEST = \ ${GOPKG_PREFIX}/image_effect1 \ ${GOPKG_PREFIX}/inputdevices1 \ ${GOPKG_PREFIX}/inputdevices1/iso639 \ + ${GOPKG_PREFIX}/inputdevices1/internal/inputmanager \ ${GOPKG_PREFIX}/langselector1 \ ${GOPKG_PREFIX}/lastore1 \ ${GOPKG_PREFIX}/loader \ @@ -110,6 +111,15 @@ LANGUAGES = $(basename $(notdir $(wildcard misc/po/*.po))) all: build +WAYLAND_SCANNER ?= go run ../dde-api/cmd/go-wayland-scanner/main.go +TREELAND_INPUT_MANAGER_XML ?= /usr/share/treeland-protocols/treeland-input-manager-unstable-v1.xml + +.PHONY: generate-treeland-input-manager +generate-treeland-input-manager: + $(WAYLAND_SCANNER) -package inputmanager \ + -o inputdevices1/internal/inputmanager/wayland-treeland-input-manager-unstable-v1-client-protocol.go \ + "$(TREELAND_INPUT_MANAGER_XML)" + prepare: @mkdir -p out/bin @mkdir -p ${GOPATH_DIR}/src/$(dir ${GOPKG_PREFIX}); diff --git a/debian/control b/debian/control index 0a6688efa..914c6de21 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: admin Priority: optional Maintainer: Deepin Packages Builder Build-Depends: - dde-api-dev (>> 3.17.1+), + dde-api-dev (>= 6.2.2), debhelper-compat (= 11), deepin-desktop-schemas, deepin-gettext-tools, diff --git a/debian/copyright b/debian/copyright index 08031e9bb..917b6b5b2 100644 --- a/debian/copyright +++ b/debian/copyright @@ -20,3 +20,24 @@ License: GPL-3+ . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". + +Files: inputdevices1/internal/inputmanager/wayland-treeland-input-manager-unstable-v1-client-protocol.go +Copyright: 2026 UnionTech Software Technology Co., Ltd. +License: Expat + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. diff --git a/inputdevices1/internal/inputmanager/layout.go b/inputdevices1/internal/inputmanager/layout.go new file mode 100644 index 000000000..be2007f68 --- /dev/null +++ b/inputdevices1/internal/inputmanager/layout.go @@ -0,0 +1,130 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +package inputmanager + +import ( + "context" + "fmt" + "time" + + "github.com/linuxdeepin/dde-api/wayland" + "github.com/linuxdeepin/dde-api/wayland/core" +) + +// SetKeyboardLayout updates the default Treeland seat's XKB layout and variant, +// leaving its current model and options intact. +func SetKeyboardLayout(layout, variant string) error { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + d, err := core.Connect(ctx) + if err != nil { + return err + } + defer d.Close() + deadline, _ := ctx.Deadline() + if err := d.SetDeadline(deadline); err != nil { + return err + } + Register(d.Conn) + + obj, err := d.GetRegistry() + if err != nil { + return err + } + registry := core.WlRegistry{Object: obj} + var managerName uint32 + var seats []uint32 + registry.OnGlobal(func(name uint32, iface string, version uint32) { + switch iface { + case core.WlSeatInterface.Name: + seats = append(seats, name) + case TreelandInputManagerV1Interface.Name: + if version >= 2 && managerName == 0 { + managerName = name + } + } + }) + registry.OnGlobalRemove(func(name uint32) { + if name == managerName { + managerName = 0 + } + for i, seat := range seats { + if name == seat { + seats = append(seats[:i], seats[i+1:]...) + break + } + } + }) + if err := d.Roundtrip(); err != nil { + return err + } + if managerName == 0 { + return fmt.Errorf("Treeland input manager v2 is not available") + } + if len(seats) == 0 { + return fmt.Errorf("Treeland has no Wayland seat") + } + // Treeland requires the client to bind the default wl_seat before its manager. + for _, name := range seats { + if _, err := registry.Bind(name, core.WlSeatInterface.Name, 1); err != nil { + return err + } + } + obj, err = registry.Bind(managerName, TreelandInputManagerV1Interface.Name, 2) + if err != nil { + return err + } + manager := TreelandInputManagerV1{Object: obj} + var seat *wayland.Object + manager.OnCapabilityAvailable(func(types uint32, obj *wayland.Object) { + if types&TreelandInputManagerV1DeviceTypeKeyboard != 0 && seat == nil { + seat = obj + } + }) + manager.OnCapabilityUnavailable(func(types uint32, obj *wayland.Object) { + if types&TreelandInputManagerV1DeviceTypeKeyboard != 0 && seat == obj { + seat = nil + } + }) + if err := d.Roundtrip(); err != nil { + return err + } + if seat == nil { + return fmt.Errorf("Treeland seat does not advertise keyboard capability") + } + obj, err = manager.GetKeyboardSettings(seat) + if err != nil { + return err + } + keyboard := TreelandKeyboardSettingsV1{Object: obj} + var model, options string + var ready, gotRules, failed bool + keyboard.OnXkbRules(func(_, currentModel, _, currentOptions string) { + model, options, gotRules = currentModel, currentOptions, true + }) + keyboard.OnDone(func() { ready = true }) + keyboard.OnFailed(func() { failed = true }) + for !ready && !failed && seat != nil { + if err := d.Dispatch(); err != nil { + return err + } + } + if !ready || !gotRules || failed || seat == nil { + return fmt.Errorf("Treeland keyboard settings are not ready") + } + if err := keyboard.SetXkbRules(&layout, &model, &variant, &options); err != nil { + return err + } + if err := keyboard.Apply(); err != nil { + return err + } + if err := d.Roundtrip(); err != nil { + return err + } + if failed || seat == nil { + return fmt.Errorf("Treeland did not apply the keyboard layout") + } + return nil +} diff --git a/inputdevices1/internal/inputmanager/layout_test.go b/inputdevices1/internal/inputmanager/layout_test.go new file mode 100644 index 000000000..7d673a30c --- /dev/null +++ b/inputdevices1/internal/inputmanager/layout_test.go @@ -0,0 +1,101 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +package inputmanager + +import ( + "bytes" + "encoding/binary" + "fmt" + "io" + "net" + "path/filepath" + "testing" + "time" + "unsafe" +) + +func TestSetKeyboardLayout(t *testing.T) { + // Wayland uses the host byte order. + var word binary.ByteOrder = binary.LittleEndian + one := uint16(1) + if *(*byte)(unsafe.Pointer(&one)) == 0 { + word = binary.BigEndian + } + for _, rejected := range []bool{false, true} { + t.Run(fmt.Sprintf("rejected=%t", rejected), func(t *testing.T) { + path := filepath.Join(t.TempDir(), "socket") + listener, err := net.Listen("unix", path) + if err != nil { + t.Fatal(err) + } + defer listener.Close() + t.Setenv("WAYLAND_DISPLAY", path) + serverErr := make(chan error, 1) + go func() { + c, err := listener.Accept() + if err != nil { + serverErr <- err + return + } + defer c.Close() + _ = c.SetDeadline(time.Now().Add(2 * time.Second)) + words := func(values ...uint32) []byte { + b := make([]byte, 4*len(values)) + for i, v := range values { + word.PutUint32(b[4*i:], v) + } + return b + } + text := func(s string) []byte { + b := make([]byte, 4+(len(s)+4)&^3) + word.PutUint32(b, uint32(len(s)+1)) + copy(b[4:], s) + return b + } + msg := func(id, op uint32, args []byte) []byte { return append(words(id, uint32(len(args)+8)<<16|op), args...) } + global := func(name uint32, iface string, version uint32) []byte { + return append(append(words(name), text(iface)...), words(version)...) + } + join := func(a, b, c, d string) []byte { return bytes.Join([][]byte{text(a), text(b), text(c), text(d)}, nil) } + var failed []byte + if rejected { + failed = msg(7, 3, nil) + } + for _, step := range []struct{ request, reply []byte }{ + {msg(1, 1, words(2)), append(msg(2, 0, global(40, "treeland_input_manager_v1", 2)), msg(2, 0, global(41, "wl_seat", 8))...)}, + {msg(1, 0, words(3)), msg(3, 0, words(0))}, + {msg(2, 0, append(global(41, "wl_seat", 1), words(4)...)), msg(4, 0, words(2))}, + {msg(2, 0, append(global(40, "treeland_input_manager_v1", 2), words(5)...)), msg(5, 0, words(4, 4))}, + {msg(1, 0, words(6)), msg(6, 0, words(0))}, + {msg(5, 3, words(7, 4)), append(msg(7, 5, join("us", "pc105", "", "grp:alt_shift_toggle")), msg(7, 4, nil)...)}, + {msg(7, 4, join("cz,us", "pc105", "qwerty,", "grp:alt_shift_toggle")), nil}, + {msg(7, 3, nil), failed}, + {msg(1, 0, words(8)), msg(8, 0, words(0))}, + } { + got := make([]byte, len(step.request)) + if _, err := io.ReadFull(c, got); err != nil { + serverErr <- err + return + } + if !bytes.Equal(got, step.request) { + serverErr <- fmt.Errorf("request %x, want %x", got, step.request) + return + } + if _, err := c.Write(step.reply); err != nil { + serverErr <- err + return + } + } + serverErr <- nil + }() + if err := SetKeyboardLayout("cz,us", "qwerty,"); (err != nil) != rejected { + t.Errorf("SetKeyboardLayout: %v", err) + } + if err := <-serverErr; err != nil { + t.Fatal(err) + } + }) + } +} diff --git a/inputdevices1/internal/inputmanager/wayland-treeland-input-manager-unstable-v1-client-protocol.go b/inputdevices1/internal/inputmanager/wayland-treeland-input-manager-unstable-v1-client-protocol.go new file mode 100644 index 000000000..7dcb8fa92 --- /dev/null +++ b/inputdevices1/internal/inputmanager/wayland-treeland-input-manager-unstable-v1-client-protocol.go @@ -0,0 +1,470 @@ +// Code generated by go-wayland-scanner; DO NOT EDIT. +// +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// SPDX-License-Identifier: MIT + +package inputmanager + +import wl "github.com/linuxdeepin/dde-api/wayland" + +func Register(c *wl.Conn) { + c.Register( + &TreelandInputManagerV1Interface, + &TreelandPointerDeviceConfigurationV1Interface, + &TreelandMouseSettingsV1Interface, + &TreelandTouchpadSettingsV1Interface, + &TreelandKeyboardSettingsV1Interface, + ) +} + +type TreelandInputManagerV1 struct{ *wl.Object } + +const TreelandInputManagerV1DeviceTypeMouse = 1 +const TreelandInputManagerV1DeviceTypeTouchpad = 2 +const TreelandInputManagerV1DeviceTypeKeyboard = 4 +const TreelandInputManagerV1StateDisabled = 0 +const TreelandInputManagerV1StateEnabled = 1 + +func (p TreelandInputManagerV1) Destroy() error { + _, err := p.Object.Request(0, 1, true, "", 0, nil) + return err +} +func (p TreelandInputManagerV1) GetMouseSettings(arg1 *wl.Object) (*wl.Object, error) { + return p.Object.Request(1, 1, false, "treeland_mouse_settings_v1", 0, func(e *wl.Encoder, id uint32) { + e.Uint(id) + e.Object(arg1, "wl_seat", false) + }) +} +func (p TreelandInputManagerV1) GetTouchpadSettings(arg1 *wl.Object) (*wl.Object, error) { + return p.Object.Request(2, 1, false, "treeland_touchpad_settings_v1", 0, func(e *wl.Encoder, id uint32) { + e.Uint(id) + e.Object(arg1, "wl_seat", false) + }) +} +func (p TreelandInputManagerV1) GetKeyboardSettings(arg1 *wl.Object) (*wl.Object, error) { + return p.Object.Request(3, 1, false, "treeland_keyboard_settings_v1", 0, func(e *wl.Encoder, id uint32) { + e.Uint(id) + e.Object(arg1, "wl_seat", false) + }) +} + +var TreelandInputManagerV1Interface = wl.Interface{Name: "treeland_input_manager_v1", Version: 2, Requests: []wl.Message{ + {Name: "destroy"}, + {Name: "get_mouse_settings", Args: []wl.Argument{{Name: "id", Type: "new_id", Interface: "treeland_mouse_settings_v1"}, {Name: "seat", Type: "object", Interface: "wl_seat"}}}, + {Name: "get_touchpad_settings", Args: []wl.Argument{{Name: "id", Type: "new_id", Interface: "treeland_touchpad_settings_v1"}, {Name: "seat", Type: "object", Interface: "wl_seat"}}}, + {Name: "get_keyboard_settings", Args: []wl.Argument{{Name: "id", Type: "new_id", Interface: "treeland_keyboard_settings_v1"}, {Name: "seat", Type: "object", Interface: "wl_seat"}}}, +}, Events: []wl.Event{ + {Message: wl.Message{Name: "capability_available", Args: []wl.Argument{{Name: "type", Type: "uint"}, {Name: "seat", Type: "object", Interface: "wl_seat"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + arg1 := d.Object("wl_seat", false) + h, _ := o.Handler(0).(func(uint32, *wl.Object)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0, arg1) + } + return nil + }}, + {Message: wl.Message{Name: "capability_unavailable", Args: []wl.Argument{{Name: "type", Type: "uint"}, {Name: "seat", Type: "object", Interface: "wl_seat"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + arg1 := d.Object("wl_seat", false) + h, _ := o.Handler(1).(func(uint32, *wl.Object)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0, arg1) + } + return nil + }}, +}} + +func (p TreelandInputManagerV1) OnCapabilityAvailable(h func(uint32, *wl.Object)) { p.Object.On(0, h) } +func (p TreelandInputManagerV1) OnCapabilityUnavailable(h func(uint32, *wl.Object)) { + p.Object.On(1, h) +} + +type TreelandPointerDeviceConfigurationV1 struct{ *wl.Object } + +const TreelandPointerDeviceConfigurationV1FeatureScrollFactor = 1 +const TreelandPointerDeviceConfigurationV1FeatureHandedMode = 2 +const TreelandPointerDeviceConfigurationV1FeatureAccelSpeed = 4 +const TreelandPointerDeviceConfigurationV1FeatureAccelerationProfile = 8 +const TreelandPointerDeviceConfigurationV1FeatureSendEventsMode = 16 +const TreelandPointerDeviceConfigurationV1FeatureNaturalScroll = 32 +const TreelandPointerDeviceConfigurationV1FeatureDisableWhileTyping = 64 +const TreelandPointerDeviceConfigurationV1FeatureTapToClick = 128 +const TreelandPointerDeviceConfigurationV1HandedModeRight = 0 +const TreelandPointerDeviceConfigurationV1HandedModeLeft = 1 +const TreelandPointerDeviceConfigurationV1AccelerationProfileNone = 0 +const TreelandPointerDeviceConfigurationV1AccelerationProfileFlat = 1 +const TreelandPointerDeviceConfigurationV1AccelerationProfileAdaptive = 2 +const TreelandPointerDeviceConfigurationV1AccelerationProfileCustom = 4 +const TreelandPointerDeviceConfigurationV1SendEventsModeEnabled = 0 +const TreelandPointerDeviceConfigurationV1SendEventsModeDisabled = 1 +const TreelandPointerDeviceConfigurationV1SendEventsModeDisabledOnExternalMouse = 2 + +func (p TreelandPointerDeviceConfigurationV1) Destroy() error { + _, err := p.Object.Request(0, 1, true, "", 0, nil) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetScrollFactor(arg0 wl.Fixed) error { + _, err := p.Object.Request(1, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Fixed(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetHandedMode(arg0 uint32) error { + _, err := p.Object.Request(2, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetAccelSpeed(arg0 wl.Fixed) error { + _, err := p.Object.Request(3, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Fixed(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetAccelerationProfile(arg0 uint32) error { + _, err := p.Object.Request(4, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetSendEventsMode(arg0 uint32) error { + _, err := p.Object.Request(5, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetNaturalScroll(arg0 uint32) error { + _, err := p.Object.Request(6, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetDisableWhileTyping(arg0 uint32) error { + _, err := p.Object.Request(7, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) SetTapToClick(arg0 uint32) error { + _, err := p.Object.Request(8, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandPointerDeviceConfigurationV1) Apply() error { + _, err := p.Object.Request(9, 1, false, "", 0, nil) + return err +} + +var TreelandPointerDeviceConfigurationV1Interface = wl.Interface{Name: "treeland_pointer_device_configuration_v1", Version: 1, Requests: []wl.Message{ + {Name: "destroy"}, + {Name: "set_scroll_factor", Args: []wl.Argument{{Name: "factor", Type: "fixed"}}}, + {Name: "set_handed_mode", Args: []wl.Argument{{Name: "mode", Type: "uint"}}}, + {Name: "set_accel_speed", Args: []wl.Argument{{Name: "accel_speed", Type: "fixed"}}}, + {Name: "set_acceleration_profile", Args: []wl.Argument{{Name: "profile", Type: "uint"}}}, + {Name: "set_send_events_mode", Args: []wl.Argument{{Name: "mode", Type: "uint"}}}, + {Name: "set_natural_scroll", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, + {Name: "set_disable_while_typing", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, + {Name: "set_tap_to_click", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, + {Name: "apply"}, +}, Events: []wl.Event{ + {Message: wl.Message{Name: "feature", Args: []wl.Argument{{Name: "feature", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(0).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "scroll_factor", Args: []wl.Argument{{Name: "factor", Type: "fixed"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Fixed() + h, _ := o.Handler(1).(func(wl.Fixed)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "handed_mode", Args: []wl.Argument{{Name: "mode", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(2).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "accel_speed", Args: []wl.Argument{{Name: "accel_speed", Type: "fixed"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Fixed() + h, _ := o.Handler(3).(func(wl.Fixed)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "acceleration_profile", Args: []wl.Argument{{Name: "profile", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(4).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "send_events_mode", Args: []wl.Argument{{Name: "mode", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(5).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "natural_scroll", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(6).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "disable_while_typing", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(7).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "tap_to_click", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(8).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "failed"}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + h, _ := o.Handler(9).(func()) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h() + } + return nil + }}, + {Message: wl.Message{Name: "done", Args: []wl.Argument{{Name: "serial", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(10).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, +}} + +func (p TreelandPointerDeviceConfigurationV1) OnFeature(h func(uint32)) { p.Object.On(0, h) } +func (p TreelandPointerDeviceConfigurationV1) OnScrollFactor(h func(wl.Fixed)) { p.Object.On(1, h) } +func (p TreelandPointerDeviceConfigurationV1) OnHandedMode(h func(uint32)) { p.Object.On(2, h) } +func (p TreelandPointerDeviceConfigurationV1) OnAccelSpeed(h func(wl.Fixed)) { p.Object.On(3, h) } +func (p TreelandPointerDeviceConfigurationV1) OnAccelerationProfile(h func(uint32)) { + p.Object.On(4, h) +} +func (p TreelandPointerDeviceConfigurationV1) OnSendEventsMode(h func(uint32)) { p.Object.On(5, h) } +func (p TreelandPointerDeviceConfigurationV1) OnNaturalScroll(h func(uint32)) { p.Object.On(6, h) } +func (p TreelandPointerDeviceConfigurationV1) OnDisableWhileTyping(h func(uint32)) { p.Object.On(7, h) } +func (p TreelandPointerDeviceConfigurationV1) OnTapToClick(h func(uint32)) { p.Object.On(8, h) } +func (p TreelandPointerDeviceConfigurationV1) OnFailed(h func()) { p.Object.On(9, h) } +func (p TreelandPointerDeviceConfigurationV1) OnDone(h func(uint32)) { p.Object.On(10, h) } + +type TreelandMouseSettingsV1 struct{ *wl.Object } + +func (p TreelandMouseSettingsV1) Destroy() error { + _, err := p.Object.Request(0, 1, true, "", 0, nil) + return err +} +func (p TreelandMouseSettingsV1) GetPointerConfiguration(arg1 uint32) (*wl.Object, error) { + return p.Object.Request(1, 1, false, "treeland_pointer_device_configuration_v1", 0, func(e *wl.Encoder, id uint32) { + e.Uint(id) + e.Uint(arg1) + }) +} + +var TreelandMouseSettingsV1Interface = wl.Interface{Name: "treeland_mouse_settings_v1", Version: 1, Requests: []wl.Message{ + {Name: "destroy"}, + {Name: "get_pointer_configuration", Args: []wl.Argument{{Name: "id", Type: "new_id", Interface: "treeland_pointer_device_configuration_v1"}, {Name: "serial", Type: "uint"}}}, +}, Events: []wl.Event{}} + +type TreelandTouchpadSettingsV1 struct{ *wl.Object } + +func (p TreelandTouchpadSettingsV1) Destroy() error { + _, err := p.Object.Request(0, 1, true, "", 0, nil) + return err +} +func (p TreelandTouchpadSettingsV1) GetPointerConfiguration(arg1 uint32) (*wl.Object, error) { + return p.Object.Request(1, 1, false, "treeland_pointer_device_configuration_v1", 0, func(e *wl.Encoder, id uint32) { + e.Uint(id) + e.Uint(arg1) + }) +} + +var TreelandTouchpadSettingsV1Interface = wl.Interface{Name: "treeland_touchpad_settings_v1", Version: 1, Requests: []wl.Message{ + {Name: "destroy"}, + {Name: "get_pointer_configuration", Args: []wl.Argument{{Name: "id", Type: "new_id", Interface: "treeland_pointer_device_configuration_v1"}, {Name: "serial", Type: "uint"}}}, +}, Events: []wl.Event{}} + +type TreelandKeyboardSettingsV1 struct{ *wl.Object } + +const TreelandKeyboardSettingsV1ToggleStateOff = 0 +const TreelandKeyboardSettingsV1ToggleStateOn = 1 +const TreelandKeyboardSettingsV1FeatureNumLock = 1 + +func (p TreelandKeyboardSettingsV1) Destroy() error { + _, err := p.Object.Request(0, 1, true, "", 0, nil) + return err +} +func (p TreelandKeyboardSettingsV1) SetRepeat(arg0 int32, arg1 int32) error { + _, err := p.Object.Request(1, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Int(arg0) + e.Int(arg1) + }) + return err +} +func (p TreelandKeyboardSettingsV1) SetNumLock(arg0 uint32) error { + _, err := p.Object.Request(2, 1, false, "", 0, func(e *wl.Encoder, id uint32) { + e.Uint(arg0) + }) + return err +} +func (p TreelandKeyboardSettingsV1) Apply() error { + _, err := p.Object.Request(3, 1, false, "", 0, nil) + return err +} +func (p TreelandKeyboardSettingsV1) SetXkbRules(arg0 *string, arg1 *string, arg2 *string, arg3 *string) error { + _, err := p.Object.Request(4, 2, false, "", 0, func(e *wl.Encoder, id uint32) { + e.NullableString(arg0) + e.NullableString(arg1) + e.NullableString(arg2) + e.NullableString(arg3) + }) + return err +} + +var TreelandKeyboardSettingsV1Interface = wl.Interface{Name: "treeland_keyboard_settings_v1", Version: 2, Requests: []wl.Message{ + {Name: "destroy"}, + {Name: "set_repeat", Args: []wl.Argument{{Name: "rate", Type: "int"}, {Name: "delay", Type: "int"}}}, + {Name: "set_num_lock", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, + {Name: "apply"}, + {Name: "set_xkb_rules", Args: []wl.Argument{{Name: "layout", Type: "string"}, {Name: "model", Type: "string"}, {Name: "variant", Type: "string"}, {Name: "options", Type: "string"}}}, +}, Events: []wl.Event{ + {Message: wl.Message{Name: "feature", Args: []wl.Argument{{Name: "feature", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(0).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "repeat", Args: []wl.Argument{{Name: "rate", Type: "int"}, {Name: "delay", Type: "int"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Int() + arg1 := d.Int() + h, _ := o.Handler(1).(func(int32, int32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0, arg1) + } + return nil + }}, + {Message: wl.Message{Name: "num_lock", Args: []wl.Argument{{Name: "state", Type: "uint"}}}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.Uint() + h, _ := o.Handler(2).(func(uint32)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0) + } + return nil + }}, + {Message: wl.Message{Name: "failed"}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + h, _ := o.Handler(3).(func()) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h() + } + return nil + }}, + {Message: wl.Message{Name: "done"}, Since: 1, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + h, _ := o.Handler(4).(func()) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h() + } + return nil + }}, + {Message: wl.Message{Name: "xkb_rules", Args: []wl.Argument{{Name: "layout", Type: "string"}, {Name: "model", Type: "string"}, {Name: "variant", Type: "string"}, {Name: "options", Type: "string"}}}, Since: 2, Destructor: false, FDs: 0, Decode: func(o *wl.Object, d *wl.Decoder) error { + arg0 := d.String() + arg1 := d.String() + arg2 := d.String() + arg3 := d.String() + h, _ := o.Handler(5).(func(string, string, string, string)) + if err := d.Finish(h != nil); err != nil { + return err + } + if h != nil { + h(arg0, arg1, arg2, arg3) + } + return nil + }}, +}} + +func (p TreelandKeyboardSettingsV1) OnFeature(h func(uint32)) { p.Object.On(0, h) } +func (p TreelandKeyboardSettingsV1) OnRepeat(h func(int32, int32)) { p.Object.On(1, h) } +func (p TreelandKeyboardSettingsV1) OnNumLock(h func(uint32)) { p.Object.On(2, h) } +func (p TreelandKeyboardSettingsV1) OnFailed(h func()) { p.Object.On(3, h) } +func (p TreelandKeyboardSettingsV1) OnDone(h func()) { p.Object.On(4, h) } +func (p TreelandKeyboardSettingsV1) OnXkbRules(h func(string, string, string, string)) { + p.Object.On(5, h) +} diff --git a/inputdevices1/keyboard.go b/inputdevices1/keyboard.go index 0039fa026..b0f204e26 100644 --- a/inputdevices1/keyboard.go +++ b/inputdevices1/keyboard.go @@ -20,6 +20,7 @@ import ( "github.com/linuxdeepin/dde-api/dxinput" "github.com/linuxdeepin/dde-daemon/common/dconfig" ddbus "github.com/linuxdeepin/dde-daemon/dbus" + "github.com/linuxdeepin/dde-daemon/inputdevices1/internal/inputmanager" accounts "github.com/linuxdeepin/go-dbus-factory/system/org.deepin.dde.accounts1" "github.com/linuxdeepin/go-lib/dbusutil" "github.com/linuxdeepin/go-lib/dbusutil/proxy" @@ -56,12 +57,6 @@ 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 { @@ -96,8 +91,7 @@ type Keyboard struct { devInfos Keyboards dsgInputConfig *dconfig.DConfig - // treelandSeatConfig 用于在 Treeland 环境下跨 app 写入 user seat DConfig - treelandSeatConfig *dconfig.DConfig + treelandLayoutMu sync.Mutex } func newKeyboard(service *dbusutil.Service) *Keyboard { @@ -126,11 +120,6 @@ 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) @@ -298,15 +287,15 @@ func (kbd *Keyboard) handleDeviceChanged() { } func (kbd *Keyboard) applyLayout() { - kbd.PropsMu.RLock() - currentLayout := kbd.CurrentLayout.Get() - kbd.PropsMu.RUnlock() - if hasTreeLand { - kbd.applyLayoutTreeLand(currentLayout) + kbd.applyLayoutTreeLand() return } + kbd.PropsMu.RLock() + currentLayout := kbd.CurrentLayout.Get() + kbd.PropsMu.RUnlock() + err := applyLayout(currentLayout) if err != nil { logger.Warningf("failed to set layout to %q: %v", currentLayout, err) @@ -583,12 +572,12 @@ 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 - } - +func (kbd *Keyboard) applyLayoutTreeLand() { + kbd.treelandLayoutMu.Lock() + defer kbd.treelandLayoutMu.Unlock() + kbd.PropsMu.RLock() + value := kbd.CurrentLayout.Get() + kbd.PropsMu.RUnlock() array := strings.Split(value, layoutDelim) if len(array) != 2 { logger.Warningf("invalid layout: %s", value) @@ -604,15 +593,8 @@ func (kbd *Keyboard) applyLayoutTreeLand(value string) { } } - 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) + if err := inputmanager.SetKeyboardLayout(layout, variant); err != nil { + logger.Warningf("failed to set Treeland layout to %q: %v", value, err) } }