feat: handle wl_seat global

This commit is contained in:
2026-02-15 12:49:46 +01:00
parent 4ddd2423b9
commit f4c646a7e0
2 changed files with 61 additions and 0 deletions

View File

@@ -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_

View File

@@ -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<struct wl_seat *>(
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<struct wl_shm *>(
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<WaylandState *>(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,