Skip to content

Commit

Permalink
live-input-configuation (#3531)
Browse files Browse the repository at this point in the history
Allow servers to dynamically update input configuration.

There's a very simple "mir_demo_server.input" addition to
`mir_demo_server` to exercise part of this API, but that is not intended
prototype.
  • Loading branch information
AlanGriffiths authored Sep 3, 2024
2 parents 8342108 + 551eb06 commit ef592f8
Show file tree
Hide file tree
Showing 10 changed files with 740 additions and 74 deletions.
43 changes: 43 additions & 0 deletions debian/libmiral7.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,47 @@ libmiral.so.7 libmiral7 #MINVER#
(c++)"miral::IdleListener::on_off(std::function<void ()> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::IdleListener::on_wake(std::function<void ()> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::IdleListener::operator()(mir::Server&) const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::InputConfiguration()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::Mouse()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::Mouse(miral::InputConfiguration::Mouse const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::acceleration() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::acceleration(std::optional<MirPointerAcceleration> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::acceleration_bias() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::acceleration_bias(std::optional<double> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::handedness() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::handedness(std::optional<MirPointerHandedness> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::hscroll_speed() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::hscroll_speed(std::optional<double> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::operator=(miral::InputConfiguration::Mouse)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::vscroll_speed() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::vscroll_speed(std::optional<double> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Mouse::~Mouse()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::Touchpad()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::Touchpad(miral::InputConfiguration::Touchpad const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::acceleration() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::acceleration(std::optional<MirPointerAcceleration> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::acceleration_bias() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::acceleration_bias(std::optional<double> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::click_mode() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::click_mode(std::optional<MirTouchpadClickMode> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::disable_while_typing() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::disable_while_typing(std::optional<bool> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::disable_with_external_mouse() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::disable_with_external_mouse(std::optional<bool> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::hscroll_speed() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::hscroll_speed(std::optional<double> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::operator=(miral::InputConfiguration::Touchpad)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::scroll_mode() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::scroll_mode(std::optional<MirTouchpadScrollMode> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::tap_to_click() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::tap_to_click(std::optional<bool> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::vscroll_speed() const@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::vscroll_speed(std::optional<double> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::Touchpad::~Touchpad()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::mouse()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::mouse(miral::InputConfiguration::Mouse const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::operator()(mir::Server&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::touchpad()@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::touchpad(miral::InputConfiguration::Touchpad const&)@MIRAL_5.1" 5.1.0
(c++)"miral::InputConfiguration::~InputConfiguration()@MIRAL_5.1" 5.1.0
(c++)"miral::WindowManagerTools::move_cursor_to(mir::geometry::generic::Point<float>)@MIRAL_5.1" 5.1.0
42 changes: 39 additions & 3 deletions examples/mir_demo_server/server_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@

#include <miral/cursor_theme.h>
#include <miral/display_configuration_option.h>
#include <miral/input_configuration.h>
#include <miral/minimal_window_manager.h>
#include <miral/config_file.h>
#include <miral/runner.h>
#include <miral/set_window_management_policy.h>
#include <miral/wayland_extensions.h>
#include <miral/x11_support.h>

#include "mir/abnormal_exit.h"
#include "mir/server.h"
#include "mir/main_loop.h"
#include "mir/report_exception.h"
#include "mir/options/option.h"
#include "mir/report_exception.h"
#include "mir/server.h"

#include <boost/exception/diagnostic_information.hpp>

#include <chrono>
#include <cstdlib>
#include <iostream>

namespace mir { class AbnormalExit; }

Expand Down Expand Up @@ -116,6 +119,38 @@ try
{
miral::MirRunner runner{argc, argv, "mir/mir_demo_server.config"};

miral::InputConfiguration input_configuration;

miral::ConfigFile test{runner, "mir_demo_server.input", miral::ConfigFile::Mode::reload_on_change,
[&input_configuration](auto& in, auto path)
{
std::cout << "** Reloading: " << path << std::endl;

auto mouse = input_configuration.mouse();
auto touchpad = input_configuration.touchpad();

for (std::string line; std::getline(in, line);)
{
std::cout << line << std::endl;

if (line == "mir_pointer_handedness_right")
mouse.handedness(mir_pointer_handedness_right);
if (line == "mir_pointer_handedness_left")
mouse.handedness(mir_pointer_handedness_left);

if (line == "mir_touchpad_scroll_mode_none")
touchpad.scroll_mode(mir_touchpad_scroll_mode_none);
if (line == "mir_touchpad_scroll_mode_two_finger_scroll")
touchpad.scroll_mode(mir_touchpad_scroll_mode_two_finger_scroll);
if (line == "mir_touchpad_scroll_mode_edge_scroll")
touchpad.scroll_mode(mir_touchpad_scroll_mode_edge_scroll);
if (line == "mir_touchpad_scroll_mode_button_down_scroll")
touchpad.scroll_mode(mir_touchpad_scroll_mode_button_down_scroll);
}
input_configuration.mouse(mouse);
input_configuration.touchpad(touchpad);
}};

runner.set_exception_handler(exception_handler);

std::function<void()> shutdown_hook{[]{}};
Expand All @@ -138,7 +173,8 @@ try
add_timeout_option_to,
miral::CursorTheme{"default:DMZ-White"},
input_filters,
test_runner
test_runner,
input_configuration,
});

