summaryrefslogtreecommitdiff
path: root/src/wm-tester/test-size-hints.c
blob: 0569efbd0d8825b4b31a707878ab66092ef513ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <glib.h>

static Bool
all_events (Display  *display,
            XEvent   *event,
            XPointer  arg)
{
  return True;
}

#if 0
static void
get_size (Display *d, Drawable draw,
          int *xp, int *yp, int *widthp, int *heightp)
{
  int x, y;
  unsigned int width, height, border, depth;
  Window root;

  XGetGeometry (d, draw, &root, &x, &y, &width, &height, &border, &depth);

  if (xp)
    *xp = x;
  if (yp)
    *yp = y;
  if (widthp)
    *widthp = width;
  if (*heightp)
    *heightp = height;
}
#endif

int
main (int argc, char **argv)
{
  Display *d;
  Window zero_min_size;
  XSizeHints hints;
  int screen;
  XEvent ev;
  int x, y, width, height;
  Pixmap pix;
  GC gc;
  XGCValues gc_vals;
  gboolean redraw_pending;

  d = XOpenDisplay (NULL);

  screen = DefaultScreen (d);

  x = 0;
  y = 0;
  width = 100;
  height = 100;

  zero_min_size = XCreateSimpleWindow (d, RootWindow (d, screen),
                                       x, y, width, height, 0,
                                       WhitePixel (d, screen),
                                       WhitePixel (d, screen));

  XSelectInput (d, zero_min_size,
                ButtonPressMask | ExposureMask | StructureNotifyMask);

  hints.flags = PMinSize;

  hints.min_width = 0;
  hints.min_height = 0;

  XSetWMNormalHints (d, zero_min_size, &hints);
  XMapWindow (d, zero_min_size);

  redraw_pending = FALSE;
  while (1)
    {
      XNextEvent (d, &ev);

      switch (ev.xany.type)
        {
        case ButtonPress:
          if (ev.xbutton.button == 1)
            {
              g_print ("Exiting on button 1 press\n");
              exit (0);
            }
          break;

        case ConfigureNotify:
          x = ev.xconfigure.x;
          y = ev.xconfigure.y;
          width = ev.xconfigure.width;
          height = ev.xconfigure.height;

          redraw_pending = TRUE;
          break;

        case Expose:
          redraw_pending = TRUE;
          break;

        default:
          break;
        }

      /* Primitive event compression */
      if (XCheckIfEvent (d, &ev, all_events, NULL))
        {
          XPutBackEvent (d, &ev);
        }
      else if (redraw_pending)
        {
          pix = XCreatePixmap (d, zero_min_size, width, height,
                               DefaultDepth (d, screen));

          gc_vals.foreground = WhitePixel (d, screen);

          gc = XCreateGC (d, pix, GCForeground, &gc_vals);

          XFillRectangle (d, pix, gc, 0, 0, width, height);

          XCopyArea (d, pix, zero_min_size, gc, 0, 0, width, height, 0, 0);

          XFreePixmap (d, pix);
          XFreeGC (d, gc);

          redraw_pending = FALSE;
        }
    }

  /* This program has an infinite loop above so a return statement would
   * just cause compiler warnings.
   */
}