summaryrefslogtreecommitdiff
path: root/src/wm-tester/test-gravity.c
blob: 0773af220049e63fe58a28747c8dbd4718f9ef0d (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
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>

int gravities[10] = {
  NorthWestGravity, 
  NorthGravity,  
  NorthEastGravity,
  WestGravity,      
  CenterGravity, 
  EastGravity,
  SouthWestGravity,
  SouthGravity,
  SouthEastGravity,
  StaticGravity
};

Window windows[10];

int x_offset[3] = { 0, -50,  -100 };
int y_offset[3] = { 0, -50,  -100 };
double screen_x_fraction[3] = { 0, 0.5, 1.0 };
double screen_y_fraction[3] = { 0, 0.5, 1.0 };
int screen_width;
int screen_height;

void calculate_position (int i, int *x, int *y)
{
  if (i == 9)
    {
      *x = 150;
      *y = 150;
    }
  else 
    {
      *x = screen_x_fraction[i % 3] * screen_width + x_offset[i % 3];
      *y = screen_y_fraction[i / 3] * screen_height + y_offset[i / 3];
    }
}

int main (int argc, char **argv)
{
  Display *d;
  Window w;
  XSizeHints hints;
  int i;
  int screen;
  XEvent ev;
  
  d = XOpenDisplay (NULL);

  screen = DefaultScreen (d);
  screen_width = DisplayWidth (d, screen);
  screen_height = DisplayHeight (d, screen);

  for (i=0; i<10; i++)
    {
      int x, y;
      
      calculate_position (i, &x, &y);

      w = XCreateSimpleWindow(d, RootWindow(d, screen), 
			      x, y, 100, 100, 0, 
			      WhitePixel(d, screen), WhitePixel(d, screen));

      windows[i] = w;

      XSelectInput (d, w, ButtonPressMask);
      
      hints.flags = USPosition | PMinSize | PMaxSize | PWinGravity;
      
      hints.min_width = 100;
      hints.min_height = 100;
      hints.max_width = 200;
      hints.max_height = 200;
      hints.win_gravity = gravities[i];
      
      XSetWMNormalHints (d, w, &hints);
      XMapWindow (d, w);
    }

  while (1)
    {
      XNextEvent (d, &ev);

      if (ev.xany.type == ButtonPress)
	{
	  for (i=0; i<10; i++)
	    {
	      if (windows[i] == ev.xbutton.window)
		{
		  if (ev.xbutton.button == Button1) 
		    { 
		      int x, y;
		      
		      calculate_position (i, &x, &y);
		      w = XMoveWindow (d, windows[i], x, y); 
		    }
		  else 
		    {
		      w = XResizeWindow (d, windows[i], 200, 200);
		    }
		  }
	      }
	}
    }
  
  return 0;
}