Skip to content

Commit

Permalink
Scroll and click modes cannot be in superposition
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGriffiths committed May 31, 2024
1 parent 229f4db commit 4565029
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 58 deletions.
12 changes: 6 additions & 6 deletions include/common/mir/input/mir_touchpad_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct MirTouchpadConfig
MirTouchpadConfig(MirTouchpadConfig const& other);
MirTouchpadConfig& operator=(MirTouchpadConfig const& other);
~MirTouchpadConfig();
MirTouchpadConfig(MirTouchpadClickModes click_mode,
MirTouchpadScrollModes scroll_mode,
MirTouchpadConfig(MirTouchpadClickMode click_mode,
MirTouchpadScrollMode scroll_mode,
int button_down_scroll_button,
bool tap_to_click,
bool disable_while_typing,
Expand All @@ -41,13 +41,13 @@ struct MirTouchpadConfig
/*!
* The click mode defines when the touchpad generates software emulated button events.
*/
MirTouchpadClickModes click_mode() const;
void click_mode(MirTouchpadClickModes) ;
MirTouchpadClickMode click_mode() const;
void click_mode(MirTouchpadClickMode modes) ;
/*!
* The scroll mode defines when the touchpad generates scroll events instead of pointer motion events.
*/
MirTouchpadScrollModes scroll_mode() const;
void scroll_mode(MirTouchpadScrollModes);
MirTouchpadScrollMode scroll_mode() const;
void scroll_mode(MirTouchpadScrollMode mode);

/*!
* Configures the button used for the on-button-down scroll mode
Expand Down
2 changes: 0 additions & 2 deletions include/core/mir_toolkit/mir_input_device_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ typedef enum MirTouchpadClickMode
mir_touchpad_click_mode_area_to_click = 1 << 0,
mir_touchpad_click_mode_finger_count = 1 << 1
} MirTouchpadClickMode;
typedef unsigned int MirTouchpadClickModes;

/**
* MirTouchpadScrollMode configures how the touchpad should generate scroll
Expand All @@ -83,7 +82,6 @@ typedef enum MirTouchpadScrollMode
mir_touchpad_scroll_mode_edge_scroll = 1 << 1,
mir_touchpad_scroll_mode_button_down_scroll = 1 << 2
} MirTouchpadScrollMode;
typedef unsigned int MirTouchpadScrollModes;

/**
* Mapping modes for touchscreen devices. The mode defines how coordinates
Expand Down
17 changes: 6 additions & 11 deletions include/platform/mir/input/touchpad_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,18 @@ int const no_scroll_button = 0;
struct TouchpadSettings
{
TouchpadSettings() {}
MirTouchpadClickModes click_mode{mir_touchpad_click_mode_finger_count};
MirTouchpadScrollModes scroll_mode{mir_touchpad_scroll_mode_two_finger_scroll};

bool operator==(TouchpadSettings const& rhs) const = default;
bool operator!=(TouchpadSettings const& rhs) const = default;

MirTouchpadClickMode click_mode{mir_touchpad_click_mode_finger_count};
MirTouchpadScrollMode scroll_mode{mir_touchpad_scroll_mode_two_finger_scroll};
int button_down_scroll_button{no_scroll_button};
bool tap_to_click{true};
bool disable_while_typing{false};
bool disable_with_mouse{false};
bool middle_mouse_button_emulation{true};
};

inline bool operator==(TouchpadSettings const& lhs, TouchpadSettings const& rhs)
{
return lhs.click_mode == rhs.click_mode && lhs.scroll_mode == rhs.scroll_mode &&
lhs.button_down_scroll_button == rhs.button_down_scroll_button && lhs.tap_to_click == rhs.tap_to_click &&
lhs.disable_while_typing == rhs.disable_while_typing && lhs.disable_with_mouse == rhs.disable_with_mouse &&
lhs.middle_mouse_button_emulation == rhs.middle_mouse_button_emulation;
}

}
}

Expand Down
33 changes: 17 additions & 16 deletions src/common/input/mir_touchpad_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
struct MirTouchpadConfig::Implementation
{
Implementation() = default;
Implementation(MirTouchpadClickModes click_mode,
MirTouchpadScrollModes scroll_mode,
Implementation(MirTouchpadClickMode click_mode,
MirTouchpadScrollMode scroll_mode,
int button_down_scroll_button,
bool tap_to_click,
bool middle_mouse_button_emulation,
Expand All @@ -36,8 +36,8 @@ struct MirTouchpadConfig::Implementation
disable_while_typing{disable_while_typing}
{
}
MirTouchpadClickModes click_mode{mir_touchpad_click_mode_finger_count};
MirTouchpadScrollModes scroll_mode{mir_touchpad_scroll_mode_two_finger_scroll};
MirTouchpadClickMode click_mode{mir_touchpad_click_mode_finger_count};
MirTouchpadScrollMode scroll_mode{mir_touchpad_scroll_mode_two_finger_scroll};
int button_down_scroll_button{0};
bool tap_to_click{true};
bool middle_mouse_button_emulation{true};
Expand Down Expand Up @@ -68,13 +68,14 @@ MirTouchpadConfig& MirTouchpadConfig::operator=(MirTouchpadConfig const& other)

MirTouchpadConfig::~MirTouchpadConfig() = default;

MirTouchpadConfig::MirTouchpadConfig(MirTouchpadClickModes click_mode,
MirTouchpadScrollModes scroll_mode,
int button_down_scroll_button,
bool tap_to_click,
bool disable_while_typing,
bool disable_with_mouse,
bool middle_mouse_button_emulation)
MirTouchpadConfig::MirTouchpadConfig(
MirTouchpadClickMode click_mode,
MirTouchpadScrollMode scroll_mode,
int button_down_scroll_button,
bool tap_to_click,
bool disable_while_typing,
bool disable_with_mouse,
bool middle_mouse_button_emulation)
: impl{std::make_unique<Implementation>(
click_mode,
scroll_mode,
Expand All @@ -87,24 +88,24 @@ MirTouchpadConfig::MirTouchpadConfig(MirTouchpadClickModes click_mode,
{
}

MirTouchpadClickModes MirTouchpadConfig::click_mode() const
MirTouchpadClickMode MirTouchpadConfig::click_mode() const
{
return impl->click_mode;
}

void MirTouchpadConfig::click_mode(MirTouchpadClickModes modes)
void MirTouchpadConfig::click_mode(MirTouchpadClickMode modes)
{
impl->click_mode = modes;
}

MirTouchpadScrollModes MirTouchpadConfig::scroll_mode() const
MirTouchpadScrollMode MirTouchpadConfig::scroll_mode() const
{
return impl->scroll_mode;
}

void MirTouchpadConfig::scroll_mode(MirTouchpadScrollModes modes)
void MirTouchpadConfig::scroll_mode(MirTouchpadScrollMode mode)
{
impl->scroll_mode = modes;
impl->scroll_mode = mode;
}

int MirTouchpadConfig::button_down_scroll_button() const
Expand Down
22 changes: 13 additions & 9 deletions src/miral/input_device_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class InputDeviceConfig : public mir::input::InputDeviceObserver
std::optional<double> mouse_scroll_speed_scale,
std::optional<double> touchpad_cursor_acceleration_bias,
std::optional<double> touchpad_scroll_speed_scale,
std::optional<MirTouchpadClickModes> click_mode,
std::optional<MirTouchpadScrollModes> scroll_mode);
std::optional<MirTouchpadClickMode> click_mode,
std::optional<MirTouchpadScrollMode> scroll_mode);
void device_added(std::shared_ptr<mi::Device> const& device) override;
void device_changed(std::shared_ptr<mi::Device> const&) override {}
void device_removed(std::shared_ptr<mi::Device> const&) override {}
Expand All @@ -64,8 +64,8 @@ class InputDeviceConfig : public mir::input::InputDeviceObserver
std::optional<double> const mouse_scroll_speed_scale;
std::optional<double> const touchpad_cursor_acceleration_bias;
std::optional<double> const touchpad_scroll_speed_scale;
std::optional<MirTouchpadClickModes> const click_mode;
std::optional<MirTouchpadScrollModes> const scroll_mode;
std::optional<MirTouchpadClickMode> const click_mode;
std::optional<MirTouchpadScrollMode> const scroll_mode;
std::optional<bool> const tap_to_click;
};

Expand All @@ -87,6 +87,7 @@ char const* const touchpad_scroll_mode_none = "none";

char const* const touchpad_click_mode_opt= "touchpad-click-mode";

char const* const touchpad_click_mode_none = "none";
char const* const touchpad_click_mode_area = "area";
char const* const touchpad_click_mode_finger_count = "finger-count";
}
Expand Down Expand Up @@ -200,18 +201,21 @@ void miral::add_input_device_configuration(::mir::Server& server)
}
};

// TODO options are not exclusive
auto convert_to_click_mode = [](std::optional<std::string> const& opt_val)
-> std::optional<MirTouchpadClickMode>
{
if (opt_val)
{
auto val = *opt_val;
if (val == touchpad_click_mode_finger_count)
if (val == touchpad_click_mode_none)
{
return mir_touchpad_click_mode_none;
}
else if (val == touchpad_click_mode_finger_count)
{
return mir_touchpad_click_mode_finger_count;
}
if (val == touchpad_click_mode_area)
else if (val == touchpad_click_mode_area)
{
return mir_touchpad_click_mode_area_to_click;
}
Expand Down Expand Up @@ -251,8 +255,8 @@ InputDeviceConfig::InputDeviceConfig(std::optional<bool> disable_while_typing,
std::optional<double> mouse_scroll_speed_scale,
std::optional<double> touchpad_cursor_acceleration_bias,
std::optional<double> touchpad_scroll_speed_scale,
std::optional<MirTouchpadClickModes> click_mode,
std::optional<MirTouchpadClickModes> scroll_mode)
std::optional<MirTouchpadClickMode> click_mode,
std::optional<MirTouchpadScrollMode> scroll_mode)
: disable_while_typing{disable_while_typing}, mouse_profile{mouse_profile},
mouse_cursor_acceleration_bias{mouse_cursor_acceleration_bias},
mouse_scroll_speed_scale{mouse_scroll_speed_scale},
Expand Down
56 changes: 42 additions & 14 deletions src/platforms/evdev/libinput_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,21 @@ mir::optional_value<mi::TouchpadSettings> mie::LibInputDevice::get_touchpad_sett
return {};

auto dev = device();
auto click_modes = libinput_device_config_click_get_method(dev);

TouchpadSettings settings;

settings.click_mode = mir_touchpad_click_mode_none;
if (click_modes & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)
settings.click_mode |= mir_touchpad_click_mode_area_to_click;
if (click_modes & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER)
settings.click_mode |= mir_touchpad_click_mode_finger_count;
switch (libinput_device_config_click_get_method(dev))
{
case LIBINPUT_CONFIG_CLICK_METHOD_NONE:
settings.click_mode = mir_touchpad_click_mode_none;
break;
case LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS:
settings.click_mode = mir_touchpad_click_mode_area_to_click;
break;
case LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER:
settings.click_mode = mir_touchpad_click_mode_finger_count;
break;
}

switch (libinput_device_config_scroll_get_method(dev))
{
Expand Down Expand Up @@ -592,7 +598,7 @@ mir::optional_value<mi::TouchpadSettings> mie::LibInputDevice::get_touchpad_sett

namespace
{
void apply_scroll_mode(libinput_device* dev, MirTouchpadScrollModes scroll_mode)
void apply_scroll_mode(libinput_device* dev, MirTouchpadScrollMode scroll_mode)
{
auto set_method = [dev](libinput_config_scroll_method method)
{
Expand Down Expand Up @@ -623,6 +629,34 @@ void apply_scroll_mode(libinput_device* dev, MirTouchpadScrollModes scroll_mode)
break;
}
}

void apply_click_mode(libinput_device* dev, MirTouchpadClickMode click_mode)
{
auto set_method = [dev](libinput_config_click_method method)
{
if (LIBINPUT_CONFIG_STATUS_SUCCESS != libinput_device_config_click_set_method(dev, method))
{
auto const default_method = libinput_device_config_click_get_default_method(dev);
mir::log_info("On device '%s': Failed to set click method to %d, using default (%d)", libinput_device_get_name(dev), method, default_method);
libinput_device_config_click_set_method(dev, default_method);
}
};
switch (click_mode)
{
case mir_touchpad_click_mode_none:
set_method(LIBINPUT_CONFIG_CLICK_METHOD_NONE);
break;

case mir_touchpad_click_mode_area_to_click:
{
set_method(LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
break;
}
case mir_touchpad_click_mode_finger_count:
set_method(LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
break;
}
}
}

void mie::LibInputDevice::apply_settings(mi::TouchpadSettings const& settings)
Expand All @@ -635,13 +669,7 @@ void mie::LibInputDevice::apply_settings(mi::TouchpadSettings const& settings)
libinput_device_config_scroll_set_button(dev, scroll_button);
}

uint32_t click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
if (settings.click_mode & mir_touchpad_click_mode_area_to_click)
click_method |= LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
if (settings.click_mode & mir_touchpad_click_mode_finger_count)
click_method |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;

libinput_device_config_click_set_method(dev, static_cast<libinput_config_click_method>(click_method));
apply_click_mode(dev, settings.click_mode);

libinput_device_config_tap_set_enabled(
dev, settings.tap_to_click ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED);
Expand Down

0 comments on commit 4565029

Please sign in to comment.