use a cache system for status bar

This commit is contained in:
Julien Danjou 2008-01-07 18:12:38 +01:00
parent dbb0456bed
commit 5c9291ff0b
18 changed files with 99 additions and 40 deletions

View File

@ -341,13 +341,13 @@ main(int argc, char *argv[])
if(csfd >= 0 && FD_ISSET(csfd, &rd)) if(csfd >= 0 && FD_ISSET(csfd, &rd))
switch (r = recv(csfd, buf, sizeof(buf)-1, MSG_TRUNC)) switch (r = recv(csfd, buf, sizeof(buf)-1, MSG_TRUNC))
{ {
case -1: case -1:
perror("awesome: error reading UNIX domain socket"); perror("awesome: error reading UNIX domain socket");
csfd = -1; csfd = -1;
break; break;
case 0: case 0:
break; break;
default: default:
if(r >= ssizeof(buf)) if(r >= ssizeof(buf))
break; break;
buf[r] = '\0'; buf[r] = '\0';
@ -360,6 +360,8 @@ main(int argc, char *argv[])
if(handler[ev.type]) if(handler[ev.type])
handler[ev.type](&ev); /* call handler */ handler[ev.type](&ev); /* call handler */
} }
statusbar_refresh();
} }
if(csfd > 0 && close(csfd)) if(csfd > 0 && close(csfd))

View File

@ -29,11 +29,11 @@
#include "rules.h" #include "rules.h"
#include "util.h" #include "util.h"
#include "xutil.h" #include "xutil.h"
#include "statusbar.h"
#include "window.h" #include "window.h"
#include "focus.h" #include "focus.h"
#include "ewmh.h" #include "ewmh.h"
#include "screen.h" #include "screen.h"
#include "widget.h"
#include "layouts/floating.h" #include "layouts/floating.h"
@ -244,6 +244,7 @@ focus(Client *c, Bool selscreen, int screen)
/* unfocus current selected client */ /* unfocus current selected client */
if(globalconf.focus->client) if(globalconf.focus->client)
{ {
widget_invalidate_cache(globalconf.focus->client->screen, WIDGET_CACHE_CLIENTS);
window_grabbuttons(get_phys_screen(globalconf.focus->client->screen), window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
globalconf.focus->client->win, False, True); globalconf.focus->client->win, False, True);
XSetWindowBorder(globalconf.display, globalconf.focus->client->win, XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
@ -274,7 +275,7 @@ focus(Client *c, Bool selscreen, int screen)
/* save sel in focus history */ /* save sel in focus history */
focus_add_client(c); focus_add_client(c);
statusbar_draw_all(screen); widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
if(globalconf.focus->client) if(globalconf.focus->client)
{ {
@ -889,19 +890,21 @@ client_maximize(Client *c, Area geometry)
* coords */ * coords */
c->isfloating = True; c->isfloating = True;
restack(c->screen); restack(c->screen);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }
else if(c->wasfloating) else if(c->wasfloating)
{ {
c->isfloating = True; c->isfloating = True;
client_resize(c, c->m_geometry, False); client_resize(c, c->m_geometry, False);
restack(c->screen); restack(c->screen);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }
else else
{ {
c->isfloating = False; c->isfloating = False;
arrange(c->screen); arrange(c->screen);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }
statusbar_draw_all(c->screen);
} }
/** Toggle maximize for client /** Toggle maximize for client

View File

@ -114,6 +114,12 @@ struct Widget
Button *buttons; Button *buttons;
/** Font */ /** Font */
XftFont *font; XftFont *font;
/** Cache */
struct
{
Bool needs_update;
int flags;
} cache;
/** Next widget */ /** Next widget */
Widget *next; Widget *next;
}; };

11
event.c
View File

@ -34,6 +34,7 @@
#include "mouse.h" #include "mouse.h"
#include "ewmh.h" #include "ewmh.h"
#include "client.h" #include "client.h"
#include "widget.h"
#include "layouts/tile.h" #include "layouts/tile.h"
#include "layouts/floating.h" #include "layouts/floating.h"
@ -166,10 +167,10 @@ handle_event_configurerequest(XEvent * e)
if(old_screen != c->screen) if(old_screen != c->screen)
{ {
statusbar_draw_all(old_screen); widget_invalidate_cache(old_screen, WIDGET_CACHE_CLIENTS);
arrange(old_screen); arrange(old_screen);
} }
statusbar_draw_all(c->screen); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
arrange(c->screen); arrange(c->screen);
} }
else else
@ -213,7 +214,7 @@ handle_event_configurenotify(XEvent * e)
globalconf.screens[screen].statusbar->width, globalconf.screens[screen].statusbar->width,
globalconf.screens[screen].statusbar->height); globalconf.screens[screen].statusbar->height);
statusbar_draw_all(screen); widget_invalidate_cache(screen, WIDGET_CACHE_ALL);
arrange(screen); arrange(screen);
} }
} }
@ -375,14 +376,14 @@ handle_event_propertynotify(XEvent * e)
break; break;
case XA_WM_HINTS: case XA_WM_HINTS:
client_updatewmhints(c); client_updatewmhints(c);
statusbar_draw_all(c->screen); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
break; break;
} }
if(ev->atom == XA_WM_NAME || ev->atom == XInternAtom(globalconf.display, "_NET_WM_NAME", False)) if(ev->atom == XA_WM_NAME || ev->atom == XInternAtom(globalconf.display, "_NET_WM_NAME", False))
{ {
client_updatetitle(c); client_updatetitle(c);
if(c == globalconf.focus->client) if(c == globalconf.focus->client)
statusbar_draw_all(c->screen); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }
} }
} }

