MCPcopy Create free account
hub / github.com/WiVRn/WiVRn / handle_input

Method handle_input

client/android/hid.cpp:248–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248bool android_hid::input_handler::handle_input(scene * current_scene, AInputEvent * event)
249{
250 const int32_t type = AInputEvent_getType(event);
251 const int32_t src = AInputEvent_getSource(event);
252 const int32_t dev = AInputEvent_getDeviceId(event);
253
254 if (type == AINPUT_EVENT_TYPE_KEY)
255 {
256 int32_t flags = AKeyEvent_getFlags(event);
257 if ((flags & AKEY_EVENT_FLAG_SOFT_KEYBOARD) != 0)
258 return false; // ignore soft keyboards
259
260 if ((src & AINPUT_SOURCE_KEYBOARD) == 0)
261 return false; // event is not from keyboard
262
263 int32_t keycode = AKeyEvent_getKeyCode(event);
264 int32_t action = AKeyEvent_getAction(event);
265
266 bool pressed;
267 switch (action)
268 {
269 case AKEY_EVENT_ACTION_DOWN:
270 pressed = true;
271 break;
272 case AKEY_EVENT_ACTION_UP:
273 pressed = false;
274 break;
275 default:
276 return false;
277 }
278
279 uint8_t vk = key_code_to_vk(keycode);
280 if (vk == 0)
281 return false;
282
283 if (pressed)
284 return current_scene->on_input_key_down(vk);
285 else
286 return current_scene->on_input_key_up(vk);
287 }
288
289 if (type == AINPUT_EVENT_TYPE_MOTION)
290 {
291 // don't care about absolute mouse due to mapping difficulties
292 if ((src & AINPUT_SOURCE_MOUSE_RELATIVE) == 0)
293 return false;
294
295 int32_t actionMasked = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK;
296 switch (actionMasked)
297 {
298 case AMOTION_EVENT_ACTION_HOVER_MOVE: // mouse move with no buttons pressed
299 case AMOTION_EVENT_ACTION_MOVE: { // mouse move with buttons pressed
300 float x = AMotionEvent_getX(event, 0);
301 float y = AMotionEvent_getY(event, 0);
302 return current_scene->on_input_mouse_move(x, y);
303 }
304 case AMOTION_EVENT_ACTION_BUTTON_PRESS:
305 case AMOTION_EVENT_ACTION_BUTTON_RELEASE: {

Callers 1

applicationMethod · 0.45

Calls 7

key_code_to_vkFunction · 0.85
on_input_key_downMethod · 0.45
on_input_key_upMethod · 0.45
on_input_mouse_moveMethod · 0.45
on_input_button_downMethod · 0.45
on_input_button_upMethod · 0.45
on_input_scrollMethod · 0.45

Tested by

no test coverage detected