[common] Use pixmap instead of drawable type

It's just more clear.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-04 16:13:41 +02:00
parent 24176ba8c7
commit 2742318f16
9 changed files with 50 additions and 49 deletions

View File

@ -108,19 +108,19 @@ draw_screen_default_visual(xcb_screen_t *s)
return NULL; return NULL;
} }
/** Get a draw context /** Create a new draw context.
* \param conn Connection ref * \param conn Connection ref.
* \param phys_screen physical screen id * \param phys_screen Physical screen id.
* \param width width * \param width Width.
* \param height height * \param height Height.
* \param dw Drawable object to store in draw_context_t * \param px Pixmap object to store.
* \param fg Foreground color. * \param fg Foreground color.
* \param bg Background color. * \param bg Background color.
* \return draw context ref * \return A draw context pointer.
*/ */
draw_context_t * draw_context_t *
draw_context_new(xcb_connection_t *conn, int phys_screen, draw_context_new(xcb_connection_t *conn, int phys_screen,
int width, int height, xcb_drawable_t dw, int width, int height, xcb_pixmap_t px,
xcolor_t fg, xcolor_t bg) xcolor_t fg, xcolor_t bg)
{ {
draw_context_t *d = p_new(draw_context_t, 1); draw_context_t *d = p_new(draw_context_t, 1);
@ -132,8 +132,8 @@ draw_context_new(xcb_connection_t *conn, int phys_screen,
d->height = height; d->height = height;
d->depth = s->root_depth; d->depth = s->root_depth;
d->visual = draw_screen_default_visual(s); d->visual = draw_screen_default_visual(s);
d->drawable = dw; d->pixmap = px;
d->surface = cairo_xcb_surface_create(conn, dw, d->visual, width, height); d->surface = cairo_xcb_surface_create(conn, px, d->visual, width, height);
d->cr = cairo_create(d->surface); d->cr = cairo_create(d->surface);
d->layout = pango_cairo_create_layout(d->cr); d->layout = pango_cairo_create_layout(d->cr);
d->fg = fg; d->fg = fg;
@ -970,7 +970,7 @@ draw_get_image_size(const char *filename)
} }
#endif /* WITH_IMLIB2 */ #endif /* WITH_IMLIB2 */
/** Rotate a drawable. /** Rotate a pixmap.
* \param ctx Draw context to draw with. * \param ctx Draw context to draw with.
* \param src Drawable to draw from. * \param src Drawable to draw from.
* \param dest Drawable to draw to. * \param dest Drawable to draw to.
@ -984,7 +984,7 @@ draw_get_image_size(const char *filename)
*/ */
void void
draw_rotate(draw_context_t *ctx, draw_rotate(draw_context_t *ctx,
xcb_drawable_t src, xcb_drawable_t dest, xcb_pixmap_t src, xcb_pixmap_t dest,
int src_w, int src_h, int src_w, int src_h,
int dest_w, int dest_h, int dest_w, int dest_h,
double angle, int tx, int ty) double angle, int tx, int ty)

View File

@ -97,7 +97,7 @@ typedef struct
typedef struct typedef struct
{ {
xcb_connection_t *connection; xcb_connection_t *connection;
xcb_drawable_t drawable; xcb_pixmap_t pixmap;
xcb_visualtype_t *visual; xcb_visualtype_t *visual;
int width; int width;
int height; int height;

View File

@ -45,9 +45,6 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
uint32_t create_win_val[3]; uint32_t create_win_val[3];
const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel }; const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };
/* The default GC is just a newly created associated to the root
* window */
xcb_drawable_t gc_draw = s->root;
sw = p_new(simple_window_t, 1); sw = p_new(simple_window_t, 1);
@ -71,11 +68,13 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
create_win_val); create_win_val);
sw->drawable = xcb_generate_id(conn); sw->pixmap = xcb_generate_id(conn);
xcb_create_pixmap(conn, s->root_depth, sw->drawable, s->root, w, h); xcb_create_pixmap(conn, s->root_depth, sw->pixmap, s->root, w, h);
/* The default GC is just a newly created associated to the root
* window */
sw->gc = xcb_generate_id(sw->connection); sw->gc = xcb_generate_id(sw->connection);
xcb_create_gc(sw->connection, sw->gc, gc_draw, gc_mask, gc_values); xcb_create_gc(sw->connection, sw->gc, s->root, gc_mask, gc_values);
sw->border_width = border_width; sw->border_width = border_width;
@ -109,15 +108,17 @@ simplewindow_resize(simple_window_t *sw, unsigned int w, unsigned int h)
{ {
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen); xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen);
const uint32_t resize_win_vals[] = { w, h }; const uint32_t resize_win_vals[] = { w, h };
xcb_pixmap_t d;
sw->geometry.width = w; sw->geometry.width = w;
sw->geometry.height = h; sw->geometry.height = h;
xcb_free_pixmap(sw->connection, sw->drawable); d = sw->pixmap;
sw->drawable = xcb_generate_id(sw->connection); sw->pixmap = xcb_generate_id(sw->connection);
xcb_create_pixmap(sw->connection, s->root_depth, sw->drawable, s->root, w, h); xcb_create_pixmap(sw->connection, s->root_depth, sw->pixmap, s->root, w, h);
xcb_configure_window(sw->connection, sw->window, xcb_configure_window(sw->connection, sw->window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
resize_win_vals); resize_win_vals);
xcb_free_pixmap(sw->connection, d);
} }
// 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

