Guest User

Untitled

a guest
Jan 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /// A listener for events emmited on a wl_registry object.
  2. trait wayland::client::RegistryListener {
  3. fn global(&mut self, registry: wayland::client::RegistryListener, name: u32, interface: &str, version: u32);
  4. fn global_remove(&mut self, registry: wayland::client::RegistryListener, name: u32);
  5. }
  6.  
  7. impl wayland::client::Registry {
  8. fn add_listener(&mut self, listener: impl RegistryListener) { ... }
  9. fn bind(...) { ... }
  10. }
  11.  
  12. struct MySeatData {
  13. name: Option<String>, // None if not yet known
  14. seat: wayland::client::Seat,
  15. }
  16.  
  17. struct MyAwesomeRegistryListener {
  18. // Whatever user data you want goes here.
  19. // You get to decide whether it's Send/Sync.
  20. seats: Vec<MySeatData>,
  21. }
  22.  
  23. impl MyAwesomeRegistryListener {
  24. fn new() -> Self {
  25. Self { seats: vec![] }
  26. }
  27.  
  28. fn find_seat_data_mut(&mut self, seat: wayland::client::Seat) -> Option<&mut MySeatData> {
  29. self.seats.iter_mut()
  30. .find(|&seat_data| seat_data.seat == seat)
  31. }
  32. }
  33.  
  34. impl wayland::client::RegistryListener for MyAwesomeRegistryListener {
  35. fn global(&mut self, registry: wayland::client::RegistryListener, name: u32, interface: &str, version: u32) {
  36. match interface {
  37. wayland::client::Seat::interface::name /* "wl_seat" */ => {
  38. let seat = registry.bind(name, ...);
  39. self.seats.push(SeatData { name: None, seat });
  40. }
  41. }
  42. }
  43. }
  44.  
  45. fn main() -> Result<(), Error> {
  46. let display = wayland::client::Display::connect()?;
  47. let registry = display.get_registry();
  48. registry.add_listener(MyAwesomeRegistryListener::new());
  49. loop {
  50. display.roundtrip()?;
  51. }
  52. }
Add Comment
Please, Sign In to add comment