1use crate::client::{Client, EventQueue};
6use crate::compositor::Surface;
7use crate::object::{NewObjectExt, ObjectRef, ObjectRefSet, RequestReceiver};
8use crate::relative_pointer::RelativePointer;
9use anyhow::{Error, Result};
10use fidl_fuchsia_ui_input3::{KeyEvent, KeyEventType};
11use fidl_fuchsia_ui_pointer::EventPhase;
12use std::collections::{BTreeSet, HashSet};
13use wayland_server_protocol::{
14 wl_keyboard, wl_pointer, wl_seat, wl_touch, WlKeyboard, WlKeyboardEvent, WlKeyboardRequest,
15 WlPointer, WlPointerRequest, WlSeat, WlSeatEvent, WlSeatRequest, WlTouch, WlTouchRequest,
16};
17use zx::{self as zx, HandleBased};
18use {fuchsia_trace as ftrace, fuchsia_wayland_core as wl};
19
20pub fn usb_to_linux_keycode(usb_keycode: u32) -> u16 {
21 match usb_keycode {
22 458756 => 30, 458757 => 48, 458758 => 46, 458759 => 32, 458760 => 18, 458761 => 33, 458762 => 34, 458763 => 35, 458764 => 23, 458765 => 36, 458766 => 37, 458767 => 38, 458768 => 50, 458769 => 49, 458770 => 24, 458771 => 25, 458772 => 16, 458773 => 19, 458774 => 31, 458775 => 20, 458776 => 22, 458777 => 47, 458778 => 17, 458779 => 45, 458780 => 21, 458781 => 44, 458782 => 2, 458783 => 3, 458784 => 4, 458785 => 5, 458786 => 6, 458787 => 7, 458788 => 8, 458789 => 9, 458790 => 10, 458791 => 11, 458792 => 28, 458793 => 1, 458794 => 14, 458795 => 15, 458796 => 57, 458797 => 12, 458798 => 13, 458799 => 26, 458800 => 27, 458801 => 43, 458802 => 0, 458803 => 39, 458804 => 40, 458805 => 41, 458806 => 51, 458807 => 52, 458808 => 53, 458809 => 58, 458810 => 59, 458811 => 60, 458812 => 61, 458813 => 62, 458814 => 63, 458815 => 64, 458816 => 65, 458817 => 66, 458818 => 67, 458819 => 68, 458820 => 87, 458821 => 88, 458822 => 210, 458823 => 70, 458824 => 119, 458825 => 110, 458826 => 102, 458827 => 104, 458828 => 111, 458829 => 107, 458830 => 109, 458831 => 106, 458832 => 105, 458833 => 108, 458834 => 103, 458835 => 69, 458836 => 98, 458837 => 55, 458838 => 74, 458839 => 78, 458840 => 96, 458841 => 79, 458842 => 80, 458843 => 81, 458844 => 75, 458845 => 76, 458846 => 77, 458847 => 71, 458848 => 72, 458849 => 73, 458850 => 82, 458851 => 83, 458852 => 0, 458855 => 117, 458870 => 139, 458976 => 29, 458977 => 42, 458978 => 56, 458979 => 125, 458980 => 97, 458981 => 54, 458982 => 100, 458983 => 126, 786658 => 113, 786665 => 115, 786666 => 114, _ => 0,
134 }
135}
136
137pub struct Seat {
139 client_version: u32,
140 keymap: zx::Vmo,
141}
142
143impl Seat {
144 pub fn new(client_version: u32, vmo: zx::Vmo) -> Self {
146 Seat { client_version, keymap: vmo }
147 }
148
149 pub fn post_seat_info(
150 &self,
151 this: wl::ObjectId,
152 client_version: u32,
153 client: &mut Client,
154 ) -> Result<(), Error> {
155 client.event_queue().post(
159 this,
160 WlSeatEvent::Capabilities {
161 capabilities: wl_seat::Capability::Pointer
162 | wl_seat::Capability::Keyboard
163 | wl_seat::Capability::Touch,
164 },
165 )?;
166 if client_version >= 2 {
167 client.event_queue().post(this, WlSeatEvent::Name { name: "unknown".to_string() })?;
168 }
169 Ok(())
170 }
171}
172
173pub struct InputDispatcher {
174 event_queue: EventQueue,
175 pressed_keys: HashSet<fidl_fuchsia_input::Key>,
176 modifiers: u32,
177 pressed_buttons: BTreeSet<u8>,
178 pointer_position: [f32; 2],
179 pub pointers: ObjectRefSet<Pointer>,
184 pub v5_pointers: ObjectRefSet<Pointer>,
185 pub relative_pointers: ObjectRefSet<RelativePointer>,
190 pub keyboards: ObjectRefSet<Keyboard>,
195 pub touches: ObjectRefSet<Touch>,
200
201 pub pointer_focus: Option<ObjectRef<Surface>>,
203
204 pub keyboard_focus: Option<ObjectRef<Surface>>,
206
207 pub keyboard_focus_source: Option<ObjectRef<Surface>>,
213}
214
215fn modifiers_from_pressed_keys(pressed_keys: &HashSet<fidl_fuchsia_input::Key>) -> u32 {
216 const SHIFT_MASK: u32 = 1 << 0;
218 const CONTROL_MASK: u32 = 1 << 2;
219 const ALT_MASK: u32 = 1 << 3;
220
221 let mut modifiers = 0;
222 if pressed_keys.contains(&fidl_fuchsia_input::Key::LeftShift)
223 || pressed_keys.contains(&fidl_fuchsia_input::Key::RightShift)
224 {
225 modifiers |= SHIFT_MASK;
226 }
227 if pressed_keys.contains(&fidl_fuchsia_input::Key::LeftAlt)
228 || pressed_keys.contains(&fidl_fuchsia_input::Key::RightAlt)
229 {
230 modifiers |= ALT_MASK;
231 }
232 if pressed_keys.contains(&fidl_fuchsia_input::Key::LeftCtrl)
233 || pressed_keys.contains(&fidl_fuchsia_input::Key::RightCtrl)
234 {
235 modifiers |= CONTROL_MASK;
236 }
237
238 modifiers
239}
240
241impl InputDispatcher {
242 pub fn has_focus(&self, surface_ref: ObjectRef<Surface>) -> bool {
244 self.keyboard_focus == Some(surface_ref)
245 }
246
247 pub fn clear_focus_on_surface_destroy(&mut self, surface: ObjectRef<Surface>) {
256 if Some(surface) == self.pointer_focus {
257 self.pointer_focus = None;
258 }
259 if Some(surface) == self.keyboard_focus {
260 self.keyboard_focus = None;
261 }
262 if Some(surface) == self.keyboard_focus_source {
263 self.keyboard_focus_source = None;
264 }
265 }
266}
267
268impl InputDispatcher {
269 pub fn new(event_queue: EventQueue) -> Self {
270 Self {
271 event_queue,
272 pressed_keys: HashSet::new(),
273 modifiers: 0,
274 pressed_buttons: BTreeSet::new(),
275 pointer_position: [-1.0, -1.0],
276 pointers: ObjectRefSet::new(),
277 v5_pointers: ObjectRefSet::new(),
278 relative_pointers: ObjectRefSet::new(),
279 keyboards: ObjectRefSet::new(),
280 touches: ObjectRefSet::new(),
281 pointer_focus: None,
282 keyboard_focus: None,
283 keyboard_focus_source: None,
284 }
285 }
286
287 fn add_keyboard_and_send_focus(&mut self, keyboard: ObjectRef<Keyboard>) -> Result<(), Error> {
288 ftrace::duration!(c"wayland", c"InputDispatcher::add_keyboard_and_send_focus");
289 if let Some(focus) = self.keyboard_focus {
290 let serial = self.event_queue.next_serial();
291 self.event_queue.post(
292 keyboard.id(),
293 wl_keyboard::Event::Enter { serial, surface: focus.id(), keys: wl::Array::new() },
294 )?;
295 self.event_queue.post(
296 keyboard.id(),
297 wl_keyboard::Event::Modifiers {
298 serial,
299 mods_depressed: self.modifiers,
300 mods_latched: 0,
301 mods_locked: 0,
302 group: 0,
303 },
304 )?;
305 }
306 assert!(self.keyboards.add(keyboard));
307 Ok(())
308 }
309
310 fn send_keyboard_enter(&self, surface: ObjectRef<Surface>) -> Result<(), Error> {
311 ftrace::duration!(c"wayland", c"InputDispatcher::send_keyboard_enter");
312 let serial = self.event_queue.next_serial();
313 self.keyboards.iter().try_for_each(|k| {
314 self.event_queue.post(
315 k.id(),
316 wl_keyboard::Event::Enter { serial, surface: surface.id(), keys: wl::Array::new() },
317 )
318 })
319 }
320
321 fn send_keyboard_modifiers(&self, modifiers: u32) -> Result<(), Error> {
322 ftrace::duration!(c"wayland", c"InputDispatcher::send_keyboard_modifiers");
323 let serial = self.event_queue.next_serial();
324 self.keyboards.iter().try_for_each(|k| {
325 self.event_queue.post(
326 k.id(),
327 wl_keyboard::Event::Modifiers {
328 serial,
329 mods_depressed: modifiers,
330 mods_latched: 0,
331 mods_locked: 0,
332 group: 0,
333 },
334 )
335 })
336 }
337
338 fn send_keyboard_leave(&self, surface: ObjectRef<Surface>) -> Result<(), Error> {
339 ftrace::duration!(c"wayland", c"InputDispatcher::send_keyboard_leave");
340 let serial = self.event_queue.next_serial();
341 self.keyboards.iter().try_for_each(|k| {
342 self.event_queue
343 .post(k.id(), wl_keyboard::Event::Leave { serial, surface: surface.id() })
344 })
345 }
346
347 fn send_key_event(
348 &self,
349 key: fidl_fuchsia_input::Key,
350 time: u32,
351 state: wl_keyboard::KeyState,
352 ) -> Result<(), Error> {
353 let linux_keycode = usb_to_linux_keycode(key.into_primitive());
355 ftrace::duration!(c"wayland", c"InputDispatcher::send_key_event", "linux_keycode" => linux_keycode as u32);
356 let serial = self.event_queue.next_serial();
357 self.keyboards.iter().try_for_each(|k| {
358 self.event_queue.post(
359 k.id(),
360 wl_keyboard::Event::Key { serial, time, key: linux_keycode as u32, state },
361 )
362 })
363 }
364
365 pub fn handle_key_event(
366 &mut self,
367 source: ObjectRef<Surface>,
368 event: &KeyEvent,
369 ) -> Result<(), Error> {
370 ftrace::duration!(c"wayland", c"InputDispatcher::handle_key_event");
371 if Some(source) == self.keyboard_focus_source && self.keyboard_focus.is_some() {
372 let key = event.key.unwrap();
373 let time_in_ms = (event.timestamp.unwrap() / 1_000_000) as u32;
374 match event.type_.unwrap() {
375 KeyEventType::Pressed if event.repeat_sequence.is_none() => {
376 self.pressed_keys.insert(key);
377 self.send_key_event(key, time_in_ms, wl_keyboard::KeyState::Pressed)?;
378 }
379 KeyEventType::Released => {
380 self.pressed_keys.remove(&key);
381 self.send_key_event(key, time_in_ms, wl_keyboard::KeyState::Released)?;
382 }
383 KeyEventType::Cancel => {
384 self.pressed_keys.remove(&key);
385 }
386 _ => (),
387 }
388 let modifiers = modifiers_from_pressed_keys(&self.pressed_keys);
389 if modifiers != self.modifiers {
390 self.send_keyboard_modifiers(modifiers)?;
391 self.modifiers = modifiers;
392 }
393 }
394 Ok(())
395 }
396
397 pub fn send_keymap_event(&mut self, keymap_vmo: zx::Vmo) -> Result<()> {
399 ftrace::duration!(c"wayland", c"InputDispatcher::send_keymap_event");
400 let clone_vmo = move || {
401 keymap_vmo.duplicate_handle(zx::Rights::SAME_RIGHTS).expect("handle can be duplicated")
402 };
403 self.keyboards.iter().try_for_each(|k| {
404 let vmo = clone_vmo();
405 let size_bytes = vmo.get_content_size().expect("size can be obtained for a VMO") as u32;
406 self.event_queue.post(
408 k.id(),
409 wl_keyboard::Event::Keymap {
410 format: wl_keyboard::KeymapFormat::XkbV1,
412 fd: vmo.into(),
413 size: size_bytes,
414 },
415 )
416 })
417 }
418
419 fn update_keyboard_focus(
420 &mut self,
421 new_focus: Option<ObjectRef<Surface>>,
422 ) -> Result<(), Error> {
423 ftrace::duration!(c"wayland", c"InputDispatcher::update_keyboard_focus");
424 if new_focus == self.keyboard_focus {
425 return Ok(());
426 }
427 if let Some(current_focus) = self.keyboard_focus {
428 self.send_keyboard_leave(current_focus)?;
429 }
430 if let Some(focus) = new_focus {
431 self.send_keyboard_enter(focus)?;
432 self.send_keyboard_modifiers(0)?;
433 self.keyboard_focus = Some(focus);
434 self.pressed_keys.clear();
435 self.modifiers = 0;
436 }
437 self.keyboard_focus = new_focus;
438 Ok(())
439 }
440
441 pub fn handle_keyboard_focus(
442 &mut self,
443 source: ObjectRef<Surface>,
444 target: ObjectRef<Surface>,
445 focused: bool,
446 ) -> Result<(), Error> {
447 ftrace::duration!(c"wayland", c"InputDispatcher::handle_keyboard_focus");
448 let keyboard_focus = if focused {
449 self.keyboard_focus_source = Some(source);
450 Some(target)
451 } else {
452 self.keyboard_focus_source = None;
453 None
454 };
455 self.update_keyboard_focus(keyboard_focus)
456 }
457
458 pub fn maybe_update_keyboard_focus(
459 &mut self,
460 source: ObjectRef<Surface>,
461 new_target: ObjectRef<Surface>,
462 ) -> Result<(), Error> {
463 ftrace::duration!(c"wayland", c"InputDispatcher::maybe_update_keyboard_focus");
464 if Some(source) == self.keyboard_focus_source {
465 self.update_keyboard_focus(Some(new_target))?;
466 }
467 Ok(())
468 }
469
470 fn send_pointer_enter(&self, surface: ObjectRef<Surface>, x: f32, y: f32) -> Result<(), Error> {
471 ftrace::duration!(c"wayland", c"InputDispatcher::send_pointer_enter");
472 let serial = self.event_queue.next_serial();
473 self.pointers.iter().try_for_each(|p| {
474 self.event_queue.post(
475 p.id(),
476 wl_pointer::Event::Enter {
477 serial,
478 surface: surface.id(),
479 surface_x: x.into(),
480 surface_y: y.into(),
481 },
482 )
483 })
484 }
485
486 fn send_pointer_leave(&self, surface: ObjectRef<Surface>) -> Result<(), Error> {
487 ftrace::duration!(c"wayland", c"InputDispatcher::send_pointer_leave");
488 let serial = self.event_queue.next_serial();
489 self.pointers.iter().try_for_each(|p| {
490 self.event_queue
491 .post(p.id(), wl_pointer::Event::Leave { serial, surface: surface.id() })
492 })
493 }
494
495 fn update_pointer_focus(
496 &mut self,
497 new_focus: Option<ObjectRef<Surface>>,
498 position: &[f32; 2],
499 ) -> Result<(), Error> {
500 ftrace::duration!(c"wayland", c"InputDispatcher::update_pointer_focus");
501 if new_focus == self.pointer_focus {
502 return Ok(());
503 }
504
505 let mut needs_frame = false;
506 if let Some(current_focus) = self.pointer_focus {
507 needs_frame = true;
508 self.send_pointer_leave(current_focus)?;
509 }
510
511 if let Some(new_focus) = new_focus {
512 needs_frame = true;
513 self.send_pointer_enter(new_focus, position[0], position[1])?;
514 self.pointer_position = *position;
515 }
516
517 self.pointer_focus = new_focus;
518 if needs_frame {
519 self.send_pointer_frame()?;
520 }
521 Ok(())
522 }
523
524 fn send_pointer_frame(&self) -> Result<(), Error> {
525 ftrace::duration!(c"wayland", c"InputDispatcher::send_pointer_frame");
526 self.v5_pointers
527 .iter()
528 .try_for_each(|p| self.event_queue.post(p.id(), wl_pointer::Event::Frame))
529 }
530
531 fn send_touch_frame(&self) -> Result<(), Error> {
532 ftrace::duration!(c"wayland", c"InputDispatcher::send_touch_frame");
533 self.touches.iter().try_for_each(|p| self.event_queue.post(p.id(), wl_touch::Event::Frame))
534 }
535
536 pub fn handle_pointer_event(
537 &mut self,
538 surface: ObjectRef<Surface>,
539 timestamp: i64,
540 position: &[f32; 2],
541 pressed_buttons: &Option<Vec<u8>>,
542 relative_motion: &Option<[f32; 2]>,
543 scroll_v: &Option<i64>,
544 scroll_h: &Option<i64>,
545 ) -> Result<(), Error> {
546 ftrace::duration!(c"wayland", c"InputDispatcher::handle_pointer_event");
547 let time_in_ms = (timestamp / 1_000_000) as u32;
548 let mut needs_frame = false;
549
550 self.update_pointer_focus(Some(surface), position)?;
551
552 if position != &self.pointer_position {
553 self.pointers.iter().try_for_each(|p| {
554 self.event_queue.post(
555 p.id(),
556 wl_pointer::Event::Motion {
557 time: time_in_ms,
558 surface_x: position[0].into(),
559 surface_y: position[1].into(),
560 },
561 )
562 })?;
563 self.pointer_position = *position;
564 needs_frame = true;
565 }
566
567 fn send_button_event(
568 event_queue: &EventQueue,
569 pointers: &ObjectRefSet<Pointer>,
570 time_in_ms: u32,
571 button: u32,
572 state: wl_pointer::ButtonState,
573 ) -> Result<(), Error> {
574 const BUTTON_BASE: u32 = 0x10f;
577
578 let serial = event_queue.next_serial();
579 pointers.iter().try_for_each(|p| {
580 event_queue.post(
581 p.id(),
582 wl_pointer::Event::Button {
583 serial,
584 time: time_in_ms,
585 button: BUTTON_BASE + button,
586 state,
587 },
588 )
589 })
590 }
591
592 let pressed_buttons = pressed_buttons.as_ref().map_or(BTreeSet::new(), |pressed_buttons| {
593 pressed_buttons.iter().map(|b| *b).collect()
594 });
595 for button in self.pressed_buttons.difference(&pressed_buttons) {
596 send_button_event(
597 &self.event_queue,
598 &self.pointers,
599 time_in_ms,
600 *button as u32,
601 wl_pointer::ButtonState::Released,
602 )?;
603 needs_frame = true;
604 }
605 for button in pressed_buttons.difference(&self.pressed_buttons) {
606 send_button_event(
607 &self.event_queue,
608 &self.pointers,
609 time_in_ms,
610 *button as u32,
611 wl_pointer::ButtonState::Pressed,
612 )?;
613 needs_frame = true;
614 }
615 self.pressed_buttons = pressed_buttons;
616
617 fn send_axis_event(
618 event_queue: &EventQueue,
619 pointers: &ObjectRefSet<Pointer>,
620 time_in_ms: u32,
621 axis: wl_pointer::Axis,
622 value: f32,
623 ) -> Result<(), Error> {
624 pointers.iter().try_for_each(|p| {
625 event_queue.post(
626 p.id(),
627 wl_pointer::Event::Axis { time: time_in_ms, axis, value: value.into() },
628 )
629 })
630 }
631
632 if let Some(scroll_v) = scroll_v {
633 send_axis_event(
634 &self.event_queue,
635 &self.pointers,
636 time_in_ms,
637 wl_pointer::Axis::VerticalScroll,
638 -(*scroll_v as f32),
639 )?;
640 needs_frame = true;
641 }
642 if let Some(scroll_h) = scroll_h {
643 send_axis_event(
644 &self.event_queue,
645 &self.pointers,
646 time_in_ms,
647 wl_pointer::Axis::HorizontalScroll,
648 *scroll_h as f32,
649 )?;
650 needs_frame = true;
651 }
652
653 if let Some(relative_motion) = relative_motion {
654 let time_in_us = (timestamp / 1_000) as u64;
655 self.relative_pointers.iter().try_for_each(|rp| {
656 RelativePointer::post_relative_motion(
657 *rp,
658 &self.event_queue,
659 time_in_us,
660 relative_motion[0].into(),
661 relative_motion[1].into(),
662 )
663 })?;
664 }
665
666 if needs_frame {
667 self.send_pointer_frame()?;
668 }
669
670 Ok(())
671 }
672
673 pub fn handle_touch_event(
674 &mut self,
675 surface: ObjectRef<Surface>,
676 timestamp: i64,
677 id: i32,
678 position: &[f32; 2],
679 phase: EventPhase,
680 ) -> Result<(), Error> {
681 ftrace::duration!(c"wayland", c"InputDispatcher::handle_touch_event");
682 let time_in_ms = (timestamp / 1_000_000) as u32;
683 let mut needs_frame = false;
684 match phase {
685 EventPhase::Change => {
686 self.touches.iter().try_for_each(|t| {
687 self.event_queue.post(
688 t.id(),
689 wl_touch::Event::Motion {
690 time: time_in_ms,
691 id,
692 x: position[0].into(),
693 y: position[1].into(),
694 },
695 )
696 })?;
697 needs_frame = true;
698 }
699 EventPhase::Add => {
700 let serial = self.event_queue.next_serial();
701 self.touches.iter().try_for_each(|t| {
702 self.event_queue.post(
703 t.id(),
704 wl_touch::Event::Down {
705 serial,
706 time: time_in_ms,
707 surface: surface.id(),
708 id,
709 x: position[0].into(),
710 y: position[1].into(),
711 },
712 )
713 })?;
714 needs_frame = true;
715 }
716 EventPhase::Remove => {
717 let serial = self.event_queue.next_serial();
718 self.touches.iter().try_for_each(|t| {
719 self.event_queue
720 .post(t.id(), wl_touch::Event::Up { serial, time: time_in_ms, id })
721 })?;
722 needs_frame = true;
723 }
724 _ => (),
725 }
726
727 if needs_frame {
728 self.send_touch_frame()?;
729 }
730
731 Ok(())
732 }
733}
734
735impl RequestReceiver<WlSeat> for Seat {
736 fn receive(
737 this: ObjectRef<Self>,
738 request: WlSeatRequest,
739 client: &mut Client,
740 ) -> Result<(), Error> {
741 match request {
742 WlSeatRequest::Release => {
743 client.delete_id(this.id())?;
744 }
745 WlSeatRequest::GetPointer { id } => {
746 let pointer = id.implement(client, Pointer)?;
747 assert!(client.input_dispatcher.pointers.add(pointer));
752 if this.get(client)?.client_version >= 5 {
753 assert!(client.input_dispatcher.v5_pointers.add(pointer));
754 }
755 }
756 WlSeatRequest::GetKeyboard { id } => {
757 let keyboard = id.implement(client, Keyboard::new(this))?;
758 let (vmo, len_bytes) = {
759 let this = this.get(client)?;
760 let vmo = this.keymap.duplicate_handle(zx::Rights::SAME_RIGHTS)?;
761 let len_bytes: u32 = vmo.get_content_size()?.try_into()?;
762 (vmo, len_bytes)
763 };
764 Keyboard::post_keymap(keyboard, client, vmo.into(), len_bytes)?;
765 client.input_dispatcher.add_keyboard_and_send_focus(keyboard)?;
766 }
767 WlSeatRequest::GetTouch { id } => {
768 let touch = id.implement(client, Touch)?;
769 assert!(client.input_dispatcher.touches.add(touch));
770 }
771 }
772 Ok(())
773 }
774}
775
776pub struct Pointer;
777
778impl RequestReceiver<WlPointer> for Pointer {
779 fn receive(
780 this: ObjectRef<Self>,
781 request: WlPointerRequest,
782 client: &mut Client,
783 ) -> Result<(), Error> {
784 match request {
785 WlPointerRequest::Release => {
786 client.input_dispatcher.pointers.remove(this);
787 client.input_dispatcher.v5_pointers.remove(this);
788 client.delete_id(this.id())?;
789 }
790 WlPointerRequest::SetCursor { .. } => {}
791 }
792 Ok(())
793 }
794}
795
796const KEY_REPEAT_RATE: i32 = 30;
797const KEY_REPEAT_DELAY: i32 = 225;
798
799pub struct Keyboard {
800 seat: ObjectRef<Seat>,
801}
802
803impl Keyboard {
804 pub fn new(seat: ObjectRef<Seat>) -> Self {
805 Self { seat }
806 }
807
808 fn post_keymap(
809 this: ObjectRef<Self>,
810 client: &mut Client,
811 keymap: zx::Handle,
812 keymap_len: u32,
813 ) -> Result<(), Error> {
814 println!("Posting keymap with len {}", keymap_len);
815 client.event_queue().post(
816 this.id(),
817 WlKeyboardEvent::Keymap {
818 format: wl_keyboard::KeymapFormat::XkbV1,
819 fd: keymap,
820 size: keymap_len,
821 },
822 )?;
823 if this.get(client)?.seat.get(client)?.client_version >= 4 {
824 client.event_queue().post(
825 this.id(),
826 WlKeyboardEvent::RepeatInfo { rate: KEY_REPEAT_RATE, delay: KEY_REPEAT_DELAY },
827 )?;
828 }
829 Ok(())
830 }
831}
832
833impl RequestReceiver<WlKeyboard> for Keyboard {
834 fn receive(
835 this: ObjectRef<Self>,
836 request: WlKeyboardRequest,
837 client: &mut Client,
838 ) -> Result<(), Error> {
839 let WlKeyboardRequest::Release = request;
840 client.input_dispatcher.keyboards.remove(this);
841 client.delete_id(this.id())?;
842 Ok(())
843 }
844}
845
846pub struct Touch;
847
848impl RequestReceiver<WlTouch> for Touch {
849 fn receive(
850 this: ObjectRef<Self>,
851 request: WlTouchRequest,
852 client: &mut Client,
853 ) -> Result<(), Error> {
854 let WlTouchRequest::Release = request;
855 client.input_dispatcher.touches.remove(this);
856 client.delete_id(this.id())?;
857 Ok(())
858 }
859}