4
ewmh.c
View File

@ -28,7 +28,7 @@
#include "focus.h" #include "focus.h"
#include "screen.h" #include "screen.h"
#include "client.h" #include "client.h"
#include "statusbar.h" #include "widget.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -265,7 +265,7 @@ ewmh_process_state_atom(Client *c, Atom state, int set)
c->ismax = True; c->ismax = True;
c->isfloating = True; c->isfloating = True;
} }
statusbar_draw_all(c->screen); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
client_resize(c, geometry, False); client_resize(c, geometry, False);
XRaiseWindow(globalconf.display, c->win); XRaiseWindow(globalconf.display, c->win);
arrange(c->screen); arrange(c->screen);

View File

@ -26,7 +26,7 @@
#include "util.h" #include "util.h"
#include "xutil.h" #include "xutil.h"
#include "focus.h" #include "focus.h"
#include "statusbar.h" #include "widget.h"
#include "ewmh.h" #include "ewmh.h"
#include "client.h" #include "client.h"
#include "screen.h" #include "screen.h"
@ -163,8 +163,6 @@ restack(int screen)
XWindowChanges wc; XWindowChanges wc;
Tag **curtags; Tag **curtags;
statusbar_draw_all(screen);
if(!sel) if(!sel)
return; return;
@ -253,7 +251,7 @@ uicb_tag_setlayout(int screen, char *arg)
if(globalconf.focus->client) if(globalconf.focus->client)
arrange(screen); arrange(screen);
else else
statusbar_draw_all(screen); widget_invalidate_cache(screen, WIDGET_CACHE_LAYOUTS);
saveawesomeprops(screen); saveawesomeprops(screen);
} }
@ -279,6 +277,7 @@ uicb_client_togglefloating(int screen, char *arg)
else if(sel->ismax) else if(sel->ismax)
client_resize(sel, sel->m_geometry, False); client_resize(sel, sel->m_geometry, False);
widget_invalidate_cache(sel->screen, WIDGET_CACHE_CLIENTS);
client_saveprops(sel); client_saveprops(sel);
arrange(screen); arrange(screen);
} }

View File

