Skip to content

Commit

Permalink
webOS wayland seat fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Feb 25, 2024
1 parent 2d05bee commit a628487
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/video/wayland/SDL_waylandevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,13 @@ static void Wayland_create_data_device(SDL_VideoData *d)
return;
}

#ifdef SDL_VIDEO_DRIVER_WAYLAND_WEBOS
if (d->input->data_device) {
/* Shouldn't be called at all on webOS, but just in case */
return;
}
#endif

data_device = SDL_calloc(1, sizeof(*data_device));
if (!data_device) {
return;
Expand Down Expand Up @@ -2060,6 +2067,13 @@ static void Wayland_create_primary_selection_device(SDL_VideoData *d)
return;
}

#ifdef SDL_VIDEO_DRIVER_WAYLAND_WEBOS
if (d->input->primary_selection_device) {
/* Shouldn't be called at all on webOS, but just in case */
return;
}
#endif

primary_selection_device = SDL_calloc(1, sizeof(*primary_selection_device));
if (!primary_selection_device) {
return;
Expand Down Expand Up @@ -2089,6 +2103,13 @@ static void Wayland_create_text_input(SDL_VideoData *d)
return;
}

#ifdef SDL_VIDEO_DRIVER_WAYLAND_WEBOS
if (d->input->text_input) {
/* Shouldn't be called at all on webOS, but just in case */
return;
}
#endif

text_input = SDL_calloc(1, sizeof(*text_input));
if (!text_input) {
return;
Expand Down Expand Up @@ -2467,6 +2488,23 @@ void Wayland_display_add_input(SDL_VideoData *d, uint32_t id, uint32_t version)
{
struct SDL_WaylandInput *input = d->input;

#ifdef SDL_VIDEO_DRIVER_WAYLAND_WEBOS
if (input->seat) {
struct SDL_WaylandInput *tail;
/* Find the tail if the input has seat */
while (input->next) {
input = input->next;
}
tail = input;
input = SDL_calloc(1, sizeof(struct SDL_WaylandInput));
if (!input) {
return;
}
input->display = d;
tail->next = input;
}
#endif

input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, SDL_min(SDL_WL_SEAT_VERSION, version));

if (d->data_device_manager) {
Expand Down Expand Up @@ -2573,6 +2611,15 @@ void Wayland_display_destroy_input(SDL_VideoData *d)
WAYLAND_xkb_keymap_unref(input->xkb.keymap);
}

#ifdef SDL_VIDEO_DRIVER_WAYLAND_WEBOS
/* Use recursive call to free up linked list */
/* Extremely evil but prevents goto usages and large changes */
if (input->next) {
d->input = input->next;
Wayland_display_destroy_input(d);
}
#endif

SDL_free(input);
d->input = NULL;
}
Expand Down
5 changes: 5 additions & 0 deletions src/video/wayland/SDL_waylandevents_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ struct SDL_WaylandInput
SDL_bool relative_mode_override;
SDL_bool warp_emulation_prohibited;
SDL_bool keyboard_is_virtual;

#ifdef SDL_VIDEO_DRIVER_WAYLAND_WEBOS
/* On webOS, multiple seats are present. This is a very evil hack to support that non-standard case */
struct SDL_WaylandInput *next;
#endif
};

extern void Wayland_PumpEvents(_THIS);
Expand Down

0 comments on commit a628487

Please sign in to comment.