Mir
event_builder.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef MIROIL_EVENT_BUILDER_H
18#define MIROIL_EVENT_BUILDER_H
19
20#include <mir_toolkit/mir_input_device_types.h>
21#include <miral/version.h>
23#include <miral/toolkit_event.h>
24#else
25#include <mir_toolkit/event.h>
26#endif
27
28#include <chrono>
29#include <memory>
30#include <sys/types.h>
31#include <vector>
32
33struct MirEvent;
34struct MirInputEvent;
35
36namespace mir { typedef std::unique_ptr<MirEvent, void(*)(MirEvent*)> EventUPtr; }
37
38namespace miroil
39{
40
41/*
42 Creates Mir input events out of Qt input events
43
44 The class is splitt into miroil::EventBuilder which does the internal mir stuff,
45 and qtmir::EventBuilder which handles the qt stuff.
46
47 One important feature is that it's able to match a QInputEvent with the MirInputEvent that originated it, so
48 it can make a MirInputEvent version of a QInputEvent containing also information that the latter does not carry,
49 such as relative axis movement for pointer devices.
50*/
51
53
54public:
55 class EventInfo {
56 public:
57 void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp);
58
59 ulong timestamp;
61 std::vector<uint8_t> cookie;
62 float relative_x{0};
63 float relative_y{0};
64 };
65
66public:
68 virtual ~EventBuilder();
69
70 // add Touch event
71 void add_touch(MirEvent &event, MirTouchId touch_id, MirTouchAction action,
72 MirTouchTooltype tooltype, float x_axis_value, float y_axis_value,
73 float pressure_value, float touch_major_value, float touch_minor_value, float size_value);
74
75 // Key event
76 mir::EventUPtr make_key_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
77 std::vector<uint8_t> const& cookie, MirKeyboardAction action, xkb_keysym_t keysym,
78 int scan_code, MirInputEventModifiers modifiers);
79
80 // Touch event
81 mir::EventUPtr make_touch_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
82 std::vector<uint8_t> const& mac, MirInputEventModifiers modifiers);
83
84 // Pointer event
85 mir::EventUPtr make_pointer_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
86 std::vector<uint8_t> const& mac, MirInputEventModifiers modifiers, MirPointerAction action,
87 MirPointerButtons buttons_pressed,
88 float x_axis_value, float y_axis_value,
89 float hscroll_value, float vscroll_value,
90 float relative_x_value, float relative_y_value);
91
92 EventInfo * find_info(ulong qtTimestamp);
93
94 /* Stores information that cannot be carried by QInputEvents so that it can be fully
95 reconstructed later given the same qtTimestamp */
96 void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp);
97
98private:
99 /*
100 Ring buffer that stores information on recent MirInputEvents that cannot be carried by QInputEvents.
101
102 When MirInputEvents are dispatched through a QML scene, not all of its information can be carried
103 by QInputEvents. Some information is lost. Thus further on, if we want to transform a QInputEvent back into
104 its original MirInputEvent so that it can be consumed by a mir::scene::Surface and properly handled by mir clients
105 we have to reach out to this EventRegistry to get the missing bits.
106
107 Given the objective of this EventRegistry (MirInputEvent reconstruction after having gone through QQuickWindow input dispatch
108 as a QInputEvent), it stores information only about the most recent MirInputEvents.
109 */
110 std::vector<EventInfo> event_info_vector;
111 size_t next_index{0};
112 size_t event_info_count{0};
113};
114
115}
116
117#endif // MIROIL_EVENT_BUILDER_H
Definition: event_builder.h:55
float relative_x
Definition: event_builder.h:62
void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp)
float relative_y
Definition: event_builder.h:63
ulong timestamp
Definition: event_builder.h:59
std::vector< uint8_t > cookie
Definition: event_builder.h:61
MirInputDeviceId device_id
Definition: event_builder.h:60
Definition: event_builder.h:52
mir::EventUPtr make_key_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp, std::vector< uint8_t > const &cookie, MirKeyboardAction action, xkb_keysym_t keysym, int scan_code, MirInputEventModifiers modifiers)
void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp)
mir::EventUPtr make_touch_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp, std::vector< uint8_t > const &mac, MirInputEventModifiers modifiers)
EventInfo * find_info(ulong qtTimestamp)
void add_touch(MirEvent &event, MirTouchId touch_id, MirTouchAction action, MirTouchTooltype tooltype, float x_axis_value, float y_axis_value, float pressure_value, float touch_major_value, float touch_minor_value, float size_value)
mir::EventUPtr make_pointer_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp, std::vector< uint8_t > const &mac, MirInputEventModifiers modifiers, MirPointerAction action, MirPointerButtons buttons_pressed, float x_axis_value, float y_axis_value, float hscroll_value, float vscroll_value, float relative_x_value, float relative_y_value)
unsigned int MirPointerButtons
Definition: enums.h:209
unsigned int MirInputEventModifiers
Definition: enums.h:77
int64_t MirInputDeviceId
Definition: mir_input_device_types.h:27
#define MIR_VERSION_NUMBER(major, minor, micro)
MIR_VERSION_NUMBER.
Definition: mir_version_number.h:34
Definition: runner.h:27
std::unique_ptr< MirEvent, void(*)(MirEvent *)> EventUPtr
Definition: event_builder.h:36
Definition: compositor.h:21
int32_t MirTouchId
An identifier for a touch-point.
Definition: toolkit_event.h:35
#define MIRAL_VERSION
MIRAL_VERSION.
Definition: version.h:62

Copyright © 2012-2023 Canonical Ltd.
Generated on Tue 2 May 10:01:24 UTC 2023
This documentation is licensed under the GPL version 2 or 3.