@ -28,7 +28,6 @@
#include "util.h" #include "util.h"
#include "event.h" #include "event.h"
#include "window.h" #include "window.h"
#include "statusbar.h"
#include "client.h" #include "client.h"
#include "layouts/floating.h" #include "layouts/floating.h"
#include "layouts/tile.h" #include "layouts/tile.h"
@ -78,7 +77,6 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
RootWindow(globalconf.display, phys_screen), RootWindow(globalconf.display, phys_screen),
&dummy, &dummy, &x1, &y, &di, &di, &dui); &dummy, &dummy, &x1, &y, &di, &di, &dui);
c->ismax = False; c->ismax = False;
statusbar_draw_all(c->screen);
for(;;) for(;;)
{ {
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);

View File

@ -25,7 +25,6 @@
#include "screen.h" #include "screen.h"
#include "tag.h" #include "tag.h"
#include "focus.h" #include "focus.h"
#include "statusbar.h"
#include "client.h" #include "client.h"
#include "layouts/floating.h" #include "layouts/floating.h"
@ -254,10 +253,6 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize)
} }
focus(c, True, c->screen); focus(c, True, c->screen);
/* redraw statusbar on all screens */
statusbar_draw_all(old_screen);
statusbar_draw_all(new_screen);
} }
/** Move mouse pointer to x_org and y_xorg of specified screen /** Move mouse pointer to x_org and y_xorg of specified screen

View File

@ -30,13 +30,13 @@
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
static void void
statusbar_draw(Statusbar *statusbar) statusbar_draw(Statusbar *statusbar)
{ {
int phys_screen = get_phys_screen(statusbar->screen); int phys_screen = get_phys_screen(statusbar->screen);
Widget *widget, *last_drawn = NULL; Widget *widget, *last_drawn = NULL;
int left = 0, right = 0; int left = 0, right = 0;
/* don't waste our time */ /* don't waste our time */
if(statusbar->position == Off) if(statusbar->position == Off)
return; return;
@ -52,12 +52,16 @@ statusbar_draw(Statusbar *statusbar)
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if (widget->alignment == AlignLeft) if (widget->alignment == AlignLeft)
{
widget->cache.needs_update = False;
left += widget->draw(widget, ctx, left, (left + right)); left += widget->draw(widget, ctx, left, (left + right));
}
/* renders right widget from last to first */ /* renders right widget from last to first */
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if (widget->alignment == AlignRight && last_drawn == widget->next) if (widget->alignment == AlignRight && last_drawn == widget->next)
{ {
widget->cache.needs_update = False;
right += widget->draw(widget, ctx, right, (left + right)); right += widget->draw(widget, ctx, right, (left + right));
last_drawn = widget; last_drawn = widget;
widget = statusbar->widgets; widget = statusbar->widgets;
@ -65,7 +69,10 @@ statusbar_draw(Statusbar *statusbar)
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if (widget->alignment == AlignFlex) if (widget->alignment == AlignFlex)
{
widget->cache.needs_update = False;
left += widget->draw(widget, ctx, left, (left + right)); left += widget->draw(widget, ctx, left, (left + right));
}
if(statusbar->position == Right if(statusbar->position == Right
|| statusbar->position == Left) || statusbar->position == Left)
@ -87,15 +94,6 @@ statusbar_draw(Statusbar *statusbar)
statusbar_display(statusbar); statusbar_display(statusbar);
} }
void
statusbar_draw_all(int screen)
{
Statusbar *statusbar;
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
statusbar_draw(statusbar);
}
void void
statusbar_display(Statusbar *statusbar) statusbar_display(Statusbar *statusbar)
{ {
@ -243,6 +241,26 @@ statusbar_update_position(Statusbar *statusbar)
while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev)); while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
} }
void
statusbar_refresh()
{
int screen;
Statusbar *statusbar;
Widget *widget;
for(screen = 0; screen < get_screen_count(); screen++)
for(statusbar = globalconf.screens[screen].statusbar;
statusbar;
statusbar = statusbar->next)
for(widget = statusbar->widgets; widget; widget = widget->next)
if(widget->cache.needs_update)
{
statusbar_draw(statusbar);
break;
}
}
Position Position
statusbar_get_position_from_str(const char *pos) statusbar_get_position_from_str(const char *pos)
{ {
@ -269,7 +287,6 @@ get_statusbar_byname(int screen, const char *name)
return NULL; return NULL;
} }
static void static void
statusbar_toggle(Statusbar *statusbar) statusbar_toggle(Statusbar *statusbar)
{ {
@ -283,7 +300,7 @@ statusbar_toggle(Statusbar *statusbar)
/** Toggle statusbar /** Toggle statusbar
* \param screen Screen ID * \param screen Screen ID
* \param arg Unused * \param arg statusbar name
* \ingroup ui_callback * \ingroup ui_callback
*/ */
void void

View File

@ -24,7 +24,8 @@
#include "config.h" #include "config.h"
void statusbar_draw_all(int); void statusbar_refresh(void);
void statusbar_draw(Statusbar *);
void statusbar_init(Statusbar *, int); void statusbar_init(Statusbar *, int);
void statusbar_display(Statusbar *); void statusbar_display(Statusbar *);
Position statusbar_get_position_from_str(const char *); Position statusbar_get_position_from_str(const char *);

2
uicb.c
View File

@ -144,7 +144,7 @@ parse_control(char *cmd)
if(!a_strlen(cmd)) if(!a_strlen(cmd))
return -1; return -1;
while((p = strchr(curcmd, '\n'))) while((p = strchr(curcmd, '\n')))
{ {
*p = '\0'; *p = '\0';

View File

@ -122,6 +122,19 @@ widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config)
widget->user_supplied_y = (widget->area.y != (int) 0xffffffff); widget->user_supplied_y = (widget->area.y != (int) 0xffffffff);
} }
void
widget_invalidate_cache(int screen, int flags)
{
Statusbar *statusbar;
Widget *widget;
for(statusbar = globalconf.screens[screen].statusbar;
statusbar;
statusbar = statusbar->next)
for(widget = statusbar->widgets; widget; widget = widget->next)
widget->cache.needs_update = (widget->cache.flags & flags);
}
/** Send command to widget /** Send command to widget
* \param screen Screen ID * \param screen Screen ID
* \param arg Widget command. Syntax depends on specific widget. * \param arg Widget command. Syntax depends on specific widget.
@ -166,7 +179,8 @@ uicb_widget_tell(int screen, char *arg)
else else
widget->tell(widget, NULL); widget->tell(widget, NULL);
statusbar_draw_all(screen); widget->cache.needs_update = True;
return; return;
} }

View File

@ -27,8 +27,14 @@
#include "config.h" #include "config.h"
#define WIDGET_CACHE_CLIENTS 1<<0
#define WIDGET_CACHE_LAYOUTS 1<<1
#define WIDGET_CACHE_TAGS 1<<2
#define WIDGET_CACHE_ALL (WIDGET_CACHE_CLIENTS | WIDGET_CACHE_LAYOUTS | WIDGET_CACHE_TAGS)
typedef Widget *(WidgetConstructor)(Statusbar *, cfg_t *); typedef Widget *(WidgetConstructor)(Statusbar *, cfg_t *);
void widget_invalidate_cache(int, int);
int widget_calculate_offset(int, int, int, int); int widget_calculate_offset(int, int, int, int);
void widget_calculate_alignments(Widget *); void widget_calculate_alignments(Widget *);
void widget_common_new(Widget*, Statusbar *, cfg_t *); void widget_common_new(Widget*, Statusbar *, cfg_t *);

View File

@ -108,6 +108,9 @@ focustitle_new(Statusbar *statusbar, cfg_t *config)
if(!w->font) if(!w->font)
w->font = globalconf.screens[statusbar->screen].font; w->font = globalconf.screens[statusbar->screen].font;
/* Set cache property */
w->cache.flags = WIDGET_CACHE_CLIENTS | WIDGET_CACHE_TAGS;
return w; return w;
} }

