Skip to content

Commit

Permalink
Make AccessibilityManager aware of "enable-key-repeat"
Browse files Browse the repository at this point in the history
  • Loading branch information
tarek-y-ismail committed Jan 30, 2025
1 parent ca56673 commit 384afb6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/include/server/mir/shell/accessibility_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define MIR_SHELL_ACCESSIBILITY_MANAGER_H

#include <memory>
#include <optional>
#include <vector>

namespace mir
Expand All @@ -30,11 +31,12 @@ class AccessibilityManager
public:
void register_keyboard_helper(std::shared_ptr<shell::KeyboardHelper>);

int repeat_rate() const;
std::optional<int> repeat_rate() const;
int repeat_delay() const;

void repeat_rate(int new_rate);
void repeat_delay(int new_rate);
void override_key_repeat_settings(bool enable);

void notify_helpers() const;

Expand All @@ -44,6 +46,7 @@ class AccessibilityManager
// 25 rate and 600 delay are the default in Weston and Sway
int repeat_rate_{25};
int repeat_delay_{600};
bool enable_key_repeat{true};
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/server/frontend_wayland/wayland_default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "input_method_v1.h"
#include "input_method_v2.h"
#include "layer_shell_v1.h"
#include "mir/shell/accessibility_manager.h"
#include "mir_shell.h"
#include "pointer_constraints_unstable_v1.h"
#include "primary_selection_v1.h"
Expand Down Expand Up @@ -366,8 +367,9 @@ std::shared_ptr<mf::Connector>
enabled_wayland_extensions.begin(),
enabled_wayland_extensions.end()};

// TODO pass this to the accessibility manager
/* auto const enable_repeat = options->get<bool>(options::enable_key_repeat_opt); */
auto const enable_repeat = options->get<bool>(options::enable_key_repeat_opt);
the_accessibility_manager()->override_key_repeat_settings(enable_repeat);

auto const x11_enabled = options->is_set(mo::x11_display_opt) && options->get<bool>(mo::x11_display_opt);

return std::make_shared<mf::WaylandConnector>(
Expand Down
5 changes: 4 additions & 1 deletion src/server/frontend_wayland/wl_seat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ void mf::WlSeat::for_each_listener(mw::Client* client, std::function<void(WlTouc

auto mf::WlSeat::make_keyboard_helper(KeyboardCallbacks* callbacks) -> std::shared_ptr<KeyboardHelper>
{
auto const default_repeat_rate = accessibility_manager->repeat_rate();
// 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_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
11 changes: 10 additions & 1 deletion src/server/shell/accessibility_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
#include "mir/shell/accessibility_manager.h"
#include "mir/shell/keyboard_helper.h"

#include <optional>

void mir::shell::AccessibilityManager::register_keyboard_helper(std::shared_ptr<KeyboardHelper> helper)
{
keyboard_helpers.push_back(helper);
}

int mir::shell::AccessibilityManager::repeat_rate() const {
std::optional<int> mir::shell::AccessibilityManager::repeat_rate() const {
if(!enable_key_repeat)
return {};
return repeat_rate_;
}

Expand All @@ -38,6 +42,11 @@ void mir::shell::AccessibilityManager::repeat_delay(int new_delay) {
repeat_delay_ = new_delay;
}

void mir::shell::AccessibilityManager::override_key_repeat_settings(bool enable)
{
enable_key_repeat = enable;
}

void mir::shell::AccessibilityManager::notify_helpers() const {
for(auto const& helper: keyboard_helpers)
helper->repeat_info_changed(repeat_rate_, repeat_delay_);
Expand Down
1 change: 1 addition & 0 deletions src/server/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ global:
mir::shell::AbstractShell::surface_ready*;
mir::shell::AbstractShell::swap_z_order*;
mir::shell::AccessibilityManager::notify_helpers*;
mir::shell::AccessibilityManager::override_key_repeat_settings*;
mir::shell::AccessibilityManager::register_keyboard_helper*;
mir::shell::AccessibilityManager::repeat_delay*;
mir::shell::AccessibilityManager::repeat_rate*;
Expand Down

0 comments on commit 384afb6

Please sign in to comment.