--- trunk/src/x11.c 2007/10/08 16:18:06 5 +++ trunk/src/x11.c 2007/10/08 16:18:11 6 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: x11.c,v 1.56 2005/03/05 12:17:53 debug Exp $ + * $Id: x11.c,v 1.58 2005/05/20 22:35:59 debug Exp $ * * X11-related functions. */ @@ -323,6 +323,60 @@ } +/* + * x11_fb_resize(): + * + * Set a new size for an X11 framebuffer window. (NOTE: I didn't think of + * this kind of functionality during the initial design, so it is probably + * buggy. It also needs some refactoring.) + */ +void x11_fb_resize(struct fb_window *win, int new_xsize, int new_ysize) +{ + int alloc_depth; + + if (win == NULL) { + fatal("x11_fb_resize(): win == NULL\n"); + return; + } + + win->x11_fb_winxsize = new_xsize; + win->x11_fb_winysize = new_ysize; + + alloc_depth = win->x11_screen_depth; + if (alloc_depth == 24) + alloc_depth = 32; + if (alloc_depth == 15) + alloc_depth = 16; + + /* Note: ximage_data seems to be freed by XDestroyImage below. */ + /* if (win->ximage_data != NULL) + free(win->ximage_data); */ + win->ximage_data = malloc(new_xsize * new_ysize * alloc_depth / 8); + if (win->ximage_data == NULL) { + fprintf(stderr, "x11_fb_resize(): out of memory " + "allocating ximage_data\n"); + exit(1); + } + + /* TODO: clear for non-truecolor modes */ + memset(win->ximage_data, 0, new_xsize * new_ysize * alloc_depth / 8); + + if (win->fb_ximage != NULL) + XDestroyImage(win->fb_ximage); + win->fb_ximage = XCreateImage(win->x11_display, CopyFromParent, + win->x11_screen_depth, ZPixmap, 0, (char *)win->ximage_data, + new_xsize, new_ysize, 8, new_xsize * alloc_depth / 8); + if (win->fb_ximage == NULL) { + fprintf(stderr, "x11_fb_resize(): out of memory " + "allocating fb_ximage\n"); + exit(1); + } + + XResizeWindow(win->x11_display, win->x11_fb_window, + new_xsize, new_ysize); +} + + /* * x11_fb_init(): *