[wiki] [sites] [dwm]Added winicon patch for dwm || AdamYuan

From: <git_AT_suckless.org>
Date: Sun, 11 Jul 2021 04:19:50 +0200

commit d121d30193c3540f810c53bfbda1956127915c30
Author: AdamYuan <y13916619121_AT_126.com>
Date: Sun Jul 11 10:19:02 2021 +0800

    [dwm]Added winicon patch for dwm
    
    Added a patch to show window icons

diff --git a/dwm.suckless.org/patches/winicon/dwm-winicon-6.2-v1.diff b/dwm.suckless.org/patches/winicon/dwm-winicon-6.2-v1.1.diff
similarity index 98%
rename from dwm.suckless.org/patches/winicon/dwm-winicon-6.2-v1.diff
rename to dwm.suckless.org/patches/winicon/dwm-winicon-6.2-v1.1.diff
index 702bce90..1c6e008a 100644
--- a/dwm.suckless.org/patches/winicon/dwm-winicon-6.2-v1.diff
+++ b/dwm.suckless.org/patches/winicon/dwm-winicon-6.2-v1.1.diff
_AT_@ -25,53 +25,59 @@ index 6d36cb7..39edf93 100644
  # flags
  CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
 diff --git a/drw.c b/drw.c
-index 8fd1ca4..304e269 100644
+index 8fd1ca4..91454e1 100644
 --- a/drw.c
 +++ b/drw.c
-_AT_@ -378,6 +378,29 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
+_AT_@ -2,6 +2,7 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <stdint.h>
+ #include <X11/Xlib.h>
+ #include <X11/Xft/Xft.h>
+
+_AT_@ -378,6 +379,27 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
          return x + (render ? w : 0);
  }
  
-+static unsigned char
-+blend(unsigned char a, unsigned char x, unsigned char y) { return ((255-a)*x + a*y) / 255; }
++static uint32_t blend32(uint32_t p1, uint32_t p2) {
++ uint32_t a = p2 >> 24;
++ uint32_t na = 255 - a;
++ uint32_t rb = ((na * (p1 & 0x00ff00ffu)) + (a * (p2 & 0x00ff00ffu))) >> 8;
++ uint32_t ag = (na * ((p1 & 0xff00ff00u) >> 8)) + (a * (0x01000000u | ((p2 & 0x0000ff00u) >> 8)));
++ return ((rb & 0x00ff00ffu) | (ag & 0xff00ff00u));
++}
 +
 +void
-+drw_img(Drw *drw, int x, int y, XImage *img, unsigned char *tmp)
++drw_img(Drw *drw, int x, int y, XImage *img, uint32_t *tmp)
 +{
 + if (!drw || !drw->scheme)
 + return;
-+ int icsz = img->width * img->height, bt = drw->scheme[ColBg].pixel, i;
-+ unsigned char *data = (unsigned char *)img->data;
-+ unsigned char r = (bt & 0x000000ff), g = (bt & 0x0000ff00)>>8, b = (bt & 0x00ff0000)>>16;
-+ memcpy(tmp, data, icsz << 2);
-+ for (i = 0; i < icsz; ++i) {
-+ unsigned char a = data[(i<<2)|3];
-+ data[(i<<2) ] = blend(a, r, data[(i<<2) ]);
-+ data[(i<<2)|1] = blend(a, g, data[(i<<2)|1]);
-+ data[(i<<2)|2] = blend(a, b, data[(i<<2)|2]);
-+ }
++ uint32_t *data = (uint32_t *)img->data, bt = drw->scheme[ColBg].pixel;
++ int icsz = img->width * img->height, i;
++ for (i = 0; i < icsz; ++i) tmp[i] = blend32(bt, data[i]);
++ img->data = (char *)tmp;
 + XPutImage(drw->dpy, drw->drawable, drw->gc, img, 0, 0, x, y, img->width, img->height);
-+
-+ memcpy(data, tmp, icsz << 2);
++ img->data = (char *)data;
 +}
 +
  void
  drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
  {
 diff --git a/drw.h b/drw.h
-index 4bcd5ad..5346bec 100644
+index 4bcd5ad..07b6433 100644
 --- a/drw.h
 +++ b/drw.h
 _AT_@ -52,6 +52,7 @@ void drw_setscheme(Drw *drw, Clr *scm);
  /* Drawing functions */
  void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
  int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
-+void drw_img(Drw *drw, int x, int y, XImage *img, unsigned char *tmp);
++void drw_img(Drw *drw, int x, int y, XImage *img, uint32_t *tmp);
  
  /* Map functions */
  void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
 diff --git a/dwm.c b/dwm.c
-index 4465af1..c98796c 100644
+index 4465af1..a1c879e 100644
 --- a/dwm.c
 +++ b/dwm.c
 _AT_@ -28,6 +28,8 @@
_AT_@ -130,12 +136,12 @@ index 4465af1..c98796c 100644
                          drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
 - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
 + drw_text(drw, x, 0, w, bh, lrpad / 2 + (m->sel->icon ? m->sel->icon->width + ICONSPACING : 0), m->sel->name, 0);
-+ static unsigned char tmp[ICONSIZE * ICONSIZE << 2];
++ static uint32_t tmp[ICONSIZE * ICONSIZE];
 + if (m->sel->icon) drw_img(drw, x + lrpad / 2, (bh - m->sel->icon->height) / 2, m->sel->icon, tmp);
                          if (m->sel->isfloating)
                                  drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
                  } else {
-_AT_@ -899,6 +907,72 @@ getstate(Window w)
+_AT_@ -899,6 +907,70 @@ getstate(Window w)
          return result;
  }
  
