Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get 'libinput Accel Profiles Available' failed #126

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 12 additions & 10 deletions dxinput/libinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,45 @@ const (
libinputPropDisableWhileTyping = "libinput Disable While Typing Enabled"
)

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

return (available[0] == 1) && (available[1] == 1)
return (available[0] == 1) && (available[1] == 1) && (available[2] == 1)
}

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

return enabled[0] == 1, enabled[1] == 1
return enabled[0] == 1, enabled[1] == 1, enabled[2] == 1
}

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

prop, err := getInt8Prop(id, libinputPropAccelProfileEnabled, 2)
prop, err := getInt8Prop(id, libinputPropAccelProfileEnabled, 3)
if err != nil {
return err
}

if useAdaptiveProfile {
prop[0] = 1
prop[1] = 0
prop[2] = 0
} else {
prop[0] = 0
prop[1] = 1
prop[2] = 0
}

return utils.SetInt8Prop(id, libinputPropAccelProfileEnabled, prop)
Expand Down
17 changes: 11 additions & 6 deletions dxinput/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ func (m *Mouse) IsAdaptiveAccelProfileEnabled() bool {
if globalWayland {
return kwayland.CanAdaptiveAccelProfile(fmt.Sprintf("%s%d", kwayland.SysNamePrefix, m.Id))
}
adaptive, _ := libinputGetAccelProfile(m.Id)
adaptive, _, _ := libinputGetAccelProfile(m.Id)
return adaptive
}

// EnableMiddleButtonEmulation enable mouse middle button emulation
// "Evdev Middle Button Emulation"
// 1 boolean value (8 bit, 0 or 1).
//
// 1 boolean value (8 bit, 0 or 1).
func (m *Mouse) EnableMiddleButtonEmulation(enabled bool) error {
if enabled == m.CanMiddleButtonEmulation() {
return nil
Expand Down Expand Up @@ -176,7 +177,8 @@ func (m *Mouse) CanMiddleButtonEmulation() bool {

// SetMiddleButtonEmulationTimeout set middle button emulation timeout
// "Evdev Middle Button Timeout"
// 1 16-bit positive value.
//
// 1 16-bit positive value.
func (m *Mouse) SetMiddleButtonEmulationTimeout(timeout int16) error {
if m.isLibinputUsed || globalWayland {
return fmt.Errorf("Libinput unsupport the property")
Expand Down Expand Up @@ -204,7 +206,8 @@ func (m *Mouse) MiddleButtonEmulationTimeout() (int16, error) {

// EnableWheelEmulation enable mouse wheel emulation
// "Evdev Wheel Emulation"
// 1 boolean value (8 bit, 0 or 1).
//
// 1 boolean value (8 bit, 0 or 1).
func (m *Mouse) EnableWheelEmulation(enabled bool) error {
if enabled == m.CanWheelEmulation() {
return nil
Expand Down Expand Up @@ -252,7 +255,8 @@ func (m *Mouse) CanWheelEmulation() bool {

// SetWheelEmulationButton set wheel emulation button
// "Evdev Wheel Emulation Button"
// 1 8-bit value, allowed range 0-32, 0 disables the button.
//
// 1 8-bit value, allowed range 0-32, 0 disables the button.
func (m *Mouse) SetWheelEmulationButton(btnNum int8) error {
old, _ := m.WheelEmulationButton()
if btnNum == old {
Expand Down Expand Up @@ -289,7 +293,8 @@ func (m *Mouse) WheelEmulationButton() (int8, error) {

// SetWheelEmulationTimeout set wheel emulation timeout
// "Evdev Wheel Emulation Timeout"
// 1 16-bit positive value.
//
// 1 16-bit positive value.
func (m *Mouse) SetWheelEmulationTimeout(timeout int16) error {
if m.isLibinputUsed || globalWayland {
return fmt.Errorf("Libinput unsupport the property")
Expand Down
Loading