wibox: remove internal geometry

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-07-28 17:18:41 +02:00
parent 13efd8a199
commit 15b1b2d7c4
2 changed files with 77 additions and 86 deletions

122
wibox.c
View File

@ -52,6 +52,13 @@ wibox_unref_simplified(wibox_t **item)
wibox_unref(globalconf.L, *item); wibox_unref(globalconf.L, *item);
} }
static void
wibox_need_update(wibox_t *wibox)
{
wibox->need_update = true;
wibox->mouse_over = NULL;
}
static int static int
have_shape(void) have_shape(void)
{ {
@ -126,14 +133,17 @@ wibox_draw_context_update(wibox_t *w, xcb_screen_t *s)
xcb_create_pixmap(globalconf.connection, xcb_create_pixmap(globalconf.connection,
s->root_depth, s->root_depth,
w->ctx.pixmap, s->root, w->ctx.pixmap, s->root,
w->geometries.internal.height, w->geometries.internal.width); w->geometry.height - (2 * w->border.width),
w->geometry.width - (2 * w->border.width));
draw_context_init(&w->ctx, phys_screen, draw_context_init(&w->ctx, phys_screen,
w->geometries.internal.height, w->geometries.internal.width, w->geometry.height - (2 * w->border.width),
w->geometry.width - (2 * w->border.width),
w->ctx.pixmap, &fg, &bg); w->ctx.pixmap, &fg, &bg);
break; break;
case East: case East:
draw_context_init(&w->ctx, phys_screen, draw_context_init(&w->ctx, phys_screen,
w->geometries.internal.width, w->geometries.internal.height, w->geometry.width - (2 * w->border.width),
w->geometry.height - (2 * w->border.width),
w->pixmap, &fg, &bg); w->pixmap, &fg, &bg);
break; break;
} }
@ -148,16 +158,11 @@ wibox_init(wibox_t *w, int phys_screen)
{ {
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
/* Copy the real protocol window geometry. */
w->geometries.internal.x = w->geometry.x;
w->geometries.internal.y = w->geometry.y;
w->geometries.internal.width = w->geometry.width;
w->geometries.internal.height = w->geometry.height;
w->window = xcb_generate_id(globalconf.connection); w->window = xcb_generate_id(globalconf.connection);
xcb_create_window(globalconf.connection, s->root_depth, w->window, s->root, xcb_create_window(globalconf.connection, s->root_depth, w->window, s->root,
w->geometries.internal.x, w->geometries.internal.y, w->geometry.x, w->geometry.y,
w->geometries.internal.width, w->geometries.internal.height, w->geometry.width - (2 * w->border.width),
w->geometry.height - (2 * w->border.width),
w->border.width, XCB_COPY_FROM_PARENT, s->root_visual, w->border.width, XCB_COPY_FROM_PARENT, s->root_visual,
XCB_CW_BACK_PIXMAP | XCB_CW_BORDER_PIXEL XCB_CW_BACK_PIXMAP | XCB_CW_BORDER_PIXEL
| XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
@ -177,7 +182,8 @@ wibox_init(wibox_t *w, int phys_screen)
/* Create a pixmap. */ /* Create a pixmap. */
w->pixmap = xcb_generate_id(globalconf.connection); w->pixmap = xcb_generate_id(globalconf.connection);
xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root, xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root,
w->geometries.internal.width, w->geometries.internal.height); w->geometry.width - (2 * w->border.width),
w->geometry.height - (2 * w->border.width));
/* Update draw context physical screen, important for Zaphod. */ /* Update draw context physical screen, important for Zaphod. */
w->ctx.phys_screen = phys_screen; w->ctx.phys_screen = phys_screen;
@ -217,51 +223,58 @@ wibox_moveresize(wibox_t *w, area_t geometry)
{ {
if(w->window) if(w->window)
{ {
int number_of_vals = 0;
uint32_t moveresize_win_vals[4], mask_vals = 0; uint32_t moveresize_win_vals[4], mask_vals = 0;
xcb_screen_t *s = xutil_screen_get(globalconf.connection, w->ctx.phys_screen);
area_t geom_internal = geometry; if(w->geometry.x != geometry.x)
geom_internal.width -= 2 * w->border.width;
geom_internal.height -= 2* w->border.width;
if(w->geometries.internal.x != geom_internal.x || w->geometries.internal.y != geom_internal.y)
{ {
w->geometries.internal.x = moveresize_win_vals[0] = geom_internal.x; w->geometry.x = moveresize_win_vals[number_of_vals++] = geometry.x;
w->geometries.internal.y = moveresize_win_vals[1] = geom_internal.y; mask_vals |= XCB_CONFIG_WINDOW_X;
mask_vals |= XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
} }
if(w->geometry.width != geometry.width || w->geometry.height != geometry.height) if(w->geometry.y != geometry.y)
{ {
if(mask_vals) w->geometry.y = moveresize_win_vals[number_of_vals++] = geometry.y;
{ mask_vals |= XCB_CONFIG_WINDOW_Y;
w->geometries.internal.width = moveresize_win_vals[2] = geom_internal.width;
w->geometries.internal.height = moveresize_win_vals[3] = geom_internal.height;
} }
else
uint16_t iw = geometry.width - (2 * w->border.width),
ih = geometry.height - (2 * w->border.width);
if(iw > 0 && w->geometry.width != geometry.width)
{ {
w->geometries.internal.width = moveresize_win_vals[0] = geom_internal.width; w->geometry.width = geometry.width;
w->geometries.internal.height = moveresize_win_vals[1] = geom_internal.height; moveresize_win_vals[number_of_vals++] = iw;
mask_vals |= XCB_CONFIG_WINDOW_WIDTH;
} }
mask_vals |= XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
if(ih > 0 && w->geometry.height != geometry.height)
{
w->geometry.height = geometry.height;
moveresize_win_vals[number_of_vals++] = ih;
mask_vals |= XCB_CONFIG_WINDOW_HEIGHT;
}
if(iw > 0 && ih > 0
&& (mask_vals & (XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT)))
{
xcb_free_pixmap(globalconf.connection, w->pixmap); xcb_free_pixmap(globalconf.connection, w->pixmap);
/* orientation != East */ /* orientation != East */
if(w->pixmap != w->ctx.pixmap) if(w->pixmap != w->ctx.pixmap)
xcb_free_pixmap(globalconf.connection, w->ctx.pixmap); xcb_free_pixmap(globalconf.connection, w->ctx.pixmap);
w->pixmap = xcb_generate_id(globalconf.connection); w->pixmap = xcb_generate_id(globalconf.connection);
xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root, geom_internal.width, geom_internal.height); xcb_screen_t *s = xutil_screen_get(globalconf.connection, w->ctx.phys_screen);
xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root, iw, ih);
wibox_draw_context_update(w, s); wibox_draw_context_update(w, s);
} }
/* Also save geometry including border. */ if(mask_vals)
w->geometry = geometry;
xcb_configure_window(globalconf.connection, w->window, mask_vals, moveresize_win_vals); xcb_configure_window(globalconf.connection, w->window, mask_vals, moveresize_win_vals);
} }
else else
w->geometry = geometry; w->geometry = geometry;
w->need_update = true; wibox_need_update(w);
} }
/** Refresh the window content by copying its pixmap data to its window. /** Refresh the window content by copying its pixmap data to its window.
@ -335,13 +348,6 @@ wibox_cursor_set(wibox_t *w, xcb_cursor_t c)
(const uint32_t[]) { c }); (const uint32_t[]) { c });
} }
static void
wibox_need_update(wibox_t *wibox)
{
wibox->need_update = true;
wibox->mouse_over = NULL;
}
static void static void
wibox_map(wibox_t *wibox) wibox_map(wibox_t *wibox)
{ {
@ -355,41 +361,33 @@ wibox_map(wibox_t *wibox)
static void static void
wibox_move(wibox_t *wibox, int16_t x, int16_t y) wibox_move(wibox_t *wibox, int16_t x, int16_t y)
{ {
wibox->geometry.x = x;
wibox->geometry.y = y;
if(wibox->window if(wibox->window
&& (x != wibox->geometries.internal.x || y != wibox->geometries.internal.y)) && (x != wibox->geometry.x || y != wibox->geometry.y))
{ {
wibox->geometry.x = wibox->geometries.internal.x = x;
wibox->geometry.y = wibox->geometries.internal.y = y;
xcb_configure_window(globalconf.connection, wibox->window, xcb_configure_window(globalconf.connection, wibox->window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
(const uint32_t[]) { x, y }); (const uint32_t[]) { x, y });
wibox->screen = screen_getbycoord(wibox->screen, x, y); wibox->screen = screen_getbycoord(wibox->screen, x, y);
} }
wibox->geometry.x = x;
wibox->geometry.y = y;
} }
static void static void
wibox_resize(wibox_t *w, uint16_t width, uint16_t height) wibox_resize(wibox_t *w, uint16_t width, uint16_t height)
{ {
if(w->window)
{
int iw = width - 2 * w->border.width; int iw = width - 2 * w->border.width;
int ih = height - 2 * w->border.width; int ih = height - 2 * w->border.width;
if(iw > 0 && ih > 0 && if(iw <= 0 || ih <= 0 || (w->geometry.width == width && w->geometry.height == height))
(w->geometries.internal.width != iw || w->geometries.internal.height != ih)) return;
if(w->window)
{ {
xcb_screen_t *s = xutil_screen_get(globalconf.connection, w->ctx.phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, w->ctx.phys_screen);
uint32_t resize_win_vals[2];
w->geometries.internal.width = resize_win_vals[0] = iw;
w->geometries.internal.height = resize_win_vals[1] = ih;
w->geometry.width = width;
w->geometry.height = height;
xcb_free_pixmap(globalconf.connection, w->pixmap); xcb_free_pixmap(globalconf.connection, w->pixmap);
/* orientation != East */ /* orientation != East */
if(w->pixmap != w->ctx.pixmap) if(w->pixmap != w->ctx.pixmap)
@ -398,15 +396,13 @@ wibox_resize(wibox_t *w, uint16_t width, uint16_t height)
xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root, iw, ih); xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root, iw, ih);
xcb_configure_window(globalconf.connection, w->window, xcb_configure_window(globalconf.connection, w->window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
resize_win_vals); (const uint32_t[]) { iw, ih });
wibox_draw_context_update(w, s); wibox_draw_context_update(w, s);
} }
}
else
{
w->geometry.width = width; w->geometry.width = width;
w->geometry.height = height; w->geometry.height = height;
}
wibox_need_update(w); wibox_need_update(w);
} }

View File

@ -74,11 +74,6 @@ struct wibox_t
xcb_gcontext_t gc; xcb_gcontext_t gc;
/** The window geometry. */ /** The window geometry. */
area_t geometry; area_t geometry;
struct
{
/** Internal geometry (matching X11 protocol) */
area_t internal;
} geometries;
/** The window border */ /** The window border */
struct struct
{ {