_AT_@ -184,12 +190,10 @@ index 4465af1..c98796c 100644
 + if (w <= h) {
 + ich = ICONSIZE; icw = w * ICONSIZE / h;
 + if (icw < 1) icw = 1;
-+ else if (icw > ICONSIZE) icw = ICONSIZE;
 + }
 + else {
 + icw = ICONSIZE; ich = h * ICONSIZE / w;
 + if (ich < 1) ich = 1;
-+ else if (ich > ICONSIZE) ich = ICONSIZE;
 + }
 +
 + unsigned char *icbuf = malloc(icw * ich << 2); if(!icbuf) { XFree(p); return NULL; }
_AT_@ -208,7 +212,7 @@ index 4465af1..c98796c 100644
  int
  gettextprop(Window w, Atom atom, char *text, unsigned int size)
  {
-_AT_@ -1030,6 +1104,8 @@ manage(Window w, XWindowAttributes *wa)
+_AT_@ -1030,6 +1102,8 @@ manage(Window w, XWindowAttributes *wa)
          c->h = c->oldh = wa->height;
          c->oldbw = wa->border_width;
  
_AT_@ -217,28 +221,19 @@ index 4465af1..c98796c 100644
          updatetitle(c);
          if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
                  c->mon = t->mon;
-_AT_@ -1235,11 +1311,18 @@ propertynotify(XEvent *e)
- drawbars();
- break;
- }
-+ int ub = 0, rdb = c == c->mon->sel;
- if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
- updatetitle(c);
-- if (c == c->mon->sel)
-- drawbar(c->mon);
-+ ub = rdb;
+_AT_@ -1240,6 +1314,11 @@ propertynotify(XEvent *e)
+ if (c == c->mon->sel)
+ drawbar(c->mon);
                  }
-+ if (ev->atom == netatom[NetWMIcon]) {
++ else if (ev->atom == netatom[NetWMIcon]) {
 + updateicon(c);
-+ ub = rdb;
++ if (c == c->mon->sel)
++ drawbar(c->mon);
 + }
-+
-+ if (ub) drawbar(c->mon);
-+
                  if (ev->atom == netatom[NetWMWindowType])
                          updatewindowtype(c);
          }
-_AT_@ -1556,6 +1639,7 @@ setup(void)
+_AT_@ -1556,6 +1635,7 @@ setup(void)
          netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
          netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
          netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
_AT_@ -246,7 +241,7 @@ index 4465af1..c98796c 100644
          netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
          netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
          netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
-_AT_@ -1746,6 +1830,15 @@ toggleview(const Arg *arg)
+_AT_@ -1746,6 +1826,15 @@ toggleview(const Arg *arg)
          }
  }
  
_AT_@ -262,7 +257,7 @@ index 4465af1..c98796c 100644
  void
  unfocus(Client *c, int setfocus)
  {
-_AT_@ -1767,6 +1860,7 @@ unmanage(Client *c, int destroyed)
+_AT_@ -1767,6 +1856,7 @@ unmanage(Client *c, int destroyed)
  
          detach(c);
          detachstack(c);
_AT_@ -270,7 +265,7 @@ index 4465af1..c98796c 100644
          if (!destroyed) {
                  wc.border_width = c->oldbw;
                  XGrabServer(dpy); /* avoid race conditions */
-_AT_@ -2001,6 +2095,13 @@ updatetitle(Client *c)
+_AT_@ -2001,6 +2091,13 @@ updatetitle(Client *c)
                  strcpy(c->name, broken);
  }
  
diff --git a/dwm.suckless.org/patches/winicon/index.md b/dwm.suckless.org/patches/winicon/index.md
index 1d29c6f7..fb555fc8 100644
--- a/dwm.suckless.org/patches/winicon/index.md
+++ b/dwm.suckless.org/patches/winicon/index.md
_AT_@ -7,6 +7,8 @@ Description
 
 ![screenshots](screenshots.png)
 
+It is recommended to enable compiler flags: **-march=native**, **-ffast-math** and **-faggressive-loop-optimizations** to gain better performance.
+
 The project is being managed and developed on this GitHub [repo](https://github.com/AdamYuan/dwm-winicon). If you discover any bugs or have any idea to optimize it, feel free to create an issue there.
 
 Configuration
_AT_@ -16,7 +18,7 @@ Configuration
 
 Download
 --------
-* [dwm-winicon-6.2-v1.diff](dwm-winicon-6.2-v1.diff)
+* [dwm-winicon-6.2-v1.1.diff](dwm-winicon-6.2-v1.1.diff) (2021-07-10)
 
 Author
 ------
Received on Sun Jul 11 2021 - 04:19:50 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 11 2021 - 04:24:44 CEST