plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

xevents.c (1173B)


      1 /*
      2  * Original code posted to comp.sources.x (see printevent.c).
      3  * Modifications by Russ Cox <rsc@swtch.com>.
      4  */
      5 
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 #include <X11/Intrinsic.h>
      9 #include "printevent.h"
     10 
     11 int
     12 main(int argc, char **argv)
     13 {
     14 	int screen;
     15 	Display *dpy;
     16 	Window window;
     17 	XEvent event;
     18 
     19 	if (!(dpy = XOpenDisplay(""))) {
     20 		printf("Failed to open display...\n");
     21 		exit(1);
     22 	}
     23 
     24 	screen = DefaultScreen(dpy);
     25 
     26 	window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100,
     27 		300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
     28 
     29 	XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask |
     30 		ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
     31 		PointerMotionMask | PointerMotionHintMask | Button1MotionMask |
     32 		Button2MotionMask | Button3MotionMask | Button4MotionMask |
     33 		Button5MotionMask | ButtonMotionMask | KeymapStateMask |
     34 		ExposureMask | VisibilityChangeMask | StructureNotifyMask |
     35 		SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask |
     36 		PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask);
     37 
     38 	XMapWindow(dpy, window);
     39 
     40 	for(;;){
     41 		XNextEvent(dpy, &event);
     42 		printevent(&event);
     43 	}
     44 }