test-size-hints.c

Go to the documentation of this file.
00001 #include <X11/Xlib.h>
00002 #include <X11/Xutil.h>
00003 #include <stdlib.h>
00004 #include <glib.h>
00005 
00006 static Bool
00007 all_events (Display  *display,
00008             XEvent   *event,
00009             XPointer  arg)
00010 {
00011   return True;
00012 }
00013 
00014 #if 0
00015 static void
00016 get_size (Display *d, Drawable draw,
00017           int *xp, int *yp, int *widthp, int *heightp)
00018 {
00019   int x, y;
00020   unsigned int width, height, border, depth;
00021   Window root;
00022   
00023   XGetGeometry (d, draw, &root, &x, &y, &width, &height, &border, &depth);
00024 
00025   if (xp)
00026     *xp = x;
00027   if (yp)
00028     *yp = y;
00029   if (widthp)
00030     *widthp = width;
00031   if (*heightp)
00032     *heightp = height;
00033 }
00034 #endif
00035 
00036 int
00037 main (int argc, char **argv)
00038 {
00039   Display *d;
00040   Window zero_min_size;
00041   XSizeHints hints;
00042   int screen;
00043   XEvent ev;
00044   int x, y, width, height;
00045   Pixmap pix;
00046   GC gc;  
00047   XGCValues gc_vals;
00048   gboolean redraw_pending;
00049   
00050   d = XOpenDisplay (NULL);
00051 
00052   screen = DefaultScreen (d);
00053 
00054   x = 0;
00055   y = 0;
00056   width = 100;
00057   height = 100;
00058   
00059   zero_min_size = XCreateSimpleWindow (d, RootWindow (d, screen), 
00060                                        x, y, width, height, 0,
00061                                        WhitePixel (d, screen),
00062                                        WhitePixel (d, screen));  
00063   
00064   XSelectInput (d, zero_min_size,
00065                 ButtonPressMask | ExposureMask | StructureNotifyMask);
00066   
00067   hints.flags = PMinSize;
00068   
00069   hints.min_width = 0;
00070   hints.min_height = 0;
00071   
00072   XSetWMNormalHints (d, zero_min_size, &hints);
00073   XMapWindow (d, zero_min_size);
00074 
00075   redraw_pending = FALSE;
00076   while (1)
00077     {
00078       XNextEvent (d, &ev);
00079       
00080       switch (ev.xany.type)
00081         {
00082         case ButtonPress:
00083           if (ev.xbutton.button == 1)
00084             {
00085               g_print ("Exiting on button 1 press\n");
00086               exit (0);
00087             }
00088           break;
00089 
00090         case ConfigureNotify:
00091           x = ev.xconfigure.x;
00092           y = ev.xconfigure.y;
00093           width = ev.xconfigure.width;
00094           height = ev.xconfigure.height;
00095 
00096           redraw_pending = TRUE;
00097           break;
00098           
00099         case Expose:
00100           redraw_pending = TRUE;
00101           break;
00102           
00103         default:
00104           break;
00105         }
00106 
00107       /* Primitive event compression */
00108       if (XCheckIfEvent (d, &ev, all_events, NULL))
00109         {
00110           XPutBackEvent (d, &ev);
00111         }
00112       else if (redraw_pending)
00113         {
00114           pix = XCreatePixmap (d, zero_min_size, width, height,
00115                                DefaultDepth (d, screen));
00116           
00117           gc_vals.foreground = WhitePixel (d, screen);
00118           
00119           gc = XCreateGC (d, pix, GCForeground, &gc_vals);
00120           
00121           XFillRectangle (d, pix, gc, 0, 0, width, height);
00122           
00123           XCopyArea (d, pix, zero_min_size, gc, 0, 0, width, height, 0, 0);
00124           
00125           XFreePixmap (d, pix);
00126           XFreeGC (d, gc);
00127 
00128           redraw_pending = FALSE;
00129         }
00130     }
00131 
00132   /* This program has an infinite loop above so a return statement would
00133    * just cause compiler warnings.
00134    */
00135 }
00136 

Generated on Sat Aug 23 22:04:19 2008 for metacity by  doxygen 1.5.5