处理st终端添加alpha补丁报错

软件版本

st:0.9.2
dwm:6.5
dmenu:5.2
st-alpha: 20220206-0.8.5

补丁连接:https://st.suckless.org/patches/alpha/st-alpha-20220206-0.8.5.diff

问题说明

st-alpha补丁可以给st终端加上半透明效果,会更加美观
给st终端打补丁会报错,报错信息如下

chong@Arch ~src/st (git)-[alpha] % patch < patchs/st-alpha-20220206-0.8.5.diff
patching file config.def.h
patching file config.mk
patching file st.h
Hunk #1 succeeded at 124 (offset -2 lines).
patching file x.c
Hunk #1 succeeded at 120 (offset 15 lines).
Hunk #2 succeeded at 259 (offset 15 lines).
Hunk #3 succeeded at 773 (offset 35 lines).
Hunk #4 succeeded at 833 (offset 35 lines).
Hunk #5 FAILED at 1127.
Hunk #6 succeeded at 1174 (offset 33 lines).
Hunk #7 FAILED at 1161.
Hunk #8 succeeded at 2148 (offset 120 lines).
2 out of 8 hunks FAILED -- saving rejects to file x.c.rej

一共给四个文件打了补丁,前三个config.def.h、config.mk和st.h都没报错。
在给x.c文件打补丁时有两个报错,且将报错信息输出到了x.c.rej文件

--- x.c
+++ x.c
@@ -1127,11 +1136,23 @@ xinit(int cols, int rows)
    Window parent;
    pid_t thispid = getpid();
    XColor xmousefg, xmousebg;
+   XWindowAttributes attr;
+   XVisualInfo vis;

   x.c中没有下面两行内容
    if (!(xw.dpy = XOpenDisplay(NULL)))
        die("can't open display\n");
    xw.scr = XDefaultScreen(xw.dpy);
-   xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+
+   if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
+       parent = XRootWindow(xw.dpy, xw.scr);
+       xw.depth = 32;
+   } else {
+       XGetWindowAttributes(xw.dpy, parent, &attr);
+       xw.depth = attr.depth;
+   }
+
+   XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
+   xw.vis = vis.visual;

    /* font */
    if (!FcInit())
@@ -1161,19 +1182,15 @@ xinit(int cols, int rows)
        | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
    xw.attrs.colormap = xw.cmap;

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

    memset(&gcvalues, 0, sizeof(gcvalues));
    gcvalues.graphics_exposures = False;
-   dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
-           &gcvalues);
-   xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
-           DefaultDepth(xw.dpy, xw.scr));
+   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);

可能因为版本兼容中有些行找不到。st 0.9.2版本是在2024年4月5号左右发布的,alpha补丁是2022年的
x.c.rej文件一共有两个报错,所以要修改x.c的两个部分,在x.c.rej文件中写明了第一部分和第二部分的行号,分别是1127和1136行左右。

修复问题

根据x.c.rej文件内容将行首-号的行,在x.c文件中找到并删除,+号的行在x.c中加入
第一部分

        Window parent, root;
        pid_t thispid = getpid();
        XColor xmousefg, xmousebg;
		/* 下面两行内容新增 */
        XWindowAttributes attr;
        XVisualInfo vis;

        xw.scr = XDefaultScreen(xw.dpy);
		/* 这里删除一行*/
		/* 这里新增下面if判断、函数和变量*/
         if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
            parent = XRootWindow(xw.dpy, xw.scr);
            xw.depth = 32;
        } else {
            XGetWindowAttributes(xw.dpy, parent, &attr);
            xw.depth = attr.depth;
        }

        XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
        xw.vis = vis.visual;
		/* 新增到这里结束*/ 

第二部分

        root = XRootWindow(xw.dpy, xw.scr);
		/* 下面删除了if判断 */
        xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t,
                        /* 修改下面一行 */
						//win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
						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, parent, GCGraphicsExposures,
        //&gcvalues);
		//xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
        //DefaultDepth(xw.dpy, xw.scr));
        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);

修改后重新编译

sudo make clean install

关闭st终端重新打开即可看到效果

posted @ 2024-08-13 23:57  夏凉浮生  阅读(78)  评论(0)    收藏  举报