Infobar: Improve selbar render: draw it on infobar barwin directly

This commit is contained in:
Martin Duquesnoy 2011-08-04 09:00:24 +02:00
parent a501bd1127
commit 48bdc94538
6 changed files with 75 additions and 73 deletions

View File

@ -295,13 +295,13 @@ client_focus(Client *c)
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
if(conf.bars.selbar)
infobar_draw_selbar(&infobar[sel->screen]);
_infobar_draw(&infobar[sel->screen]);
}
else
{
XSetInputFocus(dpy, ROOT, RevertToPointerRoot, CurrentTime);
if(conf.bars.selbar)
infobar_draw_selbar(&infobar[selscreen]);
_infobar_draw(&infobar[selscreen]);
}
return;
@ -461,7 +461,7 @@ client_get_name(Client *c)
frame_update(c);
if(conf.bars.selbar && c == sel)
infobar_draw_selbar(&infobar[c->screen]);
_infobar_draw(&infobar[c->screen]);
return;
}

View File

@ -41,11 +41,14 @@ buttonpress(XEvent *e)
{
XButtonEvent *ev = &e->xbutton;
StatusMouse *sm;
InfoBar *ib;
Client *c;
int i, j, n;
screen_get_sel();
ib = &infobar[selscreen];
/* If the mouse is on a not selected client and you click on it. */
if(((c = client_gb_win(ev->window)) || (c = client_gb_titlebar(ev->window))) && c != sel
&& (ev->button == Button1 || ev->button == Button2 || ev->button == Button3))
@ -106,17 +109,19 @@ buttonpress(XEvent *e)
conf.bars.mouse[j].func(conf.bars.mouse[j].cmd);
/* Selbar */
if(conf.bars.selbar && ev->window == infobar[selscreen].selbar->win)
if(conf.bars.selbar && ev->window == ib->bar->win)
for(i = 0; i < conf.selbar.nmouse; ++i)
if(conf.selbar.mouse[i].tag == seltag[conf.selbar.mouse[i].screen]
|| conf.selbar.mouse[i].tag < 0)
|| conf.selbar.mouse[i].tag < 0)
if(ev->button == conf.selbar.mouse[i].button)
if(conf.selbar.mouse[i].func)
conf.selbar.mouse[i].func(conf.selbar.mouse[i].cmd);
if(ev->x >= ib->selbar_geo.x && ev->x <= ib->selbar_geo.x + ib->selbar_geo.width
&& ev->y >= ib->selbar_geo.y && ev->y <= ib->selbar_geo.y + ib->selbar_geo.height)
if(conf.selbar.mouse[i].func)
conf.selbar.mouse[i].func(conf.selbar.mouse[i].cmd);
/* Tags */
for(i = 1; i < conf.ntag[selscreen] + 1; ++i)
if(ev->window == infobar[selscreen].tags[i]->win)
if(ev->window == ib->tags[i]->win)
{
for(j = 0; j < tags[selscreen][i].nmouse; ++j)
if(ev->button == tags[selscreen][i].mouse[j].button)
@ -137,15 +142,15 @@ buttonpress(XEvent *e)
}
/* Layout button */
if(ev->window == infobar[selscreen].layout_button->win && conf.nlayout > 1)
if(ev->window == ib->layout_button->win && conf.nlayout > 1)
{
if(conf.layout_system && (ev->button == Button1 || ev->button == Button3)) /* True -> menu */
{
menulayout.y = spgeo[selscreen].y + infobar[selscreen].layout_button->geo.y + INFOBARH;
menulayout.x = infobar[selscreen].layout_button->geo.x + (sgeo[selscreen].x - BORDH);
menulayout.y = spgeo[selscreen].y + ib->layout_button->geo.y + INFOBARH;
menulayout.x = ib->layout_button->geo.x + (sgeo[selscreen].x - BORDH);
if(infobar[selscreen].geo.y != spgeo[selscreen].y)
menulayout.y = infobar[selscreen].geo.y - (INFOBARH * menulayout.nitem) - SHADH;
if(ib->geo.y != spgeo[selscreen].y)
menulayout.y = ib->geo.y - (INFOBARH * menulayout.nitem) - SHADH;
uicb_menu("menulayout");
}
@ -177,6 +182,7 @@ clientmessageevent(XEvent *e)
{
XClientMessageEvent *ev = &e->xclient;
Client *c;
InfoBar *ib;
Systray *sy;
int s, mess_t = 0;
Atom rt;
@ -257,7 +263,10 @@ clientmessageevent(XEvent *e)
if(XGetWindowProperty(EVDPY, ROOT, net_atom[mess_t], 0, 4096,
False, net_atom[utf8_string], &rt, &rf, &ir, &il, &ret) == Success)
{
statustext_handle(mess_t - wmfs_statustext, (char*)ret);
ib = &infobar[mess_t - wmfs_statustext];
free(ib->statustext);
ib->statustext = xstrdup((char*)ret);
_infobar_draw(ib);
XFree(ret);
}
}

View File

@ -107,13 +107,13 @@ infobar_init(void)
/* Selbar */
if(conf.bars.selbar)
ib->selbar = barwin_create(ib->bar->win,
((conf.layout_placement)
? (j + (PAD >> 1))
: ib->layout_button->geo.x + ib->layout_button->geo.width + (PAD >> 1)), 1,
(sel) ? textw(sel->title) + PAD : 1,
ib->geo.height - 2,
conf.selbar.bg, conf.selbar.fg, False, False, False);
{
ib->selbar_geo.x = (conf.layout_placement
? ib->tags_board->geo.x + ib->tags_board->geo.width + (PAD >> 1)
: ib->layout_button->geo.x + ib->layout_button->geo.width + (PAD >> 1));
ib->selbar_geo.y = 0;
ib->selbar_geo.height = ib->geo.height;
}
/* Map/Refresh all */
barwin_map(ib->bar);
@ -125,9 +125,6 @@ infobar_init(void)
if(conf.border.layout)
barwin_map_subwin(ib->layout_button);
if(conf.bars.selbar)
barwin_map(ib->selbar);
barwin_refresh_color(ib->bar);
barwin_refresh(ib->bar);
@ -172,6 +169,22 @@ infobar_draw_layout(InfoBar *i)
return;
}
/** Draw Infobar barwin (selbar / statustext)
*\param i Infobar pointer
*/
void
_infobar_draw(InfoBar *i)
{
barwin_refresh_color(i->bar);
infobar_draw_selbar(i);
statustext_handle(i);
barwin_refresh(i->bar);
return;
}
/** Draw the InfoBar
*\param i InfoBar pointer
*/
@ -180,9 +193,8 @@ infobar_draw(InfoBar *i)
{
infobar_draw_taglist(i);
infobar_draw_layout(i);
infobar_draw_selbar(i);
barwin_refresh_color(i->bar);
statustext_handle(i->screen, i->statustext);
_infobar_draw(i);
return;
}
@ -195,40 +207,35 @@ infobar_draw_selbar(InfoBar *i)
{
char *str = NULL;
int sc = i->screen;
bool f = False;
if(!conf.bars.selbar)
return;
if(!sel || (sel && sel->screen != sc))
{
barwin_unmap(i->selbar);
return;
}
else if(sel)
barwin_map(i->selbar);
str = sel->title;
/* Truncate string if too long */
if(conf.selbar.maxlength >= 0 && sel && sel->title)
{
str = NULL;
str = xcalloc(conf.selbar.maxlength + 4, sizeof(char));
strncpy(str, sel->title, conf.selbar.maxlength);
if(strlen(sel->title) > (size_t)conf.selbar.maxlength)
strcat(str, "...");
f = True;
}
barwin_resize(i->selbar, textw(str ? str : sel->title) + PAD, i->geo.height - 2);
barwin_move(i->selbar,
((conf.layout_placement)
? (i->tags_board->geo.x + i->tags_board->geo.width + (PAD >> 1))
: (i->layout_button->geo.x + i->layout_button->geo.width + (PAD >> 1))), 1);
XSetForeground(dpy, gc, conf.selbar.bg);
XFillRectangle(dpy, i->bar->dr, gc, i->selbar_geo.x, 0, (i->selbar_geo.width = textw(str) + PAD), i->geo.height);
draw_text(i->bar->dr, i->selbar_geo.x, FHINFOBAR - 1, conf.selbar.fg, str);
barwin_refresh_color(i->selbar);
barwin_draw_text(i->selbar, (PAD >> 1), FHINFOBAR - 1, ((str) ? str : sel->title));
barwin_refresh(i->selbar);
free(str);
if(f)
free(str);
return;
}
@ -350,9 +357,6 @@ infobar_destroy(void)
barwin_delete_subwin(infobar[sc].tags_board);
barwin_delete(infobar[sc].tags_board);
if(conf.bars.selbar)
barwin_delete(infobar[sc].selbar);
barwin_delete_subwin(infobar[sc].bar);
barwin_delete(infobar[sc].bar);
}
@ -391,7 +395,6 @@ infobar_set_position(int pos)
tags[selscreen][seltag[selscreen]].barpos = pos;
barwin_move(infobar[selscreen].bar, sgeo[selscreen].x - BORDH, infobar[selscreen].geo.y);
infobar_draw(&infobar[selscreen]);
arrange(selscreen, True);
return;