// Propagate any test failure
Expand Down
125 changes: 125 additions & 0 deletions include/miral/miral/input_configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MIRAL_INPUT_CONFIGURATION_H
#define MIRAL_INPUT_CONFIGURATION_H

#include <mir_toolkit/mir_input_device_types.h>

#include <optional>
#include <memory>

namespace mir { class Server; }


namespace miral
{
/** Input configuration.
* Allow servers to make input configuration changes at runtime
* \remark Since MirAL 5.1
*/
class InputConfiguration
{
public:
InputConfiguration();
~InputConfiguration();
void operator()(mir::Server& server);

class Mouse;
class Touchpad;

auto mouse() -> Mouse;
void mouse(Mouse const& val);
auto touchpad() -> Touchpad;
void touchpad(Touchpad const& val);

private:
class Self;
std::shared_ptr<Self> self;
};

/** Input configuration for mouse pointer devices
* \remark Since MirAL 5.1
*/
class InputConfiguration::Mouse
{
public:
Mouse();
~Mouse();

Mouse(Mouse const& that);
auto operator=(Mouse that) -> Mouse&;

auto handedness() const -> std::optional<MirPointerHandedness>;
auto acceleration() const -> std::optional<MirPointerAcceleration>;
auto acceleration_bias() const -> std::optional<double>;
auto vscroll_speed() const -> std::optional<double>;
auto hscroll_speed() const -> std::optional<double>;

void handedness(std::optional<MirPointerHandedness>const& val);
void acceleration(std::optional<MirPointerAcceleration>const& val);
/// \note val will be clamped to the range [-1.0, 1.0]
void acceleration_bias(std::optional<double>const& val);
void vscroll_speed(std::optional<double>const& val);
void hscroll_speed(std::optional<double>const& val);

private:
friend class InputConfiguration::Self;
class Self;
std::unique_ptr<Self> self;
};

/** Input configuration for touchpad devices
* \remark Since MirAL 5.1
*/
class InputConfiguration::Touchpad
{
public:
Touchpad();
~Touchpad();

Touchpad(Touchpad const& that);
auto operator=(Touchpad that) -> Touchpad&;

auto disable_while_typing() const -> std::optional<bool>;
auto disable_with_external_mouse() const -> std::optional<bool>;
auto acceleration() const -> std::optional<MirPointerAcceleration>;
auto acceleration_bias() const -> std::optional<double>;
auto vscroll_speed() const -> std::optional<double>;
auto hscroll_speed() const -> std::optional<double>;
auto click_mode() const -> std::optional<MirTouchpadClickMode>;
auto scroll_mode() const -> std::optional<MirTouchpadScrollMode>;
auto tap_to_click() const -> std::optional<bool>;

void disable_while_typing(std::optional<bool>const& val);
void disable_with_external_mouse(std::optional<bool>const& val);
void acceleration(std::optional<MirPointerAcceleration>const& val);
/// \note val will be clamped to the range [-1.0, 1.0]
void acceleration_bias(std::optional<double>const& val);
void vscroll_speed(std::optional<double>const& val);
void hscroll_speed(std::optional<double>const& val);
void click_mode(std::optional<MirTouchpadClickMode>const& val);
void scroll_mode(std::optional<MirTouchpadScrollMode>const& val);
void tap_to_click(std::optional<bool>const& val);

private:
friend class InputConfiguration::Self;
class Self;
std::shared_ptr<Self> self;
};
}

#endif //MIRAL_INPUT_CONFIGURATION_H
3 changes: 2 additions & 1 deletion src/miral/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_library(miral-internal STATIC
system_compositor_window_manager.cpp system_compositor_window_manager.h
display_configuration_listeners.cpp display_configuration_listeners.h
fd_manager.cpp fd_manager.h
input_device_config.cpp input_device_config.h
input_device_config.cpp input_device_configuration_options.h input_device_config.h
launch_app.cpp launch_app.h
mru_window_list.cpp mru_window_list.h
open_desktop_entry.cpp open_desktop_entry.h
Expand Down Expand Up @@ -63,6 +63,7 @@ add_library(miral-external OBJECT
display_configuration.cpp ${miral_include}/miral/display_configuration.h
external_client.cpp ${miral_include}/miral/external_client.h
idle_listener.cpp ${miral_include}/miral/idle_listener.h
input_configuration.cpp ${miral_include}/miral/input_configuration.h
keymap.cpp ${miral_include}/miral/keymap.h
minimal_window_manager.cpp ${miral_include}/miral/minimal_window_manager.h
display_configuration_option.cpp ${miral_include}/miral/display_configuration_option.h
Expand Down
Loading

0 comments on commit ef592f8

Please sign in to comment.