aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dwm.c132
1 files changed, 126 insertions, 6 deletions
diff --git a/dwm.c b/dwm.c
index c983b33..1f4405b 100644
--- a/dwm.c
+++ b/dwm.c
@@ -176,6 +176,7 @@ static void detachstack(Client *c);
176static Monitor *dirtomon(int dir); 176static Monitor *dirtomon(int dir);
177static void drawbar(Monitor *m); 177static void drawbar(Monitor *m);
178static void drawbars(void); 178static void drawbars(void);
179static int drawstatusbar(Monitor *m, int bh, char* text);
179static void enternotify(XEvent *e); 180static void enternotify(XEvent *e);
180static void expose(XEvent *e); 181static void expose(XEvent *e);
181static void focus(Client *c); 182static void focus(Client *c);
@@ -258,10 +259,10 @@ static pid_t winpid(Window w);
258 259
259/* variables */ 260/* variables */
260static const char broken[] = "broken"; 261static const char broken[] = "broken";
261static char stext[256];
262static int statusw; 262static int statusw;
263static int statussig; 263static int statussig;
264static pid_t statuspid = -1; 264static pid_t statuspid = -1;
265static char stext[1024];
265static int screen; 266static int screen;
266static int sw, sh; /* X display screen geometry width, height */ 267static int sw, sh; /* X display screen geometry width, height */
267static int bh, blw = 0; /* bar geometry */ 268static int bh, blw = 0; /* bar geometry */
@@ -590,7 +591,7 @@ cleanup(void)
590 cleanupmon(mons); 591 cleanupmon(mons);
591 for (i = 0; i < CurLast; i++) 592 for (i = 0; i < CurLast; i++)
592 drw_cur_free(drw, cursor[i]); 593 drw_cur_free(drw, cursor[i]);
593 for (i = 0; i < LENGTH(colors); i++) 594 for (i = 0; i < LENGTH(colors) + 1; i++)
594 free(scheme[i]); 595 free(scheme[i]);
595 XDestroyWindow(dpy, wmcheckwin); 596 XDestroyWindow(dpy, wmcheckwin);
596 drw_free(drw); 597 drw_free(drw);
@@ -807,6 +808,126 @@ dirtomon(int dir)
807 return m; 808 return m;
808} 809}
809 810
811int
812drawstatusbar(Monitor *m, int bh, char* stext) {
813 int ret, i, w, x, len;
814 short isCode = 0;
815 char *text;
816 char *p;
817 Clr oldbg, oldfg;
818
819 len = strlen(stext) + 1 ;
820 if (!(text = (char*) malloc(sizeof(char)*len)))
821 die("malloc");
822 p = text;
823 memcpy(text, stext, len);
824
825 /* compute width of the status text */
826 w = 0;
827 i = -1;
828 while (text[++i]) {
829 if (text[i] == '^') {
830 if (!isCode) {
831 isCode = 1;
832 text[i] = '\0';
833 w += TEXTW(text) - lrpad;
834 text[i] = '^';
835 if (text[++i] == 'f')
836 w += atoi(text + ++i);
837 } else {
838 isCode = 0;
839 text = text + i + 1;
840 i = -1;
841 }
842 }
843 }
844 if (!isCode)
845 w += TEXTW(text) - lrpad;
846 else
847 isCode = 0;
848 text = p;
849
850 w += 2; /* 1px padding on both sides */
851 ret = x = m->ww - w;
852
853 drw_setscheme(drw, scheme[LENGTH(colors)]);
854 drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
855 drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
856 drw_rect(drw, x, 0, w, bh, 1, 1);
857 x++;
858
859 /* process status text */
860 i = -1;
861 while (text[++i]) {
862 if (text[i] == '^' && !isCode) {
863 isCode = 1;
864
865 text[i] = '\0';
866 w = TEXTW(text) - lrpad;
867 drw_text(drw, x, 0, w, bh, 0, text, 0);
868
869 x += w;
870
871 /* process code */
872 while (text[++i] != '^') {
873 if (text[i] == 'c') {
874 char buf[8];
875 memcpy(buf, (char*)text+i+1, 7);
876 buf[7] = '\0';
877 drw_clr_create(drw, &drw->scheme[ColFg], buf, alphas[i]);
878 i += 7;
879 } else if (text[i] == 'b') {
880 char buf[8];
881 memcpy(buf, (char*)text+i+1, 7);
882 buf[7] = '\0';
883 drw_clr_create(drw, &drw->scheme[ColBg], buf, alphas[i]);
884 i += 7;
885 } else if (text[i] == 'd') {
886 drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
887 drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
888 } else if (text[i] == 'w') {
889 Clr swp;
890 swp = drw->scheme[ColFg];
891 drw->scheme[ColFg] = drw->scheme[ColBg];
892 drw->scheme[ColBg] = swp;
893 } else if (text[i] == 'v') {
894 oldfg = drw->scheme[ColFg];
895 oldbg = drw->scheme[ColBg];
896 } else if (text[i] == 't') {
897 drw->scheme[ColFg] = oldfg;
898 drw->scheme[ColBg] = oldbg;
899 } else if (text[i] == 'r') {
900 int rx = atoi(text + ++i);
901 while (text[++i] != ',');
902 int ry = atoi(text + ++i);
903 while (text[++i] != ',');
904 int rw = atoi(text + ++i);
905 while (text[++i] != ',');
906 int rh = atoi(text + ++i);
907
908 drw_rect(drw, rx + x, ry, rw, rh, 1, 0);
909 } else if (text[i] == 'f') {
910 x += atoi(text + ++i);
911 }
912 }
913
914 text = text + i + 1;
915 i=-1;
916 isCode = 0;
917 }
918 }
919
920 if (!isCode) {
921 w = TEXTW(text) - lrpad;
922 drw_text(drw, x, 0, w, bh, 0, text, 0);
923 }
924
925 drw_setscheme(drw, scheme[SchemeNorm]);
926 free(p);
927
928 return ret;
929}
930
810void 931void
811drawbar(Monitor *m) 932drawbar(Monitor *m)
812{ 933{
@@ -837,9 +958,7 @@ drawbar(Monitor *m)
837 sw = statusw; 958 sw = statusw;
838 } 959 }
839 if (m == selmon) { /* status is only drawn on selected monitor */ 960 if (m == selmon) { /* status is only drawn on selected monitor */
840 drw_setscheme(drw, scheme[SchemeNorm]); 961 tw = m->ww - drawstatusbar(m, bh, stext);
841 tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
842 drw_text(drw, m->ww - tw - 2 * sp, 0, tw, bh, 0, stext, 0);
843 } 962 }
844 963
845 for (c = m->clients; c; c = c->next) { 964 for (c = m->clients; c; c = c->next) {
@@ -1750,7 +1869,8 @@ setup(void)
1750 cursor[CurResize] = drw_cur_create(drw, XC_sizing); 1869 cursor[CurResize] = drw_cur_create(drw, XC_sizing);
1751 cursor[CurMove] = drw_cur_create(drw, XC_fleur); 1870 cursor[CurMove] = drw_cur_create(drw, XC_fleur);
1752 /* init appearance */ 1871 /* init appearance */
1753 scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); 1872 scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *));
1873 scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], alphas[i], 3);
1754 for (i = 0; i < LENGTH(colors); i++) 1874 for (i = 0; i < LENGTH(colors); i++)
1755 scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3); 1875 scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3);
1756 /* init bars */ 1876 /* init bars */