1 // tests for window gravity
10 const int gravities
[ 10 ] =
24 const char* const gravity_names
[ 10 ] =
26 "NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST"
31 int get_gravity( const char* name
)
36 if( strcmp( name
, gravity_names
[ i
] ) == 0 )
37 return gravities
[ i
];
38 cerr
<< "Wrong gravity name" << endl
;
42 void test( const char* gravity
)
44 XSetWindowAttributes attrs
;
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
);
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
;
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
);
94 cerr
<< "specify gravity" << endl
;