fix BadMatch error when embedding on some windows 0fe460db
When embedded into another window, dmenu will fail with the BadMatch
error if that window have not the same colormap/depth/visual as the
root window.

That happens because dmenu inherits the colormap/depth/visual from
its parent, but draws on a pixmap created based on the root window
using a GC created for the root window (see drw.c).  A BadMatch will
occur when copying the content of the pixmap into dmenu's window.

A solution is to create dmenu's window inside root and then reparent
it if embeded.

See this mail[1] on ports@openbsd.org mailing list for context.

[1]: https://marc.info/?l=openbsd-ports&m=168072150814664&w=2
Lucas de Sena · 2023-04-05 17:11 1 file(s) · +2 −1
dmenu.c +2 −1
685 685
	swa.override_redirect = True;
686 686
	swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
687 687
	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
688 -
	win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
688 +
	win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
689 689
	                    CopyFromParent, CopyFromParent, CopyFromParent,
690 690
	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
691 691
	XSetClassHint(dpy, win, &ch);
700 700
701 701
	XMapRaised(dpy, win);
702 702
	if (embed) {
703 +
		XReparentWindow(dpy, win, parentwin, x, y);
703 704
		XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask);
704 705
		if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
705 706
			for (i = 0; i < du && dws[i] != win; ++i)