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

« back to all changes in this revision

Viewing changes to kcontrol/randr/module/randrpolltest.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
#include <X11/Xlib.h>
 
2
#include <X11/extensions/Xrandr.h>
 
3
#include <stdio.h>
 
4
#include <unistd.h>
 
5
 
 
6
int main( int argc, char* argv[] )
 
7
    {
 
8
    Display* dpy = XOpenDisplay( NULL );
 
9
    XSetWindowAttributes attrs;
 
10
    Window w = XCreateWindow( dpy, DefaultRootWindow( dpy ), 0, 0, 100, 100, 0, CopyFromParent, CopyFromParent,
 
11
        CopyFromParent, 0, &attrs );
 
12
//    XMapWindow( dpy, w );
 
13
    int base, error;
 
14
    if( !XRRQueryExtension( dpy, &base, &error ))
 
15
        return 1;
 
16
    int major = 1;
 
17
    int minor = 2;
 
18
    if( !XRRQueryVersion( dpy, &major, &minor ) || major < 1 || (major == 1 && minor < 2 ))
 
19
        return 2;
 
20
    XRRSelectInput( dpy, w,
 
21
        RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask | RROutputChangeNotifyMask | RROutputPropertyNotifyMask );
 
22
    for(;;)
 
23
        {
 
24
        XEvent ev;
 
25
        int a, b, c, d;
 
26
        static int cnt = 0;
 
27
        if( ++cnt % 30 == 0 )
 
28
            {
 
29
//            XRRFreeScreenResources(XRRGetScreenResources( dpy, w ));
 
30
            XRRGetScreenSizeRange( dpy, w, &a, &b, &c, &d );
 
31
//            XSync( dpy, False );
 
32
            printf( "Poll\n" );
 
33
            }
 
34
        sleep( 1 );
 
35
        if( !XPending( dpy ))
 
36
            continue;
 
37
        XNextEvent( dpy, &ev );
 
38
        if( ev.xany.type == base + RRScreenChangeNotify )
 
39
            {
 
40
            printf( "Screen Change\n" );
 
41
            }
 
42
        if( ev.xany.type == base + RRNotify )
 
43
            {
 
44
            XRRNotifyEvent* e = reinterpret_cast< XRRNotifyEvent* >( &ev );
 
45
            switch( e->subtype )
 
46
                {
 
47
                case RRNotify_CrtcChange:
 
48
                    printf( "Crtc Change\n" );
 
49
                    break;
 
50
                case RRNotify_OutputChange:
 
51
                    printf( "Output Change\n" );
 
52
                    break;
 
53
                case RRNotify_OutputProperty:
 
54
                    printf( "Output Property Change\n" );
 
55
                    break;
 
56
                default:
 
57
                    printf( "Unknown Notify\n" );
 
58
                    break;
 
59
                }
 
60
            }
 
61
        }
 
62
    XCloseDisplay( dpy );
 
63
    }