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

Make key repeat and delay configurable #3730

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

tarek-y-ismail
Copy link
Contributor

@tarek-y-ismail tarek-y-ismail commented Jan 28, 2025

How to test:

  • Create a file at ~/.config/mir_demo_server.input with the following content:
repeat_rate=25
repeat_delay=600
  • Run mir demo server
  • Run a wayland compatible text editor or terminal (kgx), or and X application (xterm)
  • press and hold any key
  • Change repeat_rate to a higher or lower value and watch as the repeat rate speeds or slows down
  • Change repeat_delay to a higher or lower value and watch as the duration you need to hold the key down increases or decreases.

@tarek-y-ismail tarek-y-ismail self-assigned this Jan 28, 2025
@tarek-y-ismail tarek-y-ismail marked this pull request as ready for review January 28, 2025 17:03
@tarek-y-ismail tarek-y-ismail requested a review from a team as a code owner January 28, 2025 17:03
@tarek-y-ismail tarek-y-ismail marked this pull request as draft January 28, 2025 17:09
@tarek-y-ismail tarek-y-ismail force-pushed the MIRENG-892/configurable-key-repeat branch from 4712763 to 9299fb6 Compare January 29, 2025 08:34
@tarek-y-ismail tarek-y-ismail marked this pull request as ready for review January 29, 2025 09:08
Copy link
Collaborator

@AlanGriffiths AlanGriffiths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests for the new code?

A few things need shuffling around.

Also, it would be nice to split the ConfigFile changes into a separate, precursor, PR. (They should be uncontentious and quick to land)

include/miral/miral/config_file.h Outdated Show resolved Hide resolved
src/include/server/mir/frontend/keyboard_helper.h Outdated Show resolved Hide resolved
src/include/server/mir/shell/accessibility_manager.h Outdated Show resolved Hide resolved
src/server/frontend_wayland/CMakeLists.txt Outdated Show resolved Hide resolved
src/server/report/default_server_configuration.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@mattkae mattkae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty reasonable! I've got a few points for improvement

src/include/server/mir/frontend/keyboard_helper.h Outdated Show resolved Hide resolved
src/include/server/mir/shell/accessibility_manager.h Outdated Show resolved Hide resolved
src/server/report/default_server_configuration.cpp Outdated Show resolved Hide resolved
src/include/server/mir/shell/accessibility_manager.h Outdated Show resolved Hide resolved
src/server/shell/accessibility_manager.cpp Outdated Show resolved Hide resolved
@tarek-y-ismail tarek-y-ismail force-pushed the MIRENG-892/configurable-key-repeat branch from 9299fb6 to a6b1793 Compare January 30, 2025 12:43
@tarek-y-ismail tarek-y-ismail changed the base branch from main to config-file-load-after-server-init January 30, 2025 12:43
@tarek-y-ismail tarek-y-ismail force-pushed the MIRENG-892/configurable-key-repeat branch from a6b1793 to 55c6cb7 Compare January 30, 2025 13:01
@tarek-y-ismail tarek-y-ismail force-pushed the MIRENG-892/configurable-key-repeat branch from 55c6cb7 to 384afb6 Compare January 30, 2025 15:00
@tarek-y-ismail tarek-y-ismail force-pushed the config-file-load-after-server-init branch 2 times, most recently from f6f04ce to 6a0f1b9 Compare January 30, 2025 15:10
Copy link
Contributor

@mattkae mattkae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more questions, but looking good!


auto miral::InputConfiguration::Keyboard::operator=(Keyboard that) -> Keyboard&
{
std::swap(self, that.self);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would operator= be a swap? Shouldn't there be an overrided operator= on self so that we copy all of its values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I copied and pasted the touchpad code to keep everything consistent, so they also do the same thing...

I'm not sure why that is

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the canonical way to write an assignment operator in c++: copy into the parameter and swap with *this.

src/include/server/mir/shell/accessibility_manager.h Outdated Show resolved Hide resolved
src/server/report/default_server_configuration.cpp Outdated Show resolved Hide resolved
Comment on lines 51 to 52
for(auto const& helper: keyboard_helpers)
helper->repeat_info_changed(repeat_rate_, repeat_delay_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If enable_key_repeat is false, should repeat_rate_ be std::nullopt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to: https://wayland.app/protocols/wayland#wl_keyboard:event:repeat_info, "rate of zero will disable any repeating (regardless of the value of delay).". My interpretation was that we can just deliver the rate as an optional and the delay can be a normal value. It's then up to the user to interpret it. Which reminds me that I should use repeat_rate() here as well

@tarek-y-ismail
Copy link
Contributor Author

Note to self: Just came across this while working on something else, might be a good idea to check out

return input_dispatcher(
[this]()
{
std::chrono::milliseconds const key_repeat_timeout{500};
std::chrono::milliseconds const key_repeat_delay{50};
auto const options = the_options();
// lp:1675357: Disable generation of key repeat events on nested servers
auto enable_repeat = options->get<bool>(options::enable_key_repeat_opt);
auto const idle_poking_dispatcher = std::make_shared<mi::IdlePokingDispatcher>(
the_event_filter_chain_dispatcher(),
the_idle_hub());
auto const keyboard_resync_dispatcher =
std::make_shared<mi::KeyboardResyncDispatcher>(idle_poking_dispatcher);
return std::make_shared<mi::KeyRepeatDispatcher>(
keyboard_resync_dispatcher, the_main_loop(),
enable_repeat, key_repeat_timeout, key_repeat_delay, false);
});

tarek-y-ismail and others added 2 commits January 31, 2025 15:58
Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com>
@tarek-y-ismail tarek-y-ismail force-pushed the MIRENG-892/configurable-key-repeat branch from f66af7f to d484803 Compare January 31, 2025 13:59
@tarek-y-ismail
Copy link
Contributor Author

tarek-y-ismail commented Jan 31, 2025

Note to self: Just came across this while working on something else, might be a good idea to check out

Very confused what this does since repeat on both wayland and X seem to work without any modification to it.

Edit: From a quick skim, this seems to implement key repeat on the server. For wayland and X(wayland), the code changes here suffice.

Initially, the config file is loaded before the server starts. The
changes need some server components to be applied, so they aren't
applied at that stage.

The few lines added store the changes and apply them once the server
starts.
@tarek-y-ismail tarek-y-ismail changed the base branch from config-file-load-after-server-init to main January 31, 2025 16:04
Comment on lines 123 to +126
miral::InputConfiguration input_configuration;
auto mouse = input_configuration.mouse();
auto touchpad = input_configuration.touchpad();
auto keyboard = input_configuration.keyboard();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could grow a utility class that combines these and the repeated "apply" logic?

Also, we need to be careful: we're now accessing mouse, touchpad and keyboard on multiple threads.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having said that, I like the revised approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants