add more spacing
[personal-kdebase.git] / workspace / kwin / tools / test_gravity.cpp
blob70ae193cf7c1121a8bc395ea2bcf7bf6548d0719
1 // tests for window gravity
3 #include <iostream>
4 #include <stdlib.h>
5 #include <X11/Xlib.h>
6 #include <X11/Xutil.h>
8 using namespace std;
10 const int gravities[ 10 ] =
12 NorthWestGravity,
13 NorthGravity,
14 NorthEastGravity,
15 WestGravity,
16 CenterGravity,
17 EastGravity,
18 SouthWestGravity,
19 SouthGravity,
20 SouthEastGravity,
21 StaticGravity
24 const char* const gravity_names[ 10 ] =
26 "NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST"
29 Display* dpy = NULL;
31 int get_gravity( const char* name )
33 for( int i = 0;
34 i < 10;
35 ++i )
36 if( strcmp( name, gravity_names[ i ] ) == 0 )
37 return gravities[ i ];
38 cerr << "Wrong gravity name" << endl;
39 exit( 1 );
42 void test( const char* gravity )
44 XSetWindowAttributes attrs;
45 XSizeHints hints;
46 hints.flags = USPosition | PWinGravity;
47 hints.win_gravity = get_gravity( gravity );
48 Window w = XCreateWindow( dpy, DefaultRootWindow( dpy ), 100, 100, 200, 100, 0, CopyFromParent, CopyFromParent,
49 CopyFromParent, 0, &attrs );
50 XSetWMNormalHints( dpy, w, &hints );
51 XSelectInput( dpy, w, StructureNotifyMask | ButtonPressMask );
52 XMapWindow( dpy, w );
53 for(;;)
55 XEvent ev;
56 XNextEvent( dpy, &ev );
57 if( ev.type == ConfigureNotify )
59 cout << "CONFIGURENOTIFY:" << ev.xany.send_event << ":" << ev.xconfigure.x << ":" << ev.xconfigure.y
60 << ":" << ev.xconfigure.width << ":" << ev.xconfigure.height << endl;
61 Window root, child;
62 int x, x_local, y, y_local;
63 unsigned int width, height, border, depth;
64 XGetGeometry( dpy, w, &root, &x_local, &y_local, &width, &height, &border, &depth );
65 XTranslateCoordinates( dpy, w, root, 0, 0, &x, &y, &child );
66 cout << "GEOMETRY:" << x << ":" << y << ":" << width << ":" << height << ":(" << x_local << ":" << y_local << ")" << endl;
68 else if( ev.type == ButtonPress )
70 if( ev.xbutton.button == Button1 ) // move
72 cout << "MOVE" << endl;
73 XMoveWindow( dpy, w, 100, 100 );
75 else if( ev.xbutton.button == Button2 ) // resize
77 cout << "RESIZE" << endl;
78 XResizeWindow( dpy, w, 200, 100 );
80 else if( ev.xbutton.button == Button3 ) // move and resize
82 cout << "MOVERESIZE" << endl;
83 XMoveResizeWindow( dpy, w, 100, 100, 200, 100 );
89 int main( int argc, char* argv[] )
91 dpy = XOpenDisplay( NULL );
92 if( argc != 2 )
94 cerr << "specify gravity" << endl;
95 exit( 1 );
97 test( argv[ 1 ] );
98 XCloseDisplay( dpy );