wayland.cpp 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "wayland.hpp"
  2. static void global_registry_handler(void *data, wl_registry* registry,
  3. uint32_t id, const char* interface, uint32_t version) {
  4. //std::cout << "Got register " << interface << " with id " << id << "\n";
  5. if (std::string(interface) == "wl_compositor") {
  6. wayland->compositor = (wl_compositor*)wl_registry_bind(registry, id, &wl_compositor_interface, 1);
  7. } else if(std::string(interface) == "wl_shell") {
  8. wayland->shell = (wl_shell*)wl_registry_bind(registry, id, &wl_shell_interface, 1);
  9. } else if(std::string(interface) == "wl_shm") {
  10. wayland->shm = (wl_shm*)wl_registry_bind(registry, id, &wl_shm_interface, 1);
  11. } else if(std::string(interface) == "wl_seat") {
  12. wayland->seat = (wl_seat*)wl_registry_bind(registry, id, &wl_seat_interface, 1);
  13. } else if(std::string(interface) == "wl_output") {
  14. wayland->output = (wl_output*)wl_registry_bind(registry, id, &wl_output_interface, 1);
  15. //wl_list_insert(&output_list, &output->link);
  16. //wl_output_add_listener(output->output, &output_listener, output);
  17. }
  18. }
  19. static void global_registry_remover(void *data, struct wl_registry *registry, uint32_t id) {
  20. }
  21. static const struct wl_registry_listener registry_listener = {
  22. global_registry_handler,
  23. global_registry_remover
  24. };
  25. Wayland::Wayland() {
  26. display = wl_display_connect(NULL);
  27. if (!display) {
  28. throw new std::runtime_error("Failed to connect to display.");
  29. }
  30. }
  31. Wayland::~Wayland() {
  32. wl_display_disconnect(display);
  33. }
  34. void Wayland::init() {
  35. struct wl_registry *registry = wl_display_get_registry(display);
  36. wl_registry_add_listener(registry, &registry_listener, NULL);
  37. wl_display_dispatch(display);
  38. wl_display_roundtrip(display);
  39. if (!compositor) {
  40. throw new std::runtime_error("Can't find compositor.");
  41. }
  42. egl_display = eglGetDisplay( display );
  43. eglInitialize( egl_display, NULL, NULL );
  44. if ( !egl_display ) {
  45. throw new std::runtime_error("Failed to initialize EGL! (Thats the graphics stuff.)");
  46. }
  47. }