[bar] Improve a lot the bar stuff (taglist, layout symbol, barbutton...
This commit is contained in:
128
bar.c
128
bar.c
@@ -75,7 +75,13 @@ bar_moveresize(BarWindow *bw, int x, int y, uint w, uint h)
|
|||||||
bw->dr = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
bw->dr = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||||
bw->w = w; bw->h = h;
|
bw->w = w; bw->h = h;
|
||||||
}
|
}
|
||||||
bw->x = x; bw->y = y;
|
|
||||||
|
if(x != bw->x || y != bw->y)
|
||||||
|
{
|
||||||
|
bw->x = x;
|
||||||
|
bw->y = y;
|
||||||
|
}
|
||||||
|
|
||||||
XMoveResizeWindow(dpy, bw->win, x, y, w, h);
|
XMoveResizeWindow(dpy, bw->win, x, y, w, h);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -98,48 +104,76 @@ bar_refresh(BarWindow *bw)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
draw_taglist(Drawable dr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buf[conf.ntag][256];
|
||||||
|
char p[4];
|
||||||
|
taglen[0] = PAD/2;
|
||||||
|
|
||||||
|
for(i = 0; i < conf.ntag; ++i)
|
||||||
|
{
|
||||||
|
/* Make the tags string */
|
||||||
|
ITOA(p, clientpertag(i+1));
|
||||||
|
sprintf(buf[i], "%s<%s>", tags[i+1].name, (clientpertag(i+1)) ? p : "");
|
||||||
|
|
||||||
|
/* Draw the string */
|
||||||
|
xprint(dr, taglen[i], fonth,
|
||||||
|
((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text),
|
||||||
|
((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]);
|
||||||
|
|
||||||
|
/* Draw the tag border */
|
||||||
|
XSetForeground(dpy, gc, conf.colors.tagbord);
|
||||||
|
XFillRectangle(dpy, dr, gc,
|
||||||
|
taglen[i] + textw(buf[i]) + PAD/2,
|
||||||
|
0, conf.tagbordwidth, barheight);
|
||||||
|
|
||||||
|
/* Edit taglen[i+1] for the next time */
|
||||||
|
taglen[i+1] = taglen[i] + textw(buf[i]) + PAD + conf.tagbordwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
draw_layoutsym(int x, int y)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!layoutsym)
|
||||||
|
{
|
||||||
|
layoutsym = bar_create(x, y,
|
||||||
|
textw(tags[seltag].layout.symbol) + BPAD,
|
||||||
|
barheight, 0, conf.colors.layout_bg);
|
||||||
|
XMapRaised(dpy, layoutsym->win);
|
||||||
|
}
|
||||||
|
|
||||||
|
bar_refresh_color(layoutsym);
|
||||||
|
bar_moveresize(layoutsym, x, y, textw(tags[seltag].layout.symbol) + BPAD, barheight);
|
||||||
|
|
||||||
|
xprint(layoutsym->dr, BPAD/2, fonth, conf.colors.layout_fg,
|
||||||
|
conf.colors.layout_bg, BPAD, tags[seltag].layout.symbol);
|
||||||
|
|
||||||
|
bar_refresh(layoutsym);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Top/Bottom Bar Manage Function */
|
/* Top/Bottom Bar Manage Function */
|
||||||
void
|
void
|
||||||
updatebar(void)
|
updatebar(void)
|
||||||
{
|
{
|
||||||
int i , k, sp = 6;
|
/* Refresh bar color */
|
||||||
char buf[conf.ntag][256];
|
|
||||||
char p[4];
|
|
||||||
|
|
||||||
bar_refresh_color(bar);
|
bar_refresh_color(bar);
|
||||||
|
|
||||||
/* TAGLIST */
|
/* Draw taglist */
|
||||||
{
|
draw_taglist(bar->dr);
|
||||||
for(i = 0; i < conf.ntag; ++i)
|
|
||||||
{
|
|
||||||
/* Make the tags string */
|
|
||||||
ITOA(p, clientpertag(i+1));
|
|
||||||
sprintf(buf[i], "%s<%s>", tags[i+1].name, (clientpertag(i+1)) ? p : "");
|
|
||||||
taglen[i+1] = taglen[i] + textw(buf[i]) + sp;
|
|
||||||
|
|
||||||
/* Draw tags */
|
/* Draw layout symbol */
|
||||||
xprint(bar->dr, taglen[i], fonth,
|
draw_layoutsym(taglen[conf.ntag], bary);
|
||||||
((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text),
|
|
||||||
((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), sp-1, -sp, buf[i]);
|
|
||||||
|
|
||||||
/* Tags border separation */
|
|
||||||
XSetForeground(dpy, gc, conf.colors.tagbord);
|
|
||||||
if(i > 0)
|
|
||||||
XFillRectangle(dpy, bar->dr, gc, taglen[i]-sp+1, 0, conf.tagbordwidth, barheight);
|
|
||||||
}
|
|
||||||
XFillRectangle(dpy, bar->dr, gc, taglen[conf.ntag]-sp+1, 0, conf.tagbordwidth, barheight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Layout symbol */
|
|
||||||
{
|
|
||||||
xprint(bar->dr, taglen[conf.ntag] - sp/3, fonth,
|
|
||||||
conf.colors.layout_fg, conf.colors.layout_bg,
|
|
||||||
0, 0, tags[seltag].layout.symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Draw status text */
|
/* Draw status text */
|
||||||
k = textw(bartext);
|
xprint(bar->dr, mw - textw(bartext), fonth, conf.colors.text, conf.colors.bar, 0, bartext);
|
||||||
xprint(bar->dr, mw-k, fonth, conf.colors.text, conf.colors.bar, 0, 0, bartext);
|
|
||||||
|
|
||||||
/* Bar border */
|
/* Bar border */
|
||||||
if(conf.tagbordwidth)
|
if(conf.tagbordwidth)
|
||||||
@@ -147,11 +181,11 @@ updatebar(void)
|
|||||||
XSetForeground(dpy, gc, conf.colors.tagbord);
|
XSetForeground(dpy, gc, conf.colors.tagbord);
|
||||||
XFillRectangle(dpy, bar->dr, gc, 0,
|
XFillRectangle(dpy, bar->dr, gc, 0,
|
||||||
((conf.bartop) ? barheight-1: 0), mw, 1);
|
((conf.bartop) ? barheight-1: 0), mw, 1);
|
||||||
XFillRectangle(dpy, bar->dr, gc, mw-k-5, 0, 1, barheight);
|
XFillRectangle(dpy, bar->dr, gc, mw - textw(bartext) - 5, 0, 1, barheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Refresh the bar */
|
||||||
bar_refresh(bar);
|
bar_refresh(bar);
|
||||||
XSync(dpy, False);
|
|
||||||
|
|
||||||
/* Update Bar Buttons */
|
/* Update Bar Buttons */
|
||||||
updatebutton(True);
|
updatebutton(True);
|
||||||
@@ -167,13 +201,8 @@ updatebutton(Bool c)
|
|||||||
{
|
{
|
||||||
int i, j, x, pm = 0;
|
int i, j, x, pm = 0;
|
||||||
int y = 0, hi = 0;
|
int y = 0, hi = 0;
|
||||||
XSetWindowAttributes at;
|
|
||||||
|
|
||||||
at.override_redirect = 1;
|
j = taglen[conf.ntag] + textw(tags[seltag].layout.symbol) + PAD;
|
||||||
at.background_pixmap = ParentRelative;
|
|
||||||
at.event_mask = ButtonPressMask | ExposureMask;
|
|
||||||
|
|
||||||
j = taglen[conf.ntag] + textw(tags[seltag].layout.symbol) + xftfont->ascent;
|
|
||||||
|
|
||||||
if(!conf.bartop)
|
if(!conf.bartop)
|
||||||
y = bary + 1;
|
y = bary + 1;
|
||||||
@@ -186,16 +215,15 @@ updatebutton(Bool c)
|
|||||||
if(!(x = conf.barbutton[i].x))
|
if(!(x = conf.barbutton[i].x))
|
||||||
{
|
{
|
||||||
if(i)
|
if(i)
|
||||||
pm += textw(conf.barbutton[i-1].text);
|
pm += textw(conf.barbutton[i-1].text) + BPAD;
|
||||||
x = (!i) ? j : j + pm;
|
x = (!i) ? j : j + pm;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!c)
|
if(!c)
|
||||||
{
|
{
|
||||||
conf.barbutton[i].bw = bar_create(x, y,
|
conf.barbutton[i].bw = bar_create(x, y, textw(conf.barbutton[i].text) + BPAD,
|
||||||
textw(conf.barbutton[i].text),
|
barheight + hi, 0,
|
||||||
barheight + hi,
|
conf.barbutton[i].bg_color);
|
||||||
0, conf.barbutton[i].bg_color);
|
|
||||||
XMapRaised(dpy, conf.barbutton[i].bw->win);
|
XMapRaised(dpy, conf.barbutton[i].bw->win);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +231,9 @@ updatebutton(Bool c)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
bar_refresh_color(conf.barbutton[i].bw);
|
bar_refresh_color(conf.barbutton[i].bw);
|
||||||
bar_moveresize(conf.barbutton[i].bw, x, y, textw(conf.barbutton[i].text), barheight + hi);
|
bar_moveresize(conf.barbutton[i].bw, x, y, textw(conf.barbutton[i].text) + BPAD, barheight + hi);
|
||||||
xprint(conf.barbutton[i].bw->dr, 1, fonth, conf.barbutton[i].fg_color,
|
xprint(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color,
|
||||||
conf.barbutton[i].bg_color, 0, 0, conf.barbutton[i].text);
|
conf.barbutton[i].bg_color, BPAD, conf.barbutton[i].text);
|
||||||
bar_refresh(conf.barbutton[i].bw);
|
bar_refresh(conf.barbutton[i].bw);
|
||||||
}
|
}
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
|||||||
47
event.c
47
event.c
@@ -189,34 +189,27 @@ buttonpress(XEvent ev)
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ****** */
|
|
||||||
/* LAYOUT */
|
|
||||||
/* ****** */
|
|
||||||
{
|
|
||||||
|
|
||||||
if(ev.xbutton.x >= taglen[conf.ntag] - 3
|
|
||||||
&& ev.xbutton.x < taglen[conf.ntag] +
|
|
||||||
textw(tags[seltag].layout.symbol) - 3)
|
|
||||||
{
|
|
||||||
/* BUTTON 1 / 4 */
|
|
||||||
{
|
|
||||||
if(ev.xbutton.button == Button1
|
|
||||||
|| ev.xbutton.button == Button4)
|
|
||||||
layoutswitch(True);
|
|
||||||
}
|
|
||||||
/* BUTTON 3 / 5 */
|
|
||||||
{
|
|
||||||
if(ev.xbutton.button == Button3
|
|
||||||
|| ev.xbutton.button == Button5)
|
|
||||||
layoutswitch(False);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ****** */
|
||||||
|
/* LAYOUT */
|
||||||
|
/* ****** */
|
||||||
|
else if(ev.xbutton.window == layoutsym->win)
|
||||||
|
{
|
||||||
|
/* BUTTON 1 / 4 */
|
||||||
|
{
|
||||||
|
if(ev.xbutton.button == Button1
|
||||||
|
|| ev.xbutton.button == Button4)
|
||||||
|
layoutswitch(True);
|
||||||
|
}
|
||||||
|
/* BUTTON 3 / 5 */
|
||||||
|
{
|
||||||
|
if(ev.xbutton.button == Button3
|
||||||
|
|| ev.xbutton.button == Button5)
|
||||||
|
layoutswitch(False);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* **** */
|
/* **** */
|
||||||
|
|||||||
16
util.c
16
util.c
@@ -89,7 +89,7 @@ textw(const char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xprint(Drawable d, int x, int y, char* fg, uint bg, int decx, int decw, char *str)
|
xprint(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str)
|
||||||
{
|
{
|
||||||
XftColor xftcolor;
|
XftColor xftcolor;
|
||||||
XftDraw *xftd;
|
XftDraw *xftd;
|
||||||
@@ -99,14 +99,16 @@ xprint(Drawable d, int x, int y, char* fg, uint bg, int decx, int decw, char *st
|
|||||||
|
|
||||||
/* Color the text font */
|
/* Color the text font */
|
||||||
XSetForeground(dpy, gc, bg);
|
XSetForeground(dpy, gc, bg);
|
||||||
XFillRectangle(dpy, d, gc, x - decx, 0, textw(str) - decw, barheight);
|
XFillRectangle(dpy, d, gc, x - pad/2, 0, textw(str) + pad, barheight);
|
||||||
|
|
||||||
/* Alloc text color and draw */
|
/* Alloc text color */
|
||||||
XftColorAllocName(dpy,
|
XftColorAllocName(dpy, DefaultVisual(dpy, screen),
|
||||||
DefaultVisual(dpy, screen),
|
DefaultColormap(dpy, screen), fg, &xftcolor);
|
||||||
DefaultColormap(dpy, screen),
|
|
||||||
fg, &xftcolor);
|
/* Draw the text */
|
||||||
XftDrawStringUtf8(xftd, &xftcolor, xftfont, x, y, (FcChar8 *)str, strlen(str));
|
XftDrawStringUtf8(xftd, &xftcolor, xftfont, x, y, (FcChar8 *)str, strlen(str));
|
||||||
|
|
||||||
|
/* Free the text color */
|
||||||
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor);
|
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
4
wmfs.c
4
wmfs.c
@@ -199,6 +199,7 @@ focus(Client *c)
|
|||||||
for(cc = clients; cc; cc = cc->next)
|
for(cc = clients; cc; cc = cc->next)
|
||||||
if(!ishide(cc))
|
if(!ishide(cc))
|
||||||
updatetitle(cc);
|
updatetitle(cc);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +349,6 @@ init(void)
|
|||||||
mh = DisplayHeight (dpy, screen);
|
mh = DisplayHeight (dpy, screen);
|
||||||
|
|
||||||
/* INIT TAG / LAYOUT ATTRIBUTE */
|
/* INIT TAG / LAYOUT ATTRIBUTE */
|
||||||
taglen[0] = 3;
|
|
||||||
seltag = 1;
|
seltag = 1;
|
||||||
for(i = 0; i < conf.ntag + 1; ++i)
|
for(i = 0; i < conf.ntag + 1; ++i)
|
||||||
tags[i] = conf.tag[i - 1];
|
tags[i] = conf.tag[i - 1];
|
||||||
@@ -934,7 +934,7 @@ updatetitle(Client *c)
|
|||||||
bar_refresh_color(c->tbar);
|
bar_refresh_color(c->tbar);
|
||||||
xprint(c->tbar->dr, 3, ((fonth - xftfont->descent) + ((conf.ttbarheight - fonth) / 2)),
|
xprint(c->tbar->dr, 3, ((fonth - xftfont->descent) + ((conf.ttbarheight - fonth) / 2)),
|
||||||
((c == sel) ? conf.colors.ttbar_text_focus : conf.colors.ttbar_text_normal),
|
((c == sel) ? conf.colors.ttbar_text_focus : conf.colors.ttbar_text_normal),
|
||||||
conf.colors.bar, 0, 0, c->title);
|
conf.colors.bar, 0, c->title);
|
||||||
bar_refresh(c->tbar);
|
bar_refresh(c->tbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
wmfs.h
7
wmfs.h
@@ -66,6 +66,8 @@
|
|||||||
#define BUTH conf.ttbarheight - 6
|
#define BUTH conf.ttbarheight - 6
|
||||||
#define BUTX(x, w) x + w - BUTH/400
|
#define BUTX(x, w) x + w - BUTH/400
|
||||||
#define MAXLAYOUT 3
|
#define MAXLAYOUT 3
|
||||||
|
#define PAD 8
|
||||||
|
#define BPAD 2
|
||||||
|
|
||||||
/* Client Structure & Typedef */
|
/* Client Structure & Typedef */
|
||||||
typedef const char* uicb_t;
|
typedef const char* uicb_t;
|
||||||
@@ -219,6 +221,8 @@ void bar_delete(BarWindow *bw);
|
|||||||
void bar_moveresize(BarWindow *bw, int x, int y, uint w, uint h);
|
void bar_moveresize(BarWindow *bw, int x, int y, uint w, uint h);
|
||||||
void bar_refresh_color(BarWindow *bw);
|
void bar_refresh_color(BarWindow *bw);
|
||||||
void bar_refresh(BarWindow *bw);
|
void bar_refresh(BarWindow *bw);
|
||||||
|
void draw_taglist(Drawable dr);
|
||||||
|
void draw_layoutsym(int x, int y);
|
||||||
void updatebar(void);
|
void updatebar(void);
|
||||||
void updatebutton(Bool c);
|
void updatebutton(Bool c);
|
||||||
|
|
||||||
@@ -245,7 +249,7 @@ ulong getcolor(char *color);
|
|||||||
ushort textw(const char *text);
|
ushort textw(const char *text);
|
||||||
void xprint(Drawable d, int x, int y,
|
void xprint(Drawable d, int x, int y,
|
||||||
char* fg, uint bg,
|
char* fg, uint bg,
|
||||||
int decx, int decw, char* str);
|
int pad, char* str);
|
||||||
void uicb_spawn(uicb_t);
|
void uicb_spawn(uicb_t);
|
||||||
|
|
||||||
/* tag.c */
|
/* tag.c */
|
||||||
@@ -330,6 +334,7 @@ XftFont *xftfont;
|
|||||||
|
|
||||||
/* Bar / Tags */
|
/* Bar / Tags */
|
||||||
BarWindow *bar;
|
BarWindow *bar;
|
||||||
|
BarWindow *layoutsym;
|
||||||
Tag tags[MAXTAG];
|
Tag tags[MAXTAG];
|
||||||
int barheight;
|
int barheight;
|
||||||
char bartext[1024];
|
char bartext[1024];
|
||||||
|
|||||||
Reference in New Issue
Block a user