View File

@ -201,7 +201,7 @@ statustext_text(InfoBar *ib, char *str)
*\param str String
*/
static void
statustext_normal(int sc, InfoBar *ib, char *str)
statustext_normal(InfoBar *ib, char *str)
{
char strwc[MAXSTATUS] = { 0 };
char buf[MAXSTATUS] = { 0 };
@ -219,7 +219,7 @@ statustext_normal(int sc, InfoBar *ib, char *str)
strwc[j] = str[i];
/* Draw normal text without any blocks */
draw_text(ib->bar->dr, (sgeo[sc].width - SHADH) - (textw(strwc) + sw), FHINFOBAR, ib->bar->fg, strwc);
draw_text(ib->bar->dr, (sgeo[ib->screen].width - SHADH) - (textw(strwc) + sw), FHINFOBAR, ib->bar->fg, strwc);
if(n)
{
@ -234,12 +234,12 @@ statustext_normal(int sc, InfoBar *ib, char *str)
for(j = 0, ++i; str[i] != '\\'; col[j++] = str[i++]);
/* Draw a rectangle with the bar color to draw the text properly */
draw_rectangle(ib->bar->dr, (sgeo[sc].width - SHADH) - (tw + sw),
0, INFOBARH - (sgeo[sc].width - SHADH) - tw,
draw_rectangle(ib->bar->dr, (sgeo[ib->screen].width - SHADH) - (tw + sw),
0, INFOBARH - (sgeo[ib->screen].width - SHADH) - tw,
INFOBARH, conf.colors.bar);
/* Draw text with its color */
draw_text(ib->bar->dr, (sgeo[sc].width - SHADH) - (tw + sw), FHINFOBAR, col, &buf[k]);
draw_text(ib->bar->dr, (sgeo[ib->screen].width - SHADH) - (tw + sw), FHINFOBAR, col, &buf[k]);
strncpy(buf, strwc, sizeof(buf));
++i;
@ -254,18 +254,13 @@ statustext_normal(int sc, InfoBar *ib, char *str)
*\param str String
*/
void
statustext_handle(int sc, char *str)
statustext_handle(InfoBar *ib)
{
InfoBar *ib = &infobar[sc];
char *str;
StatusMouse *sm;
char *lastst;
/* If the str == the current statustext, return (not needed) */
if(!str)
return;
/* Free previous linked list of mouse bind */
if(!sc)
if(!ib->screen)
while(!SLIST_EMPTY(&smhead))
{
sm = SLIST_FIRST(&smhead);
@ -274,15 +269,10 @@ statustext_handle(int sc, char *str)
free(sm);
}
if(sc == conf.systray.screen)
if(ib->screen == conf.systray.screen)
sw = systray_get_width();
barwin_refresh_color(ib->bar);
/* save last status text address (for free at the end) */
lastst = ib->statustext;
ib->statustext = xstrdup(str);
str = xstrdup(ib->statustext);
/* Store rectangles, located text & images properties. */
statustext_rectangle(ib, str);
@ -290,12 +280,11 @@ statustext_handle(int sc, char *str)
statustext_text(ib, str);
/* Draw normal text (and possibly colored with \#color\ blocks) */
statustext_normal(sc, ib, str);
statustext_normal(ib, str);
sw = 0;
barwin_refresh(ib->bar);
free(lastst);
free(str);
return;
}

View File

@ -270,10 +270,10 @@ typedef struct
/* InfoBar Struct */
typedef struct
{
BarWindow *bar, *selbar;
BarWindow *bar;
BarWindow *layout_button;
BarWindow *tags_board, *tags[MAXTAG];
Geo geo;
Geo geo, selbar_geo;
int screen, position;
char *statustext;
bool need_update;

View File

@ -168,6 +168,7 @@ ushort textw(char *text);
/* infobar.c */
void infobar_init(void);
void infobar_draw_layout(InfoBar *i);
void _infobar_draw(InfoBar *i);
void infobar_draw(InfoBar *i);
void infobar_draw_selbar(InfoBar *i);
void infobar_draw_taglist(InfoBar *i);
@ -364,7 +365,7 @@ void uicb_screen_prev_sel(uicb_t);
/* status.c */
void statustext_mouse(char *str, Geo area, InfoBar *infobar);
void statustext_handle(int sc, char *str);
void statustext_handle(InfoBar *ib);
/* systray.c */
bool systray_acquire(void);