I only get VisibilityNotify events at window mapping

Lucas de Sena lucas at seninha.org
Sat Sep 17 14:30:39 UTC 2022


Hi,

I'm trying to get VisibilityNotify events to check whether a given
window is obscured.

However, I only get VisibilityNotify events after mapping the window.
Obscuring it with any other window (be it a sibling or not) does not
trigger a VisibilityNotify event, nor when I unobscure it.

And when I get such event, the value of `ev.xvisibility.state` is always
`VisibilityUnobscured`, even when mapping the window below others.

Here's a sample program:

	#include <stdio.h>
	#include <X11/Xlib.h>
	
	int
	main(void)
	{
		Display *dpy;
		Window win;
		XEvent ev;
	
		if ((dpy = XOpenDisplay(NULL)) == NULL)
			return 1;
		win = XCreateWindow(
			dpy,
			XDefaultRootWindow(dpy),
			0, 0,
			100, 100,
			0,
			CopyFromParent, InputOutput, CopyFromParent,
			CWEventMask | CWBackPixel,
			&(XSetWindowAttributes){
				.event_mask = VisibilityChangeMask,
				.background_pixel = BlackPixel(dpy, DefaultScreen(dpy)),
			}
		);
		XMapWindow(dpy, win);
		while (!XNextEvent(dpy, &ev))
			if (ev.type == VisibilityNotify)
				printf("visibility: %d\n", ev.xvisibility.state);
		return 0;
	}

Is that how VisibilityNotify is supposed to work?


More information about the xorg mailing list