Skip to content

Commit

Permalink
fix BadMatch error when embedding on some windows
Browse files Browse the repository at this point in the history
When embedded, st fails with BadMatch error if the embedder's window has
non-default colormap/depth/visual.  This commit fixes that by creating
st's window inside root and then reparent it into embedder.

The reference window for dc.gc is also changed to match root's visuals.

A similar commit had been made for dmenu[1].
See this issue[2] on github for context.

[1]: https://git.suckless.org/dmenu/commit/0fe460dbd469a1d5b6a7140d0e1801935e4a923b.html
[2]: phillbush/xfiles#47

___
Adapted for `xst` by Actionless/Loveless
  • Loading branch information
phillbush authored and actionless committed Nov 19, 2024
1 parent e17d500 commit e78898e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ xinit(int cols, int rows)
{
XGCValues gcvalues;
Cursor cursor;
Window parent;
Window parent, root;
pid_t thispid = getpid();
XColor xmousefg, xmousebg;
XWindowAttributes attr;
Expand Down Expand Up @@ -1378,15 +1378,21 @@ xinit(int cols, int rows)
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;

xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
root = XRootWindow(xw.dpy, xw.scr);
if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
parent = root;
xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t,
win.w, win.h, 0, xw.depth, InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs);
if (parent != root)
XReparentWindow(xw.dpy, xw.win, parent, xw.l, xw.t);

memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False;
dc.gc = XCreateGC(xw.dpy, xw.win, GCGraphicsExposures,
&gcvalues);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);

Expand Down

0 comments on commit e78898e

Please sign in to comment.