wayland: Add support for display connect/disconnect events

This commit is contained in:
Ethan Lee 2021-11-18 00:43:55 -05:00
parent c2464653d0
commit a7a54e6452
2 changed files with 37 additions and 2 deletions

View file

@ -450,7 +450,7 @@ display_handle_done(void *data,
if (driverdata->index == -1) {
/* First time getting display info, create the VideoDisplay */
driverdata->placeholder.driverdata = driverdata;
driverdata->index = SDL_AddVideoDisplay(&driverdata->placeholder, SDL_FALSE);
driverdata->index = SDL_AddVideoDisplay(&driverdata->placeholder, SDL_TRUE);
SDL_free(driverdata->placeholder.name);
SDL_zero(driverdata->placeholder);
@ -490,6 +490,7 @@ Wayland_add_display(SDL_VideoData *d, uint32_t id)
data = SDL_malloc(sizeof *data);
SDL_zerop(data);
data->output = output;
data->registry_id = id;
data->scale_factor = 1.0;
data->index = -1;
@ -497,6 +498,35 @@ Wayland_add_display(SDL_VideoData *d, uint32_t id)
SDL_WAYLAND_register_output(output);
}
static void
Wayland_free_display(uint32_t id)
{
int num_displays = SDL_GetNumVideoDisplays();
SDL_VideoDisplay *display;
SDL_WaylandOutputData *data;
int i;
for (i = 0; i < num_displays; i += 1) {
display = SDL_GetDisplay(i);
data = (SDL_WaylandOutputData *) display->driverdata;
if (data->registry_id == id) {
SDL_DelVideoDisplay(i);
wl_output_destroy(data->output);
SDL_free(data);
/* Update the index for all remaining displays */
num_displays -= 1;
for (; i < num_displays; i += 1) {
display = SDL_GetDisplay(i);
data = (SDL_WaylandOutputData *) display->driverdata;
data->index -= 1;
}
return;
}
}
}
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
static void
windowmanager_hints(void *data, struct qt_windowmanager *qt_windowmanager,
@ -593,7 +623,11 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
}
static void
display_remove_global(void *data, struct wl_registry *registry, uint32_t id) {}
display_remove_global(void *data, struct wl_registry *registry, uint32_t id)
{
/* We don't get an interface, just an ID, so assume it's a wl_output :shrug: */
Wayland_free_display(id);
}
static const struct wl_registry_listener registry_listener = {
display_handle_global,

View file

@ -90,6 +90,7 @@ typedef struct {
typedef struct {
struct wl_output *output;
uint32_t registry_id;
float scale_factor;
int x, y, width, height, refresh, transform;
SDL_DisplayOrientation orientation;