From b582be717564ff0003cc98f345932754cb4effcd Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Sat, 15 Jun 2013 19:46:16 -0700 Subject: [PATCH] Handle client-requested resize (bit of a hack) --- src/video/toaru/SDL_toaruevents.c | 8 ++++++-- src/video/toaru/SDL_toaruvideo.c | 19 +++++++++++++++++-- src/video/toaru/SDL_toaruvideo.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/video/toaru/SDL_toaruevents.c b/src/video/toaru/SDL_toaruevents.c index 2a76285..2b6a0a4 100644 --- a/src/video/toaru/SDL_toaruevents.c +++ b/src/video/toaru/SDL_toaruevents.c @@ -49,8 +49,12 @@ void TOARU_PumpEvents(_THIS) { window_t * window = NULL; switch (event->command_type) { case WE_RESIZED: - fprintf(stderr, "[SDL] Window resized, need to update buffers!\n"); - SDL_PrivateResize(evt->width - this->hidden->x_w, evt->height - this->hidden->x_h); + fprintf(stderr, "[SDL] Received RESIZE message from server.\n"); + if (this->hidden->triggered_resize != 2) { + fprintf(stderr, "--- From a natural resize. Informing SDL.\n"); + this->hidden->triggered_resize = 1; + SDL_PrivateResize(evt->width - this->hidden->x_w, evt->height - this->hidden->x_h); + } break; case WE_FOCUSCHG: window = wins_get_window(evt->wid); diff --git a/src/video/toaru/SDL_toaruvideo.c b/src/video/toaru/SDL_toaruvideo.c index 883f952..085115d 100644 --- a/src/video/toaru/SDL_toaruvideo.c +++ b/src/video/toaru/SDL_toaruvideo.c @@ -149,6 +149,7 @@ int TOARU_VideoInit(_THIS, SDL_PixelFormat *vformat) setup_windowing(); init_decorations(); + this->hidden->triggered_resize = 0; /* We're done! */ return(0); @@ -159,20 +160,34 @@ SDL_Rect **TOARU_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) return (SDL_Rect **) -1; } +extern void wins_send_command(wid_t, int16_t, int16_t, uint16_t, uint16_t, int, int); + SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { if ( this->hidden->window) { - fprintf(stderr, "waaat, already have a window! need to resize instead!\n"); + fprintf(stderr, "Resize request to %d x %d.\n", width, height); + if (!this->hidden->triggered_resize) { + this->hidden->triggered_resize = 2; + fprintf(stderr, "Requesting window resize.\n"); + window_t * w = (window_t *) this->hidden->window; + wins_send_command(w->wid, 0, 0, width + this->hidden->x_w, height + this->hidden->x_h, WC_RESIZE, 0); + fprintf(stderr, "Window resize request completed.\n"); + } else { + this->hidden->triggered_resize = 0; + } + + fprintf(stderr, "Resizing client window buffer...\n"); resize_window_buffer_client(this->hidden->window, 0, 0, width + this->hidden->x_w, height + this->hidden->x_h); + + fprintf(stderr, "Reinitializing graphics context...\n"); reinit_graphics_window(this->hidden->ctx, this->hidden->window); if (this->hidden->bordered) { this->hidden->buffer = realloc(this->hidden->buffer, sizeof(uint32_t) * width * height); this->hidden->redraw_borders = 1; } - } else { if (flags & SDL_NOFRAME) { diff --git a/src/video/toaru/SDL_toaruvideo.h b/src/video/toaru/SDL_toaruvideo.h index d383e54..f0b64e7 100644 --- a/src/video/toaru/SDL_toaruvideo.h +++ b/src/video/toaru/SDL_toaruvideo.h @@ -42,6 +42,7 @@ struct SDL_PrivateVideoData { int x_w, x_h; int o_w, o_h; int redraw_borders; + int triggered_resize; }; #endif /* _SDL_nullvideo_h */