void Wayland_display_destroy_input(SDL_VideoData *d) { struct SDL_WaylandInput *input = d->input; if (!input) return; if (input->keyboard) wl_keyboard_destroy(input->keyboard); if (input->pointer) wl_pointer_destroy(input->pointer); if (input->seat) wl_seat_destroy(input->seat); if (input->xkb.state) WAYLAND_xkb_state_unref(input->xkb.state); if (input->xkb.keymap) WAYLAND_xkb_keymap_unref(input->xkb.keymap); SDL_free(input); d->input = NULL; }
static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size) { struct SDL_WaylandInput *input = data; char *map_str; if (!data) { close(fd); return; } if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { close(fd); return; } map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (map_str == MAP_FAILED) { close(fd); return; } input->xkb.keymap = WAYLAND_xkb_keymap_new_from_string(input->display->xkb_context, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, 0); munmap(map_str, size); close(fd); if (!input->xkb.keymap) { fprintf(stderr, "failed to compile keymap\n"); return; } input->xkb.state = WAYLAND_xkb_state_new(input->xkb.keymap); if (!input->xkb.state) { fprintf(stderr, "failed to create XKB state\n"); WAYLAND_xkb_keymap_unref(input->xkb.keymap); input->xkb.keymap = NULL; return; } }
void Wayland_display_destroy_input(SDL_VideoData *d) { struct SDL_WaylandInput *input = d->input; if (!input) return; if (input->data_device != NULL) { Wayland_data_device_clear_selection(input->data_device); if (input->data_device->selection_offer != NULL) { Wayland_data_offer_destroy(input->data_device->selection_offer); } if (input->data_device->drag_offer != NULL) { Wayland_data_offer_destroy(input->data_device->drag_offer); } if (input->data_device->data_device != NULL) { wl_data_device_release(input->data_device->data_device); } SDL_free(input->data_device); } if (input->keyboard) wl_keyboard_destroy(input->keyboard); if (input->pointer) wl_pointer_destroy(input->pointer); if (input->seat) wl_seat_destroy(input->seat); if (input->xkb.state) WAYLAND_xkb_state_unref(input->xkb.state); if (input->xkb.keymap) WAYLAND_xkb_keymap_unref(input->xkb.keymap); SDL_free(input); d->input = NULL; }