summaryrefslogtreecommitdiff
path: root/src/test.c
blob: 107852832722bc11659bb88d6c0989aeebfd8b51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdlib.h>
#include <stdio.h>

#include "Xlib-wayland.h"

static void
print_event(XEvent *e)
{
	switch (e->type) {
	case MapNotify:
		printf("got MapNotify event: window %d\n",
		       e->xmap.window);
		break;
	case ReparentNotify:
		printf("got ReparentNotify event: window %d\n",
		       e->xmap.window);
		break;
	case MotionNotify:
		printf("got MotionNotify event: window %d\n",
		       e->xmap.window);
		break;
	case ButtonPress:
		printf("got ButtonPress event: window %d\n",
		       e->xmap.window);
		break;
	case ButtonRelease:
		printf("got ButtonRelease event: window %d\n",
		       e->xmap.window);
		break;
	case EnterNotify:
		printf("got EnterNotify event: window %d\n",
		       e->xmap.window);
		break;
	case LeaveNotify:
		printf("got LeaveaNotify event: window %d\n",
		       e->xmap.window);
		break;
	default:
		printf("got event type %d\n", e->type);
		break;
	}
}

static void
wait_for(Display *display, int type)
{
	XEvent e;

	while (1) {
		XNextEvent(display, &e);
		print_event(&e);
		if (e.type == MapNotify)
			break;

	}
}

int main(int argc, char *argv[])
{
	Display *display;
	Window win;
	XID root;
	XSetWindowAttributes attributes;

	display = XOpenDisplay(NULL);
	root = XRootWindow(display, 0);
	printf("opened display %p, root window is %d\n", display, root);
	attributes.event_mask =
		LeaveWindowMask |
		EnterWindowMask |
		Button1MotionMask |
		ButtonPressMask |
		ButtonReleaseMask |
		StructureNotifyMask;
	win = XCreateWindow(display, root,
			    100, 100, 200, 200, 0, 24,
			    InputOutput, NULL, CWEventMask, &attributes);

	printf("created window %d\n", win);

	XMapWindow(display, win);
	XFlush(display);

	wait_for(display, MapNotify);

	wait_for(display, MapNotify);

	XCloseDisplay(display);

	return 0;
}