Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] cant patch st with st-alpha
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
vcmota
n00b
n00b


Joined: 19 Jun 2017
Posts: 47

PostPosted: Sun Nov 19, 2017 12:57 am    Post subject: [SOLVED] cant patch st with st-alpha Reply with quote

I am setting up a novel gentoo install using DWM as window manager. I managed to properly configure everything I wanted in DWM itself, but regarding ST (the suckless.org simple terminal) I just dont know how to set up some of the patches, namely those which refears to changes in the file "config.mk". Here is an example from the patch "st-alpha-0.7.diff":

Code:
 
diff --git a/config.mk b/config.mk
index c84c5ee..19a03bb 100644
--- a/config.mk
+++ b/config.mk
@@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
 INCS = -I. -I/usr/include -I${X11INC} \
        `pkg-config --cflags fontconfig` \
        `pkg-config --cflags freetype2`
-LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXext -lXft -lXrender\
        `pkg-config --libs fontconfig`  \
        `pkg-config --libs freetype2`


That feels like the dumbest question ever made on these forums, but here it goes: who the hack is config.mk in gentoo? It seams that such a file exists whenever DWM is installed in binary distros, but I looked everywhere and there seems to be nothing in Gentoo that refers to this file. I suspect that the extension ".mk" refers to makefile, which means that one should modify the libraries with which ST is compiled in order to properly apply this patch. In Gentoo that would imply modifying the ebuild itself, which seems kind of absurd for a patch.

Thak you all!


Last edited by vcmota on Mon Nov 20, 2017 10:38 am; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 11415

PostPosted: Sun Nov 19, 2017 1:38 am    Post subject: Reply with quote

.mk is a traditional suffix for files in Makefile syntax. Based on the name, I suspect that the Makefile includes config.mk to define various user-configurable settings. It is most likely distributed with the package's Makefile, or possibly generated based on a configure script.

Where did you get this patch? Why do you think you need any patches? What instructions were provided with the patch?
Back to top
View user's profile Send private message
vcmota
n00b
n00b


Joined: 19 Jun 2017
Posts: 47

PostPosted: Sun Nov 19, 2017 2:11 am    Post subject: Reply with quote

Hu wrote:
.mk is a traditional suffix for files in Makefile syntax. Based on the name, I suspect that the Makefile includes config.mk to define various user-configurable settings. It is most likely distributed with the package's Makefile, or possibly generated based on a configure script.

Where did you get this patch? Why do you think you need any patches? What instructions were provided with the patch?


Thank you Hu for your response. I got this patch from https://st.suckless.org/patches/alpha/, it is supposed to allow for an adjustable transparency for the terminal. The instructions are minimal, as with any other suckless tool, but after learning from trial and error how to install other suckless tools patches I have figured that reading the ".diff" file gives you all the instructions you often needs. For the patch I am interested here is the text in the respective .diff file:

Code:
diff --git a/config.def.h b/config.def.h
index b41747f..e22ebd2 100644
--- a/config.def.h
+++ b/config.def.h
@@ -82,6 +82,9 @@ static char termname[] = "st-256color";
  */
 static unsigned int tabspaces = 8;
 
+/* bg opacity */
+static const int alpha = 0xdd;
+
 /* Terminal colors (16 first used in escape sequence) */
 static const char *colorname[] = {
    /* 8 normal colors */
@@ -109,6 +112,7 @@ static const char *colorname[] = {
    /* more colors can be added after 255 to use with DefaultXX */
    "#cccccc",
    "#555555",
+   "black",
 };
 
 
@@ -117,7 +121,7 @@ static const char *colorname[] = {
  * foreground, background, cursor, reverse cursor
  */
 static unsigned int defaultfg = 7;
-static unsigned int defaultbg = 0;
+static unsigned int defaultbg = 257;
 static unsigned int defaultcs = 256;
 static unsigned int defaultrcs = 257;
 
diff --git a/config.mk b/config.mk
index c84c5ee..19a03bb 100644
--- a/config.mk
+++ b/config.mk
@@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
 INCS = -I. -I/usr/include -I${X11INC} \
        `pkg-config --cflags fontconfig` \
        `pkg-config --cflags freetype2`
-LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXext -lXft -lXrender\
        `pkg-config --libs fontconfig`  \
        `pkg-config --libs freetype2`
 
diff --git a/st.c b/st.c
index 2594c65..f9ba75b 100644
--- a/st.c
+++ b/st.c
@@ -61,6 +61,7 @@ char *argv0;
 #define XK_ANY_MOD    UINT_MAX
 #define XK_NO_MOD     0
 #define XK_SWITCH_MOD (1<<13)
+#define OPAQUE 0Xff
 
 /* macros */
 #define MIN(a, b)      ((a) < (b) ? (a) : (b))
@@ -81,6 +82,8 @@ char *argv0;
             (t1.tv_nsec-t2.tv_nsec)/1E6)
 #define MODBIT(x, set, bit)   ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
 
+#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL)
+
 #define TRUECOLOR(r,g,b)   (1 << 24 | (r) << 16 | (g) << 8 | (b))
 #define IS_TRUECOL(x)      (1 << 24 & (x))
 #define TRUERED(x)      (((x) & 0xff0000) >> 8)
@@ -268,6 +271,7 @@ typedef struct {
    int w, h; /* window width and height */
    int ch; /* char height */
    int cw; /* char width  */
+   int depth; /*  bit depth */
    char state; /* focus, redraw, visible */
    int cursor; /* cursor style */
 } XWindow;
@@ -3137,7 +3141,7 @@ xresize(int col, int row)
 
    XFreePixmap(xw.dpy, xw.buf);
    xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h,
-         DefaultDepth(xw.dpy, xw.scr));
+         xw.depth);
    XftDrawChange(xw.draw, xw.buf);
    xclear(0, 0, xw.w, xw.h);
 }
