[wiki] [official] user: joten || joten

From: <hg_AT_suckmore.org>
Date: Mon, 17 Nov 2008 19:19:58 +0000 (GMT)

changeset: 183:0b5df7af6213
user: joten_AT_localhost.localdomain
date: Mon Nov 17 19:33:59 2008 +0100
files: dwm/pull requestes/color_status_bar.md dwm/pull requestes/dwm-5.2-colorstatus.diff dwm/pull requestes/dwm-5.2-colorstatus.xinitrc
description:
user: joten
changed dwm/pull requestes/color_status_bar.md
changed dwm/pull requestes/dwm-5.2-colorstatus.diff
changed dwm/pull requestes/dwm-5.2-colorstatus.xinitrc


diff -r a04dc5d73e8e -r 0b5df7af6213 dwm/pull requestes/color_status_bar.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwm/pull requestes/color_status_bar.md Mon Nov 17 19:33:59 2008 +0100
_AT_@ -0,0 +1,43 @@
+# COLOR STATUS BAR #
+
+## Description ##
+
+This pull request adds some color to the status bar. It allows you to change the colorset of text portions from "norm" to "sel" (and back) and to invert the colorset (the foreground becomes the background color and vice versa).
+
+
+## Usage ##
+
+Download the pull request and apply it according to the [general instructions](.). The pull request will make the following changes:
+
+ * colorstatus.c: adding the file
+ * dwm.c: adding the include-line for 'colorstatus.c'
+ * dwm.c ('drawbar' function): adding the int-variable 'stextw'
+ * dwm.c ('drawbar' function): changing the 'drawtext' section for stext
+
+
+## Configuration ##
+
+The configuration is done in the file '.xinitrc', where you define the status bar text. You can add the following tags:
+
+ * '[c]' (without quotes): toggles the colorset (norm -> sel or sel -> norm depending on the currently selected colorset)
+ * '[i]' (without quotes): inverts the current colorset (fgcolor -> bgcolor and bgcolor -> fgcolor)
+
+The change is appllied from the position of the tag onwards. To revert the change you have to set the same tag again.
+
+### Example ###
+echo -e NEW mail: $mailnew \| VOL front: $audiofront \| BAT:[i]$batpercent[i]\| CPU: $cpuavgload \| $datestr[c]$timestr
+
+
+## Download ##
+
+ * [dwm-5.2-colorstatus.diff][1] (4.1k, 141 additional lines) (20081117)
+ * [.xinitrc example][2] (0.8k) (20081117)
+
+
+## Comment ##
+If you find any bugs or may improve the code, feel free to do so and push the changes to the wiki.
+
+
+[1]: http://www.suckmore.org/dwm/pull requestes/dwm-5.2-colorstatus.diff
+[2]: http://www.suckmore.org/dwm/pull requestes/dwm-5.2-colorstatus.xinitrc
+
diff -r a04dc5d73e8e -r 0b5df7af6213 dwm/pull requestes/dwm-5.2-colorstatus.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwm/pull requestes/dwm-5.2-colorstatus.diff Mon Nov 17 19:33:59 2008 +0100
_AT_@ -0,0 +1,183 @@
+diff -up dwm-5.2-original/colorstatus.c dwm-5.2-modified/colorstatus.c
+--- /dev/null 2008-11-17 18:12:14.000000000 +0100
++++ dwm-5.2-modified/colorstatus.c 2008-11-17 18:09:29.000000000 +0100
+_AT_@ -0,0 +1,144 @@
++int
++drawstatustext(int x) {
++ char cd[] = "[c]", id[] = "[i]";
++ char buf1[256] = {0};
++ Bool parse = True;
++ Bool cs = False, is = False;
++ int stextw = 0;
++
++ strcpy(buf1, stext);
++ while(parse) {
++ char *cp = 0, *ip = 0;
++
++ cp = strstr(buf1, cd);
++ ip = strstr(buf1, id);
++ if(cp != NULL || ip != NULL) {
++ char buf2[256] = {0}, buf3[256] = {0};
++ size_t clen2 = -1, ilen2 = -1, len2 = 0, dlen = 0, offset3 = 0, len3 = 0;
++
++ if(cp != NULL)
++ clen2 = cp - buf1;
++ if(ip != NULL)
++ ilen2 = ip - buf1;
++ if(clen2 < 0) {
++ len2 = ilen2;
++ dlen = strlen(id);
++ }
++ else if(ilen2 < 0) {
++ len2 = clen2;
++ dlen = strlen(cd);
++ }
++ else if(clen2 < ilen2) {
++ len2 = clen2;
++ dlen = strlen(cd);
++ }
++ else {
++ len2 = ilen2;
++ dlen = strlen(id);
++ }
++ strncpy(buf2, buf1, len2);
++ offset3 = len2 + dlen;
++ len3 = strlen(buf1) - offset3;
++ strncpy(buf3, buf1 + offset3, len3);
++ if(buf2 != NULL && strlen(buf2) > 0)
++ stextw = stextw + TEXTW(buf2);
++
++ memset(buf1, '\0', sizeof(buf1));
++ strcpy(buf1, buf3);
++ }
++ else {
++ stextw = stextw + TEXTW(buf1);
++ parse = False;
++ }
++ }
++ dc.x = ww - stextw;
++
++ memset(buf1, '\0', sizeof(buf1));
++ strcpy(buf1, stext);
++ parse = True;
++ while(parse) {
++ char *cp = 0, *ip = 0;
++
++ cp = strstr(buf1, cd);
++ ip = strstr(buf1, id);
++ if(cp != NULL || ip != NULL) {
++ char buf2[256] = {0}, buf3[256] = {0};
++ size_t clen2 = -1, ilen2 = -1, len2 = 0, dlen = 0, offset3 = 0, len3 = 0;
++ Bool cs3 = cs, is3 = is;
++
++ if(cp != NULL)
++ clen2 = cp - buf1;
++ if(ip != NULL)
++ ilen2 = ip - buf1;
++ if(clen2 < 0) {
++ len2 = ilen2;
++ dlen = strlen(id);
++ is3 = !is;
++ }
++ else if(ilen2 < 0) {
++ len2 = clen2;
++ dlen = strlen(cd);
++ cs3 = !cs;
++ }
++ else if(clen2 < ilen2) {
++ len2 = clen2;
++ dlen = strlen(cd);
++ cs3 = !cs;
++ }
++ else {
++ len2 = ilen2;
++ dlen = strlen(id);
++ is3 = !is;
++ }
++
++ strncpy(buf2, buf1, len2);
++ offset3 = len2 + dlen;
++ len3 = strlen(buf1) - offset3;
++ strncpy(buf3, buf1 + offset3, len3);
++ if(buf2 != NULL && strlen(buf2) > 0) {
++ dc.w = TEXTW(buf2);
++ if(cs) {
++ if(is)
++ drawtext(buf2, dc.sel, True);
++ else
++ drawtext(buf2, dc.sel, False);
++ }
++ else {
++ if(is)
++ drawtext(buf2, dc.norm, True);
++ else
++ drawtext(buf2, dc.norm, False);
++ }
++ dc.x = dc.x + dc.w;
++ }
++
++ cs = cs3;
++ is = is3;
++ memset(buf1, '\0', sizeof(buf1));
++ strcpy(buf1, buf3);
++ }
++ else {
++ dc.w = TEXTW(buf1);
++ dc.x = ww - dc.w;
++ if(dc.x < x) {
++ dc.x = x;
++ dc.w = ww - x;
++ }
++ if(cs) {
++ if(is)
++ drawtext(buf1, dc.sel, True);
++ else
++ drawtext(buf1, dc.sel, False);
++ }
++ else {
++ if(is)
++ drawtext(buf1, dc.norm, True);
++ else
++ drawtext(buf1, dc.norm, False);
++ }
++ parse = False;
++ }
++ }
++
++ return(stextw);
++}
+diff -up dwm-5.2-original/dwm.c dwm-5.2-modified/dwm.c
+--- dwm-5.2-original/dwm.c 2008-09-09 21:46:17.000000000 +0200
++++ dwm-5.2-modified/dwm.c 2008-11-17 18:09:29.000000000 +0100
+_AT_@ -239,6 +239,7 @@ static Layout *lt[] = { NULL, NULL };
+ static Window root, barwin;
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
++#include "colorstatus.c"
+
+ /* compile-time check if all tags fit into an unsigned int bit array. */
+ struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
+_AT_@ -495,6 +496,7 @@ drawbar(void) {
+ unsigned int i, occ = 0, urg = 0;
+ unsigned long *col;
+ Client *c;
++ int stextw = 0;
+
+ for(c = clients; c; c = c->next) {
+ occ |= c->tags;
+_AT_@ -517,13 +519,8 @@ drawbar(void) {
+ }
+ else
+ x = dc.x;
+- dc.w = TEXTW(stext);
+- dc.x = ww - dc.w;
+- if(dc.x < x) {
+- dc.x = x;
+- dc.w = ww - x;
+- }
+- drawtext(stext, dc.norm, False);
++ stextw = drawstatustext(x);
++ dc.x = ww - stextw;
+ if((dc.w = dc.x - x) > bh) {
+ dc.x = x;
+ if(sel) {
diff -r a04dc5d73e8e -r 0b5df7af6213 dwm/pull requestes/dwm-5.2-colorstatus.xinitrc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwm/pull requestes/dwm-5.2-colorstatus.xinitrc Mon Nov 17 19:33:59 2008 +0100
_AT_@ -0,0 +1,24 @@
+while true
+do
+ datestr=`date '+%a, %x'`
+ timestr=`date '+%H:%M'`
+
+ cpuavgload=`uptime | sed -n 's/.*: //; s/, .*// p'`
+
+ batcurrent=`sed -n 's/ mAh//; s/remaining[ a-z:]*// p' /proc/acpi/battery/BAT1/state`
+ batfull=`sed -n 's/ mAh//; s/last full[ a-z:]*// p' /proc/acpi/battery/BAT1/info`
+ batpercent=`echo "($batcurrent*100)/$batfull" | bc`
+ if [ $batpercent -lt 10 ]
+ then batpercent=`echo [c]$batpercent%[c]`
+ else batpercent=`echo $batpercent%`
+ fi
+
+ audiofront=`amixer sget Front | sed -n 's/\] \[[^%]*\]//; s/[ ]*Front Left: Playback [0-9]* \[// p'`
+
+ mailnew=`claws-mail --status inbox | sed -n 's/ [ 0-9ClawsMinotrug\.]*// p'`
+
+ echo -e NEW mail: $mailnew \| VOL front: $audiofront \| BAT:[i]$batpercent[i]\| CPU: $cpuavgload \| $datestr[c]$timestr
+
+ sleep 2
+done | dwm
+
Received on Mon Nov 17 2008 - 20:19:58 CET

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:30:28 CEST