You are not logged in.
So la1111, if I'm not mistaken your patch enables you to use colors in the statusbar, without having to define them in config.h? E.g. you keep dc.sel and dc.norm in dwm.c, instead of the dc.colors?
Last edited by Unia (2012-11-11 11:38:07)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
yeah, that's correct. I just finished it up and made the patch, which I posted here:
https://gist.github.com/4054818
https://gist.github.com/4054818
I tested it with 5.9 and 6.0 tarballs, and it applied/compiled properly.
you set a color externally by putting the ansi code for that color in your status bar script. it actually doesn't mess with the default config.h whatsoever.
For example, from a bash prompt or something:
perl -e '`xsetroot -name "\x1b[38;5;196mHello World \x1b[0m\x1b[48;5;196mRed Background\x1b[0m"`'
it supports the standard ansi escape codes (16 colors~) plus the xterm 256 color mode colors.
more info on ansi color codes here:
http://www.frexx.de/xterm-256-notes/
a bit more info is in the diff. It's kind of a big patch, but it's a lot cleaner in that it doesn't muck around with the other code.
This is my first C project, so it could probably use a once-over to check for memory leaks; but hopefully that won't be an issue
here's a screenshot of my status script updated to use pretty colored output - as you can see my battery is discharging and my wifi signal is a bit weak
Last edited by la11111 (2012-11-11 13:33:35)
Offline
@la11111
Please edit your gist link. It is not working.
Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github
Offline
ah, sorry, corrected. i posted git:// instead of https://
Offline
Thanks,
Can you post a config.h regarding normal{fg, bg} and selected{bg, fg} colors ?
Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github
Offline
sure, here's the relevant section from the stock config.h file:
/* See LICENSE file for copyright and license details. */
/* appearance */
static const char font[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#cccccc";
static const char normbgcolor[] = "#cccccc";
static const char normfgcolor[] = "#000000";
static const char selbordercolor[] = "#0066ff";
static const char selbgcolor[] = "#0066ff";
static const char selfgcolor[] = "#ffffff";
Offline
Oh i get it.
There is no need to define a color array.
Thanks.
EDIT: typo
Last edited by illusionist (2012-11-11 14:00:38)
Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github
Offline
y
it supports the standard ansi escape codes (16 colors~) plus the xterm 256 color mode colors.
more info on ansi color codes here:
Some of that is useful, but it adds to confusion regarding ANSI (which specified exactly 8 colors)
Offline
True, I just added them for in case someone tried to use them.
Besides those colors, I use the same 256 colors that Xterm uses. ( "#rgb", where r/g/b = "00", "5f", "87", "af", "d6", "ff") So there's no question there.
It wouldn't be difficult to allow for arbitrary #xxxxxx colors to be specified, but then, you wouldn't be able to test your status script in the terminal, which is why I did it that way.
it's not a true ansi sequence, but pretty much all terminal emulators support it nowadays.
also, here's a link to a perl script that will print out all of the colors that my patch supports with the escape code / hex value:
http://www.vim.org/scripts/script.php?script_id=1349
Last edited by la11111 (2012-11-11 15:48:42)
Offline
@illusionist
forgot to reply to your last question - do you mean the space on the right, in that screenshot?
I'm not sure how my patch would behave in different locales - it relies on ascii escape '\x1b' so I'm not sure how that translates to 2-byte text, if anything would be different at all.
Offline
I created a patch if you don't wanna use Xft. It could be cleaner but I'm just a novice.
EDIT: Now you can switch on / off xft by commenting lines in config.mk.
--- a/config.mk 2012-11-11 20:09:21.174319764 +0100
+++ b/config.mk 2012-11-11 19:36:25.990617582 +0100
@@ -10,13 +10,17 @@
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
+#Xft
+#XFTINC = /usr/include/freetype2
+#XFTLIBS = -lutil -lXext -lXft -lfontconfig
+
# Xinerama, comment if you don't want it
XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA
# includes and libs
-INCS = -I${X11INC} -I/usr/include/freetype2
-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} -lutil -lXext -lXft -lfontconfig
+INCS = -I${X11INC} -I${XFTINC}
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XFTLIBS}
# flags
CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
--- a/dwm.c 2012-11-11 20:46:08.738079237 +0100
+++ b/dwm.c 2012-11-11 20:45:51.781409248 +0100
@@ -37,8 +37,10 @@
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
+#ifdef XFT
#include <fontconfig/fontconfig.h>
#include <X11/Xft/Xft.h>
+#endif /* XFT */
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
@@ -102,15 +104,25 @@
typedef struct {
int x, y, w, h;
+#ifdef XFT
XftColor norm[ColLast];
XftColor sel[ColLast];
+#else
+ unsigned long norm[ColLast];
+ unsigned long sel[ColLast];
+#endif
Drawable drawable;
GC gc;
struct {
int ascent;
int descent;
int height;
+#ifdef XFT
XftFont *xfont;
+#else
+ XFontSet set;
+ XFontStruct *xfont;
+#endif
} font;
} DC; /* draw context */
@@ -180,15 +192,24 @@
static Monitor *dirtomon(int dir);
static void drawbar(Monitor *m);
static void drawbars(void);
+#ifdef XFT
static void drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]);
static void drawtext(const char *text, XftColor col[ColLast], Bool invert);
+#else
+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);
+#endif
static void enternotify(XEvent *e);
static void expose(XEvent *e);
static void focus(Client *c);
static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
+#ifdef XFT
static XftColor getcolor(const char *colstr);
+#else
+static unsigned long getcolor(const char *colstr);
+#endif
static Bool getrootptr(int *x, int *y);
static long getstate(Window w);
static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
@@ -488,6 +509,13 @@
for(m = mons; m; m = m->next)
while(m->stack)
unmanage(m->stack, False);
+#ifdef XFT
+#else
+ if(dc.font.set)
+ XFreeFontSet(dpy, dc.font.set);
+ else
+ XFreeFont(dpy, dc.font.xfont);
+#endif
XUngrabKey(dpy, AnyKey, AnyModifier, root);
XFreePixmap(dpy, dc.drawable);
XFreeGC(dpy, dc.gc);
@@ -720,7 +748,11 @@
drawbar(Monitor *m) {
int x;
unsigned int i, occ = 0, urg = 0;
+#ifdef XFT
XftColor *col;
+#else
+ unsigned long *col;
+#endif
Client *c;
for(c = m->clients; c; c = c->next) {
@@ -775,10 +807,18 @@
}
void
+#ifdef XFT
drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) {
+#else
+drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
+#endif
int x;
+#ifdef XFT
XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG].pixel);
+#else
+ XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
+#endif
x = (dc.font.ascent + dc.font.descent + 2) / 4;
if(filled)
XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1);
@@ -787,12 +827,22 @@
}
void
+#ifdef XFT
drawtext(const char *text, XftColor col[ColLast], Bool invert) {
+#else
+drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
+#endif
char buf[256];
int i, x, y, h, len, olen;
+#ifdef XFT
XftDraw *d;
+#endif
+#ifdef XFT
XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG].pixel);
+#else
+ XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
+#endif
XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
if(!text)
return;
@@ -807,11 +857,19 @@
memcpy(buf, text, len);
if(len < olen)
for(i = len; i && i > len - 3; buf[--i] = '.');
+#ifdef XFT
d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen));
XftDrawStringUtf8(d, &col[invert ? ColBG : ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
XftDrawDestroy(d);
+#else
+ XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
+ if(dc.font.set)
+ XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
+ else
+ XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
+#endif
}
void
@@ -857,7 +915,11 @@
detachstack(c);
attachstack(c);
grabbuttons(c, True);
+#ifdef XFT
XSetWindowBorder(dpy, c->win, dc.sel[ColBorder].pixel);
+#else
+ XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
+#endif
setfocus(c);
}
else {
@@ -931,14 +993,32 @@
return atom;
}
+#ifdef XFT
XftColor
+#else
+unsigned long
+#endif
getcolor(const char *colstr) {
+#ifdef XFT
XftColor color;
+#else
+ Colormap cmap = DefaultColormap(dpy, screen);
+ XColor color;
+#endif
+#ifdef XFT
if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
+#else
+ if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
+#endif
die("error, cannot allocate color '%s'\n", colstr);
+#ifdef XFT
+
return color;
+#else
+return color.pixel;
+#endif
}
Bool
@@ -1040,12 +1120,44 @@
void
initfont(const char *fontstr) {
+#ifdef XFT
if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr))
&& !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed")))
die("error, cannot load font: '%s'\n", fontstr);
dc.font.ascent = dc.font.xfont->ascent;
dc.font.descent = dc.font.xfont->descent;
+#else
+ char *def, **missing;
+ int n;
+
+ dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
+ if(missing) {
+ while(n--)
+ fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
+ XFreeStringList(missing);
+ }
+ if(dc.font.set) {
+ XFontStruct **xfonts;
+ char **font_names;
+
+ dc.font.ascent = dc.font.descent = 0;
+ XExtentsOfFontSet(dc.font.set);
+ n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
+ while(n--) {
+ dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
+ dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
+ xfonts++;
+ }
+ }
+ else {
+ if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
+ && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
+ die("error, cannot load font: '%s'\n", fontstr);
+ dc.font.ascent = dc.font.xfont->ascent;
+ dc.font.descent = dc.font.xfont->descent;
+ }
+#endif
dc.font.height = dc.font.ascent + dc.font.descent;
}
@@ -1127,7 +1239,11 @@
wc.border_width = c->bw;
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
+#ifdef XFT
XSetWindowBorder(dpy, w, dc.norm[ColBorder].pixel);
+#else
+ XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
+#endif
configure(c); /* propagates border_width, if size doesn't change */
updatewindowtype(c);
updatesizehints(c);
@@ -1616,6 +1732,11 @@
dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
+#ifdef XFT
+#else
+ if(!dc.font.set)
+ XSetFont(dpy, dc.gc, dc.font.xfont->fid);
+#endif
/* init bars */
updatebars();
updatestatus();
@@ -1686,9 +1807,18 @@
int
textnw(const char *text, unsigned int len) {
+#ifdef XFT
XGlyphInfo ext;
XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext);
return ext.xOff;
+#else
+ XRectangle r;
+ if(dc.font.set) {
+ XmbTextExtents(dc.font.set, text, len, NULL, &r);
+ return r.width;
+ }
+ return XTextWidth(dc.font.xfont, text, len);
+#endif
}
void
@@ -1768,7 +1898,11 @@
if(!c)
return;
grabbuttons(c, False);
+#ifdef XFT
XSetWindowBorder(dpy, c->win, dc.norm[ColBorder].pixel);
+#else
+ XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
+#endif
if(setfocus) {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
Last edited by Ypnose (2012-11-11 20:16:44)
Offline
@la11111
Couple of hunks failed on vanilla 6.0-1, but easy fix and I must say I like it. Definitely makes things easier than using the regular statuscolors if you want more than a few colors. I just might have to play with it a bit now
Registered Linux user #536591.
Offline
Is there a patch that can make dwm to overlap borders of clients in tile mode?
Offline
Nice It patches fine on vanilla 5.9 and 6, but that's all I've tested with. did you pull 6.0-1 from hg?
I can do a better job of putting it together probably, since modifications to the original code are so minimal.
I also added it to the wiki under dwm/patches/ansistatuscolors.
Offline
Well, I fixed it to patch better on 6&up - also fixed a pretty serious memory leak - dwm's not supposed to be using 400MB of memory ... oops!
Offline
Hi, can anyone suggest me a patch which allows the selection of windows using dmenu in dwm just like in musca wm?
Using Openbox + Tint2 + Idesk
Offline
@Unia
How to fix the systray patch on monocle mode?
You mean that little border underneath it? I'm not sure what would be a clean way to remove that. A dirty fix would be to set the border color in monocle mode the same as normal background color.
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Ok thanks dude!!
I will see another way to make it.
Please share if you do!
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
@Unia,
I saw the transparent bar patch in your repo and the commit message related to it. I modified the patch little bit. Now you can set the transparency in config.h. But there are some (maybe one) issue.
1) It needs composite manager. (which is obvious since we are setting the window property )
2) The systray patch needs to be modified to work with transparency.
Here is the patch :
Patch
and put this in config.h
static const float opacity = 0.60; ( max 0.75 )
Let me know what you think about it.
Last edited by illusionist (2012-11-19 18:19:19)
Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github
Offline
@Unia,
I saw the transparent bar patch in your repo and the commit message related to it. I modified the patch little bit. Now you can set the transparency in config.h. But there are some (maybe one) issue.
1) It needs composite manager. (which is obvious since we are setting the window property )
2) The systray patch needs to be modified to work with transparency.Here is the patch :
Patch
and put this in config.h
static const float opacity = 0.60; ( max 0.75 )Let me know what you think about it.
Perfect! Before I set a color with 0x00000000 syntax, but it was confusing and didn't always give the desired result.
One question though; does this also make the text transparent? On my version it does (and I think this one too) and I was meaning to look into it. It does. Is there any way possible to not make the text transparent? That would make this patch perfect!
EDIT: And I know about the systray. In my previous version (which used pseudo-transparency) I messed with it but it's complicated. With this patch it should be easier, seeing the system tray is made with an XCreateSimpleWindow command. I think that means it's just another window just like the statusbar; so I think you can apply the same lines.
EDIT2: Here's one with a working transparent system tray: https://gist.github.com/4113641
Right now I use the unsigned long real_opacity[] = { opacity * 0xffffffff }; line twice. I think it's cleaner if we use this only once and place it in a common part of the code. I don't where this would go, though. Anyone?
Last edited by Unia (2012-11-19 20:28:33)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Ok thanks dude!!
I will see another way to make it.
I found out why the little border appears. The fix I use for not displaying a border in monocle mode, simply moves the border "out of display": the left, right and bottom border dissapear off-screen and the top border gets moved under the statusbar. The systray picks this up and displays it regardless.
When you use the single_window_no_border patch found on numerous places (OK100's GitHub, for example) it doesn't display a border under the system tray on monocle mode. However, I do have some other issues with this patch.
Is there a simple approach to just not draw any border only when in monocle mode, instead of drawing them off-screen? The single_window_no_border patch comes close, but also removes borders when there's one client in any other layout and when I remove those lines, it doesn't restore a border when I float the window or change layout from monocle. Who can help me fix that?
Last edited by Unia (2012-11-19 21:28:59)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Is there any way possible to not make the text transparent?
Not with transparent window hint method. There are three (relevant) transparency methods each with pros and cons:
1) pseudotransparency, which we worked through over email. This allows for the background to appear transparent while the text is full strenght. But this takes more code to set up, and it is harder to implement semi-transparent effects.
2) Managed "True" transparency. This is what you are currently using. This is easy to set up, but requries a composite manager to be running and it makes everything (including text) transparent/translucent.
3) Client "True" transparency. This is implemented through an alpha layer visual implemented within the client program (your dwm patch). This takes a good bit more coding (AFAIK - I haven't used this method). But this would allow for semi-transparent backgrounds but full strength text.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
^ I see. Other tilers (at least Awesome, and I think Subtle too) do allow transparent statusbars without making the text transparent too. Do you know which method they use?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline