sites

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

dwm-statuscolors-20200413-14f723a.diff (3633B)


      1 From 14f723a7812cf5a2a7b924a3bf494e51bfedf7bc Mon Sep 17 00:00:00 2001
      2 From: Christian Tenllado <ctenllado@gmail.com>
      3 Date: Mon, 13 Apr 2020 18:12:36 +0200
      4 Subject: [PATCH] statuscolors, fix status text width computation
      5 
      6 This is an updated version of the statuscolors patch that fixes the
      7 computation of the text width. The previous version of the patch
      8 inculded all the byte codes that are used to select the color schemes
      9 when computing the width, obaining a width that is larger than the real
     10 width. This patch fixes that by adding up the widths of the individual
     11 chunks, separated by the codes that select the color schemes.
     12 ---
     13  config.def.h | 13 ++++++++++---
     14  dwm.c        | 40 +++++++++++++++++++++++++++++++++++++---
     15  2 files changed, 47 insertions(+), 6 deletions(-)
     16 
     17 diff --git a/config.def.h b/config.def.h
     18 index 1c0b587..df92695 100644
     19 --- a/config.def.h
     20 +++ b/config.def.h
     21 @@ -12,10 +12,17 @@ static const char col_gray2[]       = "#444444";
     22  static const char col_gray3[]       = "#bbbbbb";
     23  static const char col_gray4[]       = "#eeeeee";
     24  static const char col_cyan[]        = "#005577";
     25 +static const char col_black[]       = "#000000";
     26 +static const char col_red[]         = "#ff0000";
     27 +static const char col_yellow[]      = "#ffff00";
     28 +static const char col_white[]       = "#ffffff";
     29 +
     30  static const char *colors[][3]      = {
     31 -	/*               fg         bg         border   */
     32 -	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
     33 -	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
     34 +	/*					fg         bg          border   */
     35 +	[SchemeNorm] =	 { col_gray3, col_gray1,  col_gray2 },
     36 +	[SchemeSel]  =	 { col_gray4, col_cyan,   col_cyan },
     37 +	[SchemeWarn] =	 { col_black, col_yellow, col_red },
     38 +	[SchemeUrgent]=	 { col_white, col_red,    col_red },
     39  };
     40  
     41  /* tagging */
     42 diff --git a/dwm.c b/dwm.c
     43 index 4465af1..0856993 100644
     44 --- a/dwm.c
     45 +++ b/dwm.c
     46 @@ -59,7 +59,7 @@
     47  
     48  /* enums */
     49  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     50 -enum { SchemeNorm, SchemeSel }; /* color schemes */
     51 +enum { SchemeNorm, SchemeSel, SchemeWarn, SchemeUrgent }; /* color schemes */
     52  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     53         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
     54         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     55 @@ -692,6 +692,26 @@ dirtomon(int dir)
     56  	return m;
     57  }
     58  
     59 +int
     60 +textw_wosc(char *s)
     61 +{
     62 +	char *ts = s;
     63 +	char *tp = s;
     64 +	int sw = 0;
     65 +	char ctmp;
     66 +	while (1) {
     67 +		if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
     68 +		ctmp = *ts;
     69 +		*ts = '\0';
     70 +		sw += drw_fontset_getwidth(drw, tp);
     71 +		*ts = ctmp;
     72 +		if (ctmp == '\0') { break; }
     73 +		tp = ++ts;
     74 +	}
     75 +
     76 +	return sw;
     77 +}
     78 +
     79  void
     80  drawbar(Monitor *m)
     81  {
     82 @@ -699,13 +719,27 @@ drawbar(Monitor *m)
     83  	int boxs = drw->fonts->h / 9;
     84  	int boxw = drw->fonts->h / 6 + 2;
     85  	unsigned int i, occ = 0, urg = 0;
     86 +	char *ts = stext;
     87 +	char *tp = stext;
     88 +	int tx = 0;
     89 +	char ctmp;
     90  	Client *c;
     91  
     92  	/* draw status first so it can be overdrawn by tags later */
     93  	if (m == selmon) { /* status is only drawn on selected monitor */
     94  		drw_setscheme(drw, scheme[SchemeNorm]);
     95 -		sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
     96 -		drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
     97 +		sw = textw_wosc(stext) + 2;
     98 +		while (1) {
     99 +			if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
    100 +			ctmp = *ts;
    101 +			*ts = '\0';
    102 +			drw_text(drw, m->ww - sw + tx, 0, sw - tx, bh, 0, tp, 0);
    103 +			tx += TEXTW(tp) -lrpad;
    104 +			if (ctmp == '\0') { break; }
    105 +			drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]);
    106 +			*ts = ctmp;
    107 +			tp = ++ts;
    108 +		}
    109  	}
    110  
    111  	for (c = m->clients; c; c = c->next) {
    112 -- 
    113 2.20.1
    114