View File

@ -64,6 +64,10 @@ layoutinfo_new(Statusbar *statusbar, cfg_t* config)
w = p_new(Widget, 1); w = p_new(Widget, 1);
widget_common_new(w, statusbar, config); widget_common_new(w, statusbar, config);
w->draw = layoutinfo_draw; w->draw = layoutinfo_draw;
/* Set cache property */
w->cache.flags = WIDGET_CACHE_LAYOUTS;
return w; return w;
} }

View File

@ -105,6 +105,9 @@ netwmicon_new(Statusbar *statusbar, cfg_t *config)
widget_common_new(w, statusbar, config); widget_common_new(w, statusbar, config);
w->draw = netwmicon_draw; w->draw = netwmicon_draw;
/* Set cache property */
w->cache.flags = WIDGET_CACHE_CLIENTS;
return w; return w;
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -182,6 +182,10 @@ taglist_new(Statusbar *statusbar, cfg_t *config)
widget_common_new(w, statusbar, config); widget_common_new(w, statusbar, config);
w->draw = taglist_draw; w->draw = taglist_draw;
w->button_press = taglist_button_press; w->button_press = taglist_button_press;
/* Set cache property */
w->cache.flags = WIDGET_CACHE_TAGS;
return w; return w;
} }

View File

@ -253,6 +253,9 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
if(!w->font) if(!w->font)
w->font = globalconf.screens[statusbar->screen].font; w->font = globalconf.screens[statusbar->screen].font;
/* Set cache property */
w->cache.flags = WIDGET_CACHE_CLIENTS;
return w; return w;
} }