xdemo.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:58:15 +0100
changeset 22 0db9235d68d9
parent 9 c3fecc82ade6
child 27 81a574d60c15
permissions -rw-r--r--
mysql_db is untested because we have no sponsor with a mysql database committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/xdemo.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>

int main (int argc, char **argv)
{
    Window w = 0;
    Display *dpy = XOpenDisplay (NULL);
    XEvent xev;
    int active;

    if (dpy == NULL) {
        printf ("Error opening localhost:0\n");
        return EXIT_SUCCESS;
    }

    XSynchronize (dpy, 1);
    w = XCreateSimpleWindow (dpy, DefaultRootWindow (dpy), 0, 0, 240, 60, 1, 1, 1);

    if (w < 0)
        return EXIT_SUCCESS;

    printf ("WINDOW-ID: %ld\n", w);

    XRaiseWindow (dpy, w);
    XMapWindow (dpy, w);

    printf ("Press ESC to quit\n");

    active = 1;
    XSelectInput (dpy, w, KeyPressMask);

    while (active) {
        XNextEvent (dpy, &xev);
        switch (xev.type) {
        case KeyPress:
            if (xev.xkey.keycode == 9)
                active = 0;
            printf ("Keycode = %2u\n", xev.xkey.keycode);
            break;
        default:
            printf ("Unknown Event: %d\n", xev.type);
        }
    }

    XDestroyWindow (dpy, w);
    XCloseDisplay (dpy);

    return EXIT_SUCCESS;
}