make draw functions more independant

This commit is contained in:
Julien Danjou 2008-01-24 18:43:24 +01:00
parent 82d9cec79d
commit 35803aff4c
6 changed files with 36 additions and 33 deletions

View File

@ -27,11 +27,11 @@
Bool client_isvisible(Client *, int);
Client * get_client_bywin(Client *, Window);
Client * get_client_byname(Client *, char *);
void client_ban(Client *);
void focus(Client *, Bool, int);
void client_ban(Client *);
void client_unban(Client *);
void client_manage(Window, XWindowAttributes *, int);
Bool client_resize(Client *, Area, Bool);
void client_unban(Client *);
void client_unmanage(Client *);
void client_updatewmhints(Client *);
void client_updatesizehints(Client *);

43
draw.c
View File

@ -23,11 +23,9 @@
#include <cairo-ft.h>
#include <cairo-xlib.h>
#include <math.h>
#include "structs.h"
#include "draw.h"
#include "common/util.h"
extern AwesomeConf globalconf;
/** Get a draw context
* \param phys_screen physical screen id
* \param width width
@ -35,15 +33,16 @@ extern AwesomeConf globalconf;
* \return draw context ref
*/
DrawCtx *
draw_get_context(int phys_screen, int width, int height, Drawable dw)
draw_get_context(Display *disp, int phys_screen, int width, int height, Drawable dw)
{
DrawCtx *d = p_new(DrawCtx, 1);
d->display = disp;
d->phys_screen = phys_screen;
d->width = width;
d->height = height;
d->depth = DefaultDepth(globalconf.display, phys_screen);
d->visual = DefaultVisual(globalconf.display, phys_screen);
d->depth = DefaultDepth(disp, phys_screen);
d->visual = DefaultVisual(disp, phys_screen);
d->drawable = dw;
return d;
@ -83,7 +82,7 @@ draw_text(DrawCtx *ctx,
if(!len)
return;
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create(surface);
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
cairo_set_font_face(cr, font_face);
@ -94,7 +93,7 @@ draw_text(DrawCtx *ctx,
len = sizeof(buf) - 1;
memcpy(buf, text, len);
buf[len] = 0;
while(len && (nw = (draw_textwidth(font, buf)) + padding * 2) > area.width)
while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width)
buf[--len] = 0;
if(nw > area.width)
return; /* too long */
@ -141,7 +140,7 @@ draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color)
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
@ -172,7 +171,7 @@ draw_graph(DrawCtx *ctx, int x, int y, int w, int *h, int h_index, XColor color)
cairo_t *cr;
int i;
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
@ -202,7 +201,7 @@ draw_circle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color)
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
@ -227,7 +226,7 @@ void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h,
cairo_surface_t *surface, *source;
cairo_t *cr;
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0);
cr = cairo_create (surface);
if(wanted_h > 0 && h > 0)
@ -254,7 +253,7 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename)
cairo_t *cr;
cairo_status_t cairo_st;
source = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_image_surface_create_from_png(filename);
if((cairo_st = cairo_surface_status(surface)))
{
@ -307,12 +306,12 @@ draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
cairo_t *cr;
Drawable newdrawable;
newdrawable = XCreatePixmap(globalconf.display,
RootWindow(globalconf.display, screen),
newdrawable = XCreatePixmap(ctx->display,
RootWindow(ctx->display, screen),
ctx->height, ctx->width,
ctx->depth);
surface = cairo_xlib_surface_create(globalconf.display, newdrawable, ctx->visual, ctx->height, ctx->width);
source = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_xlib_surface_create(ctx->display, newdrawable, ctx->visual, ctx->height, ctx->width);
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
cr = cairo_create (surface);
cairo_translate(cr, tx, ty);
@ -329,7 +328,7 @@ draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
}
unsigned short
draw_textwidth(XftFont *font, char *text)
draw_textwidth(Display *disp, XftFont *font, char *text)
{
cairo_surface_t *surface;
cairo_t *cr;
@ -339,10 +338,10 @@ draw_textwidth(XftFont *font, char *text)
if (!a_strlen(text))
return 0;
surface = cairo_xlib_surface_create(globalconf.display, DefaultScreen(globalconf.display),
DefaultVisual(globalconf.display, DefaultScreen(globalconf.display)),
DisplayWidth(globalconf.display, DefaultScreen(globalconf.display)),
DisplayHeight(globalconf.display, DefaultScreen(globalconf.display)));
surface = cairo_xlib_surface_create(disp, DefaultScreen(disp),
DefaultVisual(disp, DefaultScreen(disp)),
DisplayWidth(disp, DefaultScreen(disp)),
DisplayHeight(disp, DefaultScreen(disp)));
cr = cairo_create(surface);
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
cairo_set_font_face(cr, font_face);

5
draw.h
View File

@ -44,6 +44,7 @@ typedef struct
typedef struct
{
Display *display;
Drawable drawable;
Visual *visual;
int width;
@ -52,7 +53,7 @@ typedef struct
int depth;
} DrawCtx;
DrawCtx *draw_get_context(int, int, int, Drawable);
DrawCtx *draw_get_context(Display *, int, int, int, Drawable);
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg);
void draw_rectangle(DrawCtx *, Area, Bool, XColor);
void draw_graph(DrawCtx *, int, int, int, int *, int, XColor);
@ -61,7 +62,7 @@ void draw_image(DrawCtx *, int, int, int, const char *);
void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *);
Area draw_get_image_size(const char *filename);
Drawable draw_rotate(DrawCtx *, int, double, int, int);
unsigned short draw_textwidth(XftFont *, char *);
unsigned short draw_textwidth(Display *, XftFont *, char *);
Alignment draw_get_align(const char *);
#endif

View File

@ -98,7 +98,8 @@ statusbar_draw(Statusbar *statusbar)
break;
}
DrawCtx *ctx = draw_get_context(phys_screen,
DrawCtx *ctx = draw_get_context(globalconf.display,
phys_screen,
statusbar->width,
statusbar->height,
statusbar->sw->drawable);

View File

@ -75,7 +75,8 @@ taglist_draw(Widget *widget,
widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
widget->area.width += draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
widget->area.width += draw_textwidth(ctx->display, vscreen.font, tag->name)
+ vscreen.font->height;
if(!widget->user_supplied_x)
widget->area.x = widget_calculate_offset(widget->statusbar->width,
@ -89,7 +90,7 @@ taglist_draw(Widget *widget,
widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
{
w = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
w = draw_textwidth(ctx->display, vscreen.font, tag->name) + vscreen.font->height;
if(tag->selected)
colors = vscreen.colors_selected;
else if(isurgent(tag))
@ -139,7 +140,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
case Bottom:
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
width = draw_textwidth(globalconf.display, vscreen.font, tag->name)
+ vscreen.font->height;
if(ev->x >= widget->area.x + prev_width
&& ev->x < widget->area.x + prev_width + width)
{
@ -153,7 +155,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
case Right:
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) + vscreen.font->height;
if(ev->y >= widget->area.x + prev_width
&& ev->y < widget->area.x + prev_width + width)
{
@ -167,7 +169,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
default:
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) + vscreen.font->height;
if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
&& widget->statusbar->width - ev->y < widget->area.x + prev_width + width)
{

View File

@ -43,7 +43,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(d->width)
widget->area.width = d->width;
else
widget->area.width = MIN(draw_textwidth(widget->font, d->text),
widget->area.width = MIN(draw_textwidth(ctx->display, widget->font, d->text),
widget->statusbar->width - used);
widget->area.height = widget->statusbar->height;