sites

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

dwm-status2d-6.3.diff (4272B)


      1 diff --git a/dwm.c b/dwm.c
      2 index a96f33c..24b1eeb 100644
      3 --- a/dwm.c
      4 +++ b/dwm.c
      5 @@ -163,6 +163,7 @@ static void detachstack(Client *c);
      6  static Monitor *dirtomon(int dir);
      7  static void drawbar(Monitor *m);
      8  static void drawbars(void);
      9 +static int drawstatusbar(Monitor *m, int bh, char* text);
     10  static void enternotify(XEvent *e);
     11  static void expose(XEvent *e);
     12  static void focus(Client *c);
     13 @@ -237,7 +238,7 @@ static void zoom(const Arg *arg);
     14  
     15  /* variables */
     16  static const char broken[] = "broken";
     17 -static char stext[256];
     18 +static char stext[1024];
     19  static int screen;
     20  static int sw, sh;           /* X display screen geometry width, height */
     21  static int bh, blw = 0;      /* bar geometry */
     22 @@ -485,7 +486,7 @@ cleanup(void)
     23  		cleanupmon(mons);
     24  	for (i = 0; i < CurLast; i++)
     25  		drw_cur_free(drw, cursor[i]);
     26 -	for (i = 0; i < LENGTH(colors); i++)
     27 +	for (i = 0; i < LENGTH(colors) + 1; i++)
     28  		free(scheme[i]);
     29  	XDestroyWindow(dpy, wmcheckwin);
     30  	drw_free(drw);
     31 @@ -693,6 +694,114 @@ dirtomon(int dir)
     32  	return m;
     33  }
     34  
     35 +int
     36 +drawstatusbar(Monitor *m, int bh, char* stext) {
     37 +	int ret, i, w, x, len;
     38 +	short isCode = 0;
     39 +	char *text;
     40 +	char *p;
     41 +
     42 +	len = strlen(stext) + 1 ;
     43 +	if (!(text = (char*) malloc(sizeof(char)*len)))
     44 +		die("malloc");
     45 +	p = text;
     46 +	memcpy(text, stext, len);
     47 +
     48 +	/* compute width of the status text */
     49 +	w = 0;
     50 +	i = -1;
     51 +	while (text[++i]) {
     52 +		if (text[i] == '^') {
     53 +			if (!isCode) {
     54 +				isCode = 1;
     55 +				text[i] = '\0';
     56 +				w += TEXTW(text) - lrpad;
     57 +				text[i] = '^';
     58 +				if (text[++i] == 'f')
     59 +					w += atoi(text + ++i);
     60 +			} else {
     61 +				isCode = 0;
     62 +				text = text + i + 1;
     63 +				i = -1;
     64 +			}
     65 +		}
     66 +	}
     67 +	if (!isCode)
     68 +		w += TEXTW(text) - lrpad;
     69 +	else
     70 +		isCode = 0;
     71 +	text = p;
     72 +
     73 +	w += 2; /* 1px padding on both sides */
     74 +	ret = x = m->ww - w;
     75 +
     76 +	drw_setscheme(drw, scheme[LENGTH(colors)]);
     77 +	drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
     78 +	drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
     79 +	drw_rect(drw, x, 0, w, bh, 1, 1);
     80 +	x++;
     81 +
     82 +	/* process status text */
     83 +	i = -1;
     84 +	while (text[++i]) {
     85 +		if (text[i] == '^' && !isCode) {
     86 +			isCode = 1;
     87 +
     88 +			text[i] = '\0';
     89 +			w = TEXTW(text) - lrpad;
     90 +			drw_text(drw, x, 0, w, bh, 0, text, 0);
     91 +
     92 +			x += w;
     93 +
     94 +			/* process code */
     95 +			while (text[++i] != '^') {
     96 +				if (text[i] == 'c') {
     97 +					char buf[8];
     98 +					memcpy(buf, (char*)text+i+1, 7);
     99 +					buf[7] = '\0';
    100 +					drw_clr_create(drw, &drw->scheme[ColFg], buf);
    101 +					i += 7;
    102 +				} else if (text[i] == 'b') {
    103 +					char buf[8];
    104 +					memcpy(buf, (char*)text+i+1, 7);
    105 +					buf[7] = '\0';
    106 +					drw_clr_create(drw, &drw->scheme[ColBg], buf);
    107 +					i += 7;
    108 +				} else if (text[i] == 'd') {
    109 +					drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
    110 +					drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
    111 +				} else if (text[i] == 'r') {
    112 +					int rx = atoi(text + ++i);
    113 +					while (text[++i] != ',');
    114 +					int ry = atoi(text + ++i);
    115 +					while (text[++i] != ',');
    116 +					int rw = atoi(text + ++i);
    117 +					while (text[++i] != ',');
    118 +					int rh = atoi(text + ++i);
    119 +
    120 +					drw_rect(drw, rx + x, ry, rw, rh, 1, 0);
    121 +				} else if (text[i] == 'f') {
    122 +					x += atoi(text + ++i);
    123 +				}
    124 +			}
    125 +
    126 +			text = text + i + 1;
    127 +			i=-1;
    128 +			isCode = 0;
    129 +		}
    130 +	}
    131 +
    132 +	if (!isCode) {
    133 +		w = TEXTW(text) - lrpad;
    134 +		drw_text(drw, x, 0, w, bh, 0, text, 0);
    135 +	}
    136 +
    137 +	drw_setscheme(drw, scheme[SchemeNorm]);
    138 +	free(p);
    139 +
    140 +	return ret;
    141 +}
    142 +
    143  void
    144  drawbar(Monitor *m)
    145  {
    146 @@ -707,9 +816,7 @@ drawbar(Monitor *m)
    147  
    148  	/* draw status first so it can be overdrawn by tags later */
    149  	if (m == selmon) { /* status is only drawn on selected monitor */
    150 -		drw_setscheme(drw, scheme[SchemeNorm]);
    151 -		tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
    152 -		drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
    153 +		tw = m->ww - drawstatusbar(m, bh, stext);
    154  	}
    155  
    156  	for (c = m->clients; c; c = c->next) {
    157 @@ -1571,7 +1678,8 @@ setup(void)
    158  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
    159  	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
    160  	/* init appearance */
    161 -	scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
    162 +	scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *));
    163 +	scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3);
    164  	for (i = 0; i < LENGTH(colors); i++)
    165  		scheme[i] = drw_scm_create(drw, colors[i], 3);
    166  	/* init bars */