Skip to content

Commit 13ff8dc

Browse files
committed
fix: get 'libinput Accel Profiles Available' failed
libinput currently supports three profiles: "adaptive", "flat" and "custom". Log: 修复无法设置鼠标加速 PMS: bug-294369
1 parent d1fb4aa commit 13ff8dc

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

dxinput/libinput.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,45 @@ const (
4343
libinputPropDisableWhileTyping = "libinput Disable While Typing Enabled"
4444
)
4545

46-
// for mouse: check if both "adaptive" and "flat" profile are avaliable
46+
// for mouse: check if both "adaptive", "flat" and "custom" profile are avaliable
4747
func libinputIsBothAccelProfileAvaliable(id int32) bool {
48-
available, err := getInt8Prop(id, libinputPropAccelProfileAvaliable, 2)
48+
available, err := getInt8Prop(id, libinputPropAccelProfileAvaliable, 3)
4949
if err != nil {
5050
return false
5151
}
5252

53-
return (available[0] == 1) && (available[1] == 1)
53+
return (available[0] == 1) && (available[1] == 1) && (available[2] == 1)
5454
}
5555

56-
// for mouse: get enabled accel profile, in order "adaptive", "flat".
57-
func libinputGetAccelProfile(id int32) (bool, bool) {
58-
enabled, err := getInt8Prop(id, libinputPropAccelProfileEnabled, 2)
56+
// for mouse: get enabled accel profile, in order "adaptive", "flat", "custom".
57+
func libinputGetAccelProfile(id int32) (bool, bool, bool) {
58+
enabled, err := getInt8Prop(id, libinputPropAccelProfileEnabled, 3)
5959
if err != nil {
60-
return false, false
60+
return false, false, false
6161
}
6262

63-
return enabled[0] == 1, enabled[1] == 1
63+
return enabled[0] == 1, enabled[1] == 1, enabled[2] == 1
6464
}
6565

66-
// for mouse: set enabled accel profile, in order "adaptive", "flat".
66+
// for mouse: set enabled accel profile, in order "adaptive", "flat", "custom".
6767
func libinputSetAccelProfile(id int32, useAdaptiveProfile bool) error {
6868
if !libinputIsBothAccelProfileAvaliable(id) {
6969
return errors.New("dde-api: device doesn't support both accel profile")
7070
}
7171

72-
prop, err := getInt8Prop(id, libinputPropAccelProfileEnabled, 2)
72+
prop, err := getInt8Prop(id, libinputPropAccelProfileEnabled, 3)
7373
if err != nil {
7474
return err
7575
}
7676

7777
if useAdaptiveProfile {
7878
prop[0] = 1
7979
prop[1] = 0
80+
prop[2] = 0
8081
} else {
8182
prop[0] = 0
8283
prop[1] = 1
84+
prop[2] = 0
8385
}
8486

8587
return utils.SetInt8Prop(id, libinputPropAccelProfileEnabled, prop)

dxinput/mouse.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,14 @@ func (m *Mouse) IsAdaptiveAccelProfileEnabled() bool {
129129
if globalWayland {
130130
return kwayland.CanAdaptiveAccelProfile(fmt.Sprintf("%s%d", kwayland.SysNamePrefix, m.Id))
131131
}
132-
adaptive, _ := libinputGetAccelProfile(m.Id)
132+
adaptive, _, _ := libinputGetAccelProfile(m.Id)
133133
return adaptive
134134
}
135135

136136
// EnableMiddleButtonEmulation enable mouse middle button emulation
137137
// "Evdev Middle Button Emulation"
138-
// 1 boolean value (8 bit, 0 or 1).
138+
//
139+
// 1 boolean value (8 bit, 0 or 1).
139140
func (m *Mouse) EnableMiddleButtonEmulation(enabled bool) error {
140141
if enabled == m.CanMiddleButtonEmulation() {
141142
return nil
@@ -176,7 +177,8 @@ func (m *Mouse) CanMiddleButtonEmulation() bool {
176177

177178
// SetMiddleButtonEmulationTimeout set middle button emulation timeout
178179
// "Evdev Middle Button Timeout"
179-
// 1 16-bit positive value.
180+
//
181+
// 1 16-bit positive value.
180182
func (m *Mouse) SetMiddleButtonEmulationTimeout(timeout int16) error {
181183
if m.isLibinputUsed || globalWayland {
182184
return fmt.Errorf("Libinput unsupport the property")
@@ -204,7 +206,8 @@ func (m *Mouse) MiddleButtonEmulationTimeout() (int16, error) {
204206

205207
// EnableWheelEmulation enable mouse wheel emulation
206208
// "Evdev Wheel Emulation"
207-
// 1 boolean value (8 bit, 0 or 1).
209+
//
210+
// 1 boolean value (8 bit, 0 or 1).
208211
func (m *Mouse) EnableWheelEmulation(enabled bool) error {
209212
if enabled == m.CanWheelEmulation() {
210213
return nil
@@ -252,7 +255,8 @@ func (m *Mouse) CanWheelEmulation() bool {
252255

253256
// SetWheelEmulationButton set wheel emulation button
254257
// "Evdev Wheel Emulation Button"
255-
// 1 8-bit value, allowed range 0-32, 0 disables the button.
258+
//
259+
// 1 8-bit value, allowed range 0-32, 0 disables the button.
256260
func (m *Mouse) SetWheelEmulationButton(btnNum int8) error {
257261
old, _ := m.WheelEmulationButton()
258262
if btnNum == old {
@@ -289,7 +293,8 @@ func (m *Mouse) WheelEmulationButton() (int8, error) {
289293

290294
// SetWheelEmulationTimeout set wheel emulation timeout
291295
// "Evdev Wheel Emulation Timeout"
292-
// 1 16-bit positive value.
296+
//
297+
// 1 16-bit positive value.
293298
func (m *Mouse) SetWheelEmulationTimeout(timeout int16) error {
294299
if m.isLibinputUsed || globalWayland {
295300
return fmt.Errorf("Libinput unsupport the property")

0 commit comments

Comments
 (0)