Mir
Loading...
Searching...
No Matches
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/toolkit_event.h>
22
23#include <chrono>
24#include <memory>
25#include <sys/types.h>
26#include <vector>
27
28struct MirEvent;
29struct MirInputEvent;
30
31namespace mir { typedef std::unique_ptr<MirEvent, void(*)(MirEvent*)> EventUPtr; }
32
33namespace miroil
34{
35
36/*
37 Creates Mir input events out of Qt input events
38
39 The class is splitt into miroil::EventBuilder which does the internal mir stuff,
40 and qtmir::EventBuilder which handles the qt stuff.
41
42 One important feature is that it's able to match a QInputEvent with the MirInputEvent that originated it, so
43 it can make a MirInputEvent version of a QInputEvent containing also information that the latter does not carry,
44 such as relative axis movement for pointer devices.
45*/
46
48
49public:
50 class EventInfo {
51 public:
52 void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp);
53
54 ulong timestamp;
57 float relative_x{0};
58 float relative_y{0};
59 };
60
61public:
63 virtual ~EventBuilder();
64
65 // add Touch event
66 void add_touch(MirEvent &event, MirTouchId touch_id, MirTouchAction action,
67 MirTouchTooltype tooltype, float x_axis_value, float y_axis_value,
68 float pressure_value, float touch_major_value, float touch_minor_value, float size_value);
69
70 // Key event
71 mir::EventUPtr make_key_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
72 std::vector<uint8_t> const& cookie, MirKeyboardAction action, xkb_keysym_t keysym,
73 int scan_code, MirInputEventModifiers modifiers);
74
75 // Touch event
76 mir::EventUPtr make_touch_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
77 std::vector<uint8_t> const& mac, MirInputEventModifiers modifiers);
78
79 // Pointer event
80 mir::EventUPtr make_pointer_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
81 std::vector<uint8_t> const& mac, MirInputEventModifiers modifiers, MirPointerAction action,
82 MirPointerButtons buttons_pressed,
83 float x_axis_value, float y_axis_value,
84 float hscroll_value, float vscroll_value,
85 float relative_x_value, float relative_y_value);
86
87 EventInfo * find_info(ulong qtTimestamp);
88
89 /* Stores information that cannot be carried by QInputEvents so that it can be fully
90 reconstructed later given the same qtTimestamp */
91 void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp);
92
93private:
94 /*
95 Ring buffer that stores information on recent MirInputEvents that cannot be carried by QInputEvents.
96
97 When MirInputEvents are dispatched through a QML scene, not all of its information can be carried
98 by QInputEvents. Some information is lost. Thus further on, if we want to transform a QInputEvent back into
99 its original MirInputEvent so that it can be consumed by a mir::scene::Surface and properly handled by mir clients
100 we have to reach out to this EventRegistry to get the missing bits.
101
102 Given the objective of this EventRegistry (MirInputEvent reconstruction after having gone through QQuickWindow input dispatch
103 as a QInputEvent), it stores information only about the most recent MirInputEvents.
104 */
105 std::vector<EventInfo> event_info_vector;
106 size_t next_index{0};
107 size_t event_info_count{0};
108};
109
110}
111
112#endif // MIROIL_EVENT_BUILDER_H
Definition event_builder.h:50
float relative_x
Definition event_builder.h:57
void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp)
float relative_y
Definition event_builder.h:58
ulong timestamp
Definition event_builder.h:54
std::vector< uint8_t > cookie
Definition event_builder.h:56
MirInputDeviceId device_id
Definition event_builder.h:55
Definition event_builder.h:47
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
Definition runner.h:27
std::unique_ptr< MirEvent, void(*)(MirEvent *)> EventUPtr
Definition event_builder.h:31
Definition compositor.h:21
int32_t MirTouchId
An identifier for a touch-point.
Definition toolkit_event.h:35

Copyright © 2012-2024 Canonical Ltd.
Generated on Thu Mar 21 18:45:15 UTC 2024
This documentation is licensed under the GPL version 2 or 3.