Advertisement
Guest User

Untitled

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