kwin Library API Documentation

test_gravity.cpp

00001 // tests for window gravity 00002 00003 #include <iostream> 00004 #include <stdlib.h> 00005 #include <X11/Xlib.h> 00006 #include <X11/Xutil.h> 00007 00008 using namespace std; 00009 00010 const int gravities[ 10 ] = 00011 { 00012 NorthWestGravity, 00013 NorthGravity, 00014 NorthEastGravity, 00015 WestGravity, 00016 CenterGravity, 00017 EastGravity, 00018 SouthWestGravity, 00019 SouthGravity, 00020 SouthEastGravity, 00021 StaticGravity 00022 }; 00023 00024 const char* const gravity_names[ 10 ] = 00025 { 00026 "NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST" 00027 }; 00028 00029 Display* dpy = NULL; 00030 00031 int get_gravity( const char* name ) 00032 { 00033 for( int i = 0; 00034 i < 10; 00035 ++i ) 00036 if( strcmp( name, gravity_names[ i ] ) == 0 ) 00037 return gravities[ i ]; 00038 cerr << "Wrong gravity name" << endl; 00039 exit( 1 ); 00040 } 00041 00042 void test( const char* gravity ) 00043 { 00044 XSetWindowAttributes attrs; 00045 XSizeHints hints; 00046 hints.flags = USPosition | PWinGravity; 00047 hints.win_gravity = get_gravity( gravity ); 00048 Window w = XCreateWindow( dpy, DefaultRootWindow( dpy ), 100, 100, 200, 100, 0, CopyFromParent, CopyFromParent, 00049 CopyFromParent, 0, &attrs ); 00050 XSetWMNormalHints( dpy, w, &hints ); 00051 XSelectInput( dpy, w, StructureNotifyMask | ButtonPressMask ); 00052 XMapWindow( dpy, w ); 00053 for(;;) 00054 { 00055 XEvent ev; 00056 XNextEvent( dpy, &ev ); 00057 if( ev.type == ConfigureNotify ) 00058 { 00059 cout << "CONFIGURENOTIFY:" << ev.xany.send_event << ":" << ev.xconfigure.x << ":" << ev.xconfigure.y 00060 << ":" << ev.xconfigure.width << ":" << ev.xconfigure.height << endl; 00061 Window root, child; 00062 int x, x_local, y, y_local; 00063 unsigned int width, height, border, depth; 00064 XGetGeometry( dpy, w, &root, &x_local, &y_local, &width, &height, &border, &depth ); 00065 XTranslateCoordinates( dpy, w, root, 0, 0, &x, &y, &child ); 00066 cout << "GEOMETRY:" << x << ":" << y << ":" << width << ":" << height << ":(" << x_local << ":" << y_local << ")" << endl; 00067 } 00068 else if( ev.type == ButtonPress ) 00069 { 00070 if( ev.xbutton.button == Button1 ) // move 00071 { 00072 cout << "MOVE" << endl; 00073 XMoveWindow( dpy, w, 100, 100 ); 00074 } 00075 else if( ev.xbutton.button == Button2 ) // resize 00076 { 00077 cout << "RESIZE" << endl; 00078 XResizeWindow( dpy, w, 200, 100 ); 00079 } 00080 else if( ev.xbutton.button == Button3 ) // move and resize 00081 { 00082 cout << "MOVERESIZE" << endl; 00083 XMoveResizeWindow( dpy, w, 100, 100, 200, 100 ); 00084 } 00085 } 00086 } 00087 } 00088 00089 int main( int argc, char* argv[] ) 00090 { 00091 dpy = XOpenDisplay( NULL ); 00092 if( argc != 2 ) 00093 { 00094 cerr << "specify gravity" << endl; 00095 exit( 1 ); 00096 } 00097 test( argv[ 1 ] ); 00098 XCloseDisplay( dpy ); 00099 }
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 16 15:59:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003