@@ -3191,6 +3195,14 @@ xloadcols(void)
          else
             die("Could not allocate color %d\n", i);
       }
+
+   /* set alpha value of bg color */
+   if (USE_ARGB) {
+      dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE; //0xcccc;
+      dc.col[defaultbg].pixel &= 0x00111111;
+      dc.col[defaultbg].pixel |= alpha << 24; // 0xcc000000;
+   }
+
    loaded = 1;
 }
 
@@ -3212,6 +3224,16 @@ xsetcolorname(int x, const char *name)
    return 0;
 }
 
+void
+xtermclear(int col1, int row1, int col2, int row2) {
+   XftDrawRect(xw.draw,
+         &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
+         borderpx + col1 * xw.cw,
+         borderpx + row1 * xw.ch,
+         (col2-col1+1) * xw.cw,
+         (row2-row1+1) * xw.ch);
+}
+
 /*
  * Absolute coordinates.
  */
@@ -3443,7 +3465,38 @@ xinit(void)
    if (!(xw.dpy = XOpenDisplay(NULL)))
       die("Can't open display\n");
    xw.scr = XDefaultScreen(xw.dpy);
-   xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+   xw.depth = (USE_ARGB) ? 32: XDefaultDepth(xw.dpy, xw.scr);
+   if (! USE_ARGB)
+      xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+   else {
+      XVisualInfo *vis;
+      XRenderPictFormat *fmt;
+      int nvi;
+      int i;
+
+      XVisualInfo tpl = {
+         .screen = xw.scr,
+         .depth = 32,
+         .class = TrueColor
+      };
+
+      vis = XGetVisualInfo(xw.dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &tpl, &nvi);
+      xw.vis = NULL;
+      for(i = 0; i < nvi; i ++) {
+         fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual);
+         if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
+            xw.vis = vis[i].visual;
+            break;
+         }
+      }
+
+      XFree(vis);
+
+      if (! xw.vis) {
+         fprintf(stderr, "Couldn't find ARGB visual.\n");
+         exit(1);
+      }
+   }
 
    /* font */
    if (!FcInit())
@@ -3453,7 +3506,10 @@ xinit(void)
    xloadfonts(usedfont, 0);
 
    /* colors */
-   xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+   if (! USE_ARGB)
+      xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+   else
+      xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr), xw.vis, None);
    xloadcols();
 
    /* adjust fixed window geometry */
@@ -3476,16 +3532,17 @@ xinit(void)
    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,
-         xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
+         xw.w, xw.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,
+   xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, xw.depth);
+   dc.gc = XCreateGC(xw.dpy,
+         (USE_ARGB)? xw.buf: parent,
+         GCGraphicsExposures,
          &gcvalues);
-   xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h,
-         DefaultDepth(xw.dpy, xw.scr));
    XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
    XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
 


