diff --git a/include/state/wayland.h b/include/state/wayland.h index a229063..e9f7508 100644 --- a/include/state/wayland.h +++ b/include/state/wayland.h @@ -19,6 +19,12 @@ private: static void registry_handle_global_remove(void *data, struct wl_registry *registry, uint32_t name); + static void seat_handle_capabilities(void *data, + struct wl_seat *seat, + uint32_t capabilities); + static void seat_handle_name(void *data, + struct wl_seat *seat, + const char *name); private: WaylandState(); ~WaylandState(); @@ -33,8 +39,15 @@ private: struct xdg_wm_base_listener m_wm_base_listener; struct wl_registry_listener m_reg_listener; + struct wl_shm *m_shm; + + struct wl_seat *m_seat; + struct wl_seat_listener m_seat_listener; + struct wl_pointer* m_pointer; + friend class WaylandWindowImpl; friend class Renderer; + friend class WaylandInputHandler; }; #endif // H_WAYLAND_STATE_ diff --git a/src/state/wayland.cpp b/src/state/wayland.cpp index cb49566..23f2261 100644 --- a/src/state/wayland.cpp +++ b/src/state/wayland.cpp @@ -48,6 +48,54 @@ void WaylandState::registry_handle_global(void *data, struct wl_registry *regist xdg_wm_base_add_listener(state->m_wm_base, &state->m_wm_base_listener, NULL); } + if (interface_name == "wl_seat") { + state->m_seat = reinterpret_cast( + wl_registry_bind(registry, name, &wl_seat_interface, version)); + printf("[DEBUG] global_binding(%s): wl_seat %p\n", interface, + state->m_seat); + if (state->m_seat == NULL) { + fprintf(stderr, "ERROR: could not bind to wl_seat\n"); + } + state->m_seat_listener.capabilities = seat_handle_capabilities; + state->m_seat_listener.name = seat_handle_name; + wl_seat_add_listener(state->m_seat, &state->m_seat_listener, state); + } + if (interface_name == "wl_shm") { + state->m_shm = reinterpret_cast( + wl_registry_bind(registry, name, &wl_shm_interface, version)); + printf("[DEBUG] global_binding(%s): wl_shm %p\n", interface, + state->m_shm); + if (state->m_shm == NULL) { + fprintf(stderr, "ERROR: could not bind to wl_shm\n"); + } + } +} + +void WaylandState::seat_handle_name(void *data, + struct wl_seat *seat, + const char *name) { + UNUSED(seat); + UNUSED(data); + printf("[DEBUG] SEAT: name of the seat = %s\n", name); +} + +void WaylandState::seat_handle_capabilities(void *data, + struct wl_seat *seat, + uint32_t capabilities) { + auto state = reinterpret_cast(data); + UNUSED(state); + UNUSED(seat); + if ((capabilities & WL_SEAT_CAPABILITY_KEYBOARD) > 0) { + printf("[DEBUG] SEAT: keyboard is available\n"); + } + if ((capabilities & WL_SEAT_CAPABILITY_POINTER) > 0) { + printf("[DEBUG] SEAT: pointer is available\n"); + state->m_pointer = wl_seat_get_pointer(seat); + printf("[DEBUG] SEAT: pointer is bound under %p address\n", state->m_pointer); + } + if ((capabilities & WL_SEAT_CAPABILITY_TOUCH) > 0) { + printf("[DEBUG] SEAT: touch is available\n"); + } } void WaylandState::registry_handle_global_remove(void *data,