~ubuntu-branches/ubuntu/vivid/marco/vivid

« back to all changes in this revision

Viewing changes to src/wm-tester/test-size-hints.c

  • Committer: Package Import Robot
  • Author(s): Mike Gabriel
  • Date: 2014-01-21 19:52:39 UTC
  • Revision ID: package-import@ubuntu.com-20140121195239-c4k1v8umdw1u4n29
Tags: upstream-1.6.2
ImportĀ upstreamĀ versionĀ 1.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <X11/Xlib.h>
 
2
#include <X11/Xutil.h>
 
3
#include <stdlib.h>
 
4
#include <glib.h>
 
5
 
 
6
static Bool
 
7
all_events (Display  *display,
 
8
            XEvent   *event,
 
9
            XPointer  arg)
 
10
{
 
11
  return True;
 
12
}
 
13
 
 
14
#if 0
 
15
static void
 
16
get_size (Display *d, Drawable draw,
 
17
          int *xp, int *yp, int *widthp, int *heightp)
 
18
{
 
19
  int x, y;
 
20
  unsigned int width, height, border, depth;
 
21
  Window root;
 
22
  
 
23
  XGetGeometry (d, draw, &root, &x, &y, &width, &height, &border, &depth);
 
24
 
 
25
  if (xp)
 
26
    *xp = x;
 
27
  if (yp)
 
28
    *yp = y;
 
29
  if (widthp)
 
30
    *widthp = width;
 
31
  if (*heightp)
 
32
    *heightp = height;
 
33
}
 
34
#endif
 
35
 
 
36
int
 
37
main (int argc, char **argv)
 
38
{
 
39
  Display *d;
 
40
  Window zero_min_size;
 
41
  XSizeHints hints;
 
42
  int screen;
 
43
  XEvent ev;
 
44
  int x, y, width, height;
 
45
  Pixmap pix;
 
46
  GC gc;  
 
47
  XGCValues gc_vals;
 
48
  gboolean redraw_pending;
 
49
  
 
50
  d = XOpenDisplay (NULL);
 
51
 
 
52
  screen = DefaultScreen (d);
 
53
 
 
54
  x = 0;
 
55
  y = 0;
 
56
  width = 100;
 
57
  height = 100;
 
58
  
 
59
  zero_min_size = XCreateSimpleWindow (d, RootWindow (d, screen), 
 
60
                                       x, y, width, height, 0,
 
61
                                       WhitePixel (d, screen),
 
62
                                       WhitePixel (d, screen));  
 
63
  
 
64
  XSelectInput (d, zero_min_size,
 
65
                ButtonPressMask | ExposureMask | StructureNotifyMask);
 
66
  
 
67
  hints.flags = PMinSize;
 
68
  
 
69
  hints.min_width = 0;
 
70
  hints.min_height = 0;
 
71
  
 
72
  XSetWMNormalHints (d, zero_min_size, &hints);
 
73
  XMapWindow (d, zero_min_size);
 
74
 
 
75
  redraw_pending = FALSE;
 
76
  while (1)
 
77
    {
 
78
      XNextEvent (d, &ev);
 
79
      
 
80
      switch (ev.xany.type)
 
81
        {
 
82
        case ButtonPress:
 
83
          if (ev.xbutton.button == 1)
 
84
            {
 
85
              g_print ("Exiting on button 1 press\n");
 
86
              exit (0);
 
87
            }
 
88
          break;
 
89
 
 
90
        case ConfigureNotify:
 
91
          x = ev.xconfigure.x;
 
92
          y = ev.xconfigure.y;
 
93
          width = ev.xconfigure.width;
 
94
          height = ev.xconfigure.height;
 
95
 
 
96
          redraw_pending = TRUE;
 
97
          break;
 
98
          
 
99
        case Expose:
 
100
          redraw_pending = TRUE;
 
101
          break;
 
102
          
 
103
        default:
 
104
          break;
 
105
        }
 
106
 
 
107
      /* Primitive event compression */
 
108
      if (XCheckIfEvent (d, &ev, all_events, NULL))
 
109
        {
 
110
          XPutBackEvent (d, &ev);
 
111
        }
 
112
      else if (redraw_pending)
 
113
        {
 
114
          pix = XCreatePixmap (d, zero_min_size, width, height,
 
115
                               DefaultDepth (d, screen));
 
116
          
 
117
          gc_vals.foreground = WhitePixel (d, screen);
 
118
          
 
119
          gc = XCreateGC (d, pix, GCForeground, &gc_vals);
 
120
          
 
121
          XFillRectangle (d, pix, gc, 0, 0, width, height);
 
122
          
 
123
          XCopyArea (d, pix, zero_min_size, gc, 0, 0, width, height, 0, 0);
 
124
          
 
125
          XFreePixmap (d, pix);
 
126
          XFreeGC (d, gc);
 
127
 
 
128
          redraw_pending = FALSE;
 
129
        }
 
130
    }
 
131
 
 
132
  /* This program has an infinite loop above so a return statement would
 
133
   * just cause compiler warnings.
 
134
   */
 
135
}
 
136