Hi. I am very bad speak English.
I make no big patch to display icons in dwm-bar.

--- dwm.c    2008-09-10 04:46:17.000000000 +0900
+++ dwm-icon.c    2008-10-21 10:10:04.570787446 +0900
@@ -117,6 +117,7 @@
 } Key;

 typedef struct {
+    const char *icon;
     const char *symbol;
     void (*arrange)(void);
 } Layout;
@@ -146,6 +147,7 @@
 static void detachstack(Client *c);
 static void die(const char *errstr, ...);
 static void drawbar(void);
+static void drawicon(const char *file, unsigned long col[ColLast]);
 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long
col[ColLast]);
 static void drawtext(const char *text, unsigned long col[ColLast], Bool
invert);
 static void enternotify(XEvent *e);
@@ -511,8 +513,14 @@
         dc.x += dc.w;
     }
     if(blw > 0) {
-        dc.w = blw;
-        drawtext(lt[sellt]->symbol, dc.norm, False);
+        if (useicons == False) {
+            dc.w = blw;
+            drawtext(lt[sellt]->symbol, dc.norm, False);
+        }
+        else {
+            dc.w = iw;
+            drawicon(lt[sellt]->icon, dc.sel);
+        }
         x = dc.x + dc.w;
     }
     else
@@ -537,6 +545,22 @@
     XSync(dpy, False);
 }

+void
+drawicon(const char *file, unsigned long col[ColLast]) {
+    Pixmap icon;
+    unsigned int x, pw, ph;
+    x = dc.x;
+    icon = XCreatePixmap(dpy, dc.drawable, 12, 12, 1);
+    XReadBitmapFile(dpy, dc.drawable, file, &pw, &ph, &icon, &ix, &iy);
+
+    XSetForeground(dpy, dc.gc, col[ColBG]);
+    XFillRectangle(dpy, dc.drawable, dc.gc, x, 0, iw, ih);
+
+    XSetForeground(dpy, dc.gc, col[ColFG]);
+    XSetBackground(dpy, dc.gc, col[ColBG]);
+    XCopyPlane(dpy, icon, dc.drawable, dc.gc, ix, iy, iw, ih, x, 0, 1);
+}
+
 void
 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long
col[ColLast]) {
     int x;

--- config.def.h    2008-09-10 04:46:17.000000000 +0900
+++ config.def-icon.h    2008-10-21 10:13:32.293097267 +0900
@@ -28,11 +28,12 @@
 static float mfact      = 0.55; /* factor of master area size [0.05..0.95]
*/
 static Bool resizehints = True; /* False means respect size hints in tiled
resizals */

+static Bool useicons    = True; /* Use icons for Layout. True or False */
 static Layout layouts[] = {
     /* symbol     arrange function */
-    { "[]=",      tile },    /* first entry is default */
-    { "><>",      NULL },    /* no layout function means floating behavior
*/
-    { "[M]",      monocle },
+    { "~/.dwm/icons/tile.xbm", "[]=",      tile },    /* first entry is
default */
+    { "~/.dwm/icons/float.xbm", "><>",      NULL },    /* no layout
function means floating behavior */
+    { "~/.dwm/icons/monocle.xbm", "[M]",      monocle },
 };

 /* key definitions */

screenshot http://img90.imageshack.us/img90/104/20081021kp4.png

P.S. Sorry if I did sometheng wrong. I do it first time.

--
freej

Reply via email to