MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / poll_events

Function poll_events

native/linux/src/lib.rs:375–489  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

373 }
374
375 pub fn poll_events() {
376 unsafe {
377 while x11::xlib::XPending(DISPLAY) > 0 {
378 let mut event = std::mem::zeroed::<x11::xlib::XEvent>();
379 x11::xlib::XNextEvent(DISPLAY, &mut event);
380
381 match event.type_ {
382 x11::xlib::KeyPress => {
383 let keysym = x11::xlib::XLookupKeysym(
384 &mut event.key as *mut _ as *mut _,
385 0,
386 );
387 let bloom_key = map_keycode(keysym as u32);
388 if bloom_key > 0 {
389 engine().input.set_key_down(bloom_key);
390 }
391 // Decode UTF-8 typed text via XLookupString so the
392 // editor's text-input widget receives characters.
393 let mut buf = [0u8; 32];
394 let mut ks: x11::xlib::KeySym = 0;
395 let len = x11::xlib::XLookupString(
396 &mut event.key as *mut _,
397 buf.as_mut_ptr() as *mut i8,
398 buf.len() as i32,
399 &mut ks,
400 std::ptr::null_mut(),
401 );
402 if len > 0 {
403 if let Ok(s) = std::str::from_utf8(&buf[..len as usize]) {
404 for c in s.chars() {
405 let cp = c as u32;
406 if cp >= 32 || cp == 8 || cp == 13 || cp == 9 {
407 engine().input.push_char(cp);
408 }
409 }
410 }
411 }
412 }
413 x11::xlib::KeyRelease => {
414 let keysym = x11::xlib::XLookupKeysym(
415 &mut event.key as *mut _ as *mut _,
416 0,
417 );
418 let bloom_key = map_keycode(keysym as u32);
419 if bloom_key > 0 {
420 engine().input.set_key_up(bloom_key);
421 }
422 }
423 x11::xlib::MotionNotify => {
424 let motion = event.motion;
425 if RELATIVE_MODE {
426 // Ignore the motion event we generated by warping
427 // back to center — it would otherwise add a stray
428 // -delta cancelling the user's actual movement.
429 if motion.x == WARP_CENTER_X && motion.y == WARP_CENTER_Y {
430 // synthetic warp event; skip
431 } else {
432 let dx = (motion.x - WARP_CENTER_X) as f64;

Callers 1

bloom_begin_drawingFunction · 0.70

Calls 15

warp_to_centerFunction · 0.85
display_scaleFunction · 0.85
set_key_downMethod · 0.80
push_charMethod · 0.80
set_key_upMethod · 0.80
set_mouse_positionMethod · 0.80
set_mouse_button_downMethod · 0.80
set_mouse_button_upMethod · 0.80
physical_widthMethod · 0.80
physical_heightMethod · 0.80

Tested by

no test coverage detected