mirror of https://github.com/encounter/SDL.git
wayland: Changed output removal in handle_surface_leave()
No longer needs an extra malloc, handles unexpected cases like the same output being listed twice.
This commit is contained in:
parent
ce7ae4ec8d
commit
aa259ed52d
|
@ -406,21 +406,22 @@ static void
|
||||||
handle_surface_leave(void *data, struct wl_surface *surface,
|
handle_surface_leave(void *data, struct wl_surface *surface,
|
||||||
struct wl_output *output) {
|
struct wl_output *output) {
|
||||||
SDL_WindowData *window = data;
|
SDL_WindowData *window = data;
|
||||||
|
int num_outputs = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (window->num_outputs > 1) {
|
for (i = 0; i < window->num_outputs; i++) {
|
||||||
struct wl_output **new_outputs = SDL_malloc((window->num_outputs - 1) * sizeof *window->outputs), **iter = new_outputs;
|
if (window->outputs[i] == output) { /* remove this one */
|
||||||
for (i=0; i < window->num_outputs; i++) {
|
if (i == (window->num_outputs-1)) {
|
||||||
if (window->outputs[i] != output) {
|
window->outputs[i] = NULL;
|
||||||
*iter = window->outputs[i];
|
} else {
|
||||||
iter++;
|
SDL_memmove(&window->outputs[i], &window->outputs[i+1], sizeof (output) * ((window->num_outputs - i) - 1));
|
||||||
}
|
}
|
||||||
}
|
window->num_outputs--;
|
||||||
SDL_free(window->outputs);
|
i--;
|
||||||
window->outputs = new_outputs;
|
}
|
||||||
window->num_outputs--;
|
}
|
||||||
} else {
|
|
||||||
window->num_outputs = 0;
|
if (window->num_outputs == 0) {
|
||||||
SDL_free(window->outputs);
|
SDL_free(window->outputs);
|
||||||
window->outputs = NULL;
|
window->outputs = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue