rework draw stuff

- remove display from DrawCtx
- add Drawable in statusbar
This commit is contained in:
Julien Danjou 2007-12-30 12:26:11 +01:00
parent 34ddf418ad
commit 1021f86e24
6 changed files with 32 additions and 34 deletions

View File

@ -99,8 +99,10 @@ typedef struct
Window window; Window window;
/** Screen */ /** Screen */
int screen; int screen;
/** Screen */ /** Widget list */
Widget *widgets; Widget *widgets;
/** Drawable */
Drawable drawable;
} Statusbar; } Statusbar;
typedef struct Client Client; typedef struct Client Client;

41
draw.c
View File

@ -30,29 +30,20 @@
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
DrawCtx * DrawCtx *
draw_get_context(Display *display, int phys_screen, int width, int height) draw_get_context(Drawable drawable, int phys_screen, int width, int height)
{ {
DrawCtx *d; DrawCtx *d = p_new(DrawCtx, 1);
d = p_new(DrawCtx, 1);
d->phys_screen = phys_screen; d->phys_screen = phys_screen;
d->display = display;
d->width = width; d->width = width;
d->height = height; d->height = height;
d->depth = DefaultDepth(display, phys_screen); d->depth = DefaultDepth(globalconf.display, phys_screen);
d->visual = DefaultVisual(display, phys_screen); d->visual = DefaultVisual(globalconf.display, phys_screen);
d->drawable = XCreatePixmap(display, d->drawable = drawable;
RootWindow(display, phys_screen),
width, height, d->depth);
return d; return d;
}; };
void
draw_free_context(DrawCtx *ctx)
{
XFreePixmap(ctx->display, ctx->drawable);
p_delete(&ctx);
}
void void
draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *text, XColor fg, XColor bg) draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *text, XColor fg, XColor bg)
{ {
@ -67,7 +58,7 @@ draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *t
if(!a_strlen(text)) if(!a_strlen(text))
return; return;
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create(surface); cr = cairo_create(surface);
font_face = cairo_ft_font_face_create_for_pattern(font->pattern); font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
cairo_set_font_face(cr, font_face); cairo_set_font_face(cr, font_face);
@ -107,7 +98,7 @@ draw_rectangle(DrawCtx *ctx, int x, int y, int w, int h, Bool filled, XColor col
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface); cr = cairo_create (surface);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
@ -133,7 +124,7 @@ draw_circle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color)
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface); cr = cairo_create (surface);
cairo_set_line_width(cr, 1.0); cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0); cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
@ -158,7 +149,7 @@ void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h,
cairo_surface_t *surface, *source; cairo_surface_t *surface, *source;
cairo_t *cr; cairo_t *cr;
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0); source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0);
cr = cairo_create (surface); cr = cairo_create (surface);
if(wanted_h > 0 && h > 0) if(wanted_h > 0 && h > 0)
@ -184,7 +175,7 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename)
cairo_surface_t *surface, *source; cairo_surface_t *surface, *source;
cairo_t *cr; cairo_t *cr;
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); source = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_image_surface_create_from_png(filename); surface = cairo_image_surface_create_from_png(filename);
cr = cairo_create (source); cr = cairo_create (source);
if(wanted_h > 0 && (h = cairo_image_surface_get_height(surface)) > 0) if(wanted_h > 0 && (h = cairo_image_surface_get_height(surface)) > 0)
@ -226,12 +217,12 @@ draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
cairo_t *cr; cairo_t *cr;
Drawable newdrawable; Drawable newdrawable;
newdrawable = XCreatePixmap(ctx->display, newdrawable = XCreatePixmap(globalconf.display,
RootWindow(ctx->display, screen), RootWindow(globalconf.display, screen),
ctx->height, ctx->width, ctx->height, ctx->width,
ctx->depth); ctx->depth);
surface = cairo_xlib_surface_create(ctx->display, newdrawable, ctx->visual, ctx->height, ctx->width); surface = cairo_xlib_surface_create(globalconf.display, newdrawable, ctx->visual, ctx->height, ctx->width);
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); source = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface); cr = cairo_create (surface);
cairo_translate(cr, tx, ty); cairo_translate(cr, tx, ty);

4
draw.h
View File

@ -33,7 +33,6 @@ typedef struct
typedef struct typedef struct
{ {
Display *display;
Drawable drawable; Drawable drawable;
Visual *visual; Visual *visual;
int width; int width;
@ -42,8 +41,7 @@ typedef struct
int depth; int depth;
} DrawCtx; } DrawCtx;
DrawCtx *draw_get_context(Display*, int, int, int); DrawCtx *draw_get_context(Drawable, int, int, int);
void draw_free_context(DrawCtx*);
void draw_text(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); void draw_text(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg);
void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor); void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor);
void draw_circle(DrawCtx *, int, int, int, Bool, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor);

View File

@ -243,7 +243,7 @@ handle_event_enternotify(XEvent * e)
} }
void void
handle_event_expose(XEvent * e) handle_event_expose(XEvent *e)
{ {
XExposeEvent *ev = &e->xexpose; XExposeEvent *ev = &e->xexpose;
int screen; int screen;

View File

@ -45,7 +45,7 @@ statusbar_draw(int screen)
if(vscreen.statusbar->position == BarOff) if(vscreen.statusbar->position == BarOff)
return; return;
DrawCtx *ctx = draw_get_context(globalconf.display, phys_screen, DrawCtx *ctx = draw_get_context(vscreen.statusbar->drawable, phys_screen,
vscreen.statusbar->width, vscreen.statusbar->width,
vscreen.statusbar->height); vscreen.statusbar->height);
draw_rectangle(ctx, draw_rectangle(ctx,
@ -101,7 +101,7 @@ statusbar_draw(int screen)
DefaultGC(globalconf.display, phys_screen), 0, 0, DefaultGC(globalconf.display, phys_screen), 0, 0,
vscreen.statusbar->width, vscreen.statusbar->height, 0, 0); vscreen.statusbar->width, vscreen.statusbar->height, 0, 0);
draw_free_context(ctx); p_delete(&ctx);
XSync(globalconf.display, False); XSync(globalconf.display, False);
} }
@ -169,6 +169,13 @@ statusbar_init(int screen)
CWBackPixmap | CWBackPixmap |
CWEventMask, CWEventMask,
&wa); &wa);
statusbar->drawable = XCreatePixmap(globalconf.display,
RootWindow(globalconf.display, phys_screen),
statusbar->width, statusbar->height,
DefaultDepth(globalconf.display, phys_screen));
XDefineCursor(globalconf.display, XDefineCursor(globalconf.display,
statusbar->window, statusbar->window,
globalconf.cursor[CurNormal]); globalconf.cursor[CurNormal]);

View File

@ -61,8 +61,8 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
return widget->width; return widget->width;
} }
if(XGetWindowProperty(ctx->display, sel->win, if(XGetWindowProperty(globalconf.display, sel->win,
XInternAtom(ctx->display, "_NET_WM_ICON", False), XInternAtom(globalconf.display, "_NET_WM_ICON", False),
0L, LONG_MAX, False, XA_CARDINAL, &type, &format, 0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
&items, &rest, &wdata) != Success &items, &rest, &wdata) != Success
|| !wdata) || !wdata)