sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 2e1e98083a8e115a6dba752ff438f3be4b57d23f
parent 7cbd411eab8b4ade69be8f44bb9ca0289e1f52d6
Author: Clément SIPIETER <clement@6pi.fr>
Date:   Wed, 17 Dec 2014 22:43:43 +0100

Add DWM patch status2d

Diffstat:
Adwm.suckless.org/patches/dwm-r35db6d-status2d.diff | 201+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/status2d.md | 37+++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/status2d.png | 0
3 files changed, 238 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/dwm-r35db6d-status2d.diff b/dwm.suckless.org/patches/dwm-r35db6d-status2d.diff @@ -0,0 +1,201 @@ +diff --git a/drw.c b/drw.c +index b130405..6dcb25d 100644 +--- a/drw.c ++++ b/drw.c +@@ -224,3 +224,34 @@ drw_cur_free(Drw *drw, Cur *cursor) { + XFreeCursor(drw->dpy, cursor->cursor); + free(cursor); + } ++ ++void ++x_set_color(Drw *drw, Clr *color) { ++ XSetForeground(drw->dpy, drw->gc, color->rgb); ++} ++ ++void ++x_drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h) { ++ XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); ++} ++ ++void ++x_drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) { ++ char buf[256]; ++ int ty, len, olen; ++ Extnts tex; ++ ++ olen = strlen(text); ++ drw_font_getexts(drw->font, text, olen, &tex); ++ ty = y + (h / 2) - (tex.h / 2) + drw->font->ascent; ++ ++ len = MIN(olen, sizeof buf); ++ if(!len) ++ return; ++ ++ memcpy(buf, text, len); ++ if(drw->font->set) ++ XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, x, ty, buf, len); ++ else ++ XDrawString(drw->dpy, drw->drawable, drw->gc, x, ty, buf, len); ++} +diff --git a/drw.h b/drw.h +index a5f34e0..e42b897 100644 +--- a/drw.h ++++ b/drw.h +@@ -38,6 +38,7 @@ typedef struct { + unsigned int h; + } Extnts; + ++ + /* Drawable abstraction */ + Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); + void drw_resize(Drw *drw, unsigned int w, unsigned int h); +@@ -67,3 +68,8 @@ void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char + + /* Map functions */ + void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); ++ ++/* X Basic call */ ++void x_set_color(Drw *drw, Clr *color); ++void x_drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h); ++void x_drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text); +\ No newline at end of file +diff --git a/dwm.c b/dwm.c +index f896170..356394d 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -162,6 +162,7 @@ static void detach(Client *c); + static void detachstack(Client *c); + static Monitor *dirtomon(int dir); + static void drawbar(Monitor *m); ++static int drawstatusbar(Monitor *m, int bh, char* text, int xx); + static void drawbars(void); + static void enternotify(XEvent *e); + static void expose(XEvent *e); +@@ -235,7 +236,7 @@ static void zoom(const Arg *arg); + + /* variables */ + static const char broken[] = "broken"; +-static char stext[256]; ++static char stext[1024]; + static int screen; + static int sw, sh; /* X display screen geometry width, height */ + static int bh, blw = 0; /* bar geometry */ +@@ -690,6 +691,100 @@ dirtomon(int dir) { + return m; + } + ++int ++drawstatusbar(Monitor *m, int bh, char* stext, int xx) { ++ int ret, i, w, len, x; ++ short isCode = 0; ++ Clr * color = drw->scheme->fg; ++ ++ len = strlen(stext) + 1 ; ++ char *text = (char*) malloc(sizeof(char)*len); ++ char *p = text; ++ memcpy(text, stext, len); ++ ++ // compute width of the status text ++ w = 0; ++ len = 0; ++ i = -1; ++ while(text[++i]) { ++ if(text[i] != '^' && !isCode) { ++ ++len; ++ } else if (text[i] == '^') { ++ isCode = !isCode; ++ if(isCode && text[++i] == 'f') { ++ w += atoi(text + ++i); ++ } ++ } ++ } ++ ++ w += drw_font_getexts_width(drw->font, text, len); ++ ret = x = m->ww - w; ++ if(x < xx) { ++ ret = x = xx; ++ w = m->ww - xx; ++ } ++ ++ x_set_color(drw, drw->scheme->bg); ++ x_drw_rect(drw, x, 0, w, bh); ++ x_set_color(drw, color); ++ ++ // process status text ++ i = -1; ++ while(text[++i]) { ++ if(text[i] == '^' && !isCode) { ++ isCode = 1; ++ ++ // draw text ++ text[i] = '\0'; ++ w = drw_font_getexts_width(drw->font, text, strlen(text)); ++ x_drw_text(drw, x, 0, w, bh, text); ++ ++ // increment x pos ++ x += w; ++ ++ // process code ++ while(text[++i] != '^') { ++ if(text[i] == 'c') { ++ char buf[8]; ++ memcpy(buf, (char*)text+i+1, 7); ++ buf[7] = '\0'; ++ color = drw_clr_create(drw, buf); ++ x_set_color(drw, color); ++ i += 7; ++ } else if(text[i] == 'd') { ++ x_set_color(drw, drw->scheme->fg); ++ } else if(text[i] == 'r') { ++ int rx = atoi(text + ++i); ++ while(text[++i] != ','); ++ int ry = atoi(text + ++i); ++ while(text[++i] != ','); ++ int rw = atoi(text + ++i); ++ while(text[++i] != ','); ++ int rh = atoi(text + ++i); ++ ++ x_drw_rect(drw, rx + x, ry, rw, rh); ++ } else if (text[i] == 'f') { ++ x += atoi(text + ++i); ++ } ++ } ++ ++ text = text + i + 1; ++ i=-1; ++ isCode = 0; ++ } ++ } ++ ++ if(!isCode) { ++ w = drw_font_getexts_width(drw->font, text, strlen(text)) + drw->font->h; ++ x_drw_text(drw, x, 0, w, bh, text); ++ } ++ ++ x_set_color(drw, drw->scheme->bg); ++ free(p); ++ ++ return ret; ++} ++ + void + drawbar(Monitor *m) { + int x, xx, w; +@@ -715,15 +810,8 @@ drawbar(Monitor *m) { + drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); + x += w; + xx = x; +- if(m == selmon) { /* status is only drawn on selected monitor */ +- w = TEXTW(stext); +- x = m->ww - w; +- if(x < xx) { +- x = xx; +- w = m->ww - xx; +- } +- drw_text(drw, x, 0, w, bh, stext, 0); +- } ++ if(m == selmon) /* status is only drawn on selected monitor */ ++ x = drawstatusbar(m, bh, stext, xx); + else + x = m->ww; + if((w = x - xx) > bh) { diff --git a/dwm.suckless.org/patches/status2d.md b/dwm.suckless.org/patches/status2d.md @@ -0,0 +1,37 @@ +Status2d +======== + +Description +----------- +Status2d allows colors and rectangle drawing in your DWM status bar. +See below an example of my status bar with multi-cpu and battery. + +![Status2d screenshot](status2d.png) + +Download +-------- +Get the patch from github: [https://github.com/sipi/dwm-status2d](https://github.com/sipi/dwm-status2d)) + +Direct download: [dwm-r35db6d-status2d.diff](dwm-r35db6d-status2d.diff) + +apply it to dwm.c like so: + + patch -p1 dwm.c < dwm-*-status2d.diff + + +Usage +----- +* draw rectangle +Add ^rx,y,w,h^ in the status text. + +* change color +Add ^c#FF0000^ in the status text. + +* forward the x position for next drawing +Add ^f11^ in the status text. + +Example +------- +xsetroot -name "dwmstatus ^c#FF0000^ in red with red rectangle ^r0,0,10,10^^f10^^c#FFFFFF^ and white text" + + diff --git a/dwm.suckless.org/patches/status2d.png b/dwm.suckless.org/patches/status2d.png Binary files differ.