The first part, starting from "diff --git a/config.def.h b/config.def.h", describes the modifications that you have to make on the file "st.h" (here refeared to as config.def.h), which in gentoo corresponds to the file "/etc/portage/savedconfig/x11-terms/st-0.7". The third part, starting from "diff --git a/st.c b/st.c", is the part that gentoo is suppose to handle automatically (once you properly "installed" the patch), and, from my short experience with both suckless tools and gentoo, gentoo usually do that flawlessly (I have two other suckless tools patches for st sucessfully installed, named clipboard from [url]https://st.suckless.org/patches/clipboard/ [/url] and scrollback from https://st.suckless.org/patches/scrollback/, and everything worked perfectly since modifications are only needed for the st.h file). The second part, starting from "diff --git a/config.mk b/config.mk", is the one that have me stalled, because I dont know how to add those modifications to the simple terminal configuration files since I dont know where to put them. I have tried to just ignore this part but "emerge st" fails complaining of a compilation error regarding libXrender. Thank you again!
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 11415

PostPosted: Sun Nov 19, 2017 4:49 pm    Post subject: Reply with quote

I am a bit confused. Is it really the case that the author of the tool, who hosts the source of the tool, distributes these optional features (not necessarily also authored by the core developers) as undocumented patches that the end-user is expected to integrate into the source? If not, which part of my description here is inaccurate?

It would be much simpler for everyone if these patches were integrated into the main source, optionally controlled by #ifdef guards so that the patch could be toggled at compile-time.

vcmota wrote:
The first part, starting from "diff --git a/config.def.h b/config.def.h", describes the modifications that you have to make on the file "st.h" (here refeared to as config.def.h)
No. It describes changes to make to config.def.h, which is why diff refers to it by that name. It may be the case that config.def.h is used as an input to a tool that produces st.h as an output. That output then might interact with the Gentoo savedconfig feature.

vcmota wrote:
The second part, starting from "diff --git a/config.mk b/config.mk", is the one that have me stalled, because I dont know how to add those modifications to the simple terminal configuration files since I dont know where to put them.
File config.mk seems to be present in the top level of the source tree, so you need to apply this hunk as a source patch via /etc/portage/patches. If the ebuild supports eapply_user, this is very easy. If it doesn't support eapply_user, it should be upgraded so that it does.
Back to top
View user's profile Send private message
vcmota
n00b
n00b


Joined: 19 Jun 2017
Posts: 47

PostPosted: Sun Nov 19, 2017 10:39 pm    Post subject: Reply with quote

[list]Thank you Hu, your reply helped me a lot to understand patching in gentoo better.

Quote:
I am a bit confused. Is it really the case that the author of the tool, who hosts the source of the tool, distributes these optional features (not necessarily also authored by the core developers) as undocumented patches that the end-user is expected to integrate into the source? If not, which part of my description here is inaccurate?


Well, that was exactly what I was doing. That was exactly what I have been doing with many of the other DWM patches, and I must say that it has been working until now. Look, I am no computing expert, I have been learning all that stuff mostly from trial and error, and that set of steps are the ones that I have deduced to be accurate from both the information available at the https://st.suckless.org website and the patching instructions displayed here https://wiki.gentoo.org/wiki/Dwm#Patching. In fact from that last gentoo page I got the impression that all the dwm patches should be done "manually" at gentoo.

But after reading your last reply I eventually came across this other gentoo page https://wiki.gentoo.org/wiki//etc/portage/patches, which refers to patches in general for gentoo. From that page and from your reply I tried the following procedure, after verifying that the ST ebuild supported eapply_user:

1) Downloaded the .diff file from here https://st.suckless.org/patches/alpha/; 2) Renamed the .diff file into 03-st-alpha-0.7.patch; 3) Copied the .diff file into the directory /etc/portage/patches/x11-terms/st/; 4) Entered the directory /usr/portage/x11-terms/st/; 5) Run the command ebuild st-0.7.ebuild clean prepare, which return no errors 6) emerge dwm st.

If I correctly understood either your reply and the gentoo pages that procedure was suppose to work, but it didnt: the compilation failed warning that an alpha function has not been previously defined. Than I recalled the beginning of the diff file where one can read:

Code:

diff --git a/config.def.h b/config.def.h
index b41747f..e22ebd2 100644
--- a/config.def.h
+++ b/config.def.h
@@ -82,6 +82,9 @@ static char termname[] = "st-256color";
  */
 static unsigned int tabspaces = 8;
 
+/* bg opacity */
+static const int alpha = 0xdd;
+
 /* Terminal colors (16 first used in escape sequence) */
 static const char *colorname[] = {
    /* 8 normal colors */
@@ -109,6 +112,7 @@ static const char *colorname[] = {
    /* more colors can be added after 255 to use with DefaultXX */
    "#cccccc",
    "#555555",
+   "black",
 };
 


So that is what I did: I manually added the instructions above (the lines starting with "+") to the file /etc/portage/savedconfig/x11-terms/st-0.7 and again hit "emerge dwm st", and the compilation worked, apparently flawlessly. So I restarted DWM but was desapointed to realize that there was no transparency, the terminal background changed its color from black to gray but that was all, no transparency. So I just went back from all the changes I did and successfully restored my actual configuration.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 11415

PostPosted: Mon Nov 20, 2017 12:36 am    Post subject: Reply with quote

Your step 5 was unnecessary, but not harmful. It can be dropped without side effects. Otherwise, you did the right thing. The use of savedconfig is strange here. Normally, the savedconfig should be an actual configuration file only, but in this case it sounds like it also contained source code.
Back to top
View user's profile Send private message
vcmota
n00b
n00b


Joined: 19 Jun 2017
Posts: 47

PostPosted: Mon Nov 20, 2017 10:37 am    Post subject: Reply with quote

Thank you Hu for all your assistance. I will mark this thread as SOLVED, since the major problem here was that I did not knew how to setup the patch, and now I know... I gues... Well, I am also going to contact the upstream to see what is missing, since the patch has not worked after all.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum