File: fake_input_device_impl.h

package info (click to toggle)
mir 2.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,636 kB
  • sloc: cpp: 174,574; xml: 13,422; ansic: 8,221; python: 1,337; sh: 874; makefile: 216; javascript: 37
file content (118 lines) | stat: -rw-r--r-- 4,752 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * 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 MIR_TEST_FRAMEWORK_FAKE_INPUT_DEVICE_IMPL_H_
#define MIR_TEST_FRAMEWORK_FAKE_INPUT_DEVICE_IMPL_H_

#include "mir_test_framework/fake_input_device.h"

#include "mir/input/input_device.h"
#include "mir/input/pointer_settings.h"
#include "mir/input/touchscreen_settings.h"
#include "mir/input/input_device_info.h"
#include "mir/geometry/point.h"
#include "mir/geometry/displacement.h"

#include <mutex>
#include <functional>
#include <vector>

namespace mir
{
namespace input
{
class OutputInfo;
}
namespace dispatch
{
class ActionQueue;
}
}

namespace mir_test_framework
{
class FakeInputDeviceImpl : public FakeInputDevice
{
public:
    FakeInputDeviceImpl(mir::input::InputDeviceInfo const& info);
    void emit_device_removal() override;
    void emit_runtime_error() override;
    void emit_event(mir::input::synthesis::KeyParameters const& key_params) override;
    void emit_event(mir::input::synthesis::ButtonParameters const& button) override;
    void emit_event(mir::input::synthesis::MotionParameters const& motion) override;
    void emit_event(mir::input::synthesis::TouchParameters const& touch) override;
    void emit_touch_sequence(std::function<mir::input::synthesis::TouchParameters(int)> const& event_generator,
                             int count,
                             std::chrono::duration<double> delay) override;
    void emit_key_state(std::vector<uint32_t> const& key_syms) override;
    virtual void on_new_configuration_do(std::function<void(mir::input::InputDevice const& device)> callback) override;

private:
    class InputDevice : public mir::input::InputDevice
    {
    public:
        InputDevice(mir::input::InputDeviceInfo const& info,
                    std::shared_ptr<mir::dispatch::Dispatchable> const& dispatchable);

        void start(mir::input::InputSink* destination, mir::input::EventBuilder* builder) override;
        void stop() override;

        void synthesize_events(mir::input::synthesis::KeyParameters const& key_params);
        void synthesize_events(mir::input::synthesis::ButtonParameters const& button);
        void synthesize_events(mir::input::synthesis::MotionParameters const& motion);
        void synthesize_events(mir::input::synthesis::TouchParameters const& touch);

        void emit_key_state(std::vector<uint32_t> const& scan_codes);
        mir::input::InputDeviceInfo get_device_info() override
        {
            return info;
        }

        mir::optional_value<mir::input::PointerSettings> get_pointer_settings() const override;
        void apply_settings(mir::input::PointerSettings const& settings) override;
        mir::optional_value<mir::input::TouchpadSettings> get_touchpad_settings() const override;
        void apply_settings(mir::input::TouchpadSettings const& settings) override;
        mir::optional_value<mir::input::TouchscreenSettings> get_touchscreen_settings() const override;
        void apply_settings(mir::input::TouchscreenSettings const& settings) override;
        void set_apply_settings_callback(std::function<void(mir::input::InputDevice const&)> const& callback);

    private:
        MirPointerAction update_buttons(mir::input::synthesis::EventAction action, MirPointerButton button);
        void update_position(int rel_x, int rel_y);
        void map_touch_coordinates(float& x, float& y);
        mir::input::OutputInfo get_output_info() const;
        bool is_output_active() const;
        void trigger_callback() const;

        mir::input::InputSink* sink{nullptr};
        mir::input::EventBuilder* builder{nullptr};
        mir::input::InputDeviceInfo info;
        std::shared_ptr<mir::dispatch::Dispatchable> const queue;
        mir::geometry::PointF pos;
        mir::geometry::DisplacementF scroll;
        MirPointerButtons buttons;
        mir::input::PointerSettings settings;
        mir::input::TouchscreenSettings touchscreen;
        mutable std::mutex config_callback_mutex;
        std::function<void(mir::input::InputDevice const&)> callback;
    };
    std::shared_ptr<mir::dispatch::ActionQueue> queue;
    std::shared_ptr<InputDevice> device;
};

}

#endif