~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/tools/test_gravity.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// tests for window gravity
 
2
 
 
3
#include <iostream>
 
4
#include <stdlib.h>
 
5
#include <X11/Xlib.h>
 
6
#include <X11/Xutil.h>
 
7
 
 
8
using namespace std;
 
9
 
 
10
const int gravities[ 10 ] = {
 
11
    NorthWestGravity,
 
12
    NorthGravity,
 
13
    NorthEastGravity,
 
14
    WestGravity,
 
15
    CenterGravity,
 
16
    EastGravity,
 
17
    SouthWestGravity,
 
18
    SouthGravity,
 
19
    SouthEastGravity,
 
20
    StaticGravity
 
21
};
 
22
 
 
23
const char* const gravity_names[ 10 ] = {
 
24
    "NW", "N", "NE", "W", "C", "E", "SW", "S", "SE", "ST"
 
25
};
 
26
 
 
27
Display* dpy = NULL;
 
28
 
 
29
int get_gravity(const char* name)
 
30
{
 
31
    for (int i = 0;
 
32
            i < 10;
 
33
            ++i)
 
34
        if (strcmp(name, gravity_names[ i ]) == 0)
 
35
            return gravities[ i ];
 
36
    cerr << "Wrong gravity name" << endl;
 
37
    exit(1);
 
38
}
 
39
 
 
40
void test(const char* gravity)
 
41
{
 
42
    XSetWindowAttributes attrs;
 
43
    XSizeHints hints;
 
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);
 
50
    XMapWindow(dpy, w);
 
51
    for (;;) {
 
52
        XEvent ev;
 
53
        XNextEvent(dpy, &ev);
 
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;
 
57
            Window root, child;
 
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);
 
73
            }
 
74
        }
 
75
    }
 
76
}
 
77
 
 
78
int main(int argc, char* argv[])
 
79
{
 
80
    dpy = XOpenDisplay(NULL);
 
81
    if (argc != 2) {
 
82
        cerr << "specify gravity" << endl;
 
83
        exit(1);
 
84
    }
 
85
    test(argv[ 1 ]);
 
86
    XCloseDisplay(dpy);
 
87
}