Advertisement
Guest User

XLib resize problem.

a guest
Jul 9th, 2013
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2.  
  3.     #include <X11/Xlib.h>
  4.     #include <stdio.h>
  5.     #include <stdlib.h>
  6.     #include <string.h>
  7.      
  8.     int main(void) {
  9.        Display *d;
  10.        Window w, ww;
  11.        XEvent e;
  12.        int s;
  13.        int i;
  14.      
  15.        int width = 100, height = 100;
  16.      
  17.        d = XOpenDisplay(NULL);
  18.        if (d == NULL) {
  19.           fprintf(stderr, "Cannot open display\n");
  20.           exit(1);
  21.        }
  22.      
  23.        s = DefaultScreen(d);
  24.        w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 120, 120, 1,
  25.                                 WhitePixel(d, s), BlackPixel(d, s));
  26.      
  27.        ww = XCreateSimpleWindow(d, w, 10, 10, width, height, 1, BlackPixel(d, s), WhitePixel(d, s));
  28.      
  29.        XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask );
  30.        XSelectInput(d, ww, ExposureMask | KeyPressMask);
  31.        XMapWindow(d, w);
  32.        XMapWindow(d, ww);
  33.      
  34.        while (1) {
  35.           XNextEvent(d, &e);
  36.           if (e.type == Expose) {
  37.              for (i=0;i<1000;i++) {
  38.                XFillRectangle(d, ww, DefaultGC(d, s), 20, 20, 10, 10);
  39.                XFillRectangle(d, ww, DefaultGC(d, s), width-30, height-30, 10, 10);
  40.                XFillRectangle(d, ww, DefaultGC(d, s), 20, height-30, 10, 10);
  41.                XFillRectangle(d, ww, DefaultGC(d, s), width-30, 20, 10, 10);
  42.              }
  43.           }
  44.           if (e.type == KeyPress)
  45.              break;
  46.      
  47.           if (e.type == ConfigureNotify) {
  48.             width = e.xconfigure.width - 20;
  49.             if (width < 100) width = 100;
  50.             height = e.xconfigure.height - 20;
  51.             if (height < 100) height = 100;
  52.             XMoveResizeWindow (d, ww, 10, 10, width, height);
  53.           }
  54.        }
  55.      
  56.        XCloseDisplay(d);
  57.        return 0;
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement