Skip to content

Commit

Permalink
Make repeat_rate optional in {frontend,shell}::KeyboardHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
tarek-y-ismail committed Jan 31, 2025
1 parent 4f16caf commit d484803
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/server/mir/shell/keyboard_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef MIR_SHELL_KEYBOARD_HELPER_
#define MIR_SHELL_KEYBOARD_HELPER_

#include <optional>
namespace mir
{
namespace shell
Expand All @@ -25,7 +26,7 @@ class KeyboardHelper
{
public:
virtual ~KeyboardHelper() = default;
virtual void repeat_info_changed(int rate, int delay) const = 0;
virtual void repeat_info_changed(std::optional<int> rate, int delay) const = 0;
};
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/frontend_wayland/keyboard_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mf::KeyboardHelper::KeyboardHelper(
KeyboardCallbacks* callbacks,
std::shared_ptr<mi::Keymap> const& initial_keymap,
std::shared_ptr<input::Seat> const& seat,
int default_repeat_rate,
std::optional<int> default_repeat_rate,
int default_repeat_delay)
: callbacks{callbacks},
mir_seat{seat},
Expand All @@ -52,7 +52,7 @@ mf::KeyboardHelper::KeyboardHelper(
*/
set_keymap(initial_keymap);

callbacks->send_repeat_info(default_repeat_rate, default_repeat_delay);
repeat_info_changed(default_repeat_rate, default_repeat_delay);
}

mf::KeyboardHelper::~KeyboardHelper() = default;
Expand Down Expand Up @@ -103,9 +103,9 @@ void mf::KeyboardHelper::refresh_modifiers()
set_modifiers(mir_seat->xkb_modifiers());
}

void mf::KeyboardHelper::repeat_info_changed(int rate, int delay) const
void mf::KeyboardHelper::repeat_info_changed(std::optional<int> rate, int delay) const
{
callbacks->send_repeat_info(rate, delay);
callbacks->send_repeat_info(rate.value_or(0), delay);
}

void mf::KeyboardHelper::handle_keyboard_event(std::shared_ptr<MirKeyboardEvent const> const& event)
Expand Down
5 changes: 3 additions & 2 deletions src/server/frontend_wayland/keyboard_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "wayland_wrapper.h"
#include "mir/events/xkb_modifiers.h"

#include <optional>
#include <vector>
#include <functional>

Expand Down Expand Up @@ -75,7 +76,7 @@ class KeyboardHelper : public mir::shell::KeyboardHelper
/// Updates the modifiers from the seat
void refresh_modifiers();

void repeat_info_changed(int rate, int delay) const override;
void repeat_info_changed(std::optional<int> rate, int delay) const override;

private:
friend class mir::frontend::WlSeat;
Expand All @@ -84,7 +85,7 @@ class KeyboardHelper : public mir::shell::KeyboardHelper
KeyboardCallbacks* keybaord_impl,
std::shared_ptr<mir::input::Keymap> const& initial_keymap,
std::shared_ptr<input::Seat> const& seat,
int default_repeat_rate,
std::optional<int> default_repeat_rate,
int default_repeat_delay);

void handle_keyboard_event(std::shared_ptr<MirKeyboardEvent const> const& event);
Expand Down
2 changes: 1 addition & 1 deletion src/server/frontend_wayland/wl_seat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ auto mf::WlSeat::make_keyboard_helper(KeyboardCallbacks* callbacks) -> std::shar
// https://wayland.app/protocols/wayland#wl_keyboard:event:repeat_info
// " A rate of zero will disable any repeating (regardless of the value of
// delay)."
auto const default_repeat_rate = accessibility_manager->repeat_rate().value_or(0);
auto const default_repeat_rate = accessibility_manager->repeat_rate();
auto const default_repeat_delay = accessibility_manager->repeat_delay();
auto const keyboard_helper = std::shared_ptr<KeyboardHelper>(new KeyboardHelper(callbacks, keymap, seat, default_repeat_rate, default_repeat_delay));
accessibility_manager->register_keyboard_helper(keyboard_helper);
Expand Down
2 changes: 1 addition & 1 deletion src/server/shell/accessibility_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ void mir::shell::AccessibilityManager::override_key_repeat_settings(bool enable)

void mir::shell::AccessibilityManager::notify_helpers() const {
for(auto const& helper: keyboard_helpers)
helper->repeat_info_changed(repeat_rate_, repeat_delay_);
helper->repeat_info_changed(repeat_rate(), repeat_delay());
}

0 comments on commit d484803

Please sign in to comment.