Merge lp:~brandontschaefer/mir/capnproto-event into lp:mir
- capnproto-event
- Merge into development-branch
Status: | Work in progress |
---|---|
Proposed branch: | lp:~brandontschaefer/mir/capnproto-event |
Merge into: | lp:mir |
Diff against target: |
4068 lines (+1504/-1058) 43 files modified
CMakeLists.txt (+4/-2) debian/control (+2/-0) include/client/mir_toolkit/events/event.h (+1/-1) src/CMakeLists.txt (+1/-0) src/capnproto/CMakeLists.txt (+76/-0) src/capnproto/mir_event.capnp (+204/-0) src/client/CMakeLists.txt (+4/-3) src/client/event.cpp (+161/-107) src/client/events/event_builders.cpp (+180/-131) src/client/events/make_empty_event.cpp (+5/-13) src/client/events/serialization.cpp (+18/-74) src/client/input/CMakeLists.txt (+2/-0) src/client/input/android/android_input_lexicon.cpp (+1/-1) src/client/input/android/event_conversion_helpers.cpp (+12/-8) src/client/input/input_event.cpp (+219/-236) src/client/input/xkb_mapper.cpp (+7/-9) src/client/mir_cookie.cpp (+11/-10) src/client/mir_surface.cpp (+2/-2) src/client/rpc/mir_protobuf_rpc_channel.cpp (+31/-28) src/client/symbols.map (+9/-0) src/common/CMakeLists.txt (+1/-1) src/common/events/CMakeLists.txt (+38/-0) src/common/events/capnp_enums_aligned_asserts.cpp (+82/-0) src/common/events/event_private.cpp (+67/-0) src/include/client/mir/mir_cookie.h (+5/-3) src/include/common/mir/events/event_private.h (+38/-162) src/server/CMakeLists.txt (+2/-0) src/server/graphics/nested/display_buffer.cpp (+7/-5) src/server/input/android/input_sender.cpp (+24/-5) src/server/input/default_event_builder.cpp (+3/-2) src/server/input/key_repeat_dispatcher.cpp (+10/-14) src/server/input/surface_input_dispatcher.cpp (+7/-4) src/server/input/validator.cpp (+46/-46) tests/unit-tests/client/input/test_android_input_receiver.cpp (+10/-11) tests/unit-tests/client/input/test_xkb_mapper.cpp (+1/-1) tests/unit-tests/client/test_event_distributor.cpp (+11/-11) tests/unit-tests/input/android/test_android_input_sender.cpp (+0/-1) tests/unit-tests/input/test_input_event.cpp (+127/-115) tests/unit-tests/input/test_surface_input_dispatcher.cpp (+3/-3) tests/unit-tests/input/test_validator.cpp (+34/-34) tests/unit-tests/scene/test_application_session.cpp (+7/-6) tests/unit-tests/scene/test_surface.cpp (+2/-2) tests/unit-tests/scene/test_surface_impl.cpp (+29/-7) |
To merge this branch: | bzr merge lp:~brandontschaefer/mir/capnproto-event |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cemil Azizoglu (community) | Needs Resubmitting | ||
Mir CI Bot | continuous-integration | Needs Fixing | |
Daniel van Vugt | Needs Resubmitting | ||
Review via email: mp+289076@code.launchpad.net |
Commit message
Move from a union to CapnProto structure for the MirEvent.
This will give us a serializable structure in which we can pass the mir event from server --> client and vis versa (once the rpc parts are fixed).
This will allow moving over to a capnproto rpc much easier as well.
We are still using the android input sender/receiver. The next step is to remove that, and add our own input sender/receiver using CapnProto serialization.
Description of the change
Move from a union to CapnProto structure for the MirEvent.
This will give us a serializable structure in which we can pass the mir event from server --> client and vis versa (once the rpc parts are fixed).
This will allow moving over to a capnproto rpc much easier as well.
We are still using the android input sender/receiver. The next step is to remove that, and add our own input sender/receiver using CapnProto serialization.
80% of the branch is just changing accessing points, while the other 20% is the main part of how to create a CapnProto event.
CapnProto events are built using an area pool for memory. The message (which is part of the mir event) is what actually holds the memory. The mir::capnp::Event is just the way to correctly access that memory chunk. The only way to copy is to copy from a reader which makes a deep copy of everything. It is not possible to do a shallow copy (for good reasons).
A couple of things:
Preference: (*ptr)->asReader() vs ptr->event.
static_cast<..> Enums from C++ enum class --> C enums. // We need to test they are aligned!
- 3393. By Brandon Schaefer
-
* Add a test to compare enums of cpanp vs the public C interface
* Move from event.event to event->
* Rename some of the enums in capnp from redundant namespaces
- 3394. By Brandon Schaefer
-
* Change unit test to a static assert so we see the issues when compiling.
* Rename swapinterval to swapInterval
* Force the LGPL check for src/capnproto
Daniel van Vugt (vanvugt) wrote : | # |
Interesting.
Loosely, resubmit, or wait a bit. We just want to make sure 0.21 gets branched before this lands.
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3394
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 3395. By Brandon Schaefer
-
* Should add the new lib depend to deb
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3395
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 3396. By Brandon Schaefer
-
* Need to have a backup lookup for capnproto on vivid
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3396
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 3397. By Brandon Schaefer
-
* Missed the compiler library
* QUIET so the find doesnt add noise that isnt needed
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3397
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
Took a look at this and after discussion between Chris, Brandon and myself we came to the conclusion that this MP could be broken up into the following logical pieces :
- Change MirEvent from 'union' to 'struct' similar to http://
- Add setters/getters for MirEvent et friends, possibly turning them into 'class' and making members private
- Add capnproto bits
Unmerged revisions
- 3397. By Brandon Schaefer
-
* Missed the compiler library
* QUIET so the find doesnt add noise that isnt needed - 3396. By Brandon Schaefer
-
* Need to have a backup lookup for capnproto on vivid
- 3395. By Brandon Schaefer
-
* Should add the new lib depend to deb
- 3394. By Brandon Schaefer
-
* Change unit test to a static assert so we see the issues when compiling.
* Rename swapinterval to swapInterval
* Force the LGPL check for src/capnproto - 3393. By Brandon Schaefer
-
* Add a test to compare enums of cpanp vs the public C interface
* Move from event.event to event->
* Rename some of the enums in capnp from redundant namespaces - 3392. By Brandon Schaefer
-
* Couple small fixes
- 3391. By Brandon Schaefer
-
* Merge Trunk
- 3390. By Brandon Schaefer
-
* Add back the missing test commented out
- 3389. By Brandon Schaefer
-
* Switch over to using capnproto for our event structure.
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-03-16 06:59:01 +0000 |
3 | +++ CMakeLists.txt 2016-03-16 18:27:24 +0000 |
4 | @@ -188,7 +188,9 @@ |
5 | find_package(EGL REQUIRED) |
6 | find_package(GLESv2 REQUIRED) |
7 | find_package(GLM REQUIRED) |
8 | -find_package(Protobuf REQUIRED ) |
9 | +find_package(Protobuf REQUIRED) |
10 | +# Vivid doesnt have the newer capnproto, so it doesnt have a *.cmake to find (cant require) |
11 | +find_package(CapnProto QUIET) |
12 | find_package(GLog REQUIRED) |
13 | find_package(GFlags REQUIRED) |
14 | find_package(LTTngUST REQUIRED) |
15 | @@ -245,7 +247,7 @@ |
16 | |
17 | # There's no nice way to format this. Thanks CMake. |
18 | mir_add_test(NAME LGPL-required |
19 | - COMMAND /bin/sh -c "! grep -rl 'GNU General' ${PROJECT_SOURCE_DIR}/src/client ${PROJECT_SOURCE_DIR}/include/client ${PROJECT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/include/common ${PROJECT_SOURCE_DIR}/src/include/common ${PROJECT_SOURCE_DIR}/src/platform ${PROJECT_SOURCE_DIR}/include/platform ${PROJECT_SOURCE_DIR}/src/include/platform" |
20 | + COMMAND /bin/sh -c "! grep -rl 'GNU General' ${PROJECT_SOURCE_DIR}/src/client ${PROJECT_SOURCE_DIR}/include/client ${PROJECT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/include/common ${PROJECT_SOURCE_DIR}/src/include/common ${PROJECT_SOURCE_DIR}/src/platform ${PROJECT_SOURCE_DIR}/include/platform ${PROJECT_SOURCE_DIR}/src/include/platform ${PROJECT_SOURCE_DIR}/src/capnproto" |
21 | ) |
22 | mir_add_test(NAME GPL-required |
23 | COMMAND /bin/sh -c "! grep -rl 'GNU Lesser' ${PROJECT_SOURCE_DIR}/src/server ${PROJECT_SOURCE_DIR}/include/server ${PROJECT_SOURCE_DIR}/src/include/server ${PROJECT_SOURCE_DIR}/tests ${PROJECT_SOURCE_DIR}/examples" |
24 | |
25 | === modified file 'debian/control' |
26 | --- debian/control 2016-03-16 06:59:01 +0000 |
27 | +++ debian/control 2016-03-16 18:27:24 +0000 |
28 | @@ -45,6 +45,8 @@ |
29 | python3:any, |
30 | dh-python, |
31 | nettle-dev, |
32 | + libcapnp-dev, |
33 | + capnproto |
34 | Standards-Version: 3.9.4 |
35 | Homepage: https://launchpad.net/mir |
36 | # If you aren't a member of ~mir-team but need to upload packaging changes, |
37 | |
38 | === modified file 'include/client/mir_toolkit/events/event.h' |
39 | --- include/client/mir_toolkit/events/event.h 2016-03-14 10:13:49 +0000 |
40 | +++ include/client/mir_toolkit/events/event.h 2016-03-16 18:27:24 +0000 |
41 | @@ -60,7 +60,7 @@ |
42 | |
43 | typedef struct MirCookie MirCookie; |
44 | |
45 | -typedef union MirEvent MirEvent; |
46 | +typedef struct MirEvent MirEvent; |
47 | |
48 | #ifdef __cplusplus |
49 | } |
50 | |
51 | === modified file 'src/CMakeLists.txt' |
52 | --- src/CMakeLists.txt 2016-03-14 10:13:49 +0000 |
53 | +++ src/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
54 | @@ -16,6 +16,7 @@ |
55 | # the src/include/... directories should be private to the implementation |
56 | include_directories(${PROJECT_SOURCE_DIR}/src/include/common) |
57 | set(MIR_GENERATED_INCLUDE_DIRECTORIES) |
58 | +add_subdirectory(capnproto/) |
59 | add_subdirectory(common/) |
60 | add_subdirectory(protobuf/) |
61 | include_directories(${MIR_GENERATED_INCLUDE_DIRECTORIES}) |
62 | |
63 | === added directory 'src/capnproto' |
64 | === added file 'src/capnproto/CMakeLists.txt' |
65 | --- src/capnproto/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
66 | +++ src/capnproto/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
67 | @@ -0,0 +1,76 @@ |
68 | +# Copyright © 2016 Canonical Ltd. |
69 | +# |
70 | +# This program is free software: you can redistribute it and/or modify it |
71 | +# under the terms of the GNU Lesser General Public License version 3, |
72 | +# as published by the Free Software Foundation. |
73 | +# |
74 | +# This program is distributed in the hope that it will be useful, |
75 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
76 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
77 | +# GNU Lesser General Public License for more details. |
78 | +# |
79 | +# You should have received a copy of the GNU Lesser General Public License |
80 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
81 | +# |
82 | +# Author: Brandon Schaefer <brandon.schaefer@canonical.com> |
83 | + |
84 | +if (DEFINED CAPNP_LIBRARIES_LITE) |
85 | + set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
86 | + |
87 | + capnp_generate_cpp(CAPNPROTO_SRC CAPNPROTO_HDRS mir_event.capnp) |
88 | + |
89 | + add_library(mircapnproto STATIC ${CAPNPROTO_SRC}) |
90 | + target_link_libraries(mircapnproto ${CAPNP_LIBRARIES_LITE}) |
91 | +# TODO Remove this entire else statement once vivid has libproto 0.5.3 or greater |
92 | +else () |
93 | + find_library(CAPNPLIB capnp) |
94 | + if(NOT CAPNPLIB) |
95 | + message(FATAL_ERROR "libcapnp-dev not found.") |
96 | + endif() |
97 | + |
98 | + find_library(KJLIB kj) |
99 | + if(NOT KJLIB) |
100 | + message(FATAL_ERROR "capnproto not found.") |
101 | + endif() |
102 | + |
103 | + find_program(CAPNPC_BIN capnpc) |
104 | + if(NOT CAPNPC_BIN) |
105 | + message(FATAL_ERROR "Capnp compiler not found.") |
106 | + endif() |
107 | + set(CAPNPC_FLAGS "" CACHE STRING "Extra flags for capnpc.") |
108 | + |
109 | + set(CAPNPROTO_FILES ${CAPNPROTO_FILES} |
110 | + "${CMAKE_CURRENT_SOURCE_DIR}/mir_event.capnp") |
111 | + |
112 | + # Custom rules to compile .capnp files |
113 | + # Taken from lp:unity-scopes-api |
114 | + foreach(file ${CAPNPROTO_FILES}) |
115 | + |
116 | + string(REPLACE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" build_dir ${file}) |
117 | + get_filename_component(build_dir ${build_dir} PATH) |
118 | + |
119 | + get_filename_component(proto_file ${file} NAME) |
120 | + string(REPLACE ".capnp" ".capnp.c++" src_file ${proto_file}) |
121 | + string(REPLACE ".capnp" ".capnp.h" hdr_file ${proto_file}) |
122 | + |
123 | + set(src_file ${build_dir}/${src_file}) |
124 | + set(hdr_file ${build_dir}/${hdr_file}) |
125 | + |
126 | + set(CAPNPROTO_HDRS ${CAPNPROTO_HDRS} ${hdr_file}) |
127 | + set(CAPNPROTO_SRC ${CAPNPROTO_SRC} ${src_file}) |
128 | + endforeach() |
129 | + |
130 | + add_custom_command(OUTPUT ${CAPNPROTO_SRC} ${CAPNPROTO_HDRS} |
131 | + DEPENDS ${CAPNPROTO_FILES} |
132 | + COMMAND ${CAPNPC_BIN} ${CAPNPC_FLAGS} -oc++:${CMAKE_BINARY_DIR} --src-prefix=${CMAKE_SOURCE_DIR} ${CAPNPROTO_FILES}) |
133 | + |
134 | + add_library(mircapnproto STATIC ${CAPNPROTO_SRC}) |
135 | + target_link_libraries(mircapnproto ${CAPNPLIB} ${KJLIB}) |
136 | +endif() |
137 | + |
138 | +list(APPEND MIR_GENERATED_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) |
139 | + |
140 | +set( |
141 | + MIR_GENERATED_INCLUDE_DIRECTORIES ${MIR_GENERATED_INCLUDE_DIRECTORIES} |
142 | + PARENT_SCOPE |
143 | +) |
144 | |
145 | === added file 'src/capnproto/mir_event.capnp' |
146 | --- src/capnproto/mir_event.capnp 1970-01-01 00:00:00 +0000 |
147 | +++ src/capnproto/mir_event.capnp 2016-03-16 18:27:24 +0000 |
148 | @@ -0,0 +1,204 @@ |
149 | +# Copyright © 2016 Canonical Ltd. |
150 | +# |
151 | +# This program is free software: you can redistribute it and/or modify it |
152 | +# under the terms of the GNU Lesser General Public License version 3, |
153 | +# as published by the Free Software Foundation. |
154 | +# |
155 | +# This program is distributed in the hope that it will be useful, |
156 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
157 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
158 | +# GNU Lesser General Public License for more details. |
159 | +# |
160 | +# You should have received a copy of the GNU Lesser General Public License |
161 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
162 | +# |
163 | +# Author: Brandon Schaefer <brandon.schaefer@canonical.com> |
164 | + |
165 | +@0x9ff9e89b8e11dc56; |
166 | + |
167 | +# Need to namespace the InputEvent/Event since the generated (Mir)Event has all its ctors deleted. |
168 | +# Which we need a C compliant struct to be generated. So namespace these, and wrap a |
169 | +# builder in a struct MirEvent {..}; |
170 | +using Cxx = import "/capnp/c++.capnp"; |
171 | +$Cxx.namespace("mir::capnp"); |
172 | + |
173 | +struct NanoSeconds |
174 | +{ |
175 | + count @0 :Int64; |
176 | +} |
177 | + |
178 | +struct InputDeviceId |
179 | +{ |
180 | + id @0 :UInt64; |
181 | +} |
182 | + |
183 | +struct KeyboardEvent |
184 | +{ |
185 | + id @0 :Int32; |
186 | + deviceId @1 :InputDeviceId; |
187 | + sourceId @2 :Int32; |
188 | + action @3 :Action; |
189 | + modifiers @4 :UInt32; |
190 | + keyCode @5 :Int32; |
191 | + scanCode @6 :Int32; |
192 | + eventTime @7 :NanoSeconds; |
193 | + cookie @8 :Data; |
194 | + |
195 | + enum Action |
196 | + { |
197 | + up @0; |
198 | + down @1; |
199 | + repeat @2; |
200 | + } |
201 | +} |
202 | + |
203 | +struct MotionEventSet |
204 | +{ |
205 | + struct Motion |
206 | + { |
207 | + id @0 :Int32; |
208 | + x @1 :Float32; |
209 | + y @2 :Float32; |
210 | + dx @3 :Float32; |
211 | + dy @4 :Float32; |
212 | + touchMajor @5 :Float32; |
213 | + touchMinor @6 :Float32; |
214 | + size @7 :Float32; |
215 | + pressure @8 :Float32; |
216 | + orientation @9 :Float32; |
217 | + vscroll @10 :Float32; |
218 | + hscroll @11 :Float32; |
219 | + |
220 | + toolType @12 :ToolType; |
221 | + |
222 | + # TODO: We would like to store this as a TouchAction but we still encode pointer actions |
223 | + # here as well. |
224 | + action @13 :Int32; |
225 | + |
226 | + enum ToolType |
227 | + { |
228 | + unknown @0; |
229 | + finger @1; |
230 | + stylus @2; |
231 | + } |
232 | + } |
233 | + |
234 | + deviceId @0 :InputDeviceId; |
235 | + sourceId @1 :Int32; |
236 | + modifiers @2 :UInt32; |
237 | + buttons @3 :UInt32; |
238 | + eventTime @4 :NanoSeconds; |
239 | + cookie @5 :Data; |
240 | + |
241 | + count @6 :UInt32; |
242 | + motions @7 :List(Motion); |
243 | + const maxCount :UInt32 = 16; |
244 | +} |
245 | + |
246 | +struct InputConfigurationEvent |
247 | +{ |
248 | + action @0 :Action; |
249 | + when @1 :NanoSeconds; |
250 | + id @2 :InputDeviceId; |
251 | + |
252 | + enum Action |
253 | + { |
254 | + configurationChanged @0; |
255 | + deviceReset @1; |
256 | + } |
257 | +} |
258 | + |
259 | +struct SurfaceEvent |
260 | +{ |
261 | + id @0 :Int32; |
262 | + attrib @1 :Attrib; |
263 | + value @2 :Int32; |
264 | + |
265 | + enum Attrib |
266 | + { |
267 | + # Do not specify values...code relies on 0...N ordering. |
268 | + type @0; |
269 | + state @1; |
270 | + swapInterval @2; |
271 | + focus @3; |
272 | + dpi @4; |
273 | + visibility @5; |
274 | + preferredOrientation @6; |
275 | + # Must be last |
276 | + surfaceAttrib @7; |
277 | + } |
278 | +} |
279 | + |
280 | +struct ResizeEvent |
281 | +{ |
282 | + surfaceId @0 :Int32; |
283 | + width @1 :Int32; |
284 | + height @2 :Int32; |
285 | +} |
286 | + |
287 | +struct PromptSessionEvent |
288 | +{ |
289 | + newState @0 :State; |
290 | + |
291 | + enum State |
292 | + { |
293 | + stopped @0; |
294 | + started @1; |
295 | + suspended @2; |
296 | + } |
297 | +} |
298 | + |
299 | +struct OrientationEvent |
300 | +{ |
301 | + surfaceId @0 :Int32; |
302 | + direction @1 :Int32; |
303 | +} |
304 | + |
305 | +struct CloseSurfaceEvent |
306 | +{ |
307 | + surfaceId @0 :Int32; |
308 | +} |
309 | + |
310 | +struct KeymapEvent |
311 | +{ |
312 | + surfaceId @0 :Int32; |
313 | + |
314 | + deviceId @1 :InputDeviceId; |
315 | + buffer @2 :Text; |
316 | +} |
317 | + |
318 | +struct SurfaceOutputEvent |
319 | +{ |
320 | + surfaceId @0 :Int32; |
321 | + dpi @1 :Int32; |
322 | + scale @2 :Float32; |
323 | + formFactor @3 :FormFactor; |
324 | + outputId @4 :UInt32; |
325 | + |
326 | + enum FormFactor |
327 | + { |
328 | + unknown @0; |
329 | + phone @1; |
330 | + tablet @2; |
331 | + monitor @3; |
332 | + tv @4; |
333 | + projector @5; |
334 | + } |
335 | +} |
336 | + |
337 | +struct Event |
338 | +{ |
339 | + union |
340 | + { |
341 | + key @0 :KeyboardEvent; |
342 | + motionSet @1 :MotionEventSet; |
343 | + surface @2 :SurfaceEvent; |
344 | + resize @3 :ResizeEvent; |
345 | + promptSession @4 :PromptSessionEvent; |
346 | + orientation @5 :OrientationEvent; |
347 | + closeSurface @6 :CloseSurfaceEvent; |
348 | + keymap @7 :KeymapEvent; |
349 | + inputConfiguration @8 :InputConfigurationEvent; |
350 | + surfaceOutput @9 :SurfaceOutputEvent; |
351 | + } |
352 | +} |
353 | |
354 | === modified file 'src/client/CMakeLists.txt' |
355 | --- src/client/CMakeLists.txt 2016-03-16 06:59:01 +0000 |
356 | +++ src/client/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
357 | @@ -91,10 +91,10 @@ |
358 | |
359 | # Ensure protobuf C++ headers have been produced before |
360 | # trying to compile mirclientobjects |
361 | -add_dependencies(mirclientobjects mirprotobuf) |
362 | +add_dependencies(mirclientobjects mirprotobuf mircapnproto) |
363 | |
364 | -mir_add_library_with_symbols(mirclient SHARED ${symbol_map} $<TARGET_OBJECTS:mirclientobjects> $<TARGET_OBJECTS:mirsharedinput>) |
365 | -add_library(mirclient-static STATIC $<TARGET_OBJECTS:mirclientobjects> $<TARGET_OBJECTS:mirsharedinput>) |
366 | +mir_add_library_with_symbols(mirclient SHARED ${symbol_map} $<TARGET_OBJECTS:mirclientobjects> $<TARGET_OBJECTS:mirsharedinput> $<TARGET_OBJECTS:mirevents>) |
367 | +add_library(mirclient-static STATIC $<TARGET_OBJECTS:mirclientobjects> $<TARGET_OBJECTS:mirsharedinput> $<TARGET_OBJECTS:mirevents>) |
368 | |
369 | set_target_properties(mirclient |
370 | |
371 | @@ -106,6 +106,7 @@ |
372 | set(LINKS |
373 | mircommon |
374 | mirprotobuf |
375 | + mircapnproto |
376 | mircookie |
377 | |
378 | ${XKBCOMMON_LIBRARIES} |
379 | |
380 | === modified file 'src/client/event.cpp' |
381 | --- src/client/event.cpp 2016-01-29 08:18:22 +0000 |
382 | +++ src/client/event.cpp 2016-03-16 18:27:24 +0000 |
383 | @@ -14,6 +14,7 @@ |
384 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
385 | * |
386 | * Authored by: Robert Carr <robert.carr@canonical.com> |
387 | + * Brandon Schaefer <brandon.schaefer@canonical.com> |
388 | */ |
389 | |
390 | #define MIR_LOG_COMPONENT "event-access" |
391 | @@ -32,20 +33,29 @@ |
392 | #include <cstdlib> |
393 | #include <cstring> |
394 | |
395 | +#include "mir_event.capnp.h" |
396 | + |
397 | namespace ml = mir::logging; |
398 | +using Which = mir::capnp::Event::Which; |
399 | |
400 | namespace |
401 | { |
402 | template <typename EventType> |
403 | void expect_event_type(EventType const* ev, MirEventType t) |
404 | { |
405 | - if (ev->type != t) |
406 | + if (mir_event_get_type(ev) != t) |
407 | { |
408 | mir::log_critical("Expected " + mir::event_type_to_string(t) + " but event is of type " + |
409 | - mir::event_type_to_string(ev->type)); |
410 | + mir::event_type_to_string(mir_event_get_type(ev))); |
411 | abort(); |
412 | } |
413 | } |
414 | + |
415 | +template <class T> |
416 | +MirEvent const* cast_to_mir_event(T const* t) |
417 | +{ |
418 | + return reinterpret_cast<MirEvent const*>(t); |
419 | +} |
420 | } |
421 | |
422 | std::string mir::event_type_to_string(MirEventType t) |
423 | @@ -56,6 +66,8 @@ |
424 | return "mir_event_type_key"; |
425 | case mir_event_type_motion: |
426 | return "mir_event_type_motion"; |
427 | + case mir_event_type_input: |
428 | + return "mir_event_type_input"; |
429 | case mir_event_type_surface: |
430 | return "mir_event_type_surface"; |
431 | case mir_event_type_resize: |
432 | @@ -66,221 +78,263 @@ |
433 | return "mir_event_type_orientation"; |
434 | case mir_event_type_close_surface: |
435 | return "mir_event_type_close_surface"; |
436 | - case mir_event_type_input: |
437 | - return "mir_event_type_input"; |
438 | + case mir_event_type_keymap: |
439 | + return "mir_event_type_keymap"; |
440 | + case mir_event_type_input_configuration: |
441 | + return "mir_event_type_input_configuration"; |
442 | + case mir_event_type_surface_output: |
443 | + return "mir_event_type_surface_output"; |
444 | default: |
445 | abort(); |
446 | } |
447 | } |
448 | |
449 | - |
450 | -MirEventType mir_event_get_type(MirEvent const* ev) |
451 | +MirEventType mir_event_get_type(MirEvent const* ev) try |
452 | { |
453 | - switch (ev->type) |
454 | + switch (ev->event.asReader().which()) |
455 | { |
456 | - case mir_event_type_key: |
457 | - case mir_event_type_motion: |
458 | + case Which::KEY: |
459 | + case Which::MOTION_SET: |
460 | return mir_event_type_input; |
461 | + case Which::SURFACE: |
462 | + return mir_event_type_surface; |
463 | + case Which::RESIZE: |
464 | + return mir_event_type_resize; |
465 | + case Which::PROMPT_SESSION: |
466 | + return mir_event_type_prompt_session_state_change; |
467 | + case Which::ORIENTATION: |
468 | + return mir_event_type_orientation; |
469 | + case Which::CLOSE_SURFACE: |
470 | + return mir_event_type_close_surface; |
471 | + case Which::KEYMAP: |
472 | + return mir_event_type_keymap; |
473 | + case Which::INPUT_CONFIGURATION: |
474 | + return mir_event_type_input_configuration; |
475 | + case Which::SURFACE_OUTPUT: |
476 | + return mir_event_type_surface_output; |
477 | default: |
478 | - return ev->type; |
479 | + abort(); |
480 | } |
481 | +} catch(...) |
482 | +{ |
483 | + abort(); |
484 | } |
485 | |
486 | -MirInputEvent const* mir_event_get_input_event(MirEvent const* ev) |
487 | +MirInputEvent const* mir_event_get_input_event(MirEvent const* ev) try |
488 | { |
489 | - if (ev->type != mir_event_type_key && ev->type != mir_event_type_motion) |
490 | + auto ev_type = ev->event.asReader().which(); |
491 | + if (ev_type != Which::KEY && |
492 | + ev_type != Which::MOTION_SET) |
493 | { |
494 | - mir::log_critical("Expected input event but event is of type " + |
495 | - mir::event_type_to_string(ev->type)); |
496 | - abort(); |
497 | + mir::log_critical("Expected input event but event is of type " + |
498 | + mir::event_type_to_string(mir_event_get_type(ev))); |
499 | + abort(); |
500 | } |
501 | |
502 | return reinterpret_cast<MirInputEvent const*>(ev); |
503 | +} catch (...) { |
504 | + abort(); |
505 | } |
506 | |
507 | MirSurfaceEvent const* mir_event_get_surface_event(MirEvent const* ev) |
508 | { |
509 | expect_event_type(ev, mir_event_type_surface); |
510 | - |
511 | - return &ev->surface; |
512 | + return reinterpret_cast<MirSurfaceEvent const*>(ev); |
513 | } |
514 | |
515 | MirResizeEvent const* mir_event_get_resize_event(MirEvent const* ev) |
516 | { |
517 | expect_event_type(ev, mir_event_type_resize); |
518 | - |
519 | - return &ev->resize; |
520 | + return reinterpret_cast<MirResizeEvent const*>(ev); |
521 | } |
522 | |
523 | MirPromptSessionEvent const* mir_event_get_prompt_session_event(MirEvent const* ev) |
524 | { |
525 | expect_event_type(ev, mir_event_type_prompt_session_state_change); |
526 | - |
527 | - return &ev->prompt_session; |
528 | + return reinterpret_cast<MirPromptSessionEvent const*>(ev); |
529 | } |
530 | |
531 | MirOrientationEvent const* mir_event_get_orientation_event(MirEvent const* ev) |
532 | { |
533 | expect_event_type(ev, mir_event_type_orientation); |
534 | - |
535 | - return &ev->orientation; |
536 | + return reinterpret_cast<MirOrientationEvent const*>(ev); |
537 | } |
538 | |
539 | MirCloseSurfaceEvent const* mir_event_get_close_surface_event(MirEvent const* ev) |
540 | { |
541 | expect_event_type(ev, mir_event_type_close_surface); |
542 | - |
543 | - return &ev->close_surface; |
544 | + return reinterpret_cast<MirCloseSurfaceEvent const*>(ev); |
545 | } |
546 | |
547 | MirKeymapEvent const* mir_event_get_keymap_event(MirEvent const* ev) |
548 | { |
549 | expect_event_type(ev, mir_event_type_keymap); |
550 | - |
551 | - return &ev->keymap; |
552 | + return reinterpret_cast<MirKeymapEvent const*>(ev); |
553 | } |
554 | |
555 | MirInputConfigurationEvent const* mir_event_get_input_configuration_event(MirEvent const* ev) |
556 | { |
557 | expect_event_type(ev, mir_event_type_input_configuration); |
558 | - |
559 | - return &ev->input_configuration; |
560 | + return reinterpret_cast<MirInputConfigurationEvent const*>(ev); |
561 | } |
562 | |
563 | MirSurfaceOutputEvent const* mir_event_get_surface_output_event(MirEvent const* ev) |
564 | { |
565 | expect_event_type(ev, mir_event_type_surface_output); |
566 | - |
567 | - return &ev->surface_output; |
568 | + return reinterpret_cast<MirSurfaceOutputEvent const*>(ev); |
569 | } |
570 | |
571 | /* Surface event accessors */ |
572 | |
573 | -MirSurfaceAttrib mir_surface_event_get_attribute(MirSurfaceEvent const* ev) |
574 | +MirSurfaceAttrib mir_surface_event_get_attribute(MirSurfaceEvent const* surface) try |
575 | { |
576 | - expect_event_type(ev, mir_event_type_surface); |
577 | - |
578 | - return ev->attrib; |
579 | + auto reader = (*cast_to_mir_event(surface))->asReader(); |
580 | + return static_cast<MirSurfaceAttrib>(reader.getSurface().getAttrib()); |
581 | +} catch (...) { |
582 | + abort(); |
583 | } |
584 | |
585 | -int mir_surface_event_get_attribute_value(MirSurfaceEvent const* ev) |
586 | +int mir_surface_event_get_attribute_value(MirSurfaceEvent const* surface) try |
587 | { |
588 | - expect_event_type(ev, mir_event_type_surface); |
589 | - |
590 | - return ev->value; |
591 | + auto reader =(*cast_to_mir_event(surface))->asReader(); |
592 | + return reader.getSurface().getValue(); |
593 | +} catch (...) { |
594 | + abort(); |
595 | } |
596 | |
597 | /* Resize event accessors */ |
598 | |
599 | -int mir_resize_event_get_width(MirResizeEvent const* ev) |
600 | +int mir_resize_event_get_width(MirResizeEvent const* resize) try |
601 | { |
602 | - expect_event_type(ev, mir_event_type_resize); |
603 | - return ev->width; |
604 | + auto reader = (*cast_to_mir_event(resize))->asReader(); |
605 | + return reader.getResize().getWidth(); |
606 | +} catch (...) { |
607 | + abort(); |
608 | } |
609 | |
610 | -int mir_resize_event_get_height(MirResizeEvent const* ev) |
611 | +int mir_resize_event_get_height(MirResizeEvent const* resize) try |
612 | { |
613 | - expect_event_type(ev, mir_event_type_resize); |
614 | - return ev->height; |
615 | + auto reader = (*cast_to_mir_event(resize))->asReader(); |
616 | + return reader.getResize().getHeight(); |
617 | +} catch (...) { |
618 | + abort(); |
619 | } |
620 | |
621 | /* Prompt session event accessors */ |
622 | |
623 | -MirPromptSessionState mir_prompt_session_event_get_state(MirPromptSessionEvent const* ev) |
624 | +MirPromptSessionState mir_prompt_session_event_get_state(MirPromptSessionEvent const* prompt) try |
625 | { |
626 | - expect_event_type(ev, mir_event_type_prompt_session_state_change); |
627 | - return ev->new_state; |
628 | + auto reader = (*cast_to_mir_event(prompt))->asReader(); |
629 | + return static_cast<MirPromptSessionState>(reader.getPromptSession().getNewState()); |
630 | +} catch (...) { |
631 | + abort(); |
632 | } |
633 | |
634 | /* Orientation event accessors */ |
635 | |
636 | -MirOrientation mir_orientation_event_get_direction(MirOrientationEvent const* ev) |
637 | +MirOrientation mir_orientation_event_get_direction(MirOrientationEvent const* orientation) try |
638 | { |
639 | - expect_event_type(ev, mir_event_type_orientation); |
640 | - return ev->direction; |
641 | + auto reader = (*cast_to_mir_event(orientation))->asReader(); |
642 | + return static_cast<MirOrientation>(reader.getOrientation().getDirection()); |
643 | +} catch (...) { |
644 | + abort(); |
645 | } |
646 | |
647 | /* Keymap event accessors */ |
648 | |
649 | -void mir_keymap_event_get_keymap_buffer(MirKeymapEvent const* ev, char const** buffer, size_t* length) |
650 | +void mir_keymap_event_get_keymap_buffer(MirKeymapEvent const* keymap, char const** buffer, size_t* length) try |
651 | { |
652 | - expect_event_type(ev, mir_event_type_keymap); |
653 | + auto reader = (*cast_to_mir_event(keymap))->asReader(); |
654 | |
655 | - *buffer = ev->buffer; |
656 | - *length = ev->size; |
657 | + *buffer = reader.getKeymap().getBuffer().cStr(); |
658 | + *length = reader.getKeymap().getBuffer().size(); |
659 | +} catch (...) { |
660 | + abort(); |
661 | } |
662 | |
663 | -MirInputDeviceId mir_keymap_event_get_device_id(MirKeymapEvent const* ev) |
664 | +MirInputDeviceId mir_keymap_event_get_device_id(MirKeymapEvent const* keymap) try |
665 | { |
666 | - expect_event_type(ev, mir_event_type_keymap); |
667 | - |
668 | - return ev->device_id; |
669 | + auto reader = (*cast_to_mir_event(keymap))->asReader(); |
670 | + return reader.getKeymap().getDeviceId().getId(); |
671 | +} catch (...) { |
672 | + abort(); |
673 | } |
674 | |
675 | /* Input configuration event accessors */ |
676 | |
677 | -MirInputConfigurationAction mir_input_configuration_event_get_action(MirInputConfigurationEvent const* ev) |
678 | -{ |
679 | - expect_event_type(ev, mir_event_type_input_configuration); |
680 | - return ev->action; |
681 | -} |
682 | - |
683 | -int64_t mir_input_configuration_event_get_time(MirInputConfigurationEvent const* ev) |
684 | -{ |
685 | - expect_event_type(ev, mir_event_type_input_configuration); |
686 | - return ev->when.count(); |
687 | -} |
688 | - |
689 | -MirInputDeviceId mir_input_configuration_event_get_device_id(MirInputConfigurationEvent const* ev) |
690 | -{ |
691 | - expect_event_type(ev, mir_event_type_input_configuration); |
692 | - return ev->id; |
693 | +MirInputConfigurationAction mir_input_configuration_event_get_action(MirInputConfigurationEvent const* input_config) try |
694 | +{ |
695 | + auto reader = (*cast_to_mir_event(input_config))->asReader(); |
696 | + return static_cast<MirInputConfigurationAction>(reader.getInputConfiguration().getAction()); |
697 | +} catch (...) { |
698 | + abort(); |
699 | +} |
700 | + |
701 | +int64_t mir_input_configuration_event_get_time(MirInputConfigurationEvent const* input_config) try |
702 | +{ |
703 | + auto reader = (*cast_to_mir_event(input_config))->asReader(); |
704 | + return reader.getInputConfiguration().getWhen().getCount(); |
705 | +} catch (...) { |
706 | + abort(); |
707 | +} |
708 | + |
709 | +MirInputDeviceId mir_input_configuration_event_get_device_id(MirInputConfigurationEvent const* input_config) try |
710 | +{ |
711 | + auto reader = (*cast_to_mir_event(input_config))->asReader(); |
712 | + return reader.getInputConfiguration().getId().getId(); |
713 | +} catch (...) { |
714 | + abort(); |
715 | } |
716 | |
717 | /* Surface output event accessors */ |
718 | |
719 | -int mir_surface_output_event_get_dpi(MirSurfaceOutputEvent const* ev) |
720 | -{ |
721 | - expect_event_type(ev, mir_event_type_surface_output); |
722 | - return ev->dpi; |
723 | -} |
724 | - |
725 | -MirFormFactor mir_surface_output_event_get_form_factor(MirSurfaceOutputEvent const* ev) |
726 | -{ |
727 | - expect_event_type(ev, mir_event_type_surface_output); |
728 | - return ev->form_factor; |
729 | -} |
730 | - |
731 | -float mir_surface_output_event_get_scale(MirSurfaceOutputEvent const* ev) |
732 | -{ |
733 | - expect_event_type(ev, mir_event_type_surface_output); |
734 | - return ev->scale; |
735 | -} |
736 | - |
737 | -uint32_t mir_surface_output_event_get_output_id(MirSurfaceOutputEvent const *ev) |
738 | -{ |
739 | - expect_event_type(ev, mir_event_type_surface_output); |
740 | - return ev->output_id; |
741 | +int mir_surface_output_event_get_dpi(MirSurfaceOutputEvent const* surface_output) try |
742 | +{ |
743 | + auto reader = (*cast_to_mir_event(surface_output))->asReader(); |
744 | + return reader.getSurfaceOutput().getDpi(); |
745 | +} catch (...) { |
746 | + abort(); |
747 | +} |
748 | + |
749 | +MirFormFactor mir_surface_output_event_get_form_factor(MirSurfaceOutputEvent const* surface_output) try |
750 | +{ |
751 | + auto reader = (*cast_to_mir_event(surface_output))->asReader(); |
752 | + return static_cast<MirFormFactor>(reader.getSurfaceOutput().getFormFactor()); |
753 | +} catch (...) { |
754 | + abort(); |
755 | +} |
756 | + |
757 | +float mir_surface_output_event_get_scale(MirSurfaceOutputEvent const* surface_output) try |
758 | +{ |
759 | + auto reader = (*cast_to_mir_event(surface_output))->asReader(); |
760 | + return reader.getSurfaceOutput().getScale(); |
761 | +} catch (...) { |
762 | + abort(); |
763 | +} |
764 | + |
765 | +uint32_t mir_surface_output_event_get_output_id(MirSurfaceOutputEvent const* surface_output) try |
766 | +{ |
767 | + auto reader = (*cast_to_mir_event(surface_output))->asReader(); |
768 | + return reader.getSurfaceOutput().getOutputId(); |
769 | +} catch (...) { |
770 | + abort(); |
771 | } |
772 | |
773 | // TODO: Until we opaquify the MirEvent structure and add |
774 | // a ref count ref is implemented as copy. |
775 | -MirEvent const* mir_event_ref(MirEvent const* ev) |
776 | +MirEvent const* mir_event_ref(MirEvent const* ev) try |
777 | { |
778 | MirEvent *new_ev = new MirEvent; |
779 | - memcpy(new_ev, ev, sizeof(MirEvent)); |
780 | + *new_ev = *ev; |
781 | |
782 | - if (mir_event_get_type(new_ev) == mir_event_type_keymap) |
783 | - { |
784 | - // malloc to match xkbcommons allocation behavior |
785 | - auto buffer = static_cast<char*>(malloc(new_ev->keymap.size)); |
786 | - std::memcpy(buffer, ev->keymap.buffer, new_ev->keymap.size); |
787 | - new_ev->keymap.buffer = buffer; |
788 | - } |
789 | return new_ev; |
790 | +} catch (...) { |
791 | + abort(); |
792 | } |
793 | |
794 | -void mir_event_unref(MirEvent const* ev) |
795 | +void mir_event_unref(MirEvent const* ev) try |
796 | { |
797 | delete const_cast<MirEvent*>(ev); |
798 | +} catch (...) { |
799 | + abort(); |
800 | } |
801 | |
802 | === modified file 'src/client/events/event_builders.cpp' |
803 | --- src/client/events/event_builders.cpp 2016-01-29 08:18:22 +0000 |
804 | +++ src/client/events/event_builders.cpp 2016-03-16 18:27:24 +0000 |
805 | @@ -1,5 +1,5 @@ |
806 | /* |
807 | - * Copyright © 2015 Canonical Ltd. |
808 | + * Copyright © 2015-2016 Canonical Ltd. |
809 | * |
810 | * This program is free software: you can redistribute it and/or modify it |
811 | * under the terms of the GNU Lesser General Public License version 3, |
812 | @@ -14,6 +14,7 @@ |
813 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
814 | * |
815 | * Author: Robert Carr <robert.carr@canonical.com> |
816 | + * Brandon Schaefer <brandon.schaefer@canonical.com> |
817 | */ |
818 | |
819 | #define MIR_LOG_COMPONENT "event-builders" |
820 | @@ -34,77 +35,71 @@ |
821 | #include <algorithm> |
822 | #include <stdexcept> |
823 | |
824 | +#include "mir_event.capnp.h" |
825 | + |
826 | namespace mi = mir::input; |
827 | namespace mf = mir::frontend; |
828 | namespace mev = mir::events; |
829 | namespace geom = mir::geometry; |
830 | - |
831 | -namespace |
832 | -{ |
833 | - mir::cookie::Blob vector_to_cookie_as_blob(std::vector<uint8_t> const& vector) |
834 | - { |
835 | - mir::cookie::Blob blob{{}}; |
836 | - |
837 | - if (vector.size() > blob.size()) |
838 | - { |
839 | - throw std::runtime_error("Vector size " + std::to_string(vector.size()) + |
840 | - " is larger then array size: " + |
841 | - std::to_string(blob.size())); |
842 | - } |
843 | - |
844 | - std::copy_n(vector.begin(), vector.size(), blob.begin()); |
845 | - |
846 | - return blob; |
847 | - } |
848 | -} |
849 | +namespace mcap = mir::capnp; |
850 | |
851 | mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, MirOrientation orientation) |
852 | { |
853 | auto e = make_empty_event(); |
854 | - |
855 | - e->type = mir_event_type_orientation; |
856 | - e->orientation.surface_id = surface_id.as_value(); |
857 | - e->orientation.direction = orientation; |
858 | + e->event.initOrientation(); |
859 | + auto orientation_event = e->event.getOrientation(); |
860 | + |
861 | + orientation_event.setSurfaceId(surface_id.as_value()); |
862 | + orientation_event.setDirection(orientation); |
863 | + |
864 | return e; |
865 | } |
866 | |
867 | mir::EventUPtr mev::make_event(MirPromptSessionState state) |
868 | { |
869 | auto e = make_empty_event(); |
870 | - |
871 | - e->type = mir_event_type_prompt_session_state_change; |
872 | - e->prompt_session.new_state = state; |
873 | + e->event.initPromptSession(); |
874 | + auto prompt_session = e->event.getPromptSession(); |
875 | + |
876 | + prompt_session.setNewState(static_cast<mcap::PromptSessionEvent::State>(state)); |
877 | + |
878 | return e; |
879 | } |
880 | |
881 | mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, geom::Size const& size) |
882 | { |
883 | auto e = make_empty_event(); |
884 | + e->event.initResize(); |
885 | + auto resize = e->event.getResize(); |
886 | |
887 | - e->type = mir_event_type_resize; |
888 | - e->resize.surface_id = surface_id.as_value(); |
889 | - e->resize.width = size.width.as_int(); |
890 | - e->resize.height = size.height.as_int(); |
891 | + resize.setSurfaceId(surface_id.as_value()); |
892 | + resize.setWidth(size.width.as_int()); |
893 | + resize.setHeight(size.height.as_int()); |
894 | + |
895 | return e; |
896 | } |
897 | |
898 | mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, MirSurfaceAttrib attribute, int value) |
899 | { |
900 | auto e = make_empty_event(); |
901 | - |
902 | - e->type = mir_event_type_surface; |
903 | - e->surface.id = surface_id.as_value(); |
904 | - e->surface.attrib = attribute; |
905 | - e->surface.value = value; |
906 | + e->event.initSurface(); |
907 | + auto surface = e->event.getSurface(); |
908 | + |
909 | + surface.setId(surface_id.as_value()); |
910 | + surface.setAttrib(static_cast<mcap::SurfaceEvent::Attrib>(attribute)); |
911 | + surface.setValue(value); |
912 | + |
913 | return e; |
914 | } |
915 | |
916 | mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id) |
917 | { |
918 | auto e = make_empty_event(); |
919 | - |
920 | - e->type = mir_event_type_close_surface; |
921 | - e->close_surface.surface_id = surface_id.as_value(); |
922 | + e->event.initCloseSurface(); |
923 | + auto close_surface = e->event.getCloseSurface(); |
924 | + |
925 | + close_surface.setSurfaceId(surface_id.as_value()); |
926 | + |
927 | return e; |
928 | } |
929 | |
930 | @@ -116,13 +111,14 @@ |
931 | uint32_t output_id) |
932 | { |
933 | auto e = make_empty_event(); |
934 | + e->event.initSurfaceOutput(); |
935 | + auto surface_output = e->event.getSurfaceOutput(); |
936 | |
937 | - e->type = mir_event_type_surface_output; |
938 | - e->surface_output.surface_id = surface_id.as_value(); |
939 | - e->surface_output.dpi = dpi; |
940 | - e->surface_output.scale = scale; |
941 | - e->surface_output.form_factor = form_factor; |
942 | - e->surface_output.output_id = output_id; |
943 | + surface_output.setSurfaceId(surface_id.as_value()); |
944 | + surface_output.setDpi(dpi); |
945 | + surface_output.setScale(scale); |
946 | + surface_output.setFormFactor(static_cast<mcap::SurfaceOutputEvent::FormFactor>(form_factor)); |
947 | + surface_output.setOutputId(output_id); |
948 | |
949 | return e; |
950 | } |
951 | @@ -163,35 +159,41 @@ |
952 | int scan_code, MirInputEventModifiers modifiers) |
953 | { |
954 | auto e = make_empty_event(); |
955 | - |
956 | - e->type = mir_event_type_key; |
957 | - auto& kev = e->key; |
958 | - kev.device_id = device_id; |
959 | - kev.source_id = AINPUT_SOURCE_KEYBOARD; |
960 | - kev.event_time = timestamp; |
961 | - kev.cookie = vector_to_cookie_as_blob(cookie); |
962 | - kev.action = action; |
963 | - kev.key_code = key_code; |
964 | - kev.scan_code = scan_code; |
965 | - kev.modifiers = modifiers; |
966 | + e->event.initKey(); |
967 | + auto kev = e->event.getKey(); |
968 | + |
969 | + auto device = kev.getDeviceId(); |
970 | + device.setId(device_id); |
971 | + |
972 | + auto nanoseconds = kev.getEventTime(); |
973 | + nanoseconds.setCount(timestamp.count()); |
974 | + |
975 | + ::capnp::Data::Reader cookie_data(cookie.data(), cookie.size()); |
976 | + |
977 | + kev.setSourceId(AINPUT_SOURCE_KEYBOARD); |
978 | + kev.setCookie(cookie_data); |
979 | + kev.setAction(static_cast<mcap::KeyboardEvent::Action>(action)); |
980 | + kev.setKeyCode(key_code); |
981 | + kev.setScanCode(scan_code); |
982 | + kev.setModifiers(modifiers); |
983 | |
984 | return e; |
985 | } |
986 | |
987 | -void mev::set_modifier(MirEvent& event, MirInputEventModifiers modifiers) |
988 | +void mev::set_modifier(MirEvent& e, MirInputEventModifiers modifiers) |
989 | { |
990 | - switch(event.type) |
991 | + switch(e->which()) |
992 | { |
993 | - case mir_event_type_key: |
994 | + case mcap::Event::Which::KEY: |
995 | { |
996 | - auto& kev = event.key; |
997 | - kev.modifiers = modifiers; |
998 | + auto kev = e->getKey(); |
999 | + kev.setModifiers(modifiers); |
1000 | break; |
1001 | } |
1002 | - case mir_event_type_motion: |
1003 | + case mcap::Event::Which::MOTION_SET: |
1004 | { |
1005 | - auto& mev = event.motion; |
1006 | - mev.modifiers = modifiers; |
1007 | + auto mev = e->getMotionSet(); |
1008 | + mev.setModifiers(modifiers); |
1009 | break; |
1010 | } |
1011 | default: |
1012 | @@ -199,25 +201,44 @@ |
1013 | } |
1014 | } |
1015 | |
1016 | -void mev::set_cursor_position(MirEvent& event, mir::geometry::Point const& pos) |
1017 | -{ |
1018 | - if (event.type != mir_event_type_motion && |
1019 | - event.motion.source_id != AINPUT_SOURCE_MOUSE && |
1020 | - event.motion.pointer_count == 1) |
1021 | - BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor position is only valid for pointer events.")); |
1022 | - |
1023 | - event.motion.pointer_coordinates[0].x = pos.x.as_float(); |
1024 | - event.motion.pointer_coordinates[0].y = pos.y.as_float(); |
1025 | -} |
1026 | - |
1027 | -void mev::set_button_state(MirEvent& event, MirPointerButtons button_state) |
1028 | -{ |
1029 | - if (event.type != mir_event_type_motion && |
1030 | - event.motion.source_id != AINPUT_SOURCE_MOUSE && |
1031 | - event.motion.pointer_count == 1) |
1032 | - BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor position is only valid for pointer events.")); |
1033 | - |
1034 | - event.motion.buttons = button_state; |
1035 | +namespace |
1036 | +{ |
1037 | +bool event_is_pointer_event(MirEvent& e) |
1038 | +{ |
1039 | + if (e->which() != mcap::Event::Which::MOTION_SET) |
1040 | + { |
1041 | + BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor position is only valid for pointer events.")); |
1042 | + } |
1043 | + |
1044 | + auto mev = e->getMotionSet(); |
1045 | + if (mev.getSourceId() != AINPUT_SOURCE_MOUSE && |
1046 | + mev.getMotions().size() == 1) |
1047 | + { |
1048 | + BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor position is only valid for pointer events.")); |
1049 | + } |
1050 | + |
1051 | + return true; |
1052 | +} |
1053 | +} |
1054 | + |
1055 | +void mev::set_cursor_position(MirEvent& e, mir::geometry::Point const& pos) |
1056 | +{ |
1057 | + if (event_is_pointer_event(e)) |
1058 | + { |
1059 | + auto mev = e->getMotionSet(); |
1060 | + auto pointerCoord = mev.getMotions(); |
1061 | + pointerCoord[0].setX(pos.x.as_float()); |
1062 | + pointerCoord[0].setY(pos.y.as_float()); |
1063 | + } |
1064 | +} |
1065 | + |
1066 | +void mev::set_button_state(MirEvent& e, MirPointerButtons button_state) |
1067 | +{ |
1068 | + if (event_is_pointer_event(e)) |
1069 | + { |
1070 | + auto mev = e->getMotionSet(); |
1071 | + mev.setButtons(button_state); |
1072 | + } |
1073 | } |
1074 | |
1075 | // Deprecated version with uint64_t mac |
1076 | @@ -240,14 +261,21 @@ |
1077 | std::vector<uint8_t> const& cookie, MirInputEventModifiers modifiers) |
1078 | { |
1079 | auto e = make_empty_event(); |
1080 | - |
1081 | - e->type = mir_event_type_motion; |
1082 | - auto& mev = e->motion; |
1083 | - mev.device_id = device_id; |
1084 | - mev.event_time = timestamp; |
1085 | - mev.cookie = vector_to_cookie_as_blob(cookie); |
1086 | - mev.modifiers = modifiers; |
1087 | - mev.source_id = AINPUT_SOURCE_TOUCHSCREEN; |
1088 | + e->event.initMotionSet(); |
1089 | + auto mev = e->event.getMotionSet(); |
1090 | + |
1091 | + auto device = mev.getDeviceId(); |
1092 | + device.setId(device_id); |
1093 | + |
1094 | + auto nanoseconds = mev.getEventTime(); |
1095 | + nanoseconds.setCount(timestamp.count()); |
1096 | + |
1097 | + ::capnp::Data::Reader cookie_data(cookie.data(), cookie.size()); |
1098 | + |
1099 | + mev.setCookie(cookie_data); |
1100 | + mev.setModifiers(modifiers); |
1101 | + mev.setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
1102 | + mev.initMotions(mcap::MotionEventSet::MAX_COUNT); |
1103 | |
1104 | return e; |
1105 | } |
1106 | @@ -270,17 +298,19 @@ |
1107 | MirTouchTooltype tooltype, float x_axis_value, float y_axis_value, |
1108 | float pressure_value, float touch_major_value, float touch_minor_value, float size_value) |
1109 | { |
1110 | - auto& mev = event.motion; |
1111 | - auto& pc = mev.pointer_coordinates[mev.pointer_count++]; |
1112 | - pc.id = touch_id; |
1113 | - pc.tool_type = tooltype; |
1114 | - pc.x = x_axis_value; |
1115 | - pc.y = y_axis_value; |
1116 | - pc.pressure = pressure_value; |
1117 | - pc.touch_major = touch_major_value; |
1118 | - pc.touch_minor = touch_minor_value; |
1119 | - pc.size = size_value; |
1120 | - pc.action = action; |
1121 | + auto mev = event->getMotionSet(); |
1122 | + auto pointer_count = mev.getCount(); |
1123 | + auto pc = mev.getMotions()[pointer_count]; |
1124 | + pc.setId(touch_id); |
1125 | + pc.setToolType(static_cast<mcap::MotionEventSet::Motion::ToolType>(tooltype)); |
1126 | + pc.setX(x_axis_value); |
1127 | + pc.setY(y_axis_value); |
1128 | + pc.setPressure(pressure_value); |
1129 | + pc.setTouchMajor(touch_major_value); |
1130 | + pc.setTouchMinor(touch_minor_value); |
1131 | + pc.setSize(size_value); |
1132 | + pc.setAction(action); |
1133 | + mev.setCount(pointer_count + 1); |
1134 | } |
1135 | |
1136 | mir::EventUPtr mev::make_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp, |
1137 | @@ -291,25 +321,32 @@ |
1138 | float relative_x_value, float relative_y_value) |
1139 | { |
1140 | auto e = make_empty_event(); |
1141 | - |
1142 | - e->type = mir_event_type_motion; |
1143 | - auto& mev = e->motion; |
1144 | - mev.device_id = device_id; |
1145 | - mev.event_time = timestamp; |
1146 | - mev.cookie = vector_to_cookie_as_blob(cookie); |
1147 | - mev.modifiers = modifiers; |
1148 | - mev.source_id = AINPUT_SOURCE_MOUSE; |
1149 | - mev.buttons = buttons_pressed; |
1150 | - |
1151 | - mev.pointer_count = 1; |
1152 | - auto& pc = mev.pointer_coordinates[0]; |
1153 | - mev.pointer_coordinates[0].action = action; |
1154 | - pc.x = x_axis_value; |
1155 | - pc.y = y_axis_value; |
1156 | - pc.dx = relative_x_value; |
1157 | - pc.dy = relative_y_value; |
1158 | - pc.hscroll = hscroll_value; |
1159 | - pc.vscroll = vscroll_value; |
1160 | + e->event.initMotionSet(); |
1161 | + auto mev = e->event.getMotionSet(); |
1162 | + |
1163 | + auto device = mev.getDeviceId(); |
1164 | + device.setId(device_id); |
1165 | + |
1166 | + auto nanoseconds = mev.getEventTime(); |
1167 | + nanoseconds.setCount(timestamp.count()); |
1168 | + |
1169 | + ::capnp::Data::Reader cookie_data(cookie.data(), cookie.size()); |
1170 | + |
1171 | + mev.setCookie(cookie_data); |
1172 | + mev.setModifiers(modifiers); |
1173 | + mev.setSourceId(AINPUT_SOURCE_MOUSE); |
1174 | + mev.setButtons(buttons_pressed); |
1175 | + |
1176 | + mev.setCount(1); |
1177 | + mev.initMotions(1); |
1178 | + auto pc = mev.getMotions()[0]; |
1179 | + pc.setAction(action); |
1180 | + pc.setX(x_axis_value); |
1181 | + pc.setY(y_axis_value); |
1182 | + pc.setDx(relative_x_value); |
1183 | + pc.setDy(relative_y_value); |
1184 | + pc.setHscroll(hscroll_value); |
1185 | + pc.setVscroll(vscroll_value); |
1186 | |
1187 | return e; |
1188 | } |
1189 | @@ -366,6 +403,8 @@ |
1190 | std::string const& layout, std::string const& variant, std::string const& options) |
1191 | { |
1192 | auto e = make_empty_event(); |
1193 | + e->event.initKeymap(); |
1194 | + auto keymap = e->event.getKeymap(); |
1195 | |
1196 | auto ctx = mi::make_unique_context(); |
1197 | auto map = mi::make_unique_keymap(ctx.get(), model, layout, variant, options); |
1198 | @@ -373,12 +412,17 @@ |
1199 | if (!map.get()) |
1200 | BOOST_THROW_EXCEPTION(std::runtime_error("failed to assemble keymap from given parameters")); |
1201 | |
1202 | - e->type = mir_event_type_keymap; |
1203 | - e->keymap.surface_id = surface_id.as_value(); |
1204 | - e->keymap.device_id = id; |
1205 | + auto device = keymap.getDeviceId(); |
1206 | + device.setId(id); |
1207 | + |
1208 | + keymap.setSurfaceId(surface_id.as_value()); |
1209 | + |
1210 | // TODO consider caching compiled keymaps |
1211 | - e->keymap.buffer = xkb_keymap_get_as_string(map.get(), XKB_KEYMAP_FORMAT_TEXT_V1); |
1212 | - e->keymap.size = strlen(e->keymap.buffer); |
1213 | + char* keymap_as_string = xkb_keymap_get_as_string(map.get(), XKB_KEYMAP_FORMAT_TEXT_V1); |
1214 | + ::capnp::Text::Reader buffer_text(keymap_as_string); |
1215 | + |
1216 | + keymap.setBuffer(buffer_text); |
1217 | + std::free(keymap_as_string); |
1218 | |
1219 | return e; |
1220 | } |
1221 | @@ -386,11 +430,16 @@ |
1222 | mir::EventUPtr mev::make_event(MirInputConfigurationAction action, MirInputDeviceId id, std::chrono::nanoseconds time) |
1223 | { |
1224 | auto e = make_empty_event(); |
1225 | - |
1226 | - e->type = mir_event_type_input_configuration; |
1227 | - e->input_configuration.action = action; |
1228 | - e->input_configuration.when = time; |
1229 | - e->input_configuration.id = id; |
1230 | + e->event.initInputConfiguration(); |
1231 | + auto input_configuration = e->event.getInputConfiguration(); |
1232 | + |
1233 | + auto device = input_configuration.getId(); |
1234 | + device.setId(id); |
1235 | + |
1236 | + auto nanoseconds = input_configuration.getWhen(); |
1237 | + nanoseconds.setCount(time.count()); |
1238 | + |
1239 | + input_configuration.setAction(static_cast<mcap::InputConfigurationEvent::Action>(action)); |
1240 | |
1241 | return e; |
1242 | } |
1243 | |
1244 | === modified file 'src/client/events/make_empty_event.cpp' |
1245 | --- src/client/events/make_empty_event.cpp 2016-01-22 16:40:15 +0000 |
1246 | +++ src/client/events/make_empty_event.cpp 2016-03-16 18:27:24 +0000 |
1247 | @@ -19,24 +19,16 @@ |
1248 | #include "make_empty_event.h" |
1249 | #include "mir/events/event_private.h" |
1250 | |
1251 | +#include <capnp/message.h> |
1252 | + |
1253 | #include <cstring> |
1254 | #include <cstdlib> |
1255 | |
1256 | namespace mev = mir::events; |
1257 | -namespace |
1258 | -{ |
1259 | - void delete_event(MirEvent *e) |
1260 | - { |
1261 | - // xkbcommon creates the keymap through malloc |
1262 | - if (e && e->type == mir_event_type_keymap) |
1263 | - std::free(const_cast<char*>(e->keymap.buffer)); |
1264 | - delete e; |
1265 | - } |
1266 | -} |
1267 | |
1268 | mir::EventUPtr mev::make_empty_event() |
1269 | { |
1270 | - auto e = new MirEvent; |
1271 | - std::memset(e, 0, sizeof (MirEvent)); |
1272 | - return mir::EventUPtr(e, delete_event); |
1273 | + auto e = new MirEvent(); |
1274 | + |
1275 | + return mir::EventUPtr(e, [](MirEvent* e) { delete e; }); |
1276 | } |
1277 | |
1278 | === modified file 'src/client/events/serialization.cpp' |
1279 | --- src/client/events/serialization.cpp 2016-01-22 16:40:15 +0000 |
1280 | +++ src/client/events/serialization.cpp 2016-03-16 18:27:24 +0000 |
1281 | @@ -14,6 +14,7 @@ |
1282 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1283 | * |
1284 | * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1285 | + * Brandon Schaefer <brandon.schaefer@canonical.com> |
1286 | */ |
1287 | |
1288 | #include "make_empty_event.h" |
1289 | @@ -23,89 +24,32 @@ |
1290 | #include <boost/throw_exception.hpp> |
1291 | #include <cstring> |
1292 | |
1293 | +#include <capnp/serialize.h> |
1294 | + |
1295 | namespace mev = mir::events; |
1296 | |
1297 | -namespace |
1298 | -{ |
1299 | -template<typename Data> |
1300 | -char const* consume(char const* pos, Data& data) |
1301 | -{ |
1302 | - std::memcpy(&data, pos, sizeof data); |
1303 | - return pos + sizeof data; |
1304 | -} |
1305 | - |
1306 | -template<typename Data> |
1307 | -void encode(std::string& encoded, Data const& data) |
1308 | -{ |
1309 | - encoded.append(reinterpret_cast<char const*>(&data), sizeof data); |
1310 | -} |
1311 | -} |
1312 | - |
1313 | std::string mev::serialize_event(MirEvent const& event) |
1314 | { |
1315 | - auto type = mir_event_get_type(&event); |
1316 | + std::string output; |
1317 | + auto event_segments = const_cast<MirEvent&>(event).message.getSegmentsForOutput(); |
1318 | + auto flat_event = ::capnp::messageToFlatArray(event_segments); |
1319 | |
1320 | - switch (type) |
1321 | + for (auto const& c : flat_event.asBytes()) |
1322 | { |
1323 | - case mir_event_type_keymap: |
1324 | - { |
1325 | - std::string encoded; |
1326 | - auto const& keymap = event.keymap; |
1327 | - encoded.reserve(sizeof event.type + |
1328 | - sizeof keymap.surface_id + |
1329 | - sizeof keymap.device_id + |
1330 | - sizeof keymap.size + |
1331 | - keymap.size); |
1332 | - encode(encoded, event.type); |
1333 | - encode(encoded, keymap.surface_id); |
1334 | - encode(encoded, keymap.device_id); |
1335 | - encode(encoded, keymap.size); |
1336 | - encoded.append(keymap.buffer, keymap.size); |
1337 | - return encoded; |
1338 | - } |
1339 | - default: |
1340 | - return {reinterpret_cast<char const*>(&event), sizeof event}; |
1341 | + output += c; |
1342 | } |
1343 | + |
1344 | + return output; |
1345 | } |
1346 | |
1347 | mir::EventUPtr mev::deserialize_event(std::string const& raw) |
1348 | { |
1349 | - auto ev = make_empty_event(); |
1350 | - auto& event = *ev; |
1351 | - auto minimal_event_size = sizeof event.type; |
1352 | - auto const stream_size = raw.size(); |
1353 | - if (stream_size < minimal_event_size) |
1354 | - BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event")); |
1355 | - |
1356 | - char const* pos = consume(raw.data(), event.type); |
1357 | - |
1358 | - switch (event.type) |
1359 | - { |
1360 | - case mir_event_type_keymap: |
1361 | - { |
1362 | - auto& keymap = event.keymap; |
1363 | - minimal_event_size += sizeof keymap.surface_id + sizeof keymap.device_id + sizeof keymap.size; |
1364 | - |
1365 | - if (stream_size < minimal_event_size) |
1366 | - BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event")); |
1367 | - pos = consume(pos, keymap.surface_id); |
1368 | - pos = consume(pos, keymap.device_id); |
1369 | - pos = consume(pos, keymap.size); |
1370 | - |
1371 | - minimal_event_size += keymap.size; |
1372 | - |
1373 | - if (stream_size < minimal_event_size) |
1374 | - BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event")); |
1375 | - |
1376 | - auto buffer = static_cast<char*>(malloc(keymap.size)); |
1377 | - std::memcpy(buffer, pos, keymap.size); |
1378 | - keymap.buffer = buffer; |
1379 | - break; |
1380 | - } |
1381 | - default: |
1382 | - consume(raw.data(), event); |
1383 | - break; |
1384 | - } |
1385 | - |
1386 | - return ev; |
1387 | + auto e = mev::make_empty_event(); |
1388 | + kj::ArrayPtr<::capnp::word const> words(reinterpret_cast<::capnp::word const*>( |
1389 | + raw.data()), raw.size() / sizeof(::capnp::word)); |
1390 | + |
1391 | + initMessageBuilderFromFlatArrayCopy(words, e->message); |
1392 | + e->event = e->message.getRoot<mir::capnp::Event>(); |
1393 | + |
1394 | + return e; |
1395 | } |
1396 | |
1397 | === modified file 'src/client/input/CMakeLists.txt' |
1398 | --- src/client/input/CMakeLists.txt 2016-01-29 08:18:22 +0000 |
1399 | +++ src/client/input/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
1400 | @@ -30,6 +30,8 @@ |
1401 | ${CMAKE_CURRENT_SOURCE_DIR}/xkb_mapper.cpp |
1402 | ) |
1403 | |
1404 | +add_dependencies(mirsharedinput mircapnproto) |
1405 | + |
1406 | list(APPEND MIR_CLIENT_REFERENCES ${XKBCOMMON_LIBRARIES}) |
1407 | |
1408 | set(MIR_CLIENT_SOURCES ${MIR_CLIENT_SOURCES} PARENT_SCOPE) |
1409 | |
1410 | === modified file 'src/client/input/android/android_input_lexicon.cpp' |
1411 | --- src/client/input/android/android_input_lexicon.cpp 2016-01-29 08:18:22 +0000 |
1412 | +++ src/client/input/android/android_input_lexicon.cpp 2016-03-16 18:27:24 +0000 |
1413 | @@ -84,7 +84,7 @@ |
1414 | mev::add_touch(*ev, mev->getPointerId(i), action, mia::mir_tool_type_from_android(mev->getToolType(i)), |
1415 | mev->getX(i), mev->getY(i), |
1416 | mev->getPressure(i), mev->getTouchMajor(i), |
1417 | - mev->getTouchMinor(i), mev->getSize(i)); |
1418 | + mev->getTouchMinor(i), mev->getSize(i)); |
1419 | } |
1420 | return ev; |
1421 | } |
1422 | |
1423 | === modified file 'src/client/input/android/event_conversion_helpers.cpp' |
1424 | --- src/client/input/android/event_conversion_helpers.cpp 2016-03-16 06:59:01 +0000 |
1425 | +++ src/client/input/android/event_conversion_helpers.cpp 2016-03-16 18:27:24 +0000 |
1426 | @@ -201,11 +201,12 @@ |
1427 | int32_t mia::extract_masked_android_action_from(MirEvent const& ev) |
1428 | { |
1429 | int index_with_action = -1; |
1430 | - auto const& mev = ev.motion; |
1431 | + auto mev = ev.event.asReader().getMotionSet(); |
1432 | + auto pointer_count = mev.getCount(); |
1433 | |
1434 | - for (unsigned i = 0; i < mev.pointer_count; i++) |
1435 | + for (unsigned i = 0; i < pointer_count; i++) |
1436 | { |
1437 | - if (mev.pointer_coordinates[i].action == mir_touch_action_change) |
1438 | + if (mev.getMotions()[i].getAction() == mir_touch_action_change) |
1439 | continue; |
1440 | index_with_action = i; |
1441 | } |
1442 | @@ -213,16 +214,16 @@ |
1443 | return AMOTION_EVENT_ACTION_MOVE; |
1444 | |
1445 | int masked_action = AMOTION_EVENT_ACTION_MASK; |
1446 | - switch (mev.pointer_coordinates[index_with_action].action) |
1447 | + switch (mev.getMotions()[index_with_action].getAction()) |
1448 | { |
1449 | case mir_touch_action_up: |
1450 | - if (mev.pointer_count != 1) |
1451 | + if (pointer_count != 1) |
1452 | masked_action &= AMOTION_EVENT_ACTION_POINTER_UP; |
1453 | else |
1454 | masked_action &= AMOTION_EVENT_ACTION_UP; |
1455 | break; |
1456 | case mir_touch_action_down: |
1457 | - if (mev.pointer_count != 1) |
1458 | + if (pointer_count != 1) |
1459 | masked_action &= AMOTION_EVENT_ACTION_POINTER_DOWN; |
1460 | else |
1461 | masked_action &= AMOTION_EVENT_ACTION_DOWN; |
1462 | @@ -275,10 +276,13 @@ |
1463 | |
1464 | int32_t mia::extract_android_action_from(MirEvent const& event) |
1465 | { |
1466 | - if (mia::android_source_id_is_pointer_device(event.motion.source_id)) |
1467 | + auto mev = event->asReader().getMotionSet(); |
1468 | + if (mia::android_source_id_is_pointer_device(mev.getSourceId())) |
1469 | { |
1470 | return mia::android_pointer_action_from_mir( |
1471 | - static_cast<MirPointerAction>(event.motion.pointer_coordinates[0].action), event.motion.buttons); |
1472 | + static_cast<MirPointerAction>( |
1473 | + mev.getMotions()[0].getAction()), |
1474 | + mev.getButtons()); |
1475 | } |
1476 | else |
1477 | { |
1478 | |
1479 | === modified file 'src/client/input/input_event.cpp' |
1480 | --- src/client/input/input_event.cpp 2016-03-16 06:59:01 +0000 |
1481 | +++ src/client/input/input_event.cpp 2016-03-16 18:27:24 +0000 |
1482 | @@ -14,41 +14,35 @@ |
1483 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1484 | * |
1485 | * Authored by: Robert Carr <robert.carr@canonical.com> |
1486 | + * Brandon Schaefer <brandon.schaefer@canonical.com> |
1487 | */ |
1488 | |
1489 | #define MIR_LOG_COMPONENT "input-event-access" |
1490 | |
1491 | +#include "mir/event_type_to_string.h" |
1492 | #include "mir/cookie/cookie.h" |
1493 | -#include "mir/event_type_to_string.h" |
1494 | #include "mir/events/event_private.h" |
1495 | +#include "mir/mir_cookie.h" |
1496 | #include "mir/log.h" |
1497 | #include "mir/require.h" |
1498 | #include "mir_toolkit/mir_cookie.h" |
1499 | |
1500 | -#include "../mir_cookie.h" |
1501 | |
1502 | #include <string.h> |
1503 | |
1504 | namespace ml = mir::logging; |
1505 | +using Which = mir::capnp::Event::Which; |
1506 | |
1507 | namespace |
1508 | { |
1509 | -void expect_old_event_type(MirEvent const* ev, MirEventType t) |
1510 | -{ |
1511 | - if (ev->type != t) |
1512 | - { |
1513 | - mir::log_critical("Expected " + mir::event_type_to_string(t) + " but event is of type " + |
1514 | - mir::event_type_to_string(ev->type)); |
1515 | - abort(); |
1516 | - } |
1517 | -} |
1518 | - |
1519 | -std::string input_event_type_to_string(MirInputEventType input_event_type) |
1520 | -{ |
1521 | - switch (input_event_type) |
1522 | +std::string input_event_type_to_string(MirInputEventType t) |
1523 | +{ |
1524 | + switch (t) |
1525 | { |
1526 | case mir_input_event_type_key: |
1527 | return "mir_input_event_type_key"; |
1528 | + case mir_input_event_type_pointer: |
1529 | + return "mir_input_event_type_pointer"; |
1530 | case mir_input_event_type_touch: |
1531 | return "mir_input_event_type_touch"; |
1532 | default: |
1533 | @@ -56,6 +50,16 @@ |
1534 | } |
1535 | } |
1536 | |
1537 | +void expect_input_event_type(MirInputEvent const* iev, MirInputEventType t) |
1538 | +{ |
1539 | + if (mir_input_event_get_type(iev) != t) |
1540 | + { |
1541 | + mir::log_critical("Expected " + input_event_type_to_string(t) + " but event is of type " + |
1542 | + input_event_type_to_string(mir_input_event_get_type(iev))); |
1543 | + abort(); |
1544 | + } |
1545 | +} |
1546 | + |
1547 | // Never exposed in old event, so lets avoid leaking it in to a header now. |
1548 | enum |
1549 | { |
1550 | @@ -84,25 +88,6 @@ |
1551 | AINPUT_SOURCE_ANY = 0xffffff00 |
1552 | }; |
1553 | |
1554 | -MirEvent const* old_ev_from_new(MirInputEvent const* ev) |
1555 | -{ |
1556 | - return reinterpret_cast<MirEvent const*>(ev); |
1557 | -} |
1558 | - |
1559 | -MirMotionEvent const& old_mev_from_new(MirTouchEvent const* ev) |
1560 | -{ |
1561 | - auto old_ev = reinterpret_cast<MirEvent const*>(ev); |
1562 | - expect_old_event_type(old_ev, mir_event_type_motion); |
1563 | - return old_ev->motion; |
1564 | -} |
1565 | - |
1566 | -MirMotionEvent const& old_mev_from_new(MirPointerEvent const* ev) |
1567 | -{ |
1568 | - auto old_ev = reinterpret_cast<MirEvent const*>(ev); |
1569 | - expect_old_event_type(old_ev, mir_event_type_motion); |
1570 | - return old_ev->motion; |
1571 | -} |
1572 | - |
1573 | // Differentiate between MirTouchEvents and MirPointerEvents based on old device class |
1574 | MirInputEventType type_from_device_class(int32_t source_class) |
1575 | { |
1576 | @@ -118,210 +103,197 @@ |
1577 | return mir_input_event_type_touch; |
1578 | } |
1579 | } |
1580 | -} |
1581 | - |
1582 | -MirInputEventType mir_input_event_get_type(MirInputEvent const* ev) |
1583 | -{ |
1584 | - auto old_ev = old_ev_from_new(ev); |
1585 | - |
1586 | - if (old_ev->type != mir_event_type_key && old_ev->type != mir_event_type_motion) |
1587 | - { |
1588 | - mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(old_ev->type)); |
1589 | - abort(); |
1590 | - } |
1591 | - |
1592 | - switch (old_ev->type) |
1593 | - { |
1594 | - case mir_event_type_key: |
1595 | - return mir_input_event_type_key; |
1596 | - case mir_event_type_motion: |
1597 | - return type_from_device_class(old_ev->motion.source_id); |
1598 | - default: |
1599 | - abort(); |
1600 | - } |
1601 | -} |
1602 | - |
1603 | -MirInputDeviceId mir_input_event_get_device_id(MirInputEvent const* ev) |
1604 | -{ |
1605 | - auto old_ev = old_ev_from_new(ev); |
1606 | - |
1607 | - if(mir_event_get_type(old_ev) != mir_event_type_input) |
1608 | - { |
1609 | - mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(old_ev->type)); |
1610 | - abort(); |
1611 | - } |
1612 | - |
1613 | - switch (old_ev->type) |
1614 | - { |
1615 | - case mir_event_type_motion: |
1616 | - return old_ev->motion.device_id; |
1617 | - case mir_event_type_key: |
1618 | - return old_ev->key.device_id; |
1619 | - default: |
1620 | - abort(); |
1621 | - } |
1622 | -} |
1623 | - |
1624 | -int64_t mir_input_event_get_event_time(MirInputEvent const* ev) |
1625 | -{ |
1626 | - auto old_ev = old_ev_from_new(ev); |
1627 | - if(mir_event_get_type(old_ev) != mir_event_type_input) |
1628 | - { |
1629 | - mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(old_ev->type)); |
1630 | - abort(); |
1631 | - } |
1632 | - |
1633 | - switch (old_ev->type) |
1634 | - { |
1635 | - case mir_event_type_motion: |
1636 | - return old_ev->motion.event_time.count(); |
1637 | - case mir_event_type_key: |
1638 | - return old_ev->key.event_time.count(); |
1639 | - default: |
1640 | - abort(); |
1641 | - } |
1642 | -} |
1643 | - |
1644 | -MirInputEvent const* mir_pointer_event_input_event(MirPointerEvent const* event) |
1645 | -{ |
1646 | - return reinterpret_cast<MirInputEvent const*>(event); |
1647 | -} |
1648 | - |
1649 | -MirInputEvent const* mir_keyboard_event_input_event(MirKeyboardEvent const* event) |
1650 | -{ |
1651 | - return reinterpret_cast<MirInputEvent const*>(event); |
1652 | -} |
1653 | - |
1654 | -MirInputEvent const* mir_touch_event_input_event(MirTouchEvent const* event) |
1655 | -{ |
1656 | - return reinterpret_cast<MirInputEvent const*>(event); |
1657 | + |
1658 | +template <class T> |
1659 | +MirEvent const* cast_to_mir_event(T const* t) |
1660 | +{ |
1661 | + return reinterpret_cast<MirEvent const*>(t); |
1662 | +} |
1663 | +} |
1664 | + |
1665 | +MirInputEventType mir_input_event_get_type(MirInputEvent const* iev) try |
1666 | +{ |
1667 | + auto reader = (*iev)->asReader(); |
1668 | + switch (reader.which()) |
1669 | + { |
1670 | + case Which::KEY: |
1671 | + return mir_input_event_type_key; |
1672 | + case Which::MOTION_SET: |
1673 | + return type_from_device_class(reader.getMotionSet().getSourceId()); |
1674 | + default: |
1675 | + abort(); |
1676 | + } |
1677 | +} catch (...) |
1678 | +{ |
1679 | + abort(); |
1680 | +} |
1681 | + |
1682 | +MirInputDeviceId mir_input_event_get_device_id(MirInputEvent const* iev) try |
1683 | +{ |
1684 | + auto reader = (*iev)->asReader(); |
1685 | + switch (reader.which()) |
1686 | + { |
1687 | + case Which::KEY: |
1688 | + return reader.getKey().getDeviceId().getId(); |
1689 | + case Which::MOTION_SET: |
1690 | + return reader.getMotionSet().getDeviceId().getId(); |
1691 | + default: |
1692 | + abort(); |
1693 | + } |
1694 | +} catch (...) |
1695 | +{ |
1696 | + abort(); |
1697 | +} |
1698 | + |
1699 | +int64_t mir_input_event_get_event_time(MirInputEvent const* iev) try |
1700 | +{ |
1701 | + auto reader = (*iev)->asReader(); |
1702 | + switch (reader.which()) |
1703 | + { |
1704 | + case Which::KEY: |
1705 | + return reader.getKey().getEventTime().getCount(); |
1706 | + case Which::MOTION_SET: |
1707 | + return reader.getMotionSet().getEventTime().getCount(); |
1708 | + default: |
1709 | + abort(); |
1710 | + } |
1711 | +} catch (...) |
1712 | +{ |
1713 | + abort(); |
1714 | +} |
1715 | + |
1716 | +MirInputEvent const* mir_pointer_event_input_event(MirPointerEvent const* pev) |
1717 | +{ |
1718 | + expect_input_event_type(pev, mir_input_event_type_pointer); |
1719 | + return pev; |
1720 | +} |
1721 | + |
1722 | +MirInputEvent const* mir_keyboard_event_input_event(MirKeyboardEvent const* kev) |
1723 | +{ |
1724 | + expect_input_event_type(kev, mir_input_event_type_key); |
1725 | + return kev; |
1726 | +} |
1727 | + |
1728 | +MirInputEvent const* mir_touch_event_input_event(MirTouchEvent const* tev) |
1729 | +{ |
1730 | + expect_input_event_type(tev, mir_input_event_type_touch); |
1731 | + return tev; |
1732 | } |
1733 | |
1734 | /* Key event accessors */ |
1735 | |
1736 | -MirKeyboardEvent const* mir_input_event_get_keyboard_event(MirInputEvent const* ev) |
1737 | +MirKeyboardEvent const* mir_input_event_get_keyboard_event(MirInputEvent const* iev) |
1738 | { |
1739 | - if (mir_input_event_get_type(ev) != mir_input_event_type_key) |
1740 | - { |
1741 | - mir::log_critical("expected key input event but event was of type " + |
1742 | - input_event_type_to_string(mir_input_event_get_type(ev))); |
1743 | - abort(); |
1744 | - } |
1745 | - |
1746 | - return reinterpret_cast<MirKeyboardEvent const*>(ev); |
1747 | + return reinterpret_cast<MirKeyboardEvent const*>(iev); |
1748 | } |
1749 | |
1750 | MirKeyboardAction mir_keyboard_event_action(MirKeyboardEvent const* kev) |
1751 | { |
1752 | - return kev->action; |
1753 | + auto reader = (*cast_to_mir_event(kev))->asReader(); |
1754 | + return static_cast<MirKeyboardAction>(reader.getKey().getAction()); |
1755 | } |
1756 | |
1757 | xkb_keysym_t mir_keyboard_event_key_code(MirKeyboardEvent const* kev) |
1758 | { |
1759 | - return kev->key_code; |
1760 | + auto reader = (*cast_to_mir_event(kev))->asReader(); |
1761 | + return reader.getKey().getKeyCode(); |
1762 | } |
1763 | |
1764 | int mir_keyboard_event_scan_code(MirKeyboardEvent const* kev) |
1765 | { |
1766 | - return kev->scan_code; |
1767 | + auto reader = (*cast_to_mir_event(kev))->asReader(); |
1768 | + return reader.getKey().getScanCode(); |
1769 | } |
1770 | |
1771 | MirInputEventModifiers mir_keyboard_event_modifiers(MirKeyboardEvent const* kev) |
1772 | { |
1773 | - return kev->modifiers; |
1774 | + |
1775 | + auto reader = (*cast_to_mir_event(kev))->asReader(); |
1776 | + return reader.getKey().getModifiers(); |
1777 | } |
1778 | /* Touch event accessors */ |
1779 | |
1780 | -MirInputEventModifiers mir_touch_event_modifiers(MirTouchEvent const* tev) |
1781 | +MirInputEventModifiers mir_touch_event_modifiers(MirTouchEvent const* mev) |
1782 | { |
1783 | - auto const& old_mev = old_mev_from_new(tev); |
1784 | - return old_mev.modifiers; |
1785 | + auto reader = (*cast_to_mir_event(mev))->asReader(); |
1786 | + return reader.getMotionSet().getModifiers(); |
1787 | } |
1788 | |
1789 | MirTouchEvent const* mir_input_event_get_touch_event(MirInputEvent const* ev) |
1790 | { |
1791 | - if(mir_input_event_get_type(ev) != mir_input_event_type_touch) |
1792 | - { |
1793 | - mir::log_critical("expected touch input event but event was of type " + |
1794 | - input_event_type_to_string(mir_input_event_get_type(ev))); |
1795 | - abort(); |
1796 | - } |
1797 | - |
1798 | return reinterpret_cast<MirTouchEvent const*>(ev); |
1799 | } |
1800 | |
1801 | -unsigned int mir_touch_event_point_count(MirTouchEvent const* event) |
1802 | -{ |
1803 | - auto const& old_mev = reinterpret_cast<MirEvent const*>(event)->motion; |
1804 | - return old_mev.pointer_count; |
1805 | -} |
1806 | - |
1807 | -MirTouchId mir_touch_event_id(MirTouchEvent const* event, size_t touch_index) |
1808 | -{ |
1809 | - auto const& old_mev = old_mev_from_new(event); |
1810 | - |
1811 | - if (touch_index >= old_mev.pointer_count) |
1812 | - { |
1813 | - mir::log_critical("touch index is greater than pointer count"); |
1814 | - abort(); |
1815 | - } |
1816 | - |
1817 | - return old_mev.pointer_coordinates[touch_index].id; |
1818 | -} |
1819 | - |
1820 | -MirTouchAction mir_touch_event_action(MirTouchEvent const* event, size_t touch_index) |
1821 | -{ |
1822 | - auto const& old_mev = old_mev_from_new(event); |
1823 | - |
1824 | - if(touch_index > old_mev.pointer_count) |
1825 | - { |
1826 | - mir::log_critical("touch index is greater than pointer count"); |
1827 | - abort(); |
1828 | - } |
1829 | - |
1830 | - return static_cast<MirTouchAction>(old_mev.pointer_coordinates[touch_index].action); |
1831 | -} |
1832 | - |
1833 | -MirTouchTooltype mir_touch_event_tooltype(MirTouchEvent const* event, |
1834 | - size_t touch_index) |
1835 | -{ |
1836 | - auto const& old_mev = old_mev_from_new(event); |
1837 | - |
1838 | - if(touch_index > old_mev.pointer_count) |
1839 | - { |
1840 | - mir::log_critical("touch index is greater than pointer count"); |
1841 | - abort(); |
1842 | - } |
1843 | - |
1844 | - return old_mev.pointer_coordinates[touch_index].tool_type; |
1845 | -} |
1846 | - |
1847 | -float mir_touch_event_axis_value(MirTouchEvent const* event, |
1848 | +unsigned int mir_touch_event_point_count(MirTouchEvent const* tev) |
1849 | +{ |
1850 | + auto reader = (*cast_to_mir_event(tev))->asReader(); |
1851 | + return reader.getMotionSet().getCount(); |
1852 | +} |
1853 | + |
1854 | +MirTouchId mir_touch_event_id(MirTouchEvent const* tev, size_t touch_index) |
1855 | +{ |
1856 | + auto reader = (*cast_to_mir_event(tev))->asReader(); |
1857 | + if (touch_index >= reader.getMotionSet().getCount()) |
1858 | + { |
1859 | + mir::log_critical("touch index is greater than pointer count"); |
1860 | + abort(); |
1861 | + } |
1862 | + |
1863 | + return reader.getMotionSet().getMotions()[touch_index].getId(); |
1864 | +} |
1865 | + |
1866 | +MirTouchAction mir_touch_event_action(MirTouchEvent const* tev, size_t touch_index) |
1867 | +{ |
1868 | + auto reader = (*cast_to_mir_event(tev))->asReader(); |
1869 | + if (touch_index >= reader.getMotionSet().getCount()) |
1870 | + { |
1871 | + mir::log_critical("touch index is greater than pointer count"); |
1872 | + abort(); |
1873 | + } |
1874 | + |
1875 | + auto action = reader.getMotionSet().getMotions()[touch_index].getAction(); |
1876 | + return static_cast<MirTouchAction>(action); |
1877 | +} |
1878 | + |
1879 | +MirTouchTooltype mir_touch_event_tooltype(MirTouchEvent const* tev, size_t touch_index) |
1880 | +{ |
1881 | + auto reader = (*cast_to_mir_event(tev))->asReader(); |
1882 | + if (touch_index >= reader.getMotionSet().getCount()) |
1883 | + { |
1884 | + mir::log_critical("touch index is greater than pointer count"); |
1885 | + abort(); |
1886 | + } |
1887 | + |
1888 | + auto tool_type = reader.getMotionSet().getMotions()[touch_index].getToolType(); |
1889 | + return static_cast<MirTouchTooltype>(tool_type); |
1890 | +} |
1891 | + |
1892 | +float mir_touch_event_axis_value(MirTouchEvent const* tev, |
1893 | size_t touch_index, MirTouchAxis axis) |
1894 | { |
1895 | - auto const& old_mev = old_mev_from_new(event); |
1896 | - |
1897 | - if(touch_index > old_mev.pointer_count) |
1898 | + auto reader = (*cast_to_mir_event(tev))->asReader(); |
1899 | + if (touch_index >= reader.getMotionSet().getCount()) |
1900 | { |
1901 | mir::log_critical("touch index is greater than pointer count"); |
1902 | abort(); |
1903 | } |
1904 | |
1905 | - auto const& old_pc = old_mev.pointer_coordinates[touch_index]; |
1906 | + auto const& pc = reader.getMotionSet().getMotions()[touch_index]; |
1907 | + |
1908 | switch (axis) |
1909 | { |
1910 | case mir_touch_axis_x: |
1911 | - return old_pc.x; |
1912 | + return pc.getX(); |
1913 | case mir_touch_axis_y: |
1914 | - return old_pc.y; |
1915 | + return pc.getY(); |
1916 | case mir_touch_axis_pressure: |
1917 | - return old_pc.pressure; |
1918 | + return pc.getPressure(); |
1919 | case mir_touch_axis_touch_major: |
1920 | - return old_pc.touch_major; |
1921 | + return pc.getTouchMajor(); |
1922 | case mir_touch_axis_touch_minor: |
1923 | - return old_pc.touch_minor; |
1924 | + return pc.getTouchMinor(); |
1925 | case mir_touch_axis_size: |
1926 | - return old_pc.size; |
1927 | + return pc.getSize(); |
1928 | default: |
1929 | return -1; |
1930 | } |
1931 | @@ -331,80 +303,78 @@ |
1932 | |
1933 | MirPointerEvent const* mir_input_event_get_pointer_event(MirInputEvent const* ev) |
1934 | { |
1935 | - if(mir_input_event_get_type(ev) != mir_input_event_type_pointer) |
1936 | - { |
1937 | - mir::log_critical("expected pointer input event but event was of type " + |
1938 | - input_event_type_to_string(mir_input_event_get_type(ev))); |
1939 | - abort(); |
1940 | - } |
1941 | - |
1942 | return reinterpret_cast<MirPointerEvent const*>(ev); |
1943 | } |
1944 | |
1945 | MirInputEventModifiers mir_pointer_event_modifiers(MirPointerEvent const* pev) |
1946 | { |
1947 | - auto const& old_mev = old_mev_from_new(pev); |
1948 | - return old_mev.modifiers; |
1949 | + auto reader = (*cast_to_mir_event(pev))->asReader(); |
1950 | + return reader.getMotionSet().getModifiers(); |
1951 | } |
1952 | |
1953 | MirPointerAction mir_pointer_event_action(MirPointerEvent const* pev) |
1954 | { |
1955 | - auto const& old_mev = old_mev_from_new(pev); |
1956 | - return static_cast<MirPointerAction>(old_mev.pointer_coordinates[0].action); |
1957 | + auto reader = (*cast_to_mir_event(pev))->asReader(); |
1958 | + auto action = reader.getMotionSet().getMotions()[0].getAction(); |
1959 | + return static_cast<MirPointerAction>(action); |
1960 | } |
1961 | |
1962 | bool mir_pointer_event_button_state(MirPointerEvent const* pev, |
1963 | MirPointerButton button) |
1964 | { |
1965 | - auto const& old_mev = old_mev_from_new(pev); |
1966 | - return old_mev.buttons & button; |
1967 | + auto reader = (*cast_to_mir_event(pev))->asReader(); |
1968 | + auto mev = reader.getMotionSet(); |
1969 | + |
1970 | + return mev.getButtons() & button; |
1971 | } |
1972 | |
1973 | MirPointerButtons mir_pointer_event_buttons(MirPointerEvent const* pev) |
1974 | { |
1975 | - auto const& old_mev = old_mev_from_new(pev); |
1976 | - return old_mev.buttons; |
1977 | + auto reader = (*cast_to_mir_event(pev))->asReader(); |
1978 | + return reader.getMotionSet().getButtons(); |
1979 | } |
1980 | |
1981 | float mir_pointer_event_axis_value(MirPointerEvent const* pev, MirPointerAxis axis) |
1982 | { |
1983 | - auto const& old_mev = old_mev_from_new(pev); |
1984 | - switch (axis) |
1985 | - { |
1986 | - case mir_pointer_axis_x: |
1987 | - return old_mev.pointer_coordinates[0].x; |
1988 | - case mir_pointer_axis_y: |
1989 | - return old_mev.pointer_coordinates[0].y; |
1990 | - case mir_pointer_axis_relative_x: |
1991 | - return old_mev.pointer_coordinates[0].dx; |
1992 | - case mir_pointer_axis_relative_y: |
1993 | - return old_mev.pointer_coordinates[0].dy; |
1994 | - case mir_pointer_axis_vscroll: |
1995 | - return old_mev.pointer_coordinates[0].vscroll; |
1996 | - case mir_pointer_axis_hscroll: |
1997 | - return old_mev.pointer_coordinates[0].hscroll; |
1998 | - default: |
1999 | + auto reader = (*cast_to_mir_event(pev))->asReader(); |
2000 | + auto const& coord = reader.getMotionSet().getMotions()[0]; |
2001 | + |
2002 | + switch (axis) |
2003 | + { |
2004 | + case mir_pointer_axis_x: |
2005 | + return coord.getX(); |
2006 | + case mir_pointer_axis_y: |
2007 | + return coord.getY(); |
2008 | + case mir_pointer_axis_relative_x: |
2009 | + return coord.getDx(); |
2010 | + case mir_pointer_axis_relative_y: |
2011 | + return coord.getDy(); |
2012 | + case mir_pointer_axis_vscroll: |
2013 | + return coord.getVscroll(); |
2014 | + case mir_pointer_axis_hscroll: |
2015 | + return coord.getHscroll(); |
2016 | + default: |
2017 | mir::log_critical("Invalid axis enumeration " + std::to_string(axis)); |
2018 | abort(); |
2019 | - } |
2020 | + } |
2021 | } |
2022 | |
2023 | -bool mir_input_event_has_cookie(MirInputEvent const* ev) |
2024 | +bool mir_input_event_has_cookie(MirInputEvent const* iev) |
2025 | { |
2026 | - switch (mir_input_event_get_type(ev)) |
2027 | + switch (mir_input_event_get_type(iev)) |
2028 | { |
2029 | case mir_input_event_type_key: |
2030 | return true; |
2031 | case mir_input_event_type_pointer: |
2032 | { |
2033 | - auto const pev = mir_input_event_get_pointer_event(ev); |
2034 | + auto const pev = mir_input_event_get_pointer_event(iev); |
2035 | auto const pev_action = mir_pointer_event_action(pev); |
2036 | return (pev_action == mir_pointer_action_button_up || |
2037 | pev_action == mir_pointer_action_button_down); |
2038 | } |
2039 | case mir_input_event_type_touch: |
2040 | { |
2041 | - auto const tev = mir_input_event_get_touch_event(ev); |
2042 | + auto const tev = mir_input_event_get_touch_event(iev); |
2043 | auto const point_count = mir_touch_event_point_count(tev); |
2044 | for (size_t i = 0; i < point_count; i++) |
2045 | { |
2046 | @@ -432,17 +402,30 @@ |
2047 | |
2048 | MirCookie const* mir_input_event_get_cookie(MirInputEvent const* iev) try |
2049 | { |
2050 | - auto const ev = old_ev_from_new(iev); |
2051 | - |
2052 | - switch (ev->type) |
2053 | - { |
2054 | - case mir_event_type_motion: |
2055 | - return new MirCookie(ev->motion.cookie); |
2056 | - case mir_event_type_key: |
2057 | - return new MirCookie(ev->key.cookie); |
2058 | + auto reader = (*iev)->asReader(); |
2059 | + |
2060 | + switch (reader.which()) |
2061 | + { |
2062 | + case Which::KEY: |
2063 | + { |
2064 | + auto cookie = reader.getKey().getCookie(); |
2065 | + std::vector<uint8_t> cookie_data(cookie.size()); |
2066 | + std::copy(std::begin(cookie), std::end(cookie), std::begin(cookie_data)); |
2067 | + |
2068 | + return new MirCookie(cookie_data); |
2069 | + } |
2070 | + case Which::MOTION_SET: |
2071 | + { |
2072 | + auto cookie = reader.getMotionSet().getCookie(); |
2073 | + std::vector<uint8_t> cookie_data(cookie.size()); |
2074 | + std::copy(std::begin(cookie), std::end(cookie), std::begin(cookie_data)); |
2075 | + |
2076 | + return new MirCookie(cookie_data); |
2077 | + } |
2078 | default: |
2079 | { |
2080 | - mir::log_critical("expected a key or motion events, type was: " + mir::event_type_to_string(ev->type)); |
2081 | + mir::log_critical("expected a key or motion events, type was: " + |
2082 | + mir::event_type_to_string(mir_event_get_type(iev))); |
2083 | abort(); |
2084 | } |
2085 | } |
2086 | |
2087 | === modified file 'src/client/input/xkb_mapper.cpp' |
2088 | --- src/client/input/xkb_mapper.cpp 2016-01-29 08:18:22 +0000 |
2089 | +++ src/client/input/xkb_mapper.cpp 2016-03-16 18:27:24 +0000 |
2090 | @@ -77,7 +77,6 @@ |
2091 | |
2092 | namespace |
2093 | { |
2094 | - |
2095 | static uint32_t to_xkb_scan_code(uint32_t evdev_scan_code) |
2096 | { |
2097 | // xkb scancodes are offset by 8 from evdev scancodes for compatibility with X protocol. |
2098 | @@ -96,30 +95,29 @@ |
2099 | |
2100 | return XKB_KEY_NoSymbol; |
2101 | } |
2102 | - |
2103 | } |
2104 | |
2105 | -void mircv::XKBMapper::update_state_and_map_event(MirEvent& ev) |
2106 | +void mircv::XKBMapper::update_state_and_map_event(MirEvent& event) |
2107 | { |
2108 | std::lock_guard<std::mutex> lg(guard); |
2109 | |
2110 | - auto& key_ev = ev.key; |
2111 | + auto key_ev = event->getKey(); |
2112 | |
2113 | xkb_key_direction direction = XKB_KEY_DOWN; |
2114 | |
2115 | bool update_state = true; |
2116 | - if (key_ev.action == mir_keyboard_action_up) |
2117 | + if (key_ev.getAction() == mir::capnp::KeyboardEvent::Action::UP) |
2118 | direction = XKB_KEY_UP; |
2119 | - else if (key_ev.action == mir_keyboard_action_down) |
2120 | + else if (key_ev.getAction() == mir::capnp::KeyboardEvent::Action::DOWN) |
2121 | direction = XKB_KEY_DOWN; |
2122 | - else if (key_ev.action == mir_keyboard_action_repeat) |
2123 | + else if (key_ev.getAction() == mir::capnp::KeyboardEvent::Action::REPEAT) |
2124 | update_state = false; |
2125 | |
2126 | - uint32_t xkb_scan_code = to_xkb_scan_code(key_ev.scan_code); |
2127 | + uint32_t xkb_scan_code = to_xkb_scan_code(key_ev.getScanCode()); |
2128 | if (update_state) |
2129 | xkb_state_update_key(state.get(), xkb_scan_code, direction); |
2130 | |
2131 | - key_ev.key_code = keysym_for_scan_code(state.get(), xkb_scan_code); |
2132 | + key_ev.setKeyCode(keysym_for_scan_code(state.get(), xkb_scan_code)); |
2133 | } |
2134 | |
2135 | // id should be used in the future to implement per device keymaps |
2136 | |
2137 | === modified file 'src/client/mir_cookie.cpp' |
2138 | --- src/client/mir_cookie.cpp 2016-01-22 20:16:50 +0000 |
2139 | +++ src/client/mir_cookie.cpp 2016-03-16 18:27:24 +0000 |
2140 | @@ -16,34 +16,35 @@ |
2141 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
2142 | */ |
2143 | |
2144 | -#include "mir_cookie.h" |
2145 | +#include "mir/mir_cookie.h" |
2146 | |
2147 | #include "mir/require.h" |
2148 | |
2149 | #include <string.h> |
2150 | |
2151 | -MirCookie::MirCookie(void const* buffer, size_t size) |
2152 | +MirCookie::MirCookie(void const* buffer, size_t size) : |
2153 | + cookie_(size) |
2154 | { |
2155 | - memcpy(blob_.data(), buffer, size); |
2156 | + memcpy(cookie_.data(), buffer, size); |
2157 | } |
2158 | |
2159 | -MirCookie::MirCookie(mir::cookie::Blob const& blob) : |
2160 | - blob_(blob) |
2161 | +MirCookie::MirCookie(std::vector<uint8_t> const& cookie) : |
2162 | + cookie_(cookie) |
2163 | { |
2164 | } |
2165 | |
2166 | void MirCookie::copy_to(void* buffer, size_t size) const |
2167 | { |
2168 | - mir::require(size == blob_.size()); |
2169 | - memcpy(buffer, blob_.data(), size); |
2170 | + mir::require(size == cookie_.size()); |
2171 | + memcpy(buffer, cookie_.data(), size); |
2172 | } |
2173 | |
2174 | size_t MirCookie::size() const |
2175 | { |
2176 | - return blob_.size(); |
2177 | + return cookie_.size(); |
2178 | } |
2179 | |
2180 | -mir::cookie::Blob MirCookie::blob() const |
2181 | +std::vector<uint8_t> MirCookie::cookie() const |
2182 | { |
2183 | - return blob_; |
2184 | + return cookie_; |
2185 | } |
2186 | |
2187 | === modified file 'src/client/mir_surface.cpp' |
2188 | --- src/client/mir_surface.cpp 2016-03-14 10:13:49 +0000 |
2189 | +++ src/client/mir_surface.cpp 2016-03-16 18:27:24 +0000 |
2190 | @@ -28,9 +28,9 @@ |
2191 | #include "mir/client_buffer.h" |
2192 | #include "mir/dispatch/threaded_dispatcher.h" |
2193 | #include "mir/input/input_platform.h" |
2194 | +#include "mir/mir_cookie.h" |
2195 | #include "mir/input/xkb_mapper.h" |
2196 | #include "mir/cookie/cookie.h" |
2197 | -#include "mir_cookie.h" |
2198 | |
2199 | #include <cassert> |
2200 | #include <unistd.h> |
2201 | @@ -495,7 +495,7 @@ |
2202 | |
2203 | auto const event_cookie = raise_request.mutable_cookie(); |
2204 | |
2205 | - event_cookie->set_cookie(cookie->blob().data(), cookie->size()); |
2206 | + event_cookie->set_cookie(cookie->cookie().data(), cookie->size()); |
2207 | |
2208 | server->raise_surface( |
2209 | &raise_request, |
2210 | |
2211 | === modified file 'src/client/rpc/mir_protobuf_rpc_channel.cpp' |
2212 | --- src/client/rpc/mir_protobuf_rpc_channel.cpp 2016-03-16 06:59:01 +0000 |
2213 | +++ src/client/rpc/mir_protobuf_rpc_channel.cpp 2016-03-16 18:27:24 +0000 |
2214 | @@ -27,7 +27,6 @@ |
2215 | #include "../make_protobuf_object.h" |
2216 | #include "mir/input/input_devices.h" |
2217 | #include "mir/variable_length_array.h" |
2218 | -#include "mir/events/event_builders.h" |
2219 | #include "mir/events/event_private.h" |
2220 | #include "mir/events/serialization.h" |
2221 | |
2222 | @@ -340,34 +339,38 @@ |
2223 | auto const send_e = [&e](MirSurface* surface) |
2224 | { surface->handle_event(*e); }; |
2225 | |
2226 | - switch (e->type) |
2227 | + auto reader = e->event.asReader(); |
2228 | + |
2229 | + switch (e->event.asReader().which()) |
2230 | { |
2231 | - case mir_event_type_surface: |
2232 | - if (auto map = surface_map.lock()) |
2233 | - map->with_surface_do(mf::SurfaceId(e->surface.id), send_e); |
2234 | - break; |
2235 | - |
2236 | - case mir_event_type_resize: |
2237 | - if (auto map = surface_map.lock()) |
2238 | - map->with_surface_do(mf::SurfaceId(e->resize.surface_id), send_e); |
2239 | - break; |
2240 | - |
2241 | - case mir_event_type_orientation: |
2242 | - if (auto map = surface_map.lock()) |
2243 | - map->with_surface_do(mf::SurfaceId(e->orientation.surface_id), send_e); |
2244 | - break; |
2245 | - |
2246 | - case mir_event_type_close_surface: |
2247 | - if (auto map = surface_map.lock()) |
2248 | - map->with_surface_do(mf::SurfaceId(e->close_surface.surface_id), send_e); |
2249 | - break; |
2250 | - case mir_event_type_keymap: |
2251 | - if (auto map = surface_map.lock()) |
2252 | - map->with_surface_do(mf::SurfaceId(e->keymap.surface_id), send_e); |
2253 | - break; |
2254 | - case mir_event_type_surface_output: |
2255 | - if (auto map = surface_map.lock()) |
2256 | - map->with_surface_do(mf::SurfaceId(e->surface_output.surface_id), send_e); |
2257 | + case mir::capnp::Event::Which::SURFACE: |
2258 | + if (auto map = surface_map.lock()) |
2259 | + map->with_surface_do(mf::SurfaceId(reader.getSurface().getId()), send_e); |
2260 | + break; |
2261 | + |
2262 | + case mir::capnp::Event::Which::RESIZE: |
2263 | + if (auto map = surface_map.lock()) |
2264 | + map->with_surface_do(mf::SurfaceId(reader.getResize().getSurfaceId()), send_e); |
2265 | + break; |
2266 | + |
2267 | + case mir::capnp::Event::Which::ORIENTATION: |
2268 | + if (auto map = surface_map.lock()) |
2269 | + map->with_surface_do(mf::SurfaceId(reader.getOrientation().getSurfaceId()), send_e); |
2270 | + break; |
2271 | + |
2272 | + case mir::capnp::Event::Which::CLOSE_SURFACE: |
2273 | + if (auto map = surface_map.lock()) |
2274 | + map->with_surface_do(mf::SurfaceId(reader.getCloseSurface().getSurfaceId()), send_e); |
2275 | + break; |
2276 | + |
2277 | + case mir::capnp::Event::Which::KEYMAP: |
2278 | + if (auto map = surface_map.lock()) |
2279 | + map->with_surface_do(mf::SurfaceId(reader.getKeymap().getSurfaceId()), send_e); |
2280 | + break; |
2281 | + |
2282 | + case mir::capnp::Event::Which::SURFACE_OUTPUT: |
2283 | + if (auto map = surface_map.lock()) |
2284 | + map->with_surface_do(mf::SurfaceId(reader.getSurfaceOutput().getSurfaceId()), send_e); |
2285 | break; |
2286 | default: |
2287 | event_sink->handle_event(*e); |
2288 | |
2289 | === modified file 'src/client/symbols.map' |
2290 | --- src/client/symbols.map 2016-03-16 06:59:01 +0000 |
2291 | +++ src/client/symbols.map 2016-03-16 18:27:24 +0000 |
2292 | @@ -326,6 +326,15 @@ |
2293 | }; |
2294 | } MIR_CLIENT_DETAIL_9v18; |
2295 | |
2296 | +MIR_CLIENT_DETAIL_unreleased { |
2297 | + global: |
2298 | + extern "C++" { |
2299 | + mir::event_type_to_string*; |
2300 | + }; |
2301 | + local: |
2302 | + *; |
2303 | +} MIR_CLIENT_DETAIL_9v19; |
2304 | + |
2305 | MIR_CLIENT_DETAIL_private_buffer_semantics { |
2306 | global: |
2307 | mir_buffer_get_fence; |
2308 | |
2309 | === modified file 'src/common/CMakeLists.txt' |
2310 | --- src/common/CMakeLists.txt 2016-01-29 08:18:22 +0000 |
2311 | +++ src/common/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
2312 | @@ -1,6 +1,5 @@ |
2313 | add_definitions(-DMIR_LOG_COMPONENT_FALLBACK="mircommon") |
2314 | |
2315 | -set(MIR_GENERATED_INCLUDE_DIRECTORIES) |
2316 | set(MIR_COMMON_SOURCES) |
2317 | set(MIR_COMMON_REFERENCES) |
2318 | |
2319 | @@ -9,6 +8,7 @@ |
2320 | add_subdirectory(logging) |
2321 | add_subdirectory(report/lttng) |
2322 | add_subdirectory(env) |
2323 | +add_subdirectory(events) |
2324 | add_subdirectory(sharedlibrary) |
2325 | add_subdirectory(thread) |
2326 | add_subdirectory(time) |
2327 | |
2328 | === added directory 'src/common/events' |
2329 | === added file 'src/common/events/CMakeLists.txt' |
2330 | --- src/common/events/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
2331 | +++ src/common/events/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
2332 | @@ -0,0 +1,38 @@ |
2333 | +# Copyright © 2016 Canonical Ltd. |
2334 | +# |
2335 | +# This program is free software: you can redistribute it and/or modify it |
2336 | +# under the terms of the GNU Lesser General Public License version 3, |
2337 | +# as published by the Free Software Foundation. |
2338 | +# |
2339 | +# This program is distributed in the hope that it will be useful, |
2340 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
2341 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2342 | +# GNU Lesser General Public License for more details. |
2343 | +# |
2344 | +# You should have received a copy of the GNU Lesser General Public License |
2345 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
2346 | +# |
2347 | +# Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
2348 | + |
2349 | +set(EVENT_SOURCES |
2350 | + capnp_enums_aligned_asserts.cpp |
2351 | + event_private.cpp |
2352 | +) |
2353 | + |
2354 | +set( |
2355 | + MIR_GENERATED_INCLUDE_DIRECTORIES |
2356 | + ${MIR_GENERATED_INCLUDE_DIRECTORIES} |
2357 | + PARENT_SCOPE) |
2358 | + |
2359 | +add_library( |
2360 | + mirevents OBJECT |
2361 | + ${EVENT_SOURCES} |
2362 | +) |
2363 | + |
2364 | +add_dependencies(mirevents mircapnproto) |
2365 | + |
2366 | +include_directories( |
2367 | + ${PROJECT_SOURCE_DIR}/include/client |
2368 | + ${PROJECT_SOURCE_DIR}/src/include/cookie |
2369 | + ${MIR_GENERATED_INCLUDE_DIRECTORIES} |
2370 | +) |
2371 | |
2372 | === added file 'src/common/events/capnp_enums_aligned_asserts.cpp' |
2373 | --- src/common/events/capnp_enums_aligned_asserts.cpp 1970-01-01 00:00:00 +0000 |
2374 | +++ src/common/events/capnp_enums_aligned_asserts.cpp 2016-03-16 18:27:24 +0000 |
2375 | @@ -0,0 +1,82 @@ |
2376 | +/* |
2377 | + * Copyright © 2016 Canonical Ltd. |
2378 | + * |
2379 | + * This program is free software: you can redistribute it and/or modify it |
2380 | + * under the terms of the GNU Lesser General Public License version 3, |
2381 | + * as published by the Free Software Foundation. |
2382 | + * |
2383 | + * This program is distributed in the hope that it will be useful, |
2384 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2385 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2386 | + * GNU Lesser General Public License for more details. |
2387 | + * |
2388 | + * You should have received a copy of the GNU Lesser General Public License |
2389 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2390 | + * |
2391 | + * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
2392 | + */ |
2393 | + |
2394 | +#include "mir/events/event_private.h" |
2395 | +#include "mir_event.capnp.h" |
2396 | + |
2397 | +namespace mcap = mir::capnp; |
2398 | + |
2399 | +/* Static asserts that our capnp enums are equal to the c api enums. |
2400 | + This way we can tell on compile time if any of the enums are incorrect. |
2401 | +*/ |
2402 | +namespace |
2403 | +{ |
2404 | +static_assert(static_cast<MirKeyboardAction>(mcap::KeyboardEvent::Action::UP) == |
2405 | + mir_keyboard_action_up, ""); |
2406 | +static_assert(static_cast<MirKeyboardAction>(mcap::KeyboardEvent::Action::DOWN) == |
2407 | + mir_keyboard_action_down, ""); |
2408 | +static_assert(static_cast<MirKeyboardAction>(mcap::KeyboardEvent::Action::REPEAT) == |
2409 | + mir_keyboard_action_repeat, ""); |
2410 | + |
2411 | +static_assert(static_cast<MirTouchTooltype>(mcap::MotionEventSet::Motion::ToolType::UNKNOWN) == |
2412 | + mir_touch_tooltype_unknown, ""); |
2413 | +static_assert(static_cast<MirTouchTooltype>(mcap::MotionEventSet::Motion::ToolType::FINGER) == |
2414 | + mir_touch_tooltype_finger, ""); |
2415 | +static_assert(static_cast<MirTouchTooltype>(mcap::MotionEventSet::Motion::ToolType::STYLUS) == |
2416 | + mir_touch_tooltype_stylus, ""); |
2417 | + |
2418 | +static_assert(static_cast<MirInputConfigurationAction>(mcap::InputConfigurationEvent::Action::CONFIGURATION_CHANGED) == |
2419 | + mir_input_configuration_action_configuration_changed, ""); |
2420 | +static_assert(static_cast<MirInputConfigurationAction>(mcap::InputConfigurationEvent::Action::DEVICE_RESET) == |
2421 | + mir_input_configuration_action_device_reset, ""); |
2422 | + |
2423 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::TYPE) == |
2424 | + mir_surface_attrib_type, ""); |
2425 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::STATE) == |
2426 | + mir_surface_attrib_state, ""); |
2427 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::SWAP_INTERVAL) == |
2428 | + mir_surface_attrib_swapinterval, ""); |
2429 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::FOCUS) == |
2430 | + mir_surface_attrib_focus, ""); |
2431 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::DPI) == |
2432 | + mir_surface_attrib_dpi, ""); |
2433 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::VISIBILITY) == |
2434 | + mir_surface_attrib_visibility, ""); |
2435 | +static_assert(static_cast<MirSurfaceAttrib>(mcap::SurfaceEvent::Attrib::PREFERRED_ORIENTATION) == |
2436 | + mir_surface_attrib_preferred_orientation, ""); |
2437 | + |
2438 | +static_assert(static_cast<MirPromptSessionState>(mcap::PromptSessionEvent::State::STOPPED) == |
2439 | + mir_prompt_session_state_stopped, ""); |
2440 | +static_assert(static_cast<MirPromptSessionState>(mcap::PromptSessionEvent::State::STARTED) == |
2441 | + mir_prompt_session_state_started, ""); |
2442 | +static_assert(static_cast<MirPromptSessionState>(mcap::PromptSessionEvent::State::SUSPENDED) == |
2443 | + mir_prompt_session_state_suspended, ""); |
2444 | + |
2445 | +static_assert(static_cast<MirFormFactor>(mcap::SurfaceOutputEvent::FormFactor::UNKNOWN) == |
2446 | + mir_form_factor_unknown, ""); |
2447 | +static_assert(static_cast<MirFormFactor>(mcap::SurfaceOutputEvent::FormFactor::PHONE) == |
2448 | + mir_form_factor_phone, ""); |
2449 | +static_assert(static_cast<MirFormFactor>(mcap::SurfaceOutputEvent::FormFactor::TABLET) == |
2450 | + mir_form_factor_tablet, ""); |
2451 | +static_assert(static_cast<MirFormFactor>(mcap::SurfaceOutputEvent::FormFactor::MONITOR) == |
2452 | + mir_form_factor_monitor, ""); |
2453 | +static_assert(static_cast<MirFormFactor>(mcap::SurfaceOutputEvent::FormFactor::TV) == |
2454 | + mir_form_factor_tv, ""); |
2455 | +static_assert(static_cast<MirFormFactor>(mcap::SurfaceOutputEvent::FormFactor::PROJECTOR) == |
2456 | + mir_form_factor_projector, ""); |
2457 | +} |
2458 | |
2459 | === added file 'src/common/events/event_private.cpp' |
2460 | --- src/common/events/event_private.cpp 1970-01-01 00:00:00 +0000 |
2461 | +++ src/common/events/event_private.cpp 2016-03-16 18:27:24 +0000 |
2462 | @@ -0,0 +1,67 @@ |
2463 | +/* |
2464 | + * Copyright © 2016 Canonical Ltd. |
2465 | + * |
2466 | + * This program is free software: you can redistribute it and/or modify it |
2467 | + * under the terms of the GNU Lesser General Public License version 3, |
2468 | + * as published by the Free Software Foundation. |
2469 | + * |
2470 | + * This program is distributed in the hope that it will be useful, |
2471 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2472 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2473 | + * GNU Lesser General Public License for more details. |
2474 | + * |
2475 | + * You should have received a copy of the GNU Lesser General Public License |
2476 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2477 | + * |
2478 | + * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
2479 | + */ |
2480 | + |
2481 | +#include "mir/events/event_private.h" |
2482 | + |
2483 | +MirEvent::MirEvent(MirEvent const& e) |
2484 | +{ |
2485 | + auto reader = e.event.asReader(); |
2486 | + message.setRoot(reader); |
2487 | + event = message.getRoot<mir::capnp::Event>(); |
2488 | +} |
2489 | + |
2490 | +MirEvent& MirEvent::operator=(MirEvent const& e) |
2491 | +{ |
2492 | + auto reader = e.event.asReader(); |
2493 | + message.setRoot(reader); |
2494 | + event = message.getRoot<mir::capnp::Event>(); |
2495 | + return *this; |
2496 | +} |
2497 | + |
2498 | +// Deep copy from a reader |
2499 | +MirEvent::MirEvent(mir::capnp::Event::Reader& reader) |
2500 | +{ |
2501 | + message.setRoot(reader); |
2502 | + event = message.getRoot<mir::capnp::Event>(); |
2503 | +} |
2504 | + |
2505 | +MirEvent::MirEvent(::capnp::Data::Reader& reader) |
2506 | +{ |
2507 | + message.setRoot(reader); |
2508 | + event = message.getRoot<mir::capnp::Event>(); |
2509 | +} |
2510 | + |
2511 | +mir::capnp::Event::Builder& MirEvent::operator*() |
2512 | +{ |
2513 | + return event; |
2514 | +} |
2515 | + |
2516 | +mir::capnp::Event::Builder const& MirEvent::operator*() const |
2517 | +{ |
2518 | + return event; |
2519 | +} |
2520 | + |
2521 | +mir::capnp::Event::Builder* MirEvent::operator->() |
2522 | +{ |
2523 | + return &event; |
2524 | +} |
2525 | + |
2526 | +mir::capnp::Event::Builder const* MirEvent::operator->() const |
2527 | +{ |
2528 | + return &event; |
2529 | +} |
2530 | |
2531 | === renamed file 'src/client/mir_cookie.h' => 'src/include/client/mir/mir_cookie.h' |
2532 | --- src/client/mir_cookie.h 2016-01-22 20:16:50 +0000 |
2533 | +++ src/include/client/mir/mir_cookie.h 2016-03-16 18:27:24 +0000 |
2534 | @@ -22,19 +22,21 @@ |
2535 | |
2536 | #include "mir/cookie/blob.h" |
2537 | |
2538 | +#include <vector> |
2539 | + |
2540 | class MirCookie |
2541 | { |
2542 | public: |
2543 | explicit MirCookie(void const* buffer, size_t size); |
2544 | - explicit MirCookie(mir::cookie::Blob const& blob); |
2545 | + explicit MirCookie(std::vector<uint8_t> const& cookie); |
2546 | |
2547 | void copy_to(void* buffer, size_t size) const; |
2548 | size_t size() const; |
2549 | |
2550 | - mir::cookie::Blob blob() const; |
2551 | + std::vector<uint8_t> cookie() const; |
2552 | |
2553 | private: |
2554 | - mir::cookie::Blob blob_; |
2555 | + std::vector<uint8_t> cookie_; |
2556 | }; |
2557 | |
2558 | #endif // MIR_CLIENT_MIR_COOKIE_H_ |
2559 | |
2560 | === modified file 'src/include/common/mir/events/event_private.h' |
2561 | --- src/include/common/mir/events/event_private.h 2016-01-29 08:18:22 +0000 |
2562 | +++ src/include/common/mir/events/event_private.h 2016-03-16 18:27:24 +0000 |
2563 | @@ -14,6 +14,7 @@ |
2564 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2565 | * |
2566 | * Authored by: Thomas Voss <thomas.voss@canonical.com> |
2567 | + * Brandon Schaefer <brandon.schaefer@canonical.com> |
2568 | */ |
2569 | |
2570 | // ================================== |
2571 | @@ -35,167 +36,42 @@ |
2572 | #include <array> |
2573 | #include <chrono> |
2574 | |
2575 | -#ifdef __cplusplus |
2576 | -/** |
2577 | - * \addtogroup mir_toolkit |
2578 | - * @{ |
2579 | - */ |
2580 | -extern "C" { |
2581 | -#endif |
2582 | -/* TODO: To the moon. */ |
2583 | -#define MIR_INPUT_EVENT_MAX_POINTER_COUNT 16 |
2584 | - |
2585 | -// PRIVATE |
2586 | -// Direct access to MirKeyboardEvent is deprecated. Please use mir_event_get_input_event |
2587 | -// and the mir_input_event* family of functions. |
2588 | -struct MirKeyboardEvent |
2589 | -{ |
2590 | - MirEventType type; |
2591 | - |
2592 | - int32_t device_id; |
2593 | - int32_t source_id; |
2594 | - MirKeyboardAction action; |
2595 | - MirInputEventModifiers modifiers; |
2596 | - |
2597 | - int32_t key_code; |
2598 | - int32_t scan_code; |
2599 | - |
2600 | - std::chrono::nanoseconds event_time; |
2601 | - mir::cookie::Blob cookie; |
2602 | -}; |
2603 | - |
2604 | -typedef struct |
2605 | -{ |
2606 | - int id; |
2607 | - float x; |
2608 | - float y; |
2609 | - float dx; |
2610 | - float dy; |
2611 | - float touch_major; |
2612 | - float touch_minor; |
2613 | - float size; |
2614 | - float pressure; |
2615 | - float orientation; |
2616 | - float vscroll; |
2617 | - float hscroll; |
2618 | - MirTouchTooltype tool_type; |
2619 | - |
2620 | - // TODO: We would like to store this as a MirTouchAction but we still encode pointer actions |
2621 | - // here as well. |
2622 | - int action; |
2623 | -} MirMotionPointer; |
2624 | - |
2625 | -// PRIVATE |
2626 | -// Direct access to MirMotionEvent is deprecated. Please use mir_event_get_input_event |
2627 | -// and the mir_input_event* family of functions. |
2628 | -typedef struct |
2629 | -{ |
2630 | - MirEventType type; |
2631 | - |
2632 | - int32_t device_id; |
2633 | - int32_t source_id; |
2634 | - |
2635 | - MirInputEventModifiers modifiers; |
2636 | - |
2637 | - MirPointerButtons buttons; |
2638 | - std::chrono::nanoseconds event_time; |
2639 | - mir::cookie::Blob cookie; |
2640 | - |
2641 | - size_t pointer_count; |
2642 | - MirMotionPointer pointer_coordinates[MIR_INPUT_EVENT_MAX_POINTER_COUNT]; |
2643 | - /* "_coordinates" is a misnomer here because there's plenty more info than |
2644 | - just coordinates, but renaming it accurately would be an API break */ |
2645 | -} MirMotionEvent; |
2646 | - |
2647 | -struct MirInputConfigurationEvent |
2648 | -{ |
2649 | - MirEventType type; |
2650 | - |
2651 | - MirInputConfigurationAction action; |
2652 | - std::chrono::nanoseconds when; |
2653 | - MirInputDeviceId id; |
2654 | -}; |
2655 | - |
2656 | -struct MirSurfaceEvent |
2657 | -{ |
2658 | - MirEventType type; |
2659 | - |
2660 | - int id; |
2661 | - MirSurfaceAttrib attrib; |
2662 | - int value; |
2663 | -}; |
2664 | - |
2665 | -struct MirResizeEvent |
2666 | -{ |
2667 | - MirEventType type; |
2668 | - |
2669 | - int surface_id; |
2670 | - int width; |
2671 | - int height; |
2672 | -}; |
2673 | - |
2674 | -struct MirPromptSessionEvent |
2675 | -{ |
2676 | - MirEventType type; |
2677 | - |
2678 | - MirPromptSessionState new_state; |
2679 | -}; |
2680 | - |
2681 | -struct MirOrientationEvent |
2682 | -{ |
2683 | - MirEventType type; |
2684 | - |
2685 | - int surface_id; |
2686 | - MirOrientation direction; |
2687 | -}; |
2688 | - |
2689 | -struct MirCloseSurfaceEvent |
2690 | -{ |
2691 | - MirEventType type; |
2692 | - |
2693 | - int surface_id; |
2694 | -}; |
2695 | - |
2696 | -struct MirKeymapEvent |
2697 | -{ |
2698 | - MirEventType type; |
2699 | - |
2700 | - int surface_id; |
2701 | - MirInputDeviceId device_id; |
2702 | - char const* buffer; |
2703 | - size_t size; |
2704 | -}; |
2705 | - |
2706 | -struct MirSurfaceOutputEvent |
2707 | -{ |
2708 | - MirEventType type; |
2709 | - |
2710 | - int surface_id; |
2711 | - int dpi; |
2712 | - float scale; |
2713 | - MirFormFactor form_factor; |
2714 | - uint32_t output_id; |
2715 | -}; |
2716 | - |
2717 | -// Access to MirEvent is deprecated |
2718 | -union MirEvent |
2719 | -{ |
2720 | - MirEventType type; |
2721 | - MirKeyboardEvent key; |
2722 | - MirMotionEvent motion; |
2723 | - MirSurfaceEvent surface; |
2724 | - MirResizeEvent resize; |
2725 | - MirPromptSessionEvent prompt_session; |
2726 | - MirOrientationEvent orientation; |
2727 | - MirCloseSurfaceEvent close_surface; |
2728 | - MirKeymapEvent keymap; |
2729 | - MirInputConfigurationEvent input_configuration; |
2730 | - MirSurfaceOutputEvent surface_output; |
2731 | -}; |
2732 | - |
2733 | -#ifdef __cplusplus |
2734 | -} |
2735 | -/**@}*/ |
2736 | -#endif |
2737 | +#include <capnp/message.h> |
2738 | +#include "mir_event.capnp.h" |
2739 | + |
2740 | +struct MirEvent |
2741 | +{ |
2742 | + MirEvent() = default; |
2743 | + MirEvent(MirEvent const& e); |
2744 | + MirEvent& operator=(MirEvent const& e); |
2745 | + |
2746 | + // Deep copy from a reader |
2747 | + explicit MirEvent(mir::capnp::Event::Reader& reader); |
2748 | + explicit MirEvent(::capnp::Data::Reader& reader); |
2749 | + |
2750 | + mir::capnp::Event::Builder& operator*(); |
2751 | + mir::capnp::Event::Builder const& operator*() const; |
2752 | + |
2753 | + mir::capnp::Event::Builder* operator->(); |
2754 | + mir::capnp::Event::Builder const* operator->() const; |
2755 | + |
2756 | + ::capnp::MallocMessageBuilder message; |
2757 | + mir::capnp::Event::Builder event{message.initRoot<mir::capnp::Event>()}; |
2758 | +}; |
2759 | + |
2760 | +// Helper for implicit upcast to a MirEvent |
2761 | +struct MirSurfaceEvent : MirEvent { }; |
2762 | +struct MirResizeEvent : MirEvent { }; |
2763 | +struct MirPromptSessionEvent : MirEvent { }; |
2764 | +struct MirOrientationEvent : MirEvent { }; |
2765 | +struct MirCloseSurfaceEvent : MirEvent { }; |
2766 | +struct MirKeymapEvent : MirEvent { }; |
2767 | +struct MirInputConfigurationEvent : MirEvent { }; |
2768 | +struct MirSurfaceOutputEvent : MirEvent { }; |
2769 | +struct MirInputEvent : MirEvent { }; |
2770 | +struct MirKeyboardEvent : MirInputEvent { }; |
2771 | +struct MirMotionEvent : MirInputEvent { }; |
2772 | +struct MirPointerEvent : MirMotionEvent { }; |
2773 | +struct MirTouchEvent : MirMotionEvent { }; |
2774 | |
2775 | #endif /* MIR_COMMON_EVENT_PRIVATE_H_ */ |
2776 | |
2777 | === modified file 'src/server/CMakeLists.txt' |
2778 | --- src/server/CMakeLists.txt 2016-03-16 06:59:01 +0000 |
2779 | +++ src/server/CMakeLists.txt 2016-03-16 18:27:24 +0000 |
2780 | @@ -64,6 +64,7 @@ |
2781 | $<TARGET_OBJECTS:mirserverobjects> |
2782 | $<TARGET_OBJECTS:mirinput> |
2783 | $<TARGET_OBJECTS:mirscene> |
2784 | + $<TARGET_OBJECTS:mirevents> |
2785 | $<TARGET_OBJECTS:mircompositor> |
2786 | $<TARGET_OBJECTS:mirgraphics> |
2787 | $<TARGET_OBJECTS:mirfrontend> |
2788 | @@ -102,6 +103,7 @@ |
2789 | mirplatform |
2790 | mircommon |
2791 | mirprotobuf |
2792 | + mircapnproto |
2793 | mircookie |
2794 | |
2795 | ${GLog_LIBRARY} |
2796 | |
2797 | === modified file 'src/server/graphics/nested/display_buffer.cpp' |
2798 | --- src/server/graphics/nested/display_buffer.cpp 2016-01-29 08:18:22 +0000 |
2799 | +++ src/server/graphics/nested/display_buffer.cpp 2016-03-16 18:27:24 +0000 |
2800 | @@ -109,19 +109,21 @@ |
2801 | if (mir_event_get_type(&event) != mir_event_type_input) |
2802 | return; |
2803 | |
2804 | - if (event.type == mir_event_type_motion) |
2805 | + if (event->asReader().which() == mir::capnp::Event::Which::MOTION_SET) |
2806 | { |
2807 | auto my_event = event; |
2808 | auto iev = mir_event_get_input_event(&my_event); |
2809 | |
2810 | if (mir_input_event_get_type(iev) == mir_input_event_type_pointer) |
2811 | { |
2812 | - auto& motion = my_event.motion; |
2813 | + auto motion = my_event->getMotionSet(); |
2814 | |
2815 | - for (size_t i = 0; i != motion.pointer_count; ++i) |
2816 | + for (size_t i = 0; i != motion.getCount(); ++i) |
2817 | { |
2818 | - motion.pointer_coordinates[i].x += area.top_left.x.as_float(); |
2819 | - motion.pointer_coordinates[i].y += area.top_left.y.as_float(); |
2820 | + auto x = motion.getMotions()[i].getX(); |
2821 | + auto y = motion.getMotions()[i].getY(); |
2822 | + motion.getMotions()[i].setX(x + area.top_left.x.as_float()); |
2823 | + motion.getMotions()[i].setY(y + area.top_left.y.as_float()); |
2824 | } |
2825 | |
2826 | auto pev = mir_input_event_get_pointer_event(iev); |
2827 | |
2828 | === modified file 'src/server/input/android/input_sender.cpp' |
2829 | --- src/server/input/android/input_sender.cpp 2016-03-16 06:59:01 +0000 |
2830 | +++ src/server/input/android/input_sender.cpp 2016-03-16 18:27:24 +0000 |
2831 | @@ -230,6 +230,22 @@ |
2832 | }); |
2833 | } |
2834 | |
2835 | +namespace |
2836 | +{ |
2837 | +mir::cookie::Blob convert_capnp_cookie_to_blob(::capnp::Data::Reader const& cookie) |
2838 | +{ |
2839 | + if (cookie.size() > mir::cookie::default_blob_size) |
2840 | + { |
2841 | + BOOST_THROW_EXCEPTION(std::runtime_error("The cookie size must be less the mir::cookie::default_blob_size")); |
2842 | + } |
2843 | + |
2844 | + mir::cookie::Blob cookie_blob{0}; |
2845 | + std::copy(std::begin(cookie), std::end(cookie), std::begin(cookie_blob)); |
2846 | + |
2847 | + return cookie_blob; |
2848 | +} |
2849 | +} |
2850 | + |
2851 | droidinput::status_t mia::InputSender::ActiveTransfer::send_key_event(uint32_t seq, MirEvent const& event) |
2852 | { |
2853 | int32_t repeat_count = 0; |
2854 | @@ -247,7 +263,7 @@ |
2855 | mir_keyboard_event_scan_code(key_event), |
2856 | mia::android_modifiers_from_mir(mir_keyboard_event_modifiers(key_event)), |
2857 | repeat_count, |
2858 | - event.key.cookie, |
2859 | + convert_capnp_cookie_to_blob(event->asReader().getKey().getCookie()), |
2860 | event_time, |
2861 | event_time); |
2862 | } |
2863 | @@ -255,10 +271,11 @@ |
2864 | droidinput::status_t mia::InputSender::ActiveTransfer::send_touch_event(uint32_t seq, MirEvent const& event) |
2865 | { |
2866 | droidinput::status_t ret = droidinput::OK; |
2867 | - droidinput::PointerCoords coords[MIR_INPUT_EVENT_MAX_POINTER_COUNT]; |
2868 | - droidinput::PointerProperties properties[MIR_INPUT_EVENT_MAX_POINTER_COUNT]; |
2869 | + droidinput::PointerCoords coords[mir::capnp::MotionEventSet::MAX_COUNT]; |
2870 | + droidinput::PointerProperties properties[mir::capnp::MotionEventSet::MAX_COUNT]; |
2871 | auto input_event = mir_event_get_input_event(&event); |
2872 | auto touch = mir_input_event_get_touch_event(input_event); |
2873 | + auto cookie = convert_capnp_cookie_to_blob(event->asReader().getMotionSet().getCookie()); |
2874 | std::chrono::nanoseconds const event_time{mir_input_event_get_event_time(input_event)}; |
2875 | auto const x_offset = 0.0f; |
2876 | auto const y_offset = 0.0f; |
2877 | @@ -324,7 +341,7 @@ |
2878 | ret = publisher.publishMotionEvent(seq, mir_input_event_get_device_id(input_event), AINPUT_SOURCE_TOUCHSCREEN, |
2879 | state_change.android_action, flags, edge_flags, |
2880 | mia::android_modifiers_from_mir(mir_touch_event_modifiers(touch)), |
2881 | - button_state, x_offset, y_offset, x_precision, y_precision, event.motion.cookie, |
2882 | + button_state, x_offset, y_offset, x_precision, y_precision, cookie, |
2883 | event_time, event_time, contacts_in_event, properties, coords); |
2884 | } |
2885 | |
2886 | @@ -349,6 +366,8 @@ |
2887 | pointer_properties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE; |
2888 | pointer_properties.id = 0; |
2889 | |
2890 | + auto cookie = convert_capnp_cookie_to_blob(event->asReader().getMotionSet().getCookie()); |
2891 | + |
2892 | std::chrono::nanoseconds const event_time{mir_input_event_get_event_time(input_event)}; |
2893 | auto const x_offset = 0.0f; |
2894 | auto const y_offset = 0.0f; |
2895 | @@ -361,7 +380,7 @@ |
2896 | mia::android_pointer_action_from_mir(mir_pointer_event_action(pointer), mir_pointer_event_buttons(pointer)), |
2897 | flags, edge_flags, mia::android_modifiers_from_mir(mir_pointer_event_modifiers(pointer)), |
2898 | mia::android_pointer_buttons_from_mir(mir_pointer_event_buttons(pointer)), x_offset, y_offset, x_precision, |
2899 | - y_precision, event.motion.cookie, event_time, event_time, 1, &pointer_properties, &pointer_coord); |
2900 | + y_precision, cookie, event_time, event_time, 1, &pointer_properties, &pointer_coord); |
2901 | } |
2902 | |
2903 | |
2904 | |
2905 | === modified file 'src/server/input/default_event_builder.cpp' |
2906 | --- src/server/input/default_event_builder.cpp 2016-01-29 08:18:22 +0000 |
2907 | +++ src/server/input/default_event_builder.cpp 2016-03-16 18:27:24 +0000 |
2908 | @@ -53,9 +53,10 @@ |
2909 | { |
2910 | if (action == mir_touch_action_up || action == mir_touch_action_down) |
2911 | { |
2912 | - auto const cookie = cookie_authority->make_cookie(event.motion.event_time.count()); |
2913 | + auto const cookie = cookie_authority->make_cookie(event->getMotionSet().getEventTime().getCount()); |
2914 | auto const serialized_cookie = cookie->serialize(); |
2915 | - std::copy_n(std::begin(serialized_cookie), event.motion.cookie.size(), std::begin(event.motion.cookie)); |
2916 | + ::capnp::Data::Reader cookie_data(serialized_cookie.data(), serialized_cookie.size()); |
2917 | + event->getMotionSet().setCookie(cookie_data); |
2918 | } |
2919 | |
2920 | me::add_touch(event, touch_id, action, tooltype, x_axis_value, y_axis_value, pressure_value, touch_major_value, |
2921 | |
2922 | === modified file 'src/server/input/key_repeat_dispatcher.cpp' |
2923 | --- src/server/input/key_repeat_dispatcher.cpp 2016-03-16 06:59:01 +0000 |
2924 | +++ src/server/input/key_repeat_dispatcher.cpp 2016-03-16 18:27:24 +0000 |
2925 | @@ -114,16 +114,6 @@ |
2926 | return next_dispatcher->dispatch(event); |
2927 | } |
2928 | |
2929 | -namespace |
2930 | -{ |
2931 | -MirEvent copy_to_repeat_ev(MirKeyboardEvent const* kev) |
2932 | -{ |
2933 | - MirEvent repeat_ev(*reinterpret_cast<MirEvent const*>(kev)); |
2934 | - repeat_ev.key.action = mir_keyboard_action_repeat; |
2935 | - return repeat_ev; |
2936 | -} |
2937 | -} |
2938 | - |
2939 | // Returns true if the original event has been handled, that is ::dispatch should not pass it on. |
2940 | bool mi::KeyRepeatDispatcher::handle_key_input(MirInputDeviceId id, MirKeyboardEvent const* kev) |
2941 | { |
2942 | @@ -146,7 +136,9 @@ |
2943 | } |
2944 | case mir_keyboard_action_down: |
2945 | { |
2946 | - MirEvent ev = copy_to_repeat_ev(kev); |
2947 | + auto reader = reinterpret_cast<MirEvent const*>(kev)->event.asReader(); |
2948 | + MirEvent ev(reader); |
2949 | + ev->getKey().setAction(static_cast<mir::capnp::KeyboardEvent::Action>(mir_keyboard_action_repeat)); |
2950 | |
2951 | auto it = device_state.repeat_alarms_by_scancode.find(scan_code); |
2952 | if (it != device_state.repeat_alarms_by_scancode.end()) |
2953 | @@ -160,10 +152,14 @@ |
2954 | { |
2955 | std::lock_guard<std::mutex> lg(repeat_state_mutex); |
2956 | |
2957 | - ev.key.event_time = std::chrono::steady_clock::now().time_since_epoch(); |
2958 | - auto const cookie = cookie_authority->make_cookie(ev.key.event_time.count()); |
2959 | + auto event_time = ev->getKey().getEventTime(); |
2960 | + event_time.setCount(std::chrono::steady_clock::now().time_since_epoch().count()); |
2961 | + |
2962 | + auto const cookie = cookie_authority->make_cookie(event_time.getCount()); |
2963 | auto const serialized_cookie = cookie->serialize(); |
2964 | - std::copy_n(std::begin(serialized_cookie), ev.key.cookie.size(), std::begin(ev.key.cookie)); |
2965 | + ::capnp::Data::Reader cookie_data(serialized_cookie.data(), serialized_cookie.size()); |
2966 | + ev->getKey().setCookie(cookie_data); |
2967 | + |
2968 | next_dispatcher->dispatch(ev); |
2969 | |
2970 | capture_alarm->reschedule_in(repeat_delay); |
2971 | |
2972 | === modified file 'src/server/input/surface_input_dispatcher.cpp' |
2973 | --- src/server/input/surface_input_dispatcher.cpp 2016-01-29 08:18:22 +0000 |
2974 | +++ src/server/input/surface_input_dispatcher.cpp 2016-03-16 18:27:24 +0000 |
2975 | @@ -76,15 +76,18 @@ |
2976 | MirEvent to_deliver; |
2977 | to_deliver = *reinterpret_cast<MirEvent const*>(ev); |
2978 | |
2979 | - if (to_deliver.type == mir_event_type_motion) |
2980 | + if (to_deliver->which() == mir::capnp::Event::Which::MOTION_SET) |
2981 | { |
2982 | auto sx = surface->input_bounds().top_left.x.as_int(); |
2983 | auto sy = surface->input_bounds().top_left.y.as_int(); |
2984 | + auto mev = to_deliver->getMotionSet(); |
2985 | |
2986 | - for (unsigned i = 0; i < to_deliver.motion.pointer_count; i++) |
2987 | + for (unsigned i = 0; i < mev.getCount(); i++) |
2988 | { |
2989 | - to_deliver.motion.pointer_coordinates[i].x -= sx; |
2990 | - to_deliver.motion.pointer_coordinates[i].y -= sy; |
2991 | + auto x = mev.getMotions()[i].getX(); |
2992 | + auto y = mev.getMotions()[i].getY(); |
2993 | + mev.getMotions()[i].setX(x - sx); |
2994 | + mev.getMotions()[i].setY(y - sy); |
2995 | } |
2996 | } |
2997 | surface->consume(&to_deliver); |
2998 | |
2999 | === modified file 'src/server/input/validator.cpp' |
3000 | --- src/server/input/validator.cpp 2016-01-29 08:18:22 +0000 |
3001 | +++ src/server/input/validator.cpp 2016-03-16 18:27:24 +0000 |
3002 | @@ -50,8 +50,6 @@ |
3003 | } |
3004 | auto tev = mir_input_event_get_touch_event(iev); |
3005 | handle_touch_event(mir_input_event_get_device_id(iev), tev); |
3006 | - |
3007 | - return; |
3008 | } |
3009 | |
3010 | namespace |
3011 | @@ -64,63 +62,66 @@ |
3012 | |
3013 | mir::EventUPtr copy_event(MirTouchEvent const* ev) |
3014 | { |
3015 | - MirEvent *ret = new MirEvent; |
3016 | - memcpy(ret, ev, sizeof(MirEvent)); |
3017 | + auto reader = reinterpret_cast<MirEvent const*>(ev)->event.asReader(); |
3018 | + MirEvent* ret = new MirEvent(reader); |
3019 | return make_event_uptr(ret); |
3020 | } |
3021 | |
3022 | // Return a copy of ev with existing touch actions converted to change. |
3023 | // Note this is always a valid successor of ev in the event stream. |
3024 | -mir::EventUPtr convert_touch_actions_to_change(MirTouchEvent const* ev) |
3025 | +mir::EventUPtr convert_touch_actions_to_change(MirTouchEvent const* tev) |
3026 | { |
3027 | - auto ret = copy_event(ev); |
3028 | + auto ret = copy_event(tev); |
3029 | + auto mev = (*ret)->getMotionSet(); |
3030 | |
3031 | - for (size_t i = 0; i < ret->motion.pointer_count; i++) |
3032 | + for (size_t i = 0; i < mev.getCount(); i++) |
3033 | { |
3034 | - ret->motion.pointer_coordinates[i].action = mir_touch_action_change; |
3035 | + mev.getMotions()[i].setAction(mir_touch_action_change); |
3036 | } |
3037 | return ret; |
3038 | } |
3039 | |
3040 | // Helper function to find index for a given touch ID |
3041 | // TODO: Existence of this probably suggests a problem with TouchEvent API... |
3042 | -int index_for_id(MirTouchEvent const* touch_ev, MirTouchId id) |
3043 | +int index_for_id(MirTouchEvent const* tev, MirTouchId id) |
3044 | { |
3045 | - MirEvent const* ev = reinterpret_cast<MirEvent const*>(touch_ev); |
3046 | - for (size_t i = 0; i < ev->motion.pointer_count; i++) |
3047 | + MirEvent const* ev = reinterpret_cast<MirEvent const*>(tev); |
3048 | + auto mev = (*ev)->asReader().getMotionSet(); |
3049 | + |
3050 | + for (size_t i = 0; i < mev.getCount(); i++) |
3051 | { |
3052 | - if (ev->motion.pointer_coordinates[i].id == id) |
3053 | + if (mev.getMotions()[i].getId() == id) |
3054 | return i; |
3055 | } |
3056 | return -1; |
3057 | } |
3058 | |
3059 | // Return an event which is a valid successor of valid_ev but contains a mir_touch_action_down for missing_id |
3060 | -mir::EventUPtr add_missing_down(MirEvent const* valid_ev, MirTouchEvent const* ev, MirTouchId missing_id) |
3061 | +mir::EventUPtr add_missing_down(MirEvent const* valid_ev, MirTouchEvent const* tev, MirTouchId missing_id) |
3062 | { |
3063 | auto valid_tev = reinterpret_cast<MirTouchEvent const*>(valid_ev); |
3064 | |
3065 | // So as not to repeat already occurred actions, we copy the last valid (Delivered) event and replace all the actions |
3066 | // with change, then we will add a missing down for touch "missing_id" |
3067 | auto ret = convert_touch_actions_to_change(valid_tev); |
3068 | - auto index = index_for_id(ev, missing_id); |
3069 | + auto index = index_for_id(tev, missing_id); |
3070 | |
3071 | // In the case where a touch ID goes up and then reappears without a down we don't want to |
3072 | // add a new touch but merely replace the action in the last event. |
3073 | if (auto existing_index = index_for_id((MirTouchEvent const*)ret.get(), missing_id) >= 0) |
3074 | { |
3075 | - ret->motion.pointer_coordinates[existing_index].action = mir_touch_action_down; |
3076 | + (*ret)->getMotionSet().getMotions()[existing_index].setAction(mir_touch_action_down); |
3077 | } |
3078 | else |
3079 | { |
3080 | mev::add_touch(*ret, missing_id, mir_touch_action_down, |
3081 | - mir_touch_event_tooltype(ev, index), |
3082 | - mir_touch_event_axis_value(ev, index, mir_touch_axis_x), |
3083 | - mir_touch_event_axis_value(ev, index, mir_touch_axis_y), |
3084 | - mir_touch_event_axis_value(ev, index, mir_touch_axis_pressure), |
3085 | - mir_touch_event_axis_value(ev, index, mir_touch_axis_touch_major), |
3086 | - mir_touch_event_axis_value(ev, index, mir_touch_axis_touch_minor), |
3087 | - mir_touch_event_axis_value(ev, index, mir_touch_axis_size)); |
3088 | + mir_touch_event_tooltype(tev, index), |
3089 | + mir_touch_event_axis_value(tev, index, mir_touch_axis_x), |
3090 | + mir_touch_event_axis_value(tev, index, mir_touch_axis_y), |
3091 | + mir_touch_event_axis_value(tev, index, mir_touch_axis_pressure), |
3092 | + mir_touch_event_axis_value(tev, index, mir_touch_axis_touch_major), |
3093 | + mir_touch_event_axis_value(tev, index, mir_touch_axis_touch_minor), |
3094 | + mir_touch_event_axis_value(tev, index, mir_touch_axis_size)); |
3095 | } |
3096 | |
3097 | return ret; |
3098 | @@ -136,7 +137,7 @@ |
3099 | auto ret = convert_touch_actions_to_change(tev); |
3100 | auto index = index_for_id(tev, missing_an_up_id); |
3101 | |
3102 | - ret->motion.pointer_coordinates[index].action = mir_touch_action_up; |
3103 | + (*ret)->getMotionSet().getMotions()[index].setAction(mir_touch_action_up); |
3104 | |
3105 | return ret; |
3106 | } |
3107 | @@ -147,7 +148,7 @@ |
3108 | { |
3109 | auto tev = reinterpret_cast<MirTouchEvent const*>(ev); |
3110 | auto ret = copy_event(tev); |
3111 | - ret->motion.pointer_count = 0; |
3112 | + (*ret)->getMotionSet().setCount(0); |
3113 | |
3114 | for (size_t i = 0; i < mir_touch_event_point_count(tev); i++) |
3115 | { |
3116 | @@ -190,53 +191,52 @@ |
3117 | // things are fine. On the other hand if they show up with mir_touch_action_change then a touch point |
3118 | // has appeared before its gone down and thus we must inject an event signifying this touch going down. |
3119 | void mi::Validator::ensure_stream_validity_locked(std::lock_guard<std::mutex> const&, |
3120 | - MirTouchEvent const* ev, MirTouchEvent const* last_ev) |
3121 | + MirTouchEvent const* tev, MirTouchEvent const* last_tev) |
3122 | { |
3123 | TouchSet expected; |
3124 | - for (size_t i = 0; i < mir_touch_event_point_count(last_ev); i++) |
3125 | + for (size_t i = 0; i < mir_touch_event_point_count(last_tev); i++) |
3126 | { |
3127 | - auto action = mir_touch_event_action(last_ev, i); |
3128 | + auto action = mir_touch_event_action(last_tev, i); |
3129 | if (action == mir_touch_action_up) |
3130 | continue; |
3131 | - expected.insert(mir_touch_event_id(last_ev, i)); |
3132 | + expected.insert(mir_touch_event_id(last_tev, i)); |
3133 | } |
3134 | |
3135 | TouchSet found; |
3136 | - for (size_t i = 0; i < mir_touch_event_point_count(ev); i++) |
3137 | + for (size_t i = 0; i < mir_touch_event_point_count(tev); i++) |
3138 | { |
3139 | - auto id = mir_touch_event_id(ev, i); |
3140 | + auto id = mir_touch_event_id(tev, i); |
3141 | found.insert(id); |
3142 | } |
3143 | |
3144 | // Insert missing touch releases |
3145 | - auto last_ev_copy = |
3146 | - remove_old_releases_from(reinterpret_cast<MirEvent const*>(last_ev)); |
3147 | + auto last_tev_copy = |
3148 | + remove_old_releases_from(reinterpret_cast<MirEvent const*>(last_tev)); |
3149 | for (auto const& expected_id : expected) |
3150 | { |
3151 | if (found.find(expected_id) == found.end()) |
3152 | { |
3153 | - auto inject_ev = add_missing_up(last_ev_copy.get(), expected_id); |
3154 | + auto inject_ev = add_missing_up(last_tev_copy.get(), expected_id); |
3155 | dispatch_valid_event(*inject_ev); |
3156 | - last_ev_copy = remove_old_releases_from(inject_ev.get()); |
3157 | + last_tev_copy = remove_old_releases_from(inject_ev.get()); |
3158 | } |
3159 | } |
3160 | |
3161 | - for (size_t i = 0; i < mir_touch_event_point_count(ev); i++) |
3162 | + for (size_t i = 0; i < mir_touch_event_point_count(tev); i++) |
3163 | { |
3164 | - auto id = mir_touch_event_id(ev, i); |
3165 | + auto id = mir_touch_event_id(tev, i); |
3166 | if (expected.find(id) == expected.end() && |
3167 | - mir_touch_event_action(ev, i) != mir_touch_action_down) |
3168 | + mir_touch_event_action(tev, i) != mir_touch_action_down) |
3169 | { |
3170 | - |
3171 | - auto inject_ev = add_missing_down(last_ev_copy.get(), ev, id); |
3172 | + auto inject_ev = add_missing_down(last_tev_copy.get(), tev, id); |
3173 | dispatch_valid_event(*inject_ev); |
3174 | - last_ev_copy = std::move(inject_ev); |
3175 | + last_tev_copy = std::move(inject_ev); |
3176 | } |
3177 | } |
3178 | } |
3179 | |
3180 | |
3181 | -void mi::Validator::handle_touch_event(MirInputDeviceId id, MirTouchEvent const* ev) |
3182 | +void mi::Validator::handle_touch_event(MirInputDeviceId id, MirTouchEvent const* tev) |
3183 | { |
3184 | std::lock_guard<std::mutex> lg(state_guard); |
3185 | |
3186 | @@ -244,12 +244,12 @@ |
3187 | MirTouchEvent const* last_ev = nullptr; |
3188 | auto default_ev = mev::make_event(id, |
3189 | std::chrono::high_resolution_clock::now().time_since_epoch(), |
3190 | - std::vector<uint8_t>{}, /* No need for a mac, since there's no pointer count for a default event */ |
3191 | + std::vector<uint8_t>{}, // No need for a mac, since there's no pointer count for a default event |
3192 | mir_input_event_modifier_none); |
3193 | |
3194 | if (it == last_event_by_device.end()) |
3195 | { |
3196 | - last_event_by_device.insert(std::make_pair(id, copy_event(ev))); |
3197 | + last_event_by_device.insert(std::make_pair(id, copy_event(tev))); |
3198 | last_ev = reinterpret_cast<MirTouchEvent const*>(default_ev.get()); |
3199 | } |
3200 | else |
3201 | @@ -257,12 +257,12 @@ |
3202 | last_ev = mir_input_event_get_touch_event(mir_event_get_input_event(it->second.get())); |
3203 | } |
3204 | |
3205 | - ensure_stream_validity_locked(lg, ev, last_ev); |
3206 | + ensure_stream_validity_locked(lg, tev, last_ev); |
3207 | |
3208 | // Seems to be no better way to replace a non default constructible value type in an unordered_map |
3209 | // C++17 will give us insert_or_assign |
3210 | last_event_by_device.erase(id); |
3211 | - last_event_by_device.insert(std::make_pair(id, copy_event(ev))); |
3212 | + last_event_by_device.insert(std::make_pair(id, copy_event(tev))); |
3213 | |
3214 | - dispatch_valid_event(*reinterpret_cast<MirEvent const*>(ev)); |
3215 | + dispatch_valid_event(*reinterpret_cast<MirEvent const*>(tev)); |
3216 | } |
3217 | |
3218 | === modified file 'tests/unit-tests/client/input/test_android_input_receiver.cpp' |
3219 | --- tests/unit-tests/client/input/test_android_input_receiver.cpp 2016-01-29 08:18:22 +0000 |
3220 | +++ tests/unit-tests/client/input/test_android_input_receiver.cpp 2016-03-16 18:27:24 +0000 |
3221 | @@ -131,10 +131,6 @@ |
3222 | { |
3223 | public: |
3224 | AndroidInputReceiverSetup() |
3225 | - : event_handler{[this](MirEvent* ev) |
3226 | - { |
3227 | - last_event = *ev; |
3228 | - }} |
3229 | { |
3230 | auto status = droidinput::InputChannel::openInputFdPair(server_fd, client_fd); |
3231 | EXPECT_EQ(droidinput::OK, status); |
3232 | @@ -154,8 +150,7 @@ |
3233 | int server_fd, client_fd; |
3234 | |
3235 | static std::chrono::milliseconds const next_event_timeout; |
3236 | - MirEvent last_event; |
3237 | - std::function<void(MirEvent*)> event_handler; |
3238 | + std::function<void(MirEvent*)> event_handler{[this](MirEvent*) {}}; |
3239 | }; |
3240 | |
3241 | std::chrono::milliseconds const AndroidInputReceiverSetup::next_event_timeout(1000); |
3242 | @@ -163,9 +158,13 @@ |
3243 | |
3244 | TEST_F(AndroidInputReceiverSetup, receiver_receives_key_events) |
3245 | { |
3246 | + MirEvent last_event; |
3247 | mircva::InputReceiver receiver{client_fd, |
3248 | std::make_shared<mircv::XKBMapper>(), |
3249 | - event_handler, |
3250 | + [&last_event](MirEvent* ev) |
3251 | + { |
3252 | + last_event = *ev; |
3253 | + }, |
3254 | std::make_shared<mircv::NullInputReceiverReport>()}; |
3255 | TestingInputProducer producer{server_fd}; |
3256 | |
3257 | @@ -176,8 +175,8 @@ |
3258 | EXPECT_TRUE(mt::fd_becomes_readable(receiver.watch_fd(), next_event_timeout)); |
3259 | receiver.dispatch(md::FdEvent::readable); |
3260 | |
3261 | - EXPECT_EQ(mir_event_type_key, last_event.type); |
3262 | - EXPECT_EQ(producer.testing_key_event_scan_code, last_event.key.scan_code); |
3263 | + EXPECT_EQ(mir::capnp::Event::Which::KEY, last_event.event.which()); |
3264 | + EXPECT_EQ(producer.testing_key_event_scan_code, last_event.event.getKey().getScanCode()); |
3265 | } |
3266 | |
3267 | TEST_F(AndroidInputReceiverSetup, receiver_handles_events) |
3268 | @@ -257,7 +256,7 @@ |
3269 | EXPECT_TRUE(mt::fd_becomes_readable(receiver.watch_fd(), next_event_timeout)); |
3270 | receiver.dispatch(md::FdEvent::readable); |
3271 | EXPECT_TRUE(handler_called); |
3272 | - ASSERT_EQ(mir_event_type_key, ev.type); |
3273 | + ASSERT_EQ(mir::capnp::Event::Which::KEY, ev->which()); |
3274 | |
3275 | // The motion is still too new. Won't be reported yet, but is batched. |
3276 | auto start = high_resolution_clock::now(); |
3277 | @@ -284,7 +283,7 @@ |
3278 | receiver.dispatch(md::FdEvent::readable); |
3279 | |
3280 | EXPECT_TRUE(handler_called); |
3281 | - EXPECT_EQ(mir_event_type_motion, ev.type); |
3282 | + EXPECT_EQ(mir::capnp::Event::Which::MOTION_SET, ev->which()); |
3283 | } |
3284 | |
3285 | TEST_F(AndroidInputReceiverSetup, finish_signalled_after_handler) |
3286 | |
3287 | === modified file 'tests/unit-tests/client/input/test_xkb_mapper.cpp' |
3288 | --- tests/unit-tests/client/input/test_xkb_mapper.cpp 2016-01-29 08:18:22 +0000 |
3289 | +++ tests/unit-tests/client/input/test_xkb_mapper.cpp 2016-03-16 18:27:24 +0000 |
3290 | @@ -39,7 +39,7 @@ |
3291 | 0, scan_code, mir_input_event_modifier_none); |
3292 | |
3293 | mapper.update_state_and_map_event(*ev); |
3294 | - return ev->key.key_code; |
3295 | + return ev->event.getKey().getKeyCode(); |
3296 | } |
3297 | |
3298 | } |
3299 | |
3300 | === modified file 'tests/unit-tests/client/test_event_distributor.cpp' |
3301 | --- tests/unit-tests/client/test_event_distributor.cpp 2015-06-25 03:00:08 +0000 |
3302 | +++ tests/unit-tests/client/test_event_distributor.cpp 2016-03-16 18:27:24 +0000 |
3303 | @@ -43,7 +43,7 @@ |
3304 | |
3305 | MATCHER_P(MirEventTypeIs, type, "") |
3306 | { |
3307 | - return (arg.type == type); |
3308 | + return (arg.event.asReader().which() == type); |
3309 | } |
3310 | |
3311 | } |
3312 | @@ -56,10 +56,10 @@ |
3313 | event_distributor.register_event_handler([this](MirEvent const& event) { event_handled2(event); }); |
3314 | |
3315 | MirEvent e; |
3316 | - e.type = mir_event_type_prompt_session_state_change; |
3317 | + e.event.initPromptSession(); |
3318 | |
3319 | - EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.type))).Times(1); |
3320 | - EXPECT_CALL(*this, event_handled2(MirEventTypeIs(e.type))).Times(1); |
3321 | + EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.event.which()))).Times(1); |
3322 | + EXPECT_CALL(*this, event_handled2(MirEventTypeIs(e.event.which()))).Times(1); |
3323 | event_distributor.handle_event(e); |
3324 | } |
3325 | |
3326 | @@ -72,10 +72,10 @@ |
3327 | event_distributor.unregister_event_handler(reg_id2); |
3328 | |
3329 | MirEvent e; |
3330 | - e.type = mir_event_type_prompt_session_state_change; |
3331 | + e.event.initPromptSession(); |
3332 | |
3333 | - EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.type))).Times(1); |
3334 | - EXPECT_CALL(*this, event_handled2(MirEventTypeIs(e.type))).Times(0); |
3335 | + EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.event.which()))).Times(1); |
3336 | + EXPECT_CALL(*this, event_handled2(MirEventTypeIs(e.event.which()))).Times(0); |
3337 | event_distributor.handle_event(e); |
3338 | } |
3339 | |
3340 | @@ -93,10 +93,10 @@ |
3341 | reg_id2 = event_distributor.register_event_handler([this](MirEvent const& event) { event_handled2(event); }); |
3342 | |
3343 | MirEvent e; |
3344 | - e.type = mir_event_type_prompt_session_state_change; |
3345 | + e.event.initPromptSession(); |
3346 | |
3347 | - EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.type))).Times(1); |
3348 | - EXPECT_CALL(*this, event_handled2(MirEventTypeIs(e.type))).Times(0); |
3349 | + EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.event.which()))).Times(1); |
3350 | + EXPECT_CALL(*this, event_handled2(MirEventTypeIs(e.event.which()))).Times(0); |
3351 | event_distributor.handle_event(e); |
3352 | } |
3353 | |
3354 | @@ -135,7 +135,7 @@ |
3355 | }; |
3356 | |
3357 | MirEvent e; |
3358 | - e.type = mir_event_type_prompt_session_state_change; |
3359 | + e.event.initPromptSession(); |
3360 | |
3361 | std::vector<EventCatcher*> catchers; |
3362 | for (int p = 0; p < 10; p++) |
3363 | |
3364 | === modified file 'tests/unit-tests/input/android/test_android_input_sender.cpp' |
3365 | --- tests/unit-tests/input/android/test_android_input_sender.cpp 2016-03-16 06:59:01 +0000 |
3366 | +++ tests/unit-tests/input/android/test_android_input_sender.cpp 2016-03-16 18:27:24 +0000 |
3367 | @@ -44,7 +44,6 @@ |
3368 | |
3369 | #include <boost/exception/all.hpp> |
3370 | |
3371 | -//#include <algorithm> |
3372 | #include <cstring> |
3373 | |
3374 | namespace mi = mir::input; |
3375 | |
3376 | === modified file 'tests/unit-tests/input/test_input_event.cpp' |
3377 | --- tests/unit-tests/input/test_input_event.cpp 2016-01-29 08:18:22 +0000 |
3378 | +++ tests/unit-tests/input/test_input_event.cpp 2016-03-16 18:27:24 +0000 |
3379 | @@ -23,6 +23,7 @@ |
3380 | #include "mir_toolkit/events/input/input_event.h" |
3381 | |
3382 | using namespace testing; |
3383 | +namespace mcap = mir::capnp; |
3384 | |
3385 | // See: https://bugs.launchpad.net/mir/+bug/1311699 |
3386 | #define MIR_EVENT_ACTION_POINTER_INDEX_MASK 0xff00 |
3387 | @@ -61,40 +62,6 @@ |
3388 | AINPUT_SOURCE_ANY = 0xffffff00 |
3389 | }; |
3390 | |
3391 | -MirEvent a_key_ev() |
3392 | -{ |
3393 | - MirEvent key_ev; |
3394 | - memset(&key_ev, 0, sizeof(key_ev)); |
3395 | - |
3396 | - key_ev.type = mir_event_type_key; |
3397 | - |
3398 | - return key_ev; |
3399 | -} |
3400 | - |
3401 | -MirEvent a_motion_ev(int device_class = AINPUT_SOURCE_UNKNOWN) |
3402 | -{ |
3403 | - MirEvent motion_ev; |
3404 | - memset(&motion_ev, 0, sizeof(motion_ev)); |
3405 | - |
3406 | - motion_ev.type = mir_event_type_motion; |
3407 | - motion_ev.motion.source_id = device_class; |
3408 | - |
3409 | - return motion_ev; |
3410 | -} |
3411 | - |
3412 | -} |
3413 | - |
3414 | -TEST(InputEvent, old_style_key_and_motion_events_are_input_events) |
3415 | -{ |
3416 | - auto key_ev = a_key_ev(); |
3417 | - |
3418 | - EXPECT_EQ(mir_event_type_input, mir_event_get_type(&key_ev)); |
3419 | - EXPECT_EQ(mir_input_event_type_key, mir_input_event_get_type(mir_event_get_input_event(&key_ev))); |
3420 | - |
3421 | - auto motion_ev = a_motion_ev(); |
3422 | - |
3423 | - EXPECT_EQ(mir_event_type_input, mir_event_get_type(&motion_ev)); |
3424 | - EXPECT_NE(nullptr, mir_event_get_input_event(&motion_ev)); |
3425 | } |
3426 | |
3427 | // MirInputEvent properties common to all events. |
3428 | @@ -102,43 +69,52 @@ |
3429 | TEST(CommonInputEventProperties, device_id_taken_from_old_style_event) |
3430 | { |
3431 | int64_t dev_id_1 = 17, dev_id_2 = 23; |
3432 | - auto old_ev = a_motion_ev(); |
3433 | - |
3434 | - old_ev.type = mir_event_type_motion; |
3435 | - old_ev.motion.device_id = dev_id_1; |
3436 | + MirEvent old; |
3437 | + old->initMotionSet(); |
3438 | + |
3439 | + auto device = old->getMotionSet().getDeviceId(); |
3440 | + device.setId(dev_id_1); |
3441 | + |
3442 | EXPECT_EQ(dev_id_1, mir_input_event_get_device_id( |
3443 | - mir_event_get_input_event(&old_ev))); |
3444 | + mir_event_get_input_event(&old))); |
3445 | |
3446 | - old_ev.type = mir_event_type_key; |
3447 | - old_ev.motion.device_id = dev_id_2; |
3448 | + old->initKey(); |
3449 | + device = old->getKey().getDeviceId(); |
3450 | + device.setId(dev_id_2); |
3451 | EXPECT_EQ(dev_id_2, mir_input_event_get_device_id( |
3452 | - mir_event_get_input_event(&old_ev))); |
3453 | + mir_event_get_input_event(&old))); |
3454 | } |
3455 | |
3456 | TEST(CommonInputEventProperties, event_time_taken_from_old_style_event) |
3457 | { |
3458 | std::chrono::nanoseconds event_time_1{79}, event_time_2{83}; |
3459 | - auto old_ev = a_motion_ev(); |
3460 | + MirEvent old; |
3461 | + old->initMotionSet(); |
3462 | |
3463 | - old_ev.motion.event_time = event_time_1; |
3464 | + auto nanoseconds = old->getMotionSet().getEventTime(); |
3465 | + nanoseconds.setCount(event_time_1.count()); |
3466 | EXPECT_EQ(event_time_1.count(), mir_input_event_get_event_time( |
3467 | - mir_event_get_input_event(&old_ev))); |
3468 | + mir_event_get_input_event(&old))); |
3469 | |
3470 | - old_ev.type = mir_event_type_key; |
3471 | - old_ev.key.event_time = event_time_2; |
3472 | + old->initKey(); |
3473 | + nanoseconds = old->getKey().getEventTime(); |
3474 | + nanoseconds.setCount(event_time_2.count()); |
3475 | EXPECT_EQ(event_time_2.count(), mir_input_event_get_event_time( |
3476 | - mir_event_get_input_event(&old_ev))); |
3477 | + mir_event_get_input_event(&old))); |
3478 | } |
3479 | |
3480 | TEST(KeyInputEventProperties, timestamp_taken_from_old_style_event) |
3481 | { |
3482 | std::chrono::nanoseconds event_time_1{79}, event_time_2{83}; |
3483 | - auto old_ev = a_key_ev(); |
3484 | - auto const keyboard_event = mir_input_event_get_keyboard_event(mir_event_get_input_event(&old_ev)); |
3485 | + MirEvent key; |
3486 | + key->initKey(); |
3487 | + |
3488 | + auto const keyboard_event = mir_input_event_get_keyboard_event(mir_event_get_input_event(&key)); |
3489 | |
3490 | for (auto expected : {event_time_1, event_time_2}) |
3491 | { |
3492 | - old_ev.key.event_time = expected; |
3493 | + auto nanoseconds = key->getKey().getEventTime(); |
3494 | + nanoseconds.setCount(expected.count()); |
3495 | |
3496 | auto const input_event = mir_keyboard_event_input_event(keyboard_event); |
3497 | |
3498 | @@ -149,14 +125,15 @@ |
3499 | |
3500 | TEST(KeyInputEventProperties, up_and_down_actions_copied_from_old_style_event) |
3501 | { |
3502 | - auto old_ev = a_key_ev(); |
3503 | + MirEvent key; |
3504 | + key->initKey(); |
3505 | |
3506 | - old_ev.key.action = mir_keyboard_action_down; |
3507 | + key->getKey().setAction(static_cast<mcap::KeyboardEvent::Action>(mir_keyboard_action_down)); |
3508 | |
3509 | - auto new_kev = mir_input_event_get_keyboard_event(mir_event_get_input_event(&old_ev)); |
3510 | + auto new_kev = mir_input_event_get_keyboard_event(mir_event_get_input_event(&key)); |
3511 | EXPECT_EQ(mir_keyboard_action_down, mir_keyboard_event_action(new_kev)); |
3512 | |
3513 | - old_ev.key.action = mir_keyboard_action_up; |
3514 | + key->getKey().setAction(static_cast<mcap::KeyboardEvent::Action>(mir_keyboard_action_up)); |
3515 | EXPECT_EQ(mir_keyboard_action_up, mir_keyboard_event_action(new_kev)); |
3516 | } |
3517 | |
3518 | @@ -166,12 +143,13 @@ |
3519 | int scan_code = 31; |
3520 | MirInputEventModifiers modifiers = mir_input_event_modifier_shift; |
3521 | |
3522 | - auto old_ev = a_key_ev(); |
3523 | - old_ev.key.key_code = key_code; |
3524 | - old_ev.key.scan_code = scan_code; |
3525 | - old_ev.key.modifiers = modifiers; |
3526 | + MirEvent key; |
3527 | + key->initKey(); |
3528 | + key->getKey().setKeyCode(key_code); |
3529 | + key->getKey().setScanCode(scan_code); |
3530 | + key->getKey().setModifiers(modifiers); |
3531 | |
3532 | - auto new_kev = mir_input_event_get_keyboard_event(mir_event_get_input_event(&old_ev)); |
3533 | + auto new_kev = mir_input_event_get_keyboard_event(mir_event_get_input_event(&key)); |
3534 | EXPECT_EQ(key_code, mir_keyboard_event_key_code(new_kev)); |
3535 | EXPECT_EQ(scan_code, mir_keyboard_event_scan_code(new_kev)); |
3536 | EXPECT_EQ(modifiers, mir_keyboard_event_modifiers(new_kev)); |
3537 | @@ -179,13 +157,16 @@ |
3538 | |
3539 | TEST(TouchEventProperties, timestamp_taken_from_old_style_event) |
3540 | { |
3541 | + MirEvent motion; |
3542 | + motion->initMotionSet(); |
3543 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
3544 | std::chrono::nanoseconds event_time_1{79}, event_time_2{83}; |
3545 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN); |
3546 | - auto const touch_event = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev)); |
3547 | + auto const touch_event = mir_input_event_get_touch_event(mir_event_get_input_event(&motion)); |
3548 | |
3549 | for (auto expected : {event_time_1, event_time_2}) |
3550 | { |
3551 | - old_ev.motion.event_time = expected; |
3552 | + auto nanoseconds = motion->getMotionSet().getEventTime(); |
3553 | + nanoseconds.setCount(expected.count()); |
3554 | |
3555 | auto const input_event = mir_touch_event_input_event(touch_event); |
3556 | |
3557 | @@ -196,48 +177,61 @@ |
3558 | TEST(TouchEventProperties, touch_count_taken_from_pointer_count) |
3559 | { |
3560 | unsigned const pointer_count = 3; |
3561 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN); |
3562 | - |
3563 | - old_ev.motion.pointer_count = pointer_count; |
3564 | + MirEvent motion; |
3565 | + motion->initMotionSet(); |
3566 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
3567 | + motion->getMotionSet().setCount(pointer_count); |
3568 | |
3569 | - auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev)); |
3570 | + auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&motion)); |
3571 | EXPECT_EQ(pointer_count, mir_touch_event_point_count(tev)); |
3572 | } |
3573 | |
3574 | TEST(TouchEventProperties, touch_id_comes_from_pointer_coordinates) |
3575 | { |
3576 | unsigned const touch_id = 31; |
3577 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN); |
3578 | - |
3579 | - old_ev.motion.pointer_count = 1; |
3580 | - old_ev.motion.pointer_coordinates[0].id = touch_id; |
3581 | - |
3582 | - auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev)); |
3583 | + MirEvent motion; |
3584 | + motion->initMotionSet(); |
3585 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
3586 | + |
3587 | + motion->getMotionSet().setCount(1); |
3588 | + motion->getMotionSet().initMotions(1); |
3589 | + motion->getMotionSet().getMotions()[0].setId(touch_id); |
3590 | + |
3591 | + auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&motion)); |
3592 | EXPECT_EQ(touch_id, mir_touch_event_id(tev, 0)); |
3593 | } |
3594 | |
3595 | // mir_motion_action_up/down represent the start of a gesture. pointers only go up/down one at a time |
3596 | TEST(TouchEventProperties, down_and_up_actions_are_taken_from_old_event) |
3597 | { |
3598 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN); |
3599 | - old_ev.motion.pointer_count = 1; |
3600 | - old_ev.motion.pointer_coordinates[0].action = mir_touch_action_change; |
3601 | + MirEvent motion; |
3602 | + motion->initMotionSet(); |
3603 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
3604 | + motion->getMotionSet().setCount(1); |
3605 | + motion->getMotionSet().initMotions(1); |
3606 | + motion->getMotionSet().getMotions()[0].setAction(mir_touch_action_change); |
3607 | |
3608 | - auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev)); |
3609 | + auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&motion)); |
3610 | EXPECT_EQ(mir_touch_action_change, mir_touch_event_action(tev, 0)); |
3611 | } |
3612 | |
3613 | TEST(TouchEventProperties, tool_type_copied_from_old_pc) |
3614 | { |
3615 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN); |
3616 | - |
3617 | - auto& old_mev = old_ev.motion; |
3618 | - old_mev.pointer_count = 3; |
3619 | - old_mev.pointer_coordinates[0].tool_type = mir_touch_tooltype_unknown; |
3620 | - old_mev.pointer_coordinates[1].tool_type = mir_touch_tooltype_finger; |
3621 | - old_mev.pointer_coordinates[2].tool_type = mir_touch_tooltype_stylus; |
3622 | - |
3623 | - auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev)); |
3624 | + MirEvent motion; |
3625 | + motion->initMotionSet(); |
3626 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
3627 | + |
3628 | + auto mev = motion->getMotionSet(); |
3629 | + mev.setCount(3); |
3630 | + motion->getMotionSet().initMotions(3); |
3631 | + mev.getMotions()[0].setToolType( |
3632 | + static_cast<mcap::MotionEventSet::Motion::ToolType>(mir_touch_tooltype_unknown)); |
3633 | + mev.getMotions()[1].setToolType( |
3634 | + static_cast<mcap::MotionEventSet::Motion::ToolType>(mir_touch_tooltype_finger)); |
3635 | + mev.getMotions()[2].setToolType( |
3636 | + static_cast<mcap::MotionEventSet::Motion::ToolType>(mir_touch_tooltype_stylus)); |
3637 | + |
3638 | + auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&motion)); |
3639 | EXPECT_EQ(mir_touch_tooltype_unknown, mir_touch_event_tooltype(tev, 0)); |
3640 | EXPECT_EQ(mir_touch_tooltype_finger, mir_touch_event_tooltype(tev, 1)); |
3641 | EXPECT_EQ(mir_touch_tooltype_stylus, mir_touch_event_tooltype(tev, 2)); |
3642 | @@ -246,17 +240,20 @@ |
3643 | TEST(TouchEventProperties, axis_values_used_by_qtmir_copied) |
3644 | { |
3645 | float x_value = 19, y_value = 23, touch_major = .3, touch_minor = .2, pressure = .9, size = 1111; |
3646 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN); |
3647 | - old_ev.motion.pointer_count = 1; |
3648 | - auto &old_pc = old_ev.motion.pointer_coordinates[0]; |
3649 | - old_pc.x = x_value; |
3650 | - old_pc.y = y_value; |
3651 | - old_pc.touch_major = touch_major; |
3652 | - old_pc.touch_minor = touch_minor; |
3653 | - old_pc.pressure = pressure; |
3654 | - old_pc.size = size; |
3655 | + MirEvent motion; |
3656 | + motion->initMotionSet(); |
3657 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_TOUCHSCREEN); |
3658 | + motion->getMotionSet().setCount(3); |
3659 | + motion->getMotionSet().initMotions(3); |
3660 | + auto pc = motion->getMotionSet().getMotions()[0]; |
3661 | + pc.setX(x_value); |
3662 | + pc.setY(y_value); |
3663 | + pc.setTouchMajor(touch_major); |
3664 | + pc.setTouchMinor(touch_minor); |
3665 | + pc.setPressure(pressure); |
3666 | + pc.setSize(size); |
3667 | |
3668 | - auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev)); |
3669 | + auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&motion)); |
3670 | EXPECT_EQ(x_value, mir_touch_event_axis_value(tev, 0, mir_touch_axis_x)); |
3671 | EXPECT_EQ(y_value, mir_touch_event_axis_value(tev, 0, mir_touch_axis_y)); |
3672 | EXPECT_EQ(touch_major, mir_touch_event_axis_value(tev, 0, mir_touch_axis_touch_major)); |
3673 | @@ -283,9 +280,11 @@ |
3674 | TEST_P(DeviceClassTest, pointer_and_touch_events_differentiated_on_device_class) |
3675 | { |
3676 | auto const& param = GetParam(); |
3677 | - auto old_ev = a_motion_ev(param.device_class); |
3678 | + MirEvent motion; |
3679 | + motion->initMotionSet(); |
3680 | + motion->getMotionSet().setSourceId(param.device_class); |
3681 | |
3682 | - auto iev = mir_event_get_input_event(&old_ev); |
3683 | + auto iev = mir_event_get_input_event(&motion); |
3684 | EXPECT_EQ(param.expected_type, mir_input_event_get_type(iev)); |
3685 | } |
3686 | |
3687 | @@ -309,12 +308,15 @@ |
3688 | TEST(PointerInputEventProperties, timestamp_taken_from_old_style_event) |
3689 | { |
3690 | std::chrono::nanoseconds event_time_1{79}, event_time_2{83}; |
3691 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE); |
3692 | - auto const pointer_event = mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev)); |
3693 | + MirEvent motion; |
3694 | + motion->initMotionSet(); |
3695 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_MOUSE); |
3696 | + auto const pointer_event = mir_input_event_get_pointer_event(mir_event_get_input_event(&motion)); |
3697 | |
3698 | for (auto expected : {event_time_1, event_time_2}) |
3699 | { |
3700 | - old_ev.motion.event_time = expected; |
3701 | + auto nanoseconds = motion->getMotionSet().getEventTime(); |
3702 | + nanoseconds.setCount(expected.count()); |
3703 | |
3704 | auto const input_event = mir_pointer_event_input_event(pointer_event); |
3705 | |
3706 | @@ -325,25 +327,31 @@ |
3707 | TEST(PointerInputEventProperties, modifiers_taken_from_old_style_ev) |
3708 | { |
3709 | MirInputEventModifiers modifiers = mir_input_event_modifier_shift; |
3710 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE); |
3711 | - old_ev.motion.modifiers = modifiers; |
3712 | + MirEvent motion; |
3713 | + motion->initMotionSet(); |
3714 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_MOUSE); |
3715 | + motion->getMotionSet().setModifiers(modifiers); |
3716 | |
3717 | auto pointer_event = |
3718 | - mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev)); |
3719 | + mir_input_event_get_pointer_event(mir_event_get_input_event(&motion)); |
3720 | EXPECT_EQ(modifiers, mir_pointer_event_modifiers(pointer_event)); |
3721 | } |
3722 | |
3723 | TEST(PointerInputEventProperties, button_state_translated) |
3724 | { |
3725 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE); |
3726 | + MirEvent motion; |
3727 | + motion->initMotionSet(); |
3728 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_MOUSE); |
3729 | + auto mev = motion->getMotionSet(); |
3730 | |
3731 | - old_ev.motion.buttons = mir_pointer_button_primary; |
3732 | - auto pev = mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev)); |
3733 | + mev.setButtons(mir_pointer_button_primary); |
3734 | + auto pev = mir_input_event_get_pointer_event(mir_event_get_input_event(&motion)); |
3735 | |
3736 | EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_primary)); |
3737 | EXPECT_FALSE(mir_pointer_event_button_state(pev, mir_pointer_button_secondary)); |
3738 | |
3739 | - old_ev.motion.buttons |= mir_pointer_button_secondary; |
3740 | + auto buttons = mev.getButtons() | mir_pointer_button_secondary; |
3741 | + mev.setButtons(buttons); |
3742 | |
3743 | EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_primary)); |
3744 | EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_secondary)); |
3745 | @@ -356,14 +364,18 @@ |
3746 | TEST(PointerInputEventProperties, axis_values_copied) |
3747 | { |
3748 | float x = 7, y = 9.3, hscroll = 13, vscroll = 17; |
3749 | - auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE); |
3750 | - old_ev.motion.pointer_count = 0; |
3751 | - old_ev.motion.pointer_coordinates[0].x = x; |
3752 | - old_ev.motion.pointer_coordinates[0].y = y; |
3753 | - old_ev.motion.pointer_coordinates[0].vscroll = vscroll; |
3754 | - old_ev.motion.pointer_coordinates[0].hscroll = hscroll; |
3755 | + MirEvent motion; |
3756 | + motion->initMotionSet(); |
3757 | + motion->getMotionSet().setSourceId(AINPUT_SOURCE_MOUSE); |
3758 | + auto mev = motion->getMotionSet(); |
3759 | + mev.setCount(1); |
3760 | + mev.initMotions(1); |
3761 | + mev.getMotions()[0].setX(x); |
3762 | + mev.getMotions()[0].setY(y); |
3763 | + mev.getMotions()[0].setVscroll(vscroll); |
3764 | + mev.getMotions()[0].setHscroll(hscroll); |
3765 | |
3766 | - auto pev = mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev)); |
3767 | + auto pev = mir_input_event_get_pointer_event(mir_event_get_input_event(&motion)); |
3768 | EXPECT_EQ(x, mir_pointer_event_axis_value(pev, mir_pointer_axis_x)); |
3769 | EXPECT_EQ(y, mir_pointer_event_axis_value(pev, mir_pointer_axis_y)); |
3770 | EXPECT_EQ(vscroll, mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll)); |
3771 | |
3772 | === modified file 'tests/unit-tests/input/test_surface_input_dispatcher.cpp' |
3773 | --- tests/unit-tests/input/test_surface_input_dispatcher.cpp 2016-01-29 08:18:22 +0000 |
3774 | +++ tests/unit-tests/input/test_surface_input_dispatcher.cpp 2016-03-16 18:27:24 +0000 |
3775 | @@ -264,7 +264,7 @@ |
3776 | FakeKeyboard keyboard; |
3777 | auto event = keyboard.press(); |
3778 | |
3779 | - EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(*event))).Times(1); |
3780 | + EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(event.get()))).Times(1); |
3781 | |
3782 | dispatcher.start(); |
3783 | |
3784 | @@ -307,7 +307,7 @@ |
3785 | auto down_event = keyboard.press(); |
3786 | auto up_event = keyboard.release(); |
3787 | |
3788 | - EXPECT_CALL(*surface_1, consume(mt::MirKeyboardEventMatches(*down_event))).Times(1); |
3789 | + EXPECT_CALL(*surface_1, consume(mt::MirKeyboardEventMatches(down_event.get()))).Times(1); |
3790 | EXPECT_CALL(*surface_2, consume(_)).Times(0); |
3791 | |
3792 | dispatcher.start(); |
3793 | @@ -326,7 +326,7 @@ |
3794 | auto event = keyboard.press(); |
3795 | |
3796 | InSequence seq; |
3797 | - EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(*event))).Times(1); |
3798 | + EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(event.get()))).Times(1); |
3799 | |
3800 | dispatcher.start(); |
3801 | |
3802 | |
3803 | === modified file 'tests/unit-tests/input/test_validator.cpp' |
3804 | --- tests/unit-tests/input/test_validator.cpp 2016-01-29 08:18:22 +0000 |
3805 | +++ tests/unit-tests/input/test_validator.cpp 2016-03-16 18:27:24 +0000 |
3806 | @@ -87,9 +87,9 @@ |
3807 | add_another_touch(inserted_down_id1, 1, mir_touch_action_down); |
3808 | |
3809 | InSequence seq; |
3810 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id0))); |
3811 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id1))); |
3812 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch))); |
3813 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id0.get()))); |
3814 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get()))); |
3815 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch.get()))); |
3816 | |
3817 | rewriter.validate_and_dispatch(*touch); |
3818 | } |
3819 | @@ -108,10 +108,10 @@ |
3820 | add_another_touch(inserted_release, 1, mir_touch_action_up); |
3821 | |
3822 | InSequence seq; |
3823 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1))); |
3824 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2))); |
3825 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release))); |
3826 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3))); |
3827 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get()))); |
3828 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get()))); |
3829 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release.get()))); |
3830 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get()))); |
3831 | |
3832 | rewriter.validate_and_dispatch(*touch_1); |
3833 | rewriter.validate_and_dispatch(*touch_2); |
3834 | @@ -138,12 +138,12 @@ |
3835 | add_another_touch(inserted_release_id0, 2, mir_touch_action_change); |
3836 | |
3837 | InSequence seq; |
3838 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1))); |
3839 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2))); |
3840 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3))); |
3841 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release_id1))); |
3842 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release_id0))); |
3843 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_4))); |
3844 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get()))); |
3845 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get()))); |
3846 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get()))); |
3847 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id1.get()))); |
3848 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id0.get()))); |
3849 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get()))); |
3850 | |
3851 | rewriter.validate_and_dispatch(*touch_1); |
3852 | rewriter.validate_and_dispatch(*touch_2); |
3853 | @@ -169,12 +169,12 @@ |
3854 | auto inserted_down_id2 = make_touch(0, mir_touch_action_change); |
3855 | add_another_touch(inserted_down_id2, 2, mir_touch_action_down); |
3856 | |
3857 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1))); |
3858 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2))); |
3859 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3))); |
3860 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release_id1))); |
3861 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id2))); |
3862 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_4))); |
3863 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get()))); |
3864 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get()))); |
3865 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get()))); |
3866 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id1.get()))); |
3867 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id2.get()))); |
3868 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get()))); |
3869 | |
3870 | rewriter.validate_and_dispatch(*touch_1); |
3871 | rewriter.validate_and_dispatch(*touch_2); |
3872 | @@ -196,11 +196,11 @@ |
3873 | auto inserted_down_id2 = make_touch(1, mir_touch_action_change); |
3874 | add_another_touch(inserted_down_id2, 2, mir_touch_action_down); |
3875 | |
3876 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1))); |
3877 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2))); |
3878 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_up_id0))); |
3879 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id2))); |
3880 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3))); |
3881 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get()))); |
3882 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get()))); |
3883 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_up_id0.get()))); |
3884 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id2.get()))); |
3885 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get()))); |
3886 | |
3887 | rewriter.validate_and_dispatch(*touch_1); |
3888 | rewriter.validate_and_dispatch(*touch_2); |
3889 | @@ -226,12 +226,12 @@ |
3890 | add_another_touch(inserted_down_id1, 1, mir_touch_action_down); |
3891 | |
3892 | InSequence seq; |
3893 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1))); |
3894 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2))); |
3895 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3))); |
3896 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_4))); |
3897 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id1))); |
3898 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_5))); |
3899 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get()))); |
3900 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get()))); |
3901 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get()))); |
3902 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get()))); |
3903 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get()))); |
3904 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_5.get()))); |
3905 | |
3906 | rewriter.validate_and_dispatch(*touch_1); |
3907 | rewriter.validate_and_dispatch(*touch_2); |
3908 | @@ -252,10 +252,10 @@ |
3909 | auto inserted_up_id0 = make_touch(0, mir_touch_action_up); |
3910 | auto inserted_down_id1 = make_touch(1, mir_touch_action_down); |
3911 | |
3912 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1))); |
3913 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_up_id0))); |
3914 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id1))); |
3915 | - EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2))); |
3916 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get()))); |
3917 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_up_id0.get()))); |
3918 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get()))); |
3919 | + EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get()))); |
3920 | |
3921 | rewriter.validate_and_dispatch(*touch_1); |
3922 | rewriter.validate_and_dispatch(*touch_2); |
3923 | |
3924 | === modified file 'tests/unit-tests/scene/test_application_session.cpp' |
3925 | --- tests/unit-tests/scene/test_application_session.cpp 2016-03-16 06:59:01 +0000 |
3926 | +++ tests/unit-tests/scene/test_application_session.cpp 2016-03-16 18:27:24 +0000 |
3927 | @@ -95,7 +95,8 @@ |
3928 | } |
3929 | |
3930 | MATCHER_P(EqPromptSessionEventState, state, "") { |
3931 | - return arg.type == mir_event_type_prompt_session_state_change && arg.prompt_session.new_state == state; |
3932 | + return arg->asReader().which() == mir::capnp::Event::Which::PROMPT_SESSION && |
3933 | + arg->asReader().getPromptSession().getNewState() == static_cast<mir::capnp::PromptSessionEvent::State>(state); |
3934 | } |
3935 | |
3936 | MATCHER_P(HasParent, parent, "") |
3937 | @@ -939,7 +940,7 @@ |
3938 | |
3939 | for (int i = 0; i < 2 ; ++i) |
3940 | { |
3941 | - EXPECT_THAT(event[i].surface_output.surface_id, Eq(ids[i].as_value())); |
3942 | + EXPECT_THAT(event[i]->asReader().getSurfaceOutput().getSurfaceId(), Eq(ids[i].as_value())); |
3943 | EXPECT_THAT(&event[i], SurfaceOutputEventFor(*outputs[i])); |
3944 | } |
3945 | } |
3946 | @@ -984,7 +985,7 @@ |
3947 | |
3948 | ASSERT_TRUE(event_received); |
3949 | |
3950 | - EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value())); |
3951 | + EXPECT_THAT(event->asReader().getSurfaceOutput().getSurfaceId(), Eq(id.as_value())); |
3952 | EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi)); |
3953 | } |
3954 | |
3955 | @@ -1087,7 +1088,7 @@ |
3956 | ASSERT_THAT(events_received, Ge(1)); |
3957 | auto events_expected = events_received + 1; |
3958 | |
3959 | - EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value())); |
3960 | + EXPECT_THAT(event->asReader().getSurfaceOutput().getSurfaceId(), Eq(id.as_value())); |
3961 | EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi)); |
3962 | |
3963 | // Now solely on the left output |
3964 | @@ -1096,7 +1097,7 @@ |
3965 | ASSERT_THAT(events_received, Eq(events_expected)); |
3966 | events_expected++; |
3967 | |
3968 | - EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value())); |
3969 | + EXPECT_THAT(event->asReader().getSurfaceOutput().getSurfaceId(), Eq(id.as_value())); |
3970 | EXPECT_THAT(&event, SurfaceOutputEventFor(projector)); |
3971 | |
3972 | // Now solely on the right output |
3973 | @@ -1105,7 +1106,7 @@ |
3974 | ASSERT_THAT(events_received, Eq(events_expected)); |
3975 | events_expected++; |
3976 | |
3977 | - EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value())); |
3978 | + EXPECT_THAT(event->asReader().getSurfaceOutput().getSurfaceId(), Eq(id.as_value())); |
3979 | EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi)); |
3980 | } |
3981 | |
3982 | |
3983 | === modified file 'tests/unit-tests/scene/test_surface.cpp' |
3984 | --- tests/unit-tests/scene/test_surface.cpp 2016-01-29 08:18:22 +0000 |
3985 | +++ tests/unit-tests/scene/test_surface.cpp 2016-03-16 18:27:24 +0000 |
3986 | @@ -414,8 +414,8 @@ |
3987 | mev::add_touch(*touch_event, 0, mir_touch_action_down, mir_touch_tooltype_finger, 0, 0, |
3988 | 0, 0, 0, 0); |
3989 | |
3990 | - EXPECT_CALL(mock_sender, send_event(mt::MirKeyboardEventMatches(*key_event), _)).Times(1); |
3991 | - EXPECT_CALL(mock_sender, send_event(mt::MirTouchEventMatches(*touch_event), _)).Times(1); |
3992 | + EXPECT_CALL(mock_sender, send_event(mt::MirKeyboardEventMatches(key_event.get()), _)).Times(1); |
3993 | + EXPECT_CALL(mock_sender, send_event(mt::MirTouchEventMatches(touch_event.get()), _)).Times(1); |
3994 | |
3995 | surface.consume(key_event.get()); |
3996 | surface.consume(touch_event.get()); |
3997 | |
3998 | === modified file 'tests/unit-tests/scene/test_surface_impl.cpp' |
3999 | --- tests/unit-tests/scene/test_surface_impl.cpp 2016-01-29 08:18:22 +0000 |
4000 | +++ tests/unit-tests/scene/test_surface_impl.cpp 2016-03-16 18:27:24 +0000 |
4001 | @@ -168,6 +168,29 @@ |
4002 | EXPECT_EQ(expect_size, surface->size()); |
4003 | } |
4004 | |
4005 | +MATCHER_P(MirResizeEventMatches, event, "") |
4006 | +{ |
4007 | + auto arg_resize = arg->asReader().getResize(); |
4008 | + auto arg_id = arg_resize.getSurfaceId(); |
4009 | + auto arg_width = arg_resize.getWidth(); |
4010 | + auto arg_height = arg_resize.getHeight(); |
4011 | + |
4012 | + auto resize = (*event)->asReader().getResize(); |
4013 | + auto id = resize.getSurfaceId(); |
4014 | + auto width = resize.getWidth(); |
4015 | + auto height = resize.getHeight(); |
4016 | + |
4017 | + return arg_id == id && |
4018 | + arg_width == width && |
4019 | + arg_height == height; |
4020 | +} |
4021 | + |
4022 | +MATCHER_P(MirCloseSurfaceEventMatches, event, "") |
4023 | +{ |
4024 | + return arg->asReader().which() == (*event)->asReader().which(); |
4025 | +} |
4026 | + |
4027 | + |
4028 | TEST_F(Surface, emits_resize_events) |
4029 | { |
4030 | using namespace testing; |
4031 | @@ -180,7 +203,7 @@ |
4032 | surface->add_observer(observer); |
4033 | |
4034 | auto e = mev::make_event(stub_id, new_size); |
4035 | - EXPECT_CALL(*sink, handle_event(*e)) |
4036 | + EXPECT_CALL(*sink, handle_event(MirResizeEventMatches(e.get()))) |
4037 | .Times(1); |
4038 | |
4039 | surface->resize(new_size); |
4040 | @@ -200,11 +223,11 @@ |
4041 | surface->add_observer(observer); |
4042 | |
4043 | auto e = mev::make_event(stub_id, new_size); |
4044 | - EXPECT_CALL(*sink, handle_event(*e)) |
4045 | + EXPECT_CALL(*sink, handle_event(MirResizeEventMatches(e.get()))) |
4046 | .Times(1); |
4047 | |
4048 | auto e2 = mev::make_event(stub_id, new_size2); |
4049 | - EXPECT_CALL(*sink, handle_event(*e2)) |
4050 | + EXPECT_CALL(*sink, handle_event(MirResizeEventMatches(e2.get()))) |
4051 | .Times(1); |
4052 | |
4053 | surface->resize(new_size); |
4054 | @@ -252,11 +275,10 @@ |
4055 | surface->add_observer(observer); |
4056 | |
4057 | MirEvent e; |
4058 | - memset(&e, 0, sizeof e); |
4059 | - e.type = mir_event_type_close_surface; |
4060 | - e.close_surface.surface_id = stub_id.as_value(); |
4061 | + e.event.initCloseSurface(); |
4062 | + e.event.getCloseSurface().setSurfaceId(stub_id.as_value()); |
4063 | |
4064 | - EXPECT_CALL(*sink, handle_event(e)).Times(1); |
4065 | + EXPECT_CALL(*sink, handle_event(MirCloseSurfaceEventMatches(&e))).Times(1); |
4066 | |
4067 | surface->request_client_surface_close(); |
4068 | } |
This would be a good time to change names of the event stuctures! ie. I've change MotionEvent into MotionEventSet and PointerCoords to Motions etc.