[swindow] Store gc

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-09 19:40:32 +02:00
parent 4151df7136
commit a04395ddc9
8 changed files with 20 additions and 22 deletions

View File

@ -500,7 +500,7 @@ redraw(void)
else if(geometry.width) else if(geometry.width)
draw_rectangle(globalconf.ctx, geometry, 1.0, true, globalconf.styles.normal.bg); draw_rectangle(globalconf.ctx, geometry, 1.0, true, globalconf.styles.normal.bg);
simplewindow_refresh_drawable(globalconf.sw, globalconf.default_screen); simplewindow_refresh_drawable(globalconf.sw);
xcb_aux_sync(globalconf.connection); xcb_aux_sync(globalconf.connection);
} }
@ -1374,7 +1374,7 @@ main(int argc, char **argv)
break; break;
case XCB_EXPOSE: case XCB_EXPOSE:
if(!((xcb_expose_event_t *) ev)->count) if(!((xcb_expose_event_t *) ev)->count)
simplewindow_refresh_drawable(globalconf.sw, globalconf.default_screen); simplewindow_refresh_drawable(globalconf.sw);
break; break;
default: default:
break; break;

View File

@ -221,7 +221,7 @@ main(int argc, char **argv)
p_delete(&ctx); p_delete(&ctx);
xcb_map_window(globalconf.connection, sw->window); xcb_map_window(globalconf.connection, sw->window);
simplewindow_refresh_drawable(sw, globalconf.default_screen); simplewindow_refresh_drawable(sw);
xcb_aux_sync(globalconf.connection); xcb_aux_sync(globalconf.connection);
signal(SIGALRM, &exit_on_signal); signal(SIGALRM, &exit_on_signal);
@ -241,7 +241,7 @@ main(int argc, char **argv)
case XCB_KEY_PRESS: case XCB_KEY_PRESS:
running = false; running = false;
case XCB_EXPOSE: case XCB_EXPOSE:
simplewindow_refresh_drawable(sw, globalconf.default_screen); simplewindow_refresh_drawable(sw);
break; break;
default: default:
break; break;

View File

@ -42,6 +42,11 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
SimpleWindow *sw; SimpleWindow *sw;
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen); xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
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_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(SimpleWindow, 1); sw = p_new(SimpleWindow, 1);
@ -68,6 +73,9 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
sw->drawable = xcb_generate_id(conn); sw->drawable = 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->drawable, s->root, w, h);
sw->gc = xcb_generate_id(sw->connection);
xcb_create_gc(sw->connection, sw->gc, gc_draw, gc_mask, gc_values);
return sw; return sw;
} }
@ -125,21 +133,10 @@ simplewindow_resize(SimpleWindow *sw, unsigned int w, unsigned int h)
* \param phys_screen physical screen id * \param phys_screen physical screen id
*/ */
void void
simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen) simplewindow_refresh_drawable(SimpleWindow *sw)
{ {
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, phys_screen);
/* The default GC is just a newly created associated to the root
* window */
xcb_drawable_t gc_draw = s->root;
xcb_gcontext_t gc = xcb_generate_id(sw->connection);
const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };
xcb_create_gc(sw->connection, gc, gc_draw, gc_mask, gc_values);
xcb_copy_area(sw->connection, sw->drawable, xcb_copy_area(sw->connection, sw->drawable,
sw->window, 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

@ -31,6 +31,7 @@ typedef struct SimpleWindow
int phys_screen; int phys_screen;
xcb_window_t window; xcb_window_t window;
xcb_drawable_t drawable; xcb_drawable_t drawable;
xcb_gcontext_t gc;
area_t geometry; area_t geometry;
} SimpleWindow; } SimpleWindow;
@ -38,7 +39,7 @@ SimpleWindow * simplewindow_new(xcb_connection_t *, int, int, int, unsigned int,
void simplewindow_delete(SimpleWindow **); void simplewindow_delete(SimpleWindow **);
void simplewindow_move(SimpleWindow *, int, int); void simplewindow_move(SimpleWindow *, int, int);
void simplewindow_resize(SimpleWindow *, unsigned int, unsigned int); void simplewindow_resize(SimpleWindow *, unsigned int, unsigned int);
void simplewindow_refresh_drawable(SimpleWindow *, int); void simplewindow_refresh_drawable(SimpleWindow *);
static inline void static inline void
simplewindow_move_resize(SimpleWindow *sw, int x, int y, simplewindow_move_resize(SimpleWindow *sw, int x, int y,

View File

@ -374,7 +374,7 @@ event_handle_expose(void *data __attribute__ ((unused)),
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
if(c->titlebar.sw && c->titlebar.sw->window == ev->window) if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
{ {
simplewindow_refresh_drawable(c->titlebar.sw, c->phys_screen); simplewindow_refresh_drawable(c->titlebar.sw);
return 0; return 0;
} }
} }

View File

@ -149,7 +149,7 @@ mouse_resizebar_draw(DrawCtx *ctx, style_t style, SimpleWindow *sw, area_t geome
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, sw->phys_screen); simplewindow_refresh_drawable(sw);
} }
/** Initialize the resizebar window. /** Initialize the resizebar window.

View File

@ -166,7 +166,7 @@ statusbar_display(Statusbar *statusbar)
{ {
/* don't waste our time */ /* don't waste our time */
if(statusbar->position != Off) if(statusbar->position != Off)
simplewindow_refresh_drawable(statusbar->sw, statusbar->phys_screen); simplewindow_refresh_drawable(statusbar->sw);
} }
void void

View File

@ -219,7 +219,7 @@ titlebar_draw(Client *c)
break; break;
} }
simplewindow_refresh_drawable(c->titlebar.sw, c->titlebar.sw->phys_screen); simplewindow_refresh_drawable(c->titlebar.sw);
draw_context_delete(&ctx); draw_context_delete(&ctx);
} }