From a12552e98812ca9bad66a88fd0c29aa42e9fb78e Mon Sep 17 00:00:00 2001 From: fuleyi Date: Thu, 5 Dec 2024 11:05:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=BE=E5=BC=80inputdevice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 放开inputdevice Log: 放开inputdevice pms: TASK-369379 --- bin/dde-session-daemon/main.go | 2 +- inputdevices1/inputdevices.go | 4 ++++ inputdevices1/keyboard.go | 28 +++++++++++++++++++---- inputdevices1/layout_list.go | 1 - inputdevices1/manager.go | 42 +++++++++++++++++++++++----------- inputdevices1/mouse.go | 4 ++++ inputdevices1/touchpad.go | 4 ++++ inputdevices1/trackpoint.go | 5 +++- inputdevices1/wacom.go | 5 ++++ 9 files changed, 74 insertions(+), 21 deletions(-) diff --git a/bin/dde-session-daemon/main.go b/bin/dde-session-daemon/main.go index b4641a6fa..db3f5e93e 100755 --- a/bin/dde-session-daemon/main.go +++ b/bin/dde-session-daemon/main.go @@ -41,7 +41,7 @@ var logger = log.NewLogger("daemon/dde-session-daemon") var hasDDECookie bool var hasTreeLand bool -var treeLandNotAllowModules = []string{"x-event-monitor", "keybinding", "trayicon", "screensaver", "inputdevices"} +var treeLandNotAllowModules = []string{"x-event-monitor", "keybinding", "trayicon", "screensaver"} func isInShutdown() bool { bus, err := dbus.SystemBus() diff --git a/inputdevices1/inputdevices.go b/inputdevices1/inputdevices.go index eda054b0e..425509419 100644 --- a/inputdevices1/inputdevices.go +++ b/inputdevices1/inputdevices.go @@ -85,6 +85,10 @@ func (d *Daemon) Start() error { if err != nil { logger.Warning(err) } + // TODO: treeland环境暂不支持设备变化的处理 + if hasTreeLand { + return + } if globalWayland { _manager.handleInputDeviceChanged(false) return diff --git a/inputdevices1/keyboard.go b/inputdevices1/keyboard.go index 1aaa39fbd..356d62e47 100644 --- a/inputdevices1/keyboard.go +++ b/inputdevices1/keyboard.go @@ -107,10 +107,13 @@ func newKeyboard(service *dbusutil.Service) *Keyboard { kbd.appLayoutCfg.Map = make(map[string]int) } - kbd.xConn, err = x.NewConn() - if err != nil { - logger.Error("failed to get X conn:", err) - return nil + // Treeland环境没有X + if !hasTreeLand { + kbd.xConn, err = x.NewConn() + if err != nil { + logger.Error("failed to get X conn:", err) + return nil + } } kbd.layoutMap, err = getLayoutsFromFile(kbdLayoutsXml) @@ -521,7 +524,10 @@ func (kbd *Keyboard) applyX11Repeat() { } func (kbd *Keyboard) applyRepeat() { - if globalWayland { + // TODO: treeland环境无法设置 + if hasTreeLand { + return + } else if globalWayland { if kbd.shouldUseDDEKwin() { kbd.applyKwinWaylandRepeat() } else { @@ -653,6 +659,9 @@ func (kbd *Keyboard) listenSettingsChanged() { } func (kbd *Keyboard) listenRootWindowXEvent() { + if kbd.xConn == nil { + return + } rootWin := kbd.xConn.GetDefaultScreen().Root const eventMask = x.EventMaskPropertyChange err := x.ChangeWindowAttributesChecked(kbd.xConn, rootWin, x.CWEventMask, @@ -664,6 +673,9 @@ func (kbd *Keyboard) listenRootWindowXEvent() { } func (kbd *Keyboard) handleActiveWindowChanged() { + if kbd.xConn == nil { + return + } activeWindow, err := ewmh.GetActiveWindow(kbd.xConn).Reply(kbd.xConn) if err != nil { logger.Warning(err) @@ -698,6 +710,9 @@ func (kbd *Keyboard) handleActiveWindowChanged() { } func (kbd *Keyboard) startXEventLoop() { + if kbd.xConn == nil { + return + } eventChan := make(chan x.GenericEvent, 10) kbd.xConn.AddEventChan(eventChan) @@ -713,6 +728,9 @@ func (kbd *Keyboard) startXEventLoop() { } func (kbd *Keyboard) handlePropertyNotifyEvent(ev *x.PropertyNotifyEvent) { + if kbd.xConn == nil { + return + } rootWin := kbd.xConn.GetDefaultScreen().Root if ev.Window == rootWin { kbd.handleActiveWindowChanged() diff --git a/inputdevices1/layout_list.go b/inputdevices1/layout_list.go index 3e2e011da..a010f7711 100644 --- a/inputdevices1/layout_list.go +++ b/inputdevices1/layout_list.go @@ -61,7 +61,6 @@ func getLayoutsFromFile(filename string) (layoutMap, error) { if err != nil { return nil, err } - result := make(layoutMap) for _, layout := range xmlData.Layouts { layoutName := layout.ConfigItem.Name diff --git a/inputdevices1/manager.go b/inputdevices1/manager.go index 115349ed6..ef59cb53b 100644 --- a/inputdevices1/manager.go +++ b/inputdevices1/manager.go @@ -31,6 +31,9 @@ type devicePathInfo struct { } type devicePathInfos []*devicePathInfo +// 是否是treeland环境 +var hasTreeLand = false + type Manager struct { Infos devicePathInfos // readonly WheelSpeed gsprop.Uint `prop:"access:rw"` @@ -52,6 +55,9 @@ type Manager struct { } func NewManager(service *dbusutil.Service) *Manager { + if os.Getenv("XDG_SESSION_TYPE") == "wayland" { + hasTreeLand = true + } var m = new(Manager) m.imWheelConfigFile = filepath.Join(basedir.GetUserHomeDir(), ".imwheelrc") @@ -86,7 +92,10 @@ func NewManager(service *dbusutil.Service) *Manager { m.trackPoint = newTrackPoint(service) - m.kwinManager = kwin.NewInputDeviceManager(service.Conn()) + // TODO: treeland 环境没有kwin,直接返回 + if !hasTreeLand { + m.kwinManager = kwin.NewInputDeviceManager(service.Conn()) + } m.sessionSigLoop = dbusutil.NewSignalLoop(service.Conn(), 10) m.syncConfig = dsync.NewConfig("peripherals", &syncConfig{m: m}, @@ -106,10 +115,13 @@ func (m *Manager) setWheelSpeed() { logger.Warning(err) } - err = m.setWaylandWheelSpeed(speed) - if err == nil { - logger.Info("set Wayland WheelSpeed finish") - return + // TODO: treeland环境没有kwin + if !hasTreeLand { + err = m.setWaylandWheelSpeed(speed) + if err == nil { + logger.Info("set Wayland WheelSpeed finish") + return + } } logger.Info("can not set WheelSpeed by Wayland interface, use imwheel") @@ -185,14 +197,18 @@ Shift_R,Down,Shift_R|Button5 func (m *Manager) init() { m.kbd.init() m.kbd.handleGSettings() - m.wacom.init() - m.wacom.handleGSettings() - m.tpad.init() - m.tpad.handleGSettings() - m.mouse.init() - m.mouse.handleGSettings() - m.trackPoint.init() - m.trackPoint.handleGSettings() + + //TODO: treeland环境暂不支持如下设备 + if !hasTreeLand { + m.wacom.init() + m.wacom.handleGSettings() + m.tpad.init() + m.tpad.handleGSettings() + m.mouse.init() + m.mouse.handleGSettings() + m.trackPoint.init() + m.trackPoint.handleGSettings() + } m.setWheelSpeed() m.handleGSettings() diff --git a/inputdevices1/mouse.go b/inputdevices1/mouse.go index e953d58ff..beaef4da6 100644 --- a/inputdevices1/mouse.go +++ b/inputdevices1/mouse.go @@ -70,6 +70,10 @@ func newMouse(service *dbusutil.Service, touchPad *Touchpad) *Mouse { m.DragThreshold.Bind(m.setting, mouseKeyDragThreshold) m.AdaptiveAccelProfile.Bind(m.setting, mouseKeyAdaptiveAccel) + // TODO: treeland环境暂不支持 + if hasTreeLand { + return m + } m.updateDXMouses() return m diff --git a/inputdevices1/touchpad.go b/inputdevices1/touchpad.go index eea934bc1..fe029154d 100644 --- a/inputdevices1/touchpad.go +++ b/inputdevices1/touchpad.go @@ -112,6 +112,10 @@ func newTouchpad(service *dbusutil.Service) *Touchpad { tpad.DoubleClick.Bind(tpad.mouseSetting, mouseKeyDoubleClick) tpad.DragThreshold.Bind(tpad.mouseSetting, mouseKeyDragThreshold) + // TODO: treeland环境暂不支持 + if hasTreeLand { + return tpad + } tpad.updateDXTpads() if conn, err := dbus.SystemBus(); err != nil { diff --git a/inputdevices1/trackpoint.go b/inputdevices1/trackpoint.go index 3ca374c39..321ddad4e 100644 --- a/inputdevices1/trackpoint.go +++ b/inputdevices1/trackpoint.go @@ -66,7 +66,10 @@ func newTrackPoint(service *dbusutil.Service) *TrackPoint { tp.WheelEmulationButton.Bind(tp.setting, trackPointKeyWheelButton) tp.WheelEmulationTimeout.Bind(tp.setting, trackPointKeyWheelTimeout) tp.LeftHanded.Bind(tp.setting, trackPointKeyLeftHanded) - + // TODO: treeland环境暂不支持 + if hasTreeLand { + return tp + } tp.updateDXMouses() return tp diff --git a/inputdevices1/wacom.go b/inputdevices1/wacom.go index 9825ab130..924e3de1b 100644 --- a/inputdevices1/wacom.go +++ b/inputdevices1/wacom.go @@ -163,6 +163,11 @@ func newWacom(service *dbusutil.Service) *Wacom { w.EraserRawSample.Bind(w.eraserSetting, wacomKeyRawSample) w.EraserThreshold.Bind(w.eraserSetting, wacomKeyThreshold) + // TODO: treeland环境暂不支持 + if hasTreeLand { + return w + } + w.updateDXWacoms() err := w.initX()