1
// tests for window gravity
10
const int gravities[ 10 ] = {
23
const char* const gravity_names[ 10 ] = {
24
"NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST"
29
int get_gravity(const char* name)
34
if (strcmp(name, gravity_names[ i ]) == 0)
35
return gravities[ i ];
36
cerr << "Wrong gravity name" << endl;
40
void test(const char* gravity)
42
XSetWindowAttributes attrs;
44
hints.flags = USPosition | PWinGravity;
45
hints.win_gravity = get_gravity(gravity);
46
Window w = XCreateWindow(dpy, DefaultRootWindow(dpy), 100, 100, 200, 100, 0, CopyFromParent, CopyFromParent,
47
CopyFromParent, 0, &attrs);
48
XSetWMNormalHints(dpy, w, &hints);
49
XSelectInput(dpy, w, StructureNotifyMask | ButtonPressMask);
54
if (ev.type == ConfigureNotify) {
55
cout << "CONFIGURENOTIFY:" << ev.xany.send_event << ":" << ev.xconfigure.x << ":" << ev.xconfigure.y
56
<< ":" << ev.xconfigure.width << ":" << ev.xconfigure.height << endl;
58
int x, x_local, y, y_local;
59
unsigned int width, height, border, depth;
60
XGetGeometry(dpy, w, &root, &x_local, &y_local, &width, &height, &border, &depth);
61
XTranslateCoordinates(dpy, w, root, 0, 0, &x, &y, &child);
62
cout << "GEOMETRY:" << x << ":" << y << ":" << width << ":" << height << ":(" << x_local << ":" << y_local << ")" << endl;
63
} else if (ev.type == ButtonPress) {
64
if (ev.xbutton.button == Button1) { // move
65
cout << "MOVE" << endl;
66
XMoveWindow(dpy, w, 100, 100);
67
} else if (ev.xbutton.button == Button2) { // resize
68
cout << "RESIZE" << endl;
69
XResizeWindow(dpy, w, 200, 100);
70
} else if (ev.xbutton.button == Button3) { // move and resize
71
cout << "MOVERESIZE" << endl;
72
XMoveResizeWindow(dpy, w, 100, 100, 200, 100);
78
int main(int argc, char* argv[])
80
dpy = XOpenDisplay(NULL);
82
cerr << "specify gravity" << endl;