Adding BarWidthArg, BarDrawArg, BarClickArg to keep the method signatures static

This commit is contained in:
bakkeby 2020-07-15 14:10:47 +02:00
parent f2da4d20d9
commit aa70728d00
27 changed files with 227 additions and 173 deletions

112
dwm.c
View File

@ -168,12 +168,8 @@ enum {
#if BAR_STATUSBUTTON_PATCH
ClkButton,
#endif // BAR_STATUSBUTTON_PATCH
#if BAR_TAGS_PATCH
ClkTagBar,
#endif // BAR_TAGS_PATCH
#if BAR_LTSYMBOL_PATCH
ClkLtSymbol,
#endif // BAR_LTSYMBOL_PATCH
ClkStatusText,
ClkWinTitle,
ClkClientWin,
@ -210,14 +206,31 @@ struct Bar {
int x[BARRULES]; // x position, array length == ^
};
typedef struct {
int max_width;
} BarWidthArg;
typedef struct {
int x;
int w;
} BarDrawArg;
typedef struct {
int rel_x;
int rel_y;
int rel_w;
int rel_h;
} BarClickArg;
typedef struct Monitor Monitor;
typedef struct {
int monitor;
int bar;
int alignment; // see bar alignment enum
int (*widthfunc)(Monitor *m, int max_width);
int (*drawfunc)(Monitor *m, int x, int w);
int (*clickfunc)(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
int (*widthfunc)(Monitor *m, BarWidthArg *a);
int (*drawfunc)(Monitor *m, BarDrawArg *a);
int (*clickfunc)(Monitor *m, Arg *arg, BarClickArg *a);
char *name; // for debugging
int x, w; // position, width for internal use
} BarRule;
@ -552,11 +565,13 @@ static char stext[1024];
#else
static char stext[512];
#endif // BAR_STATUS2D_PATCH
#if BAR_EXTRABAR_PATCH || BAR_STATUSCMD_PATCH
#if BAR_STATUS2D_PATCH
static char rawstext[1024];
#else
static char rawstext[512];
#endif // BAR_STATUS2D_PATCH
#endif // BAR_EXTRABAR_PATCH | BAR_STATUSCMD_PATCH
#if BAR_EXTRABAR_PATCH
#if BAR_STATUS2D_PATCH && !BAR_STATUSCOLORS_PATCH
static char estext[1024];
@ -873,6 +888,7 @@ buttonpress(XEvent *e)
Monitor *m;
XButtonPressedEvent *ev = &e->xbutton;
const BarRule *br;
BarClickArg carg = { 0, 0, 0, 0 };
click = ClkRootWin;
/* focus monitor if necessary */
@ -889,19 +905,23 @@ buttonpress(XEvent *e)
for (mi = 0, m = mons; m && m != selmon; m = m->next, mi++); // get the monitor index
for (b = 0; b < LENGTH(selmon->bars); b++) {
if (ev->window == selmon->bars[b]->win) {
fprintf(stderr, "buttonpress on bar, mi = %d\n", mi);
for (r = 0; r < LENGTH(barrules); r++) {
br = &barrules[r];
if (br->bar != b || (br->monitor == 'A' && m != selmon) || (br->monitor != -1 && br->monitor != mi) || br->clickfunc == NULL)
continue;
if (selmon->bars[b]->x[r] <= ev->x && ev->x <= selmon->bars[b]->x[r] + selmon->bars[b]->w[r]) {
click = br->clickfunc(m, &arg, ev->x - selmon->bars[b]->x[r], ev->y, selmon->bars[b]->w[r], bh);
carg.rel_x = ev->x - selmon->bars[b]->x[r];
carg.rel_y = ev->y;
carg.rel_w = selmon->bars[b]->w[r];
carg.rel_h = selmon->bars[b]->bh;
click = br->clickfunc(m, &arg, &carg);
if (click < 0)
return;
break;
}
}
break;
}
}
if (click == ClkRootWin && (c = wintoclient(ev->window))) {
@ -915,17 +935,17 @@ buttonpress(XEvent *e)
XAllowEvents(dpy, ReplayPointer, CurrentTime);
click = ClkClientWin;
}
fprintf(stderr, "click = %d, dwmblockssig = %d, ev->button = %d, mi = %d\n", click, dwmblockssig, ev->button, mi);
for (i = 0; i < LENGTH(buttons); i++)
for (i = 0; i < LENGTH(buttons); i++) {
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) {
fprintf(stderr, "found click, b.button (%d) == ev->button (%d)\n", buttons[i].button, ev->button);
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) {
#if BAR_AWESOMEBAR_PATCH
buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
#else
buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
#endif
}
}
}
void
@ -1423,24 +1443,21 @@ void
drawbar(Monitor *m)
{
Monitor *mon;
int b, r, mi;
int ret_x, w;
int b, r, w, mi;
int rx, lx, rw, lw; // bar size, split between left and right if a center module is added
const BarRule *br;
Bar *bar;
BarWidthArg warg = { 0 };
BarDrawArg darg = { 0, 0 };
for (mi = 0, mon = mons; mon && mon != m; mon = mon->next, mi++); // get the monitor index
for (b = LENGTH(m->bars) - 1; b >= 0; b--) {
fprintf(stderr, "drawbar, monitor m = %ld, mi = %d, b = %d\n", m, mi, b);
bar = m->bars[b];
if (!bar->win) {
fprintf(stderr, "%s\n", "bar->win does not exist");
if (!bar->win)
continue;
}
rw = lw = bar->bw;
rx = lx = 0;
fprintf(stderr, "lx = %d, lw = %d\n", lx, lw);
#if BAR_VTCOLORS_PATCH
drw_setscheme(drw, scheme[SchemeTagsNorm]);
@ -1457,13 +1474,18 @@ drawbar(Monitor *m)
#else
drw_setscheme(drw, scheme[SchemeNorm]);
#endif // BAR_VTCOLORS_PATCH
if (br->alignment < BAR_ALIGN_RIGHT_LEFT) {
w = br->widthfunc(m, lw);
w = MIN(lw, w);
} else {
w = br->widthfunc(m, rw);
w = MIN(rw, w);
warg.max_width = (br->alignment < BAR_ALIGN_RIGHT_LEFT ? lw : rw);
w = br->widthfunc(m, &warg);
w = MIN(warg.max_width, w);
if (lw <= 0) { // if left is exhausted, switch to right side
lw = rw;
lx = rx;
} else if (rw <= 0) {
rw = lw;
rx = lx;
}
switch(br->alignment) {
default:
case BAR_ALIGN_NONE:
@ -1523,16 +1545,9 @@ drawbar(Monitor *m)
rw = bar->x[r] - rx;
break;
}
ret_x = br->drawfunc(m, bar->x[r], bar->w[r]);
if (ret_x != bar->x[r] + bar->w[r])
fprintf(stderr, "%s - %d alignment, expected these to be the same: %d vs %d, w = %d, bx = %d\n", br->name, br->alignment, ret_x, bar->x[r] + bar->w[r], bar->w[r], bar->x[r]);
if (lw <= 0) { // if left is exhausted, switch to right side
lw = rw;
lx = rx;
rw = 0;
rx = 0;
}
darg.x = bar->x[r];
darg.w = bar->w[r];
br->drawfunc(m, &darg);
}
drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh);
}
@ -2897,26 +2912,9 @@ setup(void)
#else
scheme[i] = drw_scm_create(drw, colors[i], ColCount);
#endif // BAR_ALPHA_PATCH
// #if BAR_SYSTRAY_PATCH
// /* init system tray */
// if (showsystray)
// updatesystray();
// #endif // BAR_SYSTRAY_PATCH
/* init bars */
// Monitor *m;
// for (m = mons; m; m = m->next) {
// fprintf(stderr, "updating bar pos\n");
// updatebarpos(m);
// }
updatebars();
updatestatus();
// Monitor *m;
// for (m = mons; m; m = m->next)
// updatebarpos(m);
// for ()
// updatebarpos(selmon);
/* supporting window for NetWMCheck */
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
@ -3440,7 +3438,6 @@ updatebars(void)
for (m = mons; m; m = m->next) {
for (b = 0; b < LENGTH(m->bars); b++) {
if (!m->bars[b]->win) { // TODO add static status controls to not create / show extra bar?
fprintf(stderr, "creating bar %d at pos x = %d, y = %d, w = %d, h = %d\n", b, m->bars[b]->bx, m->bars[b]->by, m->bars[b]->bw, m->bars[b]->bh);
#if BAR_ALPHA_PATCH
m->bars[b]->win = XCreateWindow(dpy, root, m->bars[b]->bx, m->bars[b]->by, m->bars[b]->bw, m->bars[b]->bh, 0, depth,
InputOutput, visual,
@ -3472,26 +3469,21 @@ updatebarpos(Monitor *m)
int x_pad = 0;
#endif // BAR_PADDING_PATCH
// for (num_bars = 0; num_bars < LENGTH(m->bars) && m->bars[num_bars]->win; num_bars++);
num_bars = LENGTH(m->bars);
fprintf(stderr, "num_bars = %d\n", num_bars);
if (m->showbar) {
m->wh = m->wh - y_pad * num_bars - bh * num_bars;
m->wy = m->wy + bh + y_pad;
}
for (b = 0; b < num_bars; b++) {
fprintf(stderr, "setting bx to xpad %d, b = %d\n", m->mx + x_pad, b);
m->bars[b]->bx = m->mx + x_pad;
m->bars[b]->bw = m->ww - 2 * x_pad;
m->bars[b]->bh = bh;
if (m->showbar) {
fprintf(stderr, "eh? %d, b = %d\n", topbar == b, b);
m->bars[b]->by = m->topbar == b ? m->wy + m->wh : m->wy - bh;
} else {
m->bars[b]->by = -bh - y_pad;
}
fprintf(stderr, "finished with bar, bx = %d, by = %d, bw = %d, bh = %d, m = %ld\n", m->bars[b]->bx, m->bars[b]->by, m->bars[b]->bw, m->bars[b]->bh, m);
}
}

View File

@ -1,22 +1,22 @@
int
width_awesomebar(Monitor *m, int max_width)
width_awesomebar(Monitor *m, BarWidthArg *a)
{
return max_width;
return a->max_width;
}
int
draw_awesomebar(Monitor *m, int x_orig, int w)
draw_awesomebar(Monitor *m, BarDrawArg *a)
{
int n = 0, scm, remainder = 0, tabw;
unsigned int i, x = x_orig;
unsigned int i, x = a->x;
Client *c;
for (c = m->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) {
remainder = w % n;
tabw = w / n;
remainder = a->w % n;
tabw = a->w / n;
for (i = 0, c = m->clients; c; c = c->next, i++) {
if (!ISVISIBLE(c))
continue;
@ -46,11 +46,11 @@ draw_awesomebar(Monitor *m, int x_orig, int w)
x += tabw;
}
}
return x_orig + w;
return a->x + a->w;
}
int
click_awesomebar(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_awesomebar(Monitor *m, Arg *arg, BarClickArg *a)
{
int x = 0, n = 0;
Client *c;
@ -65,8 +65,8 @@ click_awesomebar(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_
if (!c || !ISVISIBLE(c))
continue;
else
x += (1.0 / (double)n) * rel_w;
} while (c && rel_x > x && (c = c->next));
x += (1.0 / (double)n) * a->rel_w;
} while (c && a->rel_x > x && (c = c->next));
if (c) {
arg->v = c;

View File

@ -1,6 +1,6 @@
static int width_awesomebar(Monitor *m, int max_width);
static int draw_awesomebar(Monitor *m, int x, int w);
static int click_awesomebar(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_awesomebar(Monitor *m, BarWidthArg *a);
static int draw_awesomebar(Monitor *m, BarDrawArg *a);
static int click_awesomebar(Monitor *m, Arg *arg, BarClickArg *a);
static void hide(Client *c);
static void show(Client *c);

View File

@ -1,13 +1,13 @@
int
width_fancybar(Monitor *m, int max_width)
width_fancybar(Monitor *m, BarWidthArg *a)
{
return max_width;
return a->max_width;
}
int
draw_fancybar(Monitor *m, int x, int w)
draw_fancybar(Monitor *m, BarDrawArg *a)
{
int ftw, mw, ew = 0, n = 0;
int ftw, mw, ew = 0, n = 0, x = a->x, w = a->w;
unsigned int i;
Client *c;
#if !BAR_HIDEVACANTTAGS_PATCH
@ -89,7 +89,7 @@ draw_fancybar(Monitor *m, int x, int w)
}
int
click_fancybar(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_fancybar(Monitor *m, Arg *arg, BarClickArg *a)
{
return ClkWinTitle;
}

View File

@ -1,3 +1,3 @@
static int width_fancybar(Monitor *m, int max_width);
static int draw_fancybar(Monitor *m, int x, int w);
static int click_fancybar(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_fancybar(Monitor *m, BarWidthArg *a);
static int draw_fancybar(Monitor *m, BarDrawArg *a);
static int click_fancybar(Monitor *m, Arg *arg, BarClickArg *a);

View File

@ -1,21 +1,21 @@
int
width_ltsymbol(Monitor *m, int max_width)
width_ltsymbol(Monitor *m, BarWidthArg *a)
{
return TEXTW(m->ltsymbol);
}
int
draw_ltsymbol(Monitor *m, int x, int w)
draw_ltsymbol(Monitor *m, BarDrawArg *a)
{
#if BAR_PANGO_PATCH
return drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0, False);
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, m->ltsymbol, 0, False);
#else
return drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, m->ltsymbol, 0);
#endif // BAR_PANGO_PATCH
}
int
click_ltsymbol(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_ltsymbol(Monitor *m, Arg *arg, BarClickArg *a)
{
return ClkLtSymbol;
}

View File

@ -1,3 +1,3 @@
static int width_ltsymbol(Monitor *m, int max_width);
static int draw_ltsymbol(Monitor *m, int x, int w);
static int click_ltsymbol(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_ltsymbol(Monitor *m, BarWidthArg *a);
static int draw_ltsymbol(Monitor *m, BarDrawArg *a);
static int click_ltsymbol(Monitor *m, Arg *arg, BarClickArg *a);

View File

@ -1,5 +1,5 @@
int
width_status(Monitor *m, int max_width)
width_status(Monitor *m, BarWidthArg *a)
{
#if BAR_PANGO_PATCH
return TEXTWM(stext) - lrpad + 2; /* 2px right padding */
@ -9,17 +9,17 @@ width_status(Monitor *m, int max_width)
}
int
draw_status(Monitor *m, int x, int w)
draw_status(Monitor *m, BarDrawArg *a)
{
#if BAR_PANGO_PATCH
return drw_text(drw, x, 0, w, bh, 0, stext, 0, True);
return drw_text(drw, a->x, 0, a->w, bh, 0, stext, 0, True);
#else
return drw_text(drw, x, 0, w, bh, 0, stext, 0);
return drw_text(drw, a->x, 0, a->w, bh, 0, stext, 0);
#endif // BAR_PANGO_PATCH
}
int
click_status(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_status(Monitor *m, Arg *arg, BarClickArg *a)
{
return ClkStatusText;
}

View File

@ -1,3 +1,3 @@
static int width_status(Monitor *m, int max_width);
static int draw_status(Monitor *m, int x, int w);
static int click_status(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_status(Monitor *m, BarWidthArg *a);
static int draw_status(Monitor *m, BarDrawArg *a);
static int click_status(Monitor *m, Arg *arg, BarClickArg *a);

View File

@ -1,17 +1,17 @@
int
width_status2d(Monitor *m, int max_width)
width_status2d(Monitor *m, BarWidthArg *a)
{
return status2dtextlength(rawstext);
}
int
draw_status2d(Monitor *m, int x, int w)
draw_status2d(Monitor *m, BarDrawArg *a)
{
return drawstatusbar(m, x, w, rawstext);
return drawstatusbar(m, a->x, a->w, rawstext);
}
int
click_status2d(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_status2d(Monitor *m, Arg *arg, BarClickArg *a)
{
return ClkStatusText;
}

View File

@ -1,5 +1,5 @@
static int width_status2d(Monitor *m, int max_width);
static int draw_status2d(Monitor *m, int x, int w);
static int click_status2d(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_status2d(Monitor *m, BarWidthArg *a);
static int draw_status2d(Monitor *m, BarDrawArg *a);
static int click_status2d(Monitor *m, Arg *arg, BarClickArg *a);
static int drawstatusbar(Monitor *m, int x, int w, char* text);
static int status2dtextlength(char* stext);

View File

@ -1,11 +1,11 @@
int
width_status2d_eb(Monitor *m, int max_width)
width_status2d_eb(Monitor *m, BarWidthArg *a)
{
return status2dtextlength(rawestext);
}
int
draw_status2d_eb(Monitor *m, int x, int w)
draw_status2d_eb(Monitor *m, BarDrawArg *a)
{
return drawstatusbar(m, x, w, rawestext);
return drawstatusbar(m, a->x, a->w, rawestext);
}

View File

@ -1,2 +1,2 @@
static int width_status2d_eb(Monitor *m, int max_width);
static int draw_status2d_eb(Monitor *m, int x, int w);
static int width_status2d_eb(Monitor *m, BarWidthArg *a);
static int draw_status2d_eb(Monitor *m, BarDrawArg *a);

View File

@ -1,21 +1,21 @@
int
width_stbutton(Monitor *m, int max_width)
width_stbutton(Monitor *m, BarWidthArg *a)
{
return TEXTW(buttonbar);
}
int
draw_stbutton(Monitor *m, int x, int w)
draw_stbutton(Monitor *m, BarDrawArg *a)
{
#if BAR_PANGO_PATCH
return drw_text(drw, x, 0, w, bh, lrpad / 2, buttonbar, 0, False);
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, buttonbar, 0, False);
#else
return drw_text(drw, x, 0, w, bh, lrpad / 2, buttonbar, 0);
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, buttonbar, 0);
#endif // BAR_PANGO_PATCH
}
int
click_stbutton(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_stbutton(Monitor *m, Arg *arg, BarClickArg *a)
{
return ClkButton;
}

View File

@ -1,3 +1,3 @@
static int width_stbutton(Monitor *m, int max_width);
static int draw_stbutton(Monitor *m, int x, int w);
static int click_stbutton(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_stbutton(Monitor *m, BarWidthArg *a);
static int draw_stbutton(Monitor *m, BarDrawArg *a);
static int click_stbutton(Monitor *m, Arg *arg, BarClickArg *a);

View File

@ -5,21 +5,21 @@ static int lastbutton;
#endif // BAR_DWMBLOCKS_PATCH
int
click_statuscmd(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_statuscmd(Monitor *m, Arg *arg, BarClickArg *a)
{
return click_statuscmd_text(m, arg, rel_x, rel_y, rawstext);
return click_statuscmd_text(m, arg, a->rel_x, rawstext);
}
#if BAR_EXTRABAR_PATCH
int
click_statuscmd_eb(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_statuscmd_eb(Monitor *m, Arg *arg, BarClickArg *a)
{
return click_statuscmd_text(m, arg, rel_x, rel_y, rawestext);
return click_statuscmd_text(m, arg, a->rel_x, rawestext);
}
#endif // BAR_EXTRABAR_PATCH
int
click_statuscmd_text(Monitor *m, Arg *arg, int rel_x, int rel_y, char *text)
click_statuscmd_text(Monitor *m, Arg *arg, int rel_x, char *text)
{
int i = -1;
int x = 0;

View File

@ -1,6 +1,6 @@
static int click_statuscmd(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int click_statuscmd(Monitor *m, Arg *arg, BarClickArg *a);
#if BAR_EXTRABAR_PATCH
static int click_statuscmd_eb(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int click_statuscmd_eb(Monitor *m, Arg *arg, BarClickArg *a);
#endif // BAR_EXTRABAR_PATCH
static int click_statuscmd_text(Monitor *m, Arg *arg, int rel_x, int rel_y, char *text);
static int click_statuscmd_text(Monitor *m, Arg *arg, int rel_x, char *text);
static void copyvalidchars(char *text, char *rawtext);

View File

@ -5,7 +5,7 @@ static int systraybarrule = -1;
static int systrayxpos = 0;
int
width_systray(Monitor *m, int max_width)
width_systray(Monitor *m, BarWidthArg *a)
{
unsigned int w = 0;
Client *i;
@ -17,15 +17,15 @@ width_systray(Monitor *m, int max_width)
}
int
draw_systray(Monitor *m, int x_pos, int w)
draw_systray(Monitor *m, BarDrawArg *a)
{
systrayxpos = x_pos;
systrayxpos = a->x;
updatesystray();
return systrayxpos + w;
return systrayxpos + a->w;
}
int
click_systray(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_systray(Monitor *m, Arg *arg, BarClickArg *a)
{
return -1;
}

View File

@ -26,9 +26,9 @@ struct Systray {
};
/* bar integration */
static int width_systray(Monitor *m, int max_width);
static int draw_systray(Monitor *m, int x_pos, int w);
static int click_systray(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_systray(Monitor *m, BarWidthArg *a);
static int draw_systray(Monitor *m, BarDrawArg *a);
static int click_systray(Monitor *m, Arg *arg, BarClickArg *a);
/* function declarations */
static Atom getatomprop(Client *c, Atom prop);

View File

@ -1,11 +1,11 @@
int
width_taggrid(Monitor *m, int max_width)
width_taggrid(Monitor *m, BarWidthArg *a)
{
return (bh / 2) * (LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0));
}
int
draw_taggrid(Monitor *m, int x_pos, int w)
draw_taggrid(Monitor *m, BarDrawArg *a)
{
unsigned int x, y, h, max_x, columns, occ = 0;
int invert, i,j, k;
@ -15,7 +15,7 @@ draw_taggrid(Monitor *m, int x_pos, int w)
occ |= c->tags;
h = bh / tagrows;
x = max_x = x_pos;
x = max_x = a->x;
y = 0;
columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0);
@ -24,7 +24,7 @@ draw_taggrid(Monitor *m, int x_pos, int w)
/* We will draw LENGTH(tags) squares in tagraws raws. */
for (j = 0, i = 0; j < tagrows; j++) {
x = x_pos;
x = a->x;
for (k = 0; k < columns && i < LENGTH(tags); k++, i++) {
invert = m->tagset[m->seltags] & 1 << i ? 0 : 1;
@ -51,12 +51,12 @@ draw_taggrid(Monitor *m, int x_pos, int w)
}
int
click_taggrid(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_taggrid(Monitor *m, Arg *arg, BarClickArg *a)
{
unsigned int i, columns;
columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0);
i = (rel_x - 0) / (bh / tagrows) + columns * (rel_y / (bh / tagrows));
i = (a->rel_x - 0) / (bh / tagrows) + columns * (a->rel_y / (bh / tagrows));
if (i >= LENGTH(tags)) {
i = LENGTH(tags) - 1;
}

View File

@ -1,4 +1,4 @@
static int width_taggrid(Monitor *m, int max_width);
static int draw_taggrid(Monitor *m, int x, int w);
static int click_taggrid(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_taggrid(Monitor *m, BarWidthArg *a);
static int draw_taggrid(Monitor *m, BarDrawArg *a);
static int click_taggrid(Monitor *m, Arg *arg, BarClickArg *a);
static void switchtag(const Arg *arg);

View File

@ -1,5 +1,5 @@
int
width_tags(Monitor *m, int max_width)
width_tags(Monitor *m, BarWidthArg *a)
{
int w, i;
for (w = 0, i = 0; i < LENGTH(tags); i++) {
@ -13,9 +13,10 @@ width_tags(Monitor *m, int max_width)
}
int
draw_tags(Monitor *m, int x, int w)
draw_tags(Monitor *m, BarDrawArg *a)
{
int invert;
int w, x = a->x;
#if BAR_ALTERNATIVE_TAGS_PATCH
int wdelta;
#endif // BAR_ALTERNATIVE_TAGS_PATCH
@ -106,7 +107,7 @@ draw_tags(Monitor *m, int x, int w)
}
int
click_tags(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_tags(Monitor *m, Arg *arg, BarClickArg *a)
{
int i = 0, x = 0;
do
@ -115,7 +116,7 @@ click_tags(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
#else
x += TEXTW(tags[i]);
#endif
while (rel_x >= x && ++i < LENGTH(tags));
while (a->rel_x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
arg->ui = 1 << i;
}

View File

@ -1,3 +1,3 @@
static int width_tags(Monitor *m, int max_width);
static int draw_tags(Monitor *m, int x, int w);
static int click_tags(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_tags(Monitor *m, BarWidthArg *a);
static int draw_tags(Monitor *m, BarDrawArg *a);
static int click_tags(Monitor *m, Arg *arg, BarClickArg *a);

70
patch/bar_vtcolors.c Normal file
View File

@ -0,0 +1,70 @@
void
get_vt_colors(void)
{
char *cfs[3] = {
"/sys/module/vt/parameters/default_red",
"/sys/module/vt/parameters/default_grn",
"/sys/module/vt/parameters/default_blu",
};
char vtcs[16][8];
char tk[] = ",";
char cl[64];
char *tp = NULL;
FILE *fp;
size_t r;
int i, c, n;
for (i = 0; i < 16; i++)
strcpy(vtcs[i], "#000000");
for (i = 0, r = 0; i < 3; i++) {
if ((fp = fopen(cfs[i], "r")) == NULL)
continue;
while ((cl[r] = fgetc(fp)) != EOF && cl[r] != '\n')
r++;
cl[r] = '\0';
for (c = 0, tp = cl, n = 0; c < 16; c++, tp++) {
if ((r = strcspn(tp, tk)) == -1)
break;
for (n = 0; r && *tp >= 48 && *tp < 58; r--, tp++)
n = n * 10 - 48 + *tp;
vtcs[c][i * 2 + 1] = n / 16 < 10 ? n / 16 + 48 : n / 16 + 87;
vtcs[c][i * 2 + 2] = n % 16 < 10 ? n % 16 + 48 : n % 16 + 87;
}
fclose(fp);
}
for (i = 0; i < LENGTH(colors); i++) {
#if FLOAT_BORDER_COLOR_PATCH
for (c = 0; c < 4; c++)
#else
for (c = 0; c < 3; c++)
#endif // FLOAT_BORDER_COLOR_PATCH
{
n = color_ptrs[i][c];
if (n > -1 && strlen(colors[i][c]) >= strlen(vtcs[n]))
memcpy(colors[i][c], vtcs[n], 7);
}
}
}
int get_luminance(char *r)
{
char *c = r;
int n[3] = {0};
int i = 0;
while (*c) {
if (*c >= 48 && *c < 58)
n[i / 2] = n[i / 2] * 16 - 48 + *c;
else if (*c >= 65 && *c < 71)
n[i / 2] = n[i / 2] * 16 - 55 + *c;
else if (*c >= 97 && *c < 103)
n[i / 2] = n[i / 2] * 16 - 87 + *c;
else
i--;
i++;
c++;
}
return (0.299 * n[0] + 0.587 * n[1] + 0.114 * n[2]) / 2.55;
}

2
patch/bar_vtcolors.h Normal file
View File

@ -0,0 +1,2 @@
static void get_vt_colors(void);
static int get_luminance(char *rgb);

View File

@ -1,11 +1,11 @@
int
width_wintitle(Monitor *m, int max_width)
width_wintitle(Monitor *m, BarWidthArg *a)
{
return max_width;
return a->max_width;
}
int
draw_wintitle(Monitor *m, int x, int w)
draw_wintitle(Monitor *m, BarDrawArg *a)
{
#if !BAR_ACTIVETAGINDICATORBAR_PATCH && !BAR_ACTIVETAGINDICATORBAR_ALT1_PATCH
#if BAR_PANGO_PATCH
@ -19,6 +19,7 @@ draw_wintitle(Monitor *m, int x, int w)
#else
int boxw = drw->fonts->h / 6 + 2;
#endif // BAR_PANGO_PATCH
int x = a->x, w = a->w;
if (m->sel) {
#if BAR_VTCOLORS_PATCH
@ -33,25 +34,17 @@ draw_wintitle(Monitor *m, int x, int w)
#endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
#if BAR_CENTEREDWINDOWNAME_PATCH
int mid = (m->ww - TEXTW(m->sel->name)) / 2 - x;
#if BAR_PADDING_PATCH && BAR_PANGO_PATCH
drw_text(drw, x, 0, w - 2*sp, bh, mid, m->sel->name, 0, False);
#elif BAR_PADDING_PATCH
drw_text(drw, x, 0, w - 2*sp, bh, mid, m->sel->name, 0);
#elif BAR_PANGO_PATCH
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0, False);
#else
drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0);
#endif // BAR_PADDING_PATCH
#endif // BAR_PANGO_PATCH
#else
#if BAR_PADDING_PATCH && BAR_PANGO_PATCH
drw_text(drw, x, 0, w - 2*sp, bh, lrpad / 2, m->sel->name, 0, False);
#elif BAR_PADDING_PATCH
drw_text(drw, x, 0, w - 2*sp, bh, lrpad / 2, m->sel->name, 0);
#elif BAR_PANGO_PATCH
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False);
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
#endif // BAR_PADDING_PATCH
#endif // BAR_PANGO_PATCH
#endif // BAR_CENTEREDWINDOWNAME_PATCH
#if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
XSync(dpy, False);
@ -61,7 +54,7 @@ draw_wintitle(Monitor *m, int x, int w)
#if BAR_ACTIVETAGINDICATORBAR_PATCH
drw_rect(drw, x + boxw, 0, w - ( 2 * boxw + 1), boxw, m->sel->isfixed, 0);
#elif BAR_ACTIVETAGINDICATORBAR_ALT1_PATCH
drw_rect(drw, x + boxw, bh - boxw/2, w - ( 2 * boxw + 1), boxw/2,
drw_rect(drw, x + boxw, bh - boxw/2, w - ( 2 * boxw + 1), boxw/2, 0);
#else
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
#endif // BAR_ACTIVETAGINDICATORBAR_PATCH
@ -71,17 +64,13 @@ draw_wintitle(Monitor *m, int x, int w)
#else
drw_setscheme(drw, scheme[SchemeNorm]);
#endif // BAR_VTCOLORS_PATCH
#if BAR_PADDING_PATCH
drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1);
#else
drw_rect(drw, x, 0, w, bh, 1, 1);
#endif // BAR_PADDING_PATCH
}
return x + w;
}
int
click_wintitle(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h)
click_wintitle(Monitor *m, Arg *arg, BarClickArg *a)
{
return ClkWinTitle;
}

View File

@ -1,3 +1,3 @@
static int width_wintitle(Monitor *m, int max_width);
static int draw_wintitle(Monitor *m, int x, int w);
static int click_wintitle(Monitor *m, Arg *arg, int rel_x, int rel_y, int rel_w, int rel_h);
static int width_wintitle(Monitor *m, BarWidthArg *a);
static int draw_wintitle(Monitor *m, BarDrawArg *a);
static int click_wintitle(Monitor *m, Arg *arg, BarClickArg *a);