@ -33,8 +33,8 @@ typedef struct simple_window_t
int phys_screen; int phys_screen;
/** The window object. */ /** The window object. */
xcb_window_t window; xcb_window_t window;
/** The drawable copied to the window object. */ /** The pixmap copied to the window object. */
xcb_drawable_t drawable; xcb_pixmap_t pixmap;
/** The graphic context. */ /** The graphic context. */
xcb_gcontext_t gc; xcb_gcontext_t gc;
/** The window geometry. */ /** The window geometry. */
@ -54,7 +54,7 @@ simplewindow_delete(simple_window_t **sw)
if(*sw) if(*sw)
{ {
xcb_destroy_window((*sw)->connection, (*sw)->window); xcb_destroy_window((*sw)->connection, (*sw)->window);
xcb_free_pixmap((*sw)->connection, (*sw)->drawable); xcb_free_pixmap((*sw)->connection, (*sw)->pixmap);
xcb_free_gc((*sw)->connection, (*sw)->gc); xcb_free_gc((*sw)->connection, (*sw)->gc);
p_delete(sw); p_delete(sw);
} }
@ -78,13 +78,13 @@ simplewindow_move_resize(simple_window_t *sw, int x, int y,
simplewindow_resize(sw, w, h); simplewindow_resize(sw, w, h);
} }
/** Refresh the window content by copying its drawable data to its window. /** Refresh the window content by copying its pixmap data to its window.
* \param sw The simple window to refresh. * \param sw The simple window to refresh.
*/ */
static inline void static inline void
simplewindow_refresh_drawable(simple_window_t *sw) simplewindow_refresh_pixmap(simple_window_t *sw)
{ {
xcb_copy_area(sw->connection, sw->drawable, xcb_copy_area(sw->connection, sw->pixmap,
sw->window, sw->gc, 0, 0, 0, 0, sw->window, sw->gc, 0, 0, 0, 0,
sw->geometry.width, sw->geometry.width,
sw->geometry.height); sw->geometry.height);

View File

@ -354,12 +354,12 @@ event_handle_expose(void *data __attribute__ ((unused)),
if(statusbar->sw if(statusbar->sw
&& statusbar->sw->window == ev->window) && statusbar->sw->window == ev->window)
{ {
simplewindow_refresh_drawable(statusbar->sw); simplewindow_refresh_pixmap(statusbar->sw);
return 0; return 0;
} }
if((c = client_getbytitlebarwin(ev->window))) if((c = client_getbytitlebarwin(ev->window)))
simplewindow_refresh_drawable(c->titlebar->sw); simplewindow_refresh_pixmap(c->titlebar->sw);
} }
return 0; return 0;

View File

@ -149,7 +149,7 @@ mouse_resizebar_draw(draw_context_t *ctx,
simplewindow_move(sw, simplewindow_move(sw,
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2, geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2); geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
simplewindow_refresh_drawable(sw); simplewindow_refresh_pixmap(sw);
} }
/** Initialize the resizebar window. /** Initialize the resizebar window.
@ -180,7 +180,7 @@ mouse_resizebar_new(int phys_screen, int border, area_t geometry,
*ctx = draw_context_new(globalconf.connection, sw->phys_screen, *ctx = draw_context_new(globalconf.connection, sw->phys_screen,
sw->geometry.width, sw->geometry.height, sw->geometry.width, sw->geometry.height,
sw->drawable, sw->pixmap,
globalconf.colors.fg, globalconf.colors.fg,
globalconf.colors.bg); globalconf.colors.bg);

View File

@ -43,12 +43,12 @@ statusbar_draw(statusbar_t *statusbar)
return; return;
widget_render(statusbar->widgets, statusbar->ctx, statusbar->sw->gc, widget_render(statusbar->widgets, statusbar->ctx, statusbar->sw->gc,
statusbar->sw->drawable, statusbar->sw->pixmap,
statusbar->screen, statusbar->position, statusbar->screen, statusbar->position,
statusbar->sw->geometry.x, statusbar->sw->geometry.y, statusbar->sw->geometry.x, statusbar->sw->geometry.y,
statusbar); statusbar);
simplewindow_refresh_drawable(statusbar->sw); simplewindow_refresh_pixmap(statusbar->sw);
xcb_aux_sync(globalconf.connection); xcb_aux_sync(globalconf.connection);
} }
@ -78,7 +78,7 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
{ {
statusbar_t *sb; statusbar_t *sb;
area_t area; area_t area;
xcb_drawable_t dw; xcb_pixmap_t dw;
xcb_screen_t *s = NULL; xcb_screen_t *s = NULL;
bool ignore = false; bool ignore = false;
@ -194,7 +194,7 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
statusbar->phys_screen, statusbar->phys_screen,
statusbar->width, statusbar->width,
statusbar->height, statusbar->height,
statusbar->sw->drawable, statusbar->sw->pixmap,
statusbar->colors.fg, statusbar->colors.fg,
statusbar->colors.bg); statusbar->colors.bg);
break; break;

View File

@ -87,27 +87,27 @@ titlebar_draw(client_t *c)
ctx = draw_context_new(globalconf.connection, c->titlebar->sw->phys_screen, ctx = draw_context_new(globalconf.connection, c->titlebar->sw->phys_screen,
c->titlebar->sw->geometry.width, c->titlebar->sw->geometry.width,
c->titlebar->sw->geometry.height, c->titlebar->sw->geometry.height,
c->titlebar->sw->drawable, c->titlebar->sw->pixmap,
c->titlebar->colors.fg, c->titlebar->colors.fg,
c->titlebar->colors.bg); c->titlebar->colors.bg);
break; break;
} }
widget_render(c->titlebar->widgets, ctx, c->titlebar->sw->gc, c->titlebar->sw->drawable, widget_render(c->titlebar->widgets, ctx, c->titlebar->sw->gc, c->titlebar->sw->pixmap,
c->screen, c->titlebar->position, c->screen, c->titlebar->position,
c->titlebar->sw->geometry.x, c->titlebar->sw->geometry.y, c->titlebar); c->titlebar->sw->geometry.x, c->titlebar->sw->geometry.y, c->titlebar);
switch(c->titlebar->position) switch(c->titlebar->position)
{ {
case Left: case Left:
draw_rotate(ctx, ctx->drawable, c->titlebar->sw->drawable, draw_rotate(ctx, ctx->pixmap, c->titlebar->sw->pixmap,
ctx->width, ctx->height, ctx->width, ctx->height,
ctx->height, ctx->width, ctx->height, ctx->width,
- M_PI_2, 0, c->titlebar->sw->geometry.height); - M_PI_2, 0, c->titlebar->sw->geometry.height);
xcb_free_pixmap(globalconf.connection, dw); xcb_free_pixmap(globalconf.connection, dw);
break; break;
case Right: case Right:
draw_rotate(ctx, ctx->drawable, c->titlebar->sw->drawable, draw_rotate(ctx, ctx->pixmap, c->titlebar->sw->pixmap,
ctx->width, ctx->height, ctx->width, ctx->height,
ctx->height, ctx->width, ctx->height, ctx->width,
M_PI_2, c->titlebar->sw->geometry.width, 0); M_PI_2, c->titlebar->sw->geometry.width, 0);
@ -116,7 +116,7 @@ titlebar_draw(client_t *c)
break; break;
} }
simplewindow_refresh_drawable(c->titlebar->sw); simplewindow_refresh_pixmap(c->titlebar->sw);
draw_context_delete(&ctx); draw_context_delete(&ctx);
} }

View File

@ -112,17 +112,17 @@ widget_common_tell(widget_t *widget,
/** Render a list of widgets. /** Render a list of widgets.
* \param wnode The list of widgets. * \param wnode The list of widgets.
* \param ctx The draw context where to render. * \param ctx The draw context where to render.
* \param rotate_dw The rotate drawable: where to rotate and render the final * \param rotate_dw The rotate pixmap: where to rotate and render the final
* \param screen The logical screen used to render. * \param screen The logical screen used to render.
* \param position The object position. * \param position The object position.
* \param x The x coordinates of the object. * \param x The x coordinates of the object.
* \param y The y coordinates of the object. * \param y The y coordinates of the object.
* drawable when the object position is right or left. * pixmap when the object position is right or left.
* \param object The object pointer. * \param object The object pointer.
* \todo Remove GC. * \todo Remove GC.
*/ */
void void
widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_drawable_t rotate_dw, widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_pixmap_t rotate_px,
int screen, position_t position, int screen, position_t position,
int x, int y, void *object) int x, int y, void *object)
{ {
@ -164,7 +164,7 @@ widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_
{ {
case Left: case Left:
draw_rotate(ctx, draw_rotate(ctx,
rootpix, ctx->drawable, rootpix, ctx->pixmap,
rootsize.width, rootsize.height, rootsize.width, rootsize.height,
ctx->width, ctx->height, ctx->width, ctx->height,
M_PI_2, M_PI_2,
@ -173,7 +173,7 @@ widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_
break; break;
case Right: case Right:
draw_rotate(ctx, draw_rotate(ctx,
rootpix, ctx->drawable, rootpix, ctx->pixmap,
rootsize.width, rootsize.height, rootsize.width, rootsize.height,
ctx->width, ctx->height, ctx->width, ctx->height,
- M_PI_2, - M_PI_2,
@ -182,7 +182,7 @@ widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_
break; break;
default: default:
xcb_copy_area(globalconf.connection, rootpix, xcb_copy_area(globalconf.connection, rootpix,
rotate_dw, gc, rotate_px, gc,
x, y, x, y,
0, 0, 0, 0,
ctx->width, ctx->height); ctx->width, ctx->height);
@ -211,13 +211,13 @@ widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_
switch(position) switch(position)
{ {
case Right: case Right:
draw_rotate(ctx, ctx->drawable, rotate_dw, draw_rotate(ctx, ctx->pixmap, rotate_px,
ctx->width, ctx->height, ctx->width, ctx->height,
ctx->height, ctx->width, ctx->height, ctx->width,
M_PI_2, ctx->height, 0); M_PI_2, ctx->height, 0);
break; break;
case Left: case Left:
draw_rotate(ctx, ctx->drawable, rotate_dw, draw_rotate(ctx, ctx->pixmap, rotate_px,
ctx->width, ctx->height, ctx->width, ctx->height,
ctx->height, ctx->width, ctx->height, ctx->width,
- M_PI_2, 0, ctx->width); - M_PI_2, 0, ctx->width);