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
|
#include <X11/X.h>
#include <X11/Xlib.h>
#include <assert.h>
//
// gcc -g -Wall -o testcase testcase.c -lX11
//
static int WindowExistsFlag;
static int window_exists_err_handler( Display* dpy, XErrorEvent* xerr )
{
(void) dpy;
if (xerr->error_code == BadWindow)
{
WindowExistsFlag = 0;
}
return 0;
}
static int window_exists( Display *dpy, Window win )
{
XWindowAttributes wa;
int (*old_handler)(Display*, XErrorEvent*);
WindowExistsFlag = 1;
old_handler = XSetErrorHandler(window_exists_err_handler);
XGetWindowAttributes( dpy, win, &wa ); /* dummy request */
XSetErrorHandler(old_handler);
return WindowExistsFlag;
}
int main()
{
int i;
Display *dpy = XOpenDisplay(NULL);
assert(dpy);
int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
for (i = 0; i < 2; i++)
{
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, blackColor, blackColor);
XMapWindow(dpy, w);
XDestroyWindow(dpy, w);
XSync(dpy, 0);
window_exists(dpy, w);
XSync(dpy, 0);
}
return 0;
}
|