Add in basic status2d/statuscmd support, will work on this a bit more.
This commit is contained in:
parent
b9259c32db
commit
e881c2ca11
5
bar.h
5
bar.h
|
@ -11,11 +11,12 @@
|
|||
* name - does nothing, intended for visual clue and for logging / debugging
|
||||
*/
|
||||
static const BarRule barrules[] = {
|
||||
/* monitor bar alignment widthfunc drawfunc clickfunc name */
|
||||
/* monitor bar alignment width function draw function click function name */
|
||||
{ -1, 0, BAR_ALIGN_LEFT, width_ltsymbol, draw_ltsymbol, click_ltsymbol, "layout" },
|
||||
{ -1, 0, BAR_ALIGN_LEFT, width_tags, draw_tags, click_tags, "tags" },
|
||||
{ 'A', 0, BAR_ALIGN_RIGHT, width_systray, draw_systray, click_systray, "systray" },
|
||||
{ 'A', 0, BAR_ALIGN_RIGHT, width_status, draw_status, click_status, "status" },
|
||||
//{ 'A', 0, BAR_ALIGN_RIGHT, width_status_basic, draw_status_basic, click_status_basic, "basic status" },
|
||||
{ 'A', 0, BAR_ALIGN_RIGHT, width_status2d, draw_status2d, click_statuscmd, "status2d" },
|
||||
//{ -1, 0, BAR_ALIGN_NONE, width_title_basic, draw_title_basic, click_title_basic, "basic title" },
|
||||
{ -1, 0, BAR_ALIGN_NONE, width_title, draw_title, click_title, "title" },
|
||||
};
|
||||
|
|
15
bar/items.c
15
bar/items.c
|
@ -1,9 +1,10 @@
|
|||
#include "../toggle.h"
|
||||
#include "tags.c"
|
||||
#include "layoutindicator.c"
|
||||
#include "statusbar.c"
|
||||
#include "title-basic.c"
|
||||
#include "title.c"
|
||||
#include "../toggle.h" /* Include what we've included */
|
||||
#include "tags.c" /* Include tags */
|
||||
#include "layoutindicator.c" /* Include layout indicator */
|
||||
#include "statusbar.c" /* Include status bar with status2d and clickstatus */
|
||||
#include "statusbar-basic.c" /* Include basic status bar */
|
||||
#include "title-basic.c" /* Include basic title */
|
||||
#include "title.c" /* Include title */
|
||||
#if USESYSTRAY
|
||||
#include "systray.c"
|
||||
#include "systray.c" /* Include systray */
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "tags.h"
|
||||
#include "layoutindicator.h"
|
||||
#include "statusbar.h"
|
||||
#include "statusbar-basic.h"
|
||||
#include "title-basic.h"
|
||||
#include "title.h"
|
||||
#if USESYSTRAY
|
||||
|
|
19
bar/statusbar-basic.c
Normal file
19
bar/statusbar-basic.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
int
|
||||
width_status_basic(Bar *bar, BarWidthArg *a)
|
||||
{
|
||||
return TEXTW(stext);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
draw_status_basic(Bar *bar, BarDrawArg *a)
|
||||
{
|
||||
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, stext, 0, True);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
click_status_basic(Bar *bar, Arg *arg, BarClickArg *a)
|
||||
{
|
||||
return ClkStatusText;
|
||||
}
|
3
bar/statusbar-basic.h
Normal file
3
bar/statusbar-basic.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
static int width_status_basic(Bar *bar, BarWidthArg *a);
|
||||
static int draw_status_basic(Bar *bar, BarDrawArg *a);
|
||||
static int click_status_basic(Bar *bar, Arg *arg, BarClickArg *a);
|
186
bar/statusbar.c
186
bar/statusbar.c
|
@ -1,19 +1,193 @@
|
|||
static int clickstatusn;
|
||||
static char lastbutton[] = "-";
|
||||
|
||||
int
|
||||
width_status(Bar *bar, BarWidthArg *a)
|
||||
width_status2d(Bar *bar, BarWidthArg *a)
|
||||
{
|
||||
return TEXTW(stext);
|
||||
return status2dtextlength(rawstext) + lrpad;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
draw_status(Bar *bar, BarDrawArg *a)
|
||||
draw_status2d(Bar *bar, BarDrawArg *a)
|
||||
{
|
||||
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, stext, 0, True);
|
||||
return drawstatusbar(a->x, rawstext);
|
||||
}
|
||||
|
||||
int
|
||||
drawstatusbar(int x, char* stext)
|
||||
{
|
||||
int i, w, len;
|
||||
short isCode = 0;
|
||||
char *text;
|
||||
char *p;
|
||||
|
||||
len = strlen(stext);
|
||||
if (!(text = (char*) malloc(sizeof(char)*(len + 1))))
|
||||
die("malloc");
|
||||
p = text;
|
||||
copyvalidchars(text, stext);
|
||||
text[len] = '\0';
|
||||
|
||||
x += lrpad / 2;
|
||||
drw_setscheme(drw, scheme[LENGTH(colors)]);
|
||||
drw->scheme[ColFg] = scheme[SchemeStatus][ColFg];
|
||||
drw->scheme[ColBg] = scheme[SchemeStatus][ColBg];
|
||||
|
||||
/* process status text */
|
||||
i = -1;
|
||||
while (text[++i]) {
|
||||
if (text[i] == '^' && !isCode) {
|
||||
isCode = 1;
|
||||
|
||||
text[i] = '\0';
|
||||
w = TEXTW(text) - lrpad;
|
||||
drw_text(drw, x, 0, w, bh, 0, text, 0, True);
|
||||
|
||||
x += w;
|
||||
|
||||
/* process code */
|
||||
while (text[++i] != '^') {
|
||||
if (text[i] == 'c') {
|
||||
char buf[8];
|
||||
if (i + 7 > len - 1) {
|
||||
i += 7;
|
||||
len = 0;
|
||||
break;
|
||||
}
|
||||
memcpy(buf, (char*)text+i+1, 7);
|
||||
buf[7] = '\0';
|
||||
drw_clr_create(drw, &drw->scheme[ColFg], buf, 0xff);
|
||||
i += 7;
|
||||
} else if (text[i] == 'b') {
|
||||
char buf[8];
|
||||
if (i + 7 > len - 1) {
|
||||
i += 7;
|
||||
len = 0;
|
||||
break;
|
||||
}
|
||||
memcpy(buf, (char*)text+i+1, 7);
|
||||
buf[7] = '\0';
|
||||
drw_clr_create(drw, &drw->scheme[ColBg], buf, 0xff);
|
||||
i += 7;
|
||||
} else if (text[i] == 'd') {
|
||||
drw->scheme[ColFg] = scheme[SchemeStatus][ColFg];
|
||||
drw->scheme[ColBg] = scheme[SchemeStatus][ColBg];
|
||||
} 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);
|
||||
|
||||
if (ry < 0)
|
||||
ry = 0;
|
||||
if (rx < 0)
|
||||
rx = 0;
|
||||
|
||||
drw_rect(drw, rx + x, ry, rw, rh, 1, 0);
|
||||
} else if (text[i] == 'f') {
|
||||
x += atoi(text + ++i);
|
||||
}
|
||||
}
|
||||
|
||||
text = text + i + 1;
|
||||
len -= i + 1;
|
||||
i=-1;
|
||||
isCode = 0;
|
||||
}
|
||||
}
|
||||
if (!isCode && len) {
|
||||
w = TEXTW(text) - lrpad;
|
||||
drw_text(drw, x, 0, w, bh, 0, text, 0, True);
|
||||
x += w;
|
||||
}
|
||||
free(p);
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeStatus]);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int
|
||||
click_status(Bar *bar, Arg *arg, BarClickArg *a)
|
||||
status2dtextlength(char* stext)
|
||||
{
|
||||
int i, w, len;
|
||||
short isCode = 0;
|
||||
char *text;
|
||||
char *p;
|
||||
|
||||
len = strlen(stext) + 1;
|
||||
if (!(text = (char*) malloc(sizeof(char)*len)))
|
||||
die("malloc");
|
||||
p = text;
|
||||
copyvalidchars(text, stext);
|
||||
|
||||
/* compute width of the status text */
|
||||
w = 0;
|
||||
i = -1;
|
||||
while (text[++i]) {
|
||||
if (text[i] == '^') {
|
||||
if (!isCode) {
|
||||
isCode = 1;
|
||||
text[i] = '\0';
|
||||
w += TEXTW(text) - lrpad;
|
||||
text[i] = '^';
|
||||
if (text[++i] == 'f')
|
||||
w += atoi(text + ++i);
|
||||
} else {
|
||||
isCode = 0;
|
||||
text = text + i + 1;
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isCode)
|
||||
w += TEXTW(text) - lrpad;
|
||||
free(p);
|
||||
return w;
|
||||
}
|
||||
|
||||
int
|
||||
click_statuscmd(Bar *bar, Arg *arg, BarClickArg *a)
|
||||
{
|
||||
return click_statuscmd_text(arg, a->rel_x, rawstext);
|
||||
}
|
||||
|
||||
int
|
||||
click_statuscmd_text(Arg *arg, int rel_x, char *text)
|
||||
{
|
||||
int i = -1;
|
||||
int x = 0;
|
||||
char ch;
|
||||
clickstatusn = 0;
|
||||
while (text[++i]) {
|
||||
if ((unsigned char)text[i] < ' ') {
|
||||
ch = text[i];
|
||||
text[i] = '\0';
|
||||
x += status2dtextlength(text);
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
if (x >= rel_x)
|
||||
break;
|
||||
if (ch <= LENGTH(clickstatuss))
|
||||
clickstatusn = ch;
|
||||
}
|
||||
}
|
||||
return ClkStatusText;
|
||||
}
|
||||
|
||||
void
|
||||
copyvalidchars(char *text, char *rawtext)
|
||||
{
|
||||
int i = -1, j = 0;
|
||||
|
||||
while (rawtext[++i]) {
|
||||
if ((unsigned char)rawtext[i] >= ' ') {
|
||||
text[j++] = rawtext[i];
|
||||
}
|
||||
}
|
||||
text[j] = '\0';
|
||||
}
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
static int width_status(Bar *bar, BarWidthArg *a);
|
||||
static int draw_status(Bar *bar, BarDrawArg *a);
|
||||
static int click_status(Bar *bar, Arg *arg, BarClickArg *a);
|
||||
static int width_status2d(Bar *bar, BarWidthArg *a);
|
||||
static int width_status2d_es(Bar *bar, BarWidthArg *a);
|
||||
static int draw_status2d(Bar *bar, BarDrawArg *a);
|
||||
static int draw_status2d_es(Bar *bar, BarDrawArg *a);
|
||||
static int drawstatusbar(int x, char *text);
|
||||
static int status2dtextlength(char *stext);
|
||||
static int click_statuscmd(Bar *bar, Arg *arg, BarClickArg *a);
|
||||
static int click_statuscmd_es(Bar *bar, Arg *arg, BarClickArg *a);
|
||||
static int click_statuscmd_text(Arg *arg, int rel_x, char *text);
|
||||
static void copyvalidchars(char *text, char *rawtext);
|
||||
|
|
78
speedwm.c
78
speedwm.c
|
@ -450,7 +450,6 @@ static void drawbar(void);
|
|||
#if USEROUNDCORNERS
|
||||
static void drawroundedcorners(Client *c);
|
||||
#endif
|
||||
static int statuslength(char *stext);
|
||||
static void enternotify(XEvent *e);
|
||||
static void expose(XEvent *e);
|
||||
static void focus(Client *c);
|
||||
|
@ -756,12 +755,6 @@ static char stext[1024]; /* max character count */
|
|||
static char rawstext[1024]; /* max character count */
|
||||
static int statusw;
|
||||
|
||||
/* clickability */
|
||||
#if USEMOUSE
|
||||
static int clickstatusn;
|
||||
static char lastbutton[] = "-";
|
||||
#endif
|
||||
|
||||
static int screen;
|
||||
static int tw, sh; /* X display screen geometry width, height */
|
||||
static int bh; /* bar geometry */
|
||||
|
@ -1701,20 +1694,6 @@ configurerequest(XEvent *e)
|
|||
XSync(dpy, False);
|
||||
}
|
||||
|
||||
/* copy status chars so we can hack on the text */
|
||||
void
|
||||
copyvalidchars(char *text, char *rawtext)
|
||||
{
|
||||
int i = -1, j = 0;
|
||||
|
||||
while(rawtext[++i]) {
|
||||
if ((unsigned char)rawtext[i] >= ' ') {
|
||||
text[j++] = rawtext[i];
|
||||
}
|
||||
}
|
||||
text[j] = '\0';
|
||||
}
|
||||
|
||||
/* init monitor */
|
||||
Monitor *
|
||||
createmon(void)
|
||||
|
@ -2041,49 +2020,6 @@ readAndSetColor(int clrIdx, char* txt) {
|
|||
}
|
||||
}
|
||||
|
||||
/* get length of printed status
|
||||
*
|
||||
* w/o this, status2d chars are included in click pos */
|
||||
int
|
||||
statuslength(char* stext)
|
||||
{
|
||||
int i = -1, w, len;
|
||||
short isCode = 0;
|
||||
char *text;
|
||||
char *p;
|
||||
|
||||
len = strlen(stext) + 1;
|
||||
if (!(text = (char*) malloc(sizeof(char)*len)))
|
||||
die("malloc");
|
||||
p = text;
|
||||
|
||||
copyvalidchars(text, stext);
|
||||
|
||||
/* compute width of the status text */
|
||||
w = 0;
|
||||
i = -1;
|
||||
while (text[++i]) {
|
||||
if (text[i] == '^') {
|
||||
if (!isCode) {
|
||||
isCode = 1;
|
||||
text[i] = '\0';
|
||||
w += TEXTWM(text) - lrpad;
|
||||
text[i] = '^';
|
||||
if (text[++i] == 'f')
|
||||
w += atoi(text + ++i);
|
||||
} else {
|
||||
isCode = 0;
|
||||
text = text + i + 1;
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isCode)
|
||||
w += TEXTWM(text) - lrpad;
|
||||
free(p);
|
||||
return w;
|
||||
}
|
||||
|
||||
/* drag mfact with mouse */
|
||||
#if USEMOUSE
|
||||
void
|
||||
|
@ -6210,23 +6146,9 @@ updatestatus(void)
|
|||
Monitor* m;
|
||||
if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)) && !selmon->hidestatus) {
|
||||
strcpy(stext, defaultstatus);
|
||||
statusw = TEXTWM(stext) - lrpad + 2;
|
||||
} else {
|
||||
if (!selmon->hidestatus) {
|
||||
copyvalidchars(stext, rawstext);
|
||||
char *text, *s, ch;
|
||||
statusw = 0;
|
||||
|
||||
for (text = s = stext; *s; s++) {
|
||||
if ((unsigned char)(*s) < ' ') {
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
statusw += TEXTWM(text) - lrpad;
|
||||
*s = ch;
|
||||
text = s + 1;
|
||||
}
|
||||
}
|
||||
statusw += TEXTWM(text) - lrpad + 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue