2007-04-29 17:35:43 +00:00
|
|
|
// tests for window gravity
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
const int gravities[ 10 ] = {
|
|
|
|
NorthWestGravity,
|
|
|
|
NorthGravity,
|
2007-04-29 17:35:43 +00:00
|
|
|
NorthEastGravity,
|
2011-01-30 14:34:42 +00:00
|
|
|
WestGravity,
|
|
|
|
CenterGravity,
|
2007-04-29 17:35:43 +00:00
|
|
|
EastGravity,
|
|
|
|
SouthWestGravity,
|
|
|
|
SouthGravity,
|
|
|
|
SouthEastGravity,
|
|
|
|
StaticGravity
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char* const gravity_names[ 10 ] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
"NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST"
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
Display* dpy = NULL;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int get_gravity(const char* name)
|
|
|
|
{
|
|
|
|
for (int i = 0;
|
|
|
|
i < 10;
|
|
|
|
++i)
|
|
|
|
if (strcmp(name, gravity_names[ i ]) == 0)
|
2007-04-29 17:35:43 +00:00
|
|
|
return gravities[ i ];
|
|
|
|
cerr << "Wrong gravity name" << endl;
|
2011-01-30 14:34:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void test(const char* gravity)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
XSetWindowAttributes attrs;
|
|
|
|
XSizeHints hints;
|
|
|
|
hints.flags = USPosition | PWinGravity;
|
2011-01-30 14:34:42 +00:00
|
|
|
hints.win_gravity = get_gravity(gravity);
|
|
|
|
Window w = XCreateWindow(dpy, DefaultRootWindow(dpy), 100, 100, 200, 100, 0, CopyFromParent, CopyFromParent,
|
|
|
|
CopyFromParent, 0, &attrs);
|
|
|
|
XSetWMNormalHints(dpy, w, &hints);
|
|
|
|
XSelectInput(dpy, w, StructureNotifyMask | ButtonPressMask);
|
|
|
|
XMapWindow(dpy, w);
|
|
|
|
for (;;) {
|
2007-04-29 17:35:43 +00:00
|
|
|
XEvent ev;
|
2011-01-30 14:34:42 +00:00
|
|
|
XNextEvent(dpy, &ev);
|
|
|
|
if (ev.type == ConfigureNotify) {
|
2007-04-29 17:35:43 +00:00
|
|
|
cout << "CONFIGURENOTIFY:" << ev.xany.send_event << ":" << ev.xconfigure.x << ":" << ev.xconfigure.y
|
2011-01-30 14:34:42 +00:00
|
|
|
<< ":" << ev.xconfigure.width << ":" << ev.xconfigure.height << endl;
|
2007-04-29 17:35:43 +00:00
|
|
|
Window root, child;
|
|
|
|
int x, x_local, y, y_local;
|
|
|
|
unsigned int width, height, border, depth;
|
2011-01-30 14:34:42 +00:00
|
|
|
XGetGeometry(dpy, w, &root, &x_local, &y_local, &width, &height, &border, &depth);
|
|
|
|
XTranslateCoordinates(dpy, w, root, 0, 0, &x, &y, &child);
|
2007-04-29 17:35:43 +00:00
|
|
|
cout << "GEOMETRY:" << x << ":" << y << ":" << width << ":" << height << ":(" << x_local << ":" << y_local << ")" << endl;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (ev.type == ButtonPress) {
|
|
|
|
if (ev.xbutton.button == Button1) { // move
|
2007-04-29 17:35:43 +00:00
|
|
|
cout << "MOVE" << endl;
|
2011-01-30 14:34:42 +00:00
|
|
|
XMoveWindow(dpy, w, 100, 100);
|
|
|
|
} else if (ev.xbutton.button == Button2) { // resize
|
2007-04-29 17:35:43 +00:00
|
|
|
cout << "RESIZE" << endl;
|
2011-01-30 14:34:42 +00:00
|
|
|
XResizeWindow(dpy, w, 200, 100);
|
|
|
|
} else if (ev.xbutton.button == Button3) { // move and resize
|
2007-04-29 17:35:43 +00:00
|
|
|
cout << "MOVERESIZE" << endl;
|
2011-01-30 14:34:42 +00:00
|
|
|
XMoveResizeWindow(dpy, w, 100, 100, 200, 100);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
dpy = XOpenDisplay(NULL);
|
|
|
|
if (argc != 2) {
|
2007-04-29 17:35:43 +00:00
|
|
|
cerr << "specify gravity" << endl;
|
2011-01-30 14:34:42 +00:00
|
|
|
exit(1);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
test(argv[ 1 ]);
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
}
|