swindow: do not store phys_screen; store border color

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-09-20 21:24:16 +02:00
parent fcc93e5f88
commit 2e17f8a662
12 changed files with 220 additions and 237 deletions

View file

@ -202,8 +202,8 @@ client_ban(client_t *c)
window_state_set(c->win, XCB_WM_STATE_ICONIC); window_state_set(c->win, XCB_WM_STATE_ICONIC);
else else
window_state_set(c->win, XCB_WM_STATE_WITHDRAWN); window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
if(c->titlebar && c->titlebar->position && c->titlebar->sw) if(c->titlebar && c->titlebar->position)
xcb_unmap_window(globalconf.connection, c->titlebar->sw->window); xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
} }
/** Give focus to client, or to first client if client is NULL. /** Give focus to client, or to first client if client is NULL.
@ -260,14 +260,13 @@ client_stack_below(client_t *c, xcb_window_t previous)
config_win_vals[1] = XCB_STACK_MODE_BELOW; config_win_vals[1] = XCB_STACK_MODE_BELOW;
if(c->titlebar if(c->titlebar
&& c->titlebar->sw
&& c->titlebar->position) && c->titlebar->position)
{ {
xcb_configure_window(globalconf.connection, xcb_configure_window(globalconf.connection,
c->titlebar->sw->window, c->titlebar->sw.window,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
config_win_vals); config_win_vals);
config_win_vals[0] = c->titlebar->sw->window; config_win_vals[0] = c->titlebar->sw.window;
} }
xcb_configure_window(globalconf.connection, c->win, xcb_configure_window(globalconf.connection, c->win,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
@ -335,14 +334,11 @@ client_stack(void)
for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++) for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++)
{ {
statusbar_t *sb = globalconf.screens[screen].statusbars.tab[i]; statusbar_t *sb = globalconf.screens[screen].statusbars.tab[i];
if(sb->sw) xcb_configure_window(globalconf.connection,
{ sb->sw.window,
xcb_configure_window(globalconf.connection, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
sb->sw->window, config_win_vals);
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, config_win_vals[0] = sb->sw.window;
config_win_vals);
config_win_vals[0] = sb->sw->window;
}
} }
/* finally stack everything else */ /* finally stack everything else */
@ -775,12 +771,12 @@ client_unban(client_t *c)
{ {
xcb_map_window(globalconf.connection, c->win); xcb_map_window(globalconf.connection, c->win);
window_state_set(c->win, XCB_WM_STATE_NORMAL); window_state_set(c->win, XCB_WM_STATE_NORMAL);
if(c->titlebar && c->titlebar->sw && c->titlebar->position) if(c->titlebar && c->titlebar->position)
{ {
if(c->isfullscreen) if(c->isfullscreen)
xcb_unmap_window(globalconf.connection, c->titlebar->sw->window); xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
else else
xcb_map_window(globalconf.connection, c->titlebar->sw->window); xcb_map_window(globalconf.connection, c->titlebar->sw.window);
} }
} }
@ -821,7 +817,7 @@ client_unmanage(client_t *c)
if(c->titlebar) if(c->titlebar)
{ {
simplewindow_delete(&c->titlebar->sw); xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
titlebar_unref(&c->titlebar); titlebar_unref(&c->titlebar);
c->titlebar = NULL; c->titlebar = NULL;
} }
@ -1294,7 +1290,7 @@ luaA_client_newindex(lua_State *L)
/* If client had a titlebar, unref it */ /* If client had a titlebar, unref it */
if((*c)->titlebar) if((*c)->titlebar)
{ {
simplewindow_delete(&(*c)->titlebar->sw); xcb_unmap_window(globalconf.connection, (*c)->titlebar->sw.window);
titlebar_unref(&(*c)->titlebar); titlebar_unref(&(*c)->titlebar);
(*c)->titlebar = NULL; (*c)->titlebar = NULL;
client_need_arrange(*c); client_need_arrange(*c);
@ -1303,8 +1299,7 @@ luaA_client_newindex(lua_State *L)
if(t) if(t)
{ {
/* Attach titlebar to client */ /* Attach titlebar to client */
(*c)->titlebar = *t; (*c)->titlebar = titlebar_ref(t);
titlebar_ref(t);
titlebar_init(*c); titlebar_init(*c);
} }
client_stack(); client_stack();

33
event.c
View file

@ -81,14 +81,14 @@ event_handle_mouse_button(client_t *c,
/** Get a widget node from a statusbar by coords. /** Get a widget node from a statusbar by coords.
* \param Container position. * \param Container position.
* \param widgets The widget list. * \param widgets The widget list.
* \param height The container height.
* \param width The container width. * \param width The container width.
* \param height The container height.
* \param x X coordinate of the widget. * \param x X coordinate of the widget.
* \param y Y coordinate of the widget. * \param y Y coordinate of the widget.
* \return A widget node. * \return A widget node.
*/ */
static widget_node_t * static widget_node_t *
widget_getbycoords(position_t position, widget_node_t *widgets, int height, int width, int x, int y) widget_getbycoords(position_t position, widget_node_t *widgets, int width, int height, int x, int y)
{ {
int tmp; int tmp;
widget_node_t *w; widget_node_t *w;
@ -98,13 +98,13 @@ widget_getbycoords(position_t position, widget_node_t *widgets, int height, int
{ {
case Right: case Right:
tmp = y; tmp = y;
y = height - x; y = width - x;
x = tmp; x = tmp;
break; break;
case Left: case Left:
tmp = y; tmp = y;
y = x; y = x;
x = width - tmp; x = height - tmp;
break; break;
default: default:
break; break;
@ -141,18 +141,18 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++) for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++)
{ {
statusbar_t *statusbar = globalconf.screens[screen].statusbars.tab[i]; statusbar_t *statusbar = globalconf.screens[screen].statusbars.tab[i];
if(statusbar->sw if(statusbar->sw.window == ev->event || statusbar->sw.window == ev->child)
&& (statusbar->sw->window == ev->event || statusbar->sw->window == ev->child))
{ {
/* If the statusbar is child, then x,y are /* If the statusbar is child, then x,y are
* relative to root window */ * relative to root window */
if(statusbar->sw->window == ev->child) if(statusbar->sw.window == ev->child)
{ {
ev->event_x -= statusbar->sw->geometry.x; ev->event_x -= statusbar->sw.geometry.x;
ev->event_y -= statusbar->sw->geometry.y; ev->event_y -= statusbar->sw.geometry.y;
} }
if((w = widget_getbycoords(statusbar->position, statusbar->widgets, if((w = widget_getbycoords(statusbar->position, statusbar->widgets,
statusbar->width, statusbar->height, statusbar->sw.geometry.width,
statusbar->sw.geometry.height,
ev->event_x, ev->event_y))) ev->event_x, ev->event_y)))
w->widget->button(w, ev, statusbar->screen, statusbar, AWESOME_TYPE_STATUSBAR); w->widget->button(w, ev, statusbar->screen, statusbar, AWESOME_TYPE_STATUSBAR);
/* return even if no widget match */ /* return even if no widget match */
@ -388,7 +388,8 @@ event_handle_motionnotify(void *data __attribute__ ((unused)),
if(statusbar) if(statusbar)
{ {
w = widget_getbycoords(statusbar->position, statusbar->widgets, w = widget_getbycoords(statusbar->position, statusbar->widgets,
statusbar->width, statusbar->height, statusbar->sw.geometry.width,
statusbar->sw.geometry.height,
ev->event_x, ev->event_y); ev->event_x, ev->event_y);
event_handle_widget_motionnotify(statusbar, event_handle_widget_motionnotify(statusbar,
AWESOME_TYPE_STATUSBAR, AWESOME_TYPE_STATUSBAR,
@ -397,7 +398,8 @@ event_handle_motionnotify(void *data __attribute__ ((unused)),
else if((c = client_getbytitlebarwin(ev->event))) else if((c = client_getbytitlebarwin(ev->event)))
{ {
w = widget_getbycoords(c->titlebar->position, c->titlebar->widgets, w = widget_getbycoords(c->titlebar->position, c->titlebar->widgets,
c->titlebar->width, c->titlebar->height, c->titlebar->sw.geometry.width,
c->titlebar->sw.geometry.height,
ev->event_x, ev->event_y); ev->event_x, ev->event_y);
event_handle_widget_motionnotify(c->titlebar, event_handle_widget_motionnotify(c->titlebar,
AWESOME_TYPE_TITLEBAR, AWESOME_TYPE_TITLEBAR,
@ -502,16 +504,15 @@ event_handle_expose(void *data __attribute__ ((unused)),
for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++) for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++)
{ {
statusbar_t *statusbar = globalconf.screens[screen].statusbars.tab[i]; statusbar_t *statusbar = globalconf.screens[screen].statusbars.tab[i];
if(statusbar->sw if(statusbar->sw.window == ev->window)
&& statusbar->sw->window == ev->window)
{ {
simplewindow_refresh_pixmap(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_pixmap(c->titlebar->sw); simplewindow_refresh_pixmap(&c->titlebar->sw);
} }
return 0; return 0;

54
mouse.c
View file

@ -260,15 +260,15 @@ mouse_infobox_draw(simple_window_t *sw,
#define MOUSE_INFOBOX_STRING_DEFAULT "0000x0000+0000+0000" #define MOUSE_INFOBOX_STRING_DEFAULT "0000x0000+0000+0000"
/** Initialize the infobox window. /** Initialize the infobox window.
* \param sw The simple window to init.
* \param phys_screen Physical screen number. * \param phys_screen Physical screen number.
* \param border Border size of the client. * \param border Border size of the client.
* \param geometry Client geometry. * \param geometry Client geometry.
* \return The simple window. * \return The simple window.
*/ */
static simple_window_t * static void
mouse_infobox_new(int phys_screen, int border, area_t geometry) mouse_infobox_new(simple_window_t *sw, int phys_screen, int border, area_t geometry)
{ {
simple_window_t *sw;
area_t geom; area_t geom;
draw_parser_data_t pdata; draw_parser_data_t pdata;
@ -282,17 +282,15 @@ mouse_infobox_new(int phys_screen, int border, area_t geometry)
geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2; geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2;
geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2; geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2;
sw = simplewindow_new(phys_screen, simplewindow_init(sw, phys_screen,
geom.x, geom.y, geom.x, geom.y,
geom.width, geom.height, 0, geom.width, geom.height, 0,
Top, &globalconf.colors.fg, &globalconf.colors.bg); Top, &globalconf.colors.fg, &globalconf.colors.bg);
xcb_map_window(globalconf.connection, sw->window); xcb_map_window(globalconf.connection, sw->window);
mouse_infobox_draw(sw, geometry, border); mouse_infobox_draw(sw, geometry, border);
draw_parser_data_wipe(&pdata); draw_parser_data_wipe(&pdata);
return sw;
} }
/** Get the pointer position. /** Get the pointer position.
@ -477,7 +475,7 @@ mouse_client_move(client_t *c, int snap, bool infobox)
/* current layout */ /* current layout */
layout_t *layout; layout_t *layout;
/* the infobox */ /* the infobox */
simple_window_t *sw = NULL; simple_window_t sw;
/* the root window */ /* the root window */
xcb_window_t root; xcb_window_t root;
@ -496,7 +494,9 @@ mouse_client_move(client_t *c, int snap, bool infobox)
return; return;
if(infobox && (client_isfloating(c) || layout == layout_floating)) if(infobox && (client_isfloating(c) || layout == layout_floating))
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry); mouse_infobox_new(&sw, c->phys_screen, c->border, c->geometry);
else
infobox = false;
/* for each motion event */ /* for each motion event */
while(mouse_track_mouse_drag(&mouse_x, &mouse_y)) while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
@ -517,8 +517,8 @@ mouse_client_move(client_t *c, int snap, bool infobox)
c->ismoving = false; c->ismoving = false;
/* draw the infobox */ /* draw the infobox */
if(sw) if(infobox)
mouse_infobox_draw(sw, c->geometry, c->border); mouse_infobox_draw(&sw, c->geometry, c->border);
statusbar_refresh(); statusbar_refresh();
@ -560,8 +560,8 @@ mouse_client_move(client_t *c, int snap, bool infobox)
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME); xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
/* free the infobox */ /* free the infobox */
if(sw) if(infobox)
simplewindow_delete(&sw); simplewindow_wipe(&sw);
} }
@ -579,7 +579,7 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
/* the other is moved with the mouse */ /* the other is moved with the mouse */
int mouse_x = 0, mouse_y = 0; int mouse_x = 0, mouse_y = 0;
/* the infobox */ /* the infobox */
simple_window_t *sw = NULL; simple_window_t sw;
size_t cursor = CurResize; size_t cursor = CurResize;
int top, bottom, left, right; int top, bottom, left, right;
@ -626,7 +626,7 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
/* create the infobox */ /* create the infobox */
if(infobox) if(infobox)
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry); mouse_infobox_new(&sw, c->phys_screen, c->border, c->geometry);
/* for each motion event */ /* for each motion event */
while(mouse_track_mouse_drag(&mouse_x, &mouse_y)) while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
@ -699,16 +699,16 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
titlebar_draw(c); titlebar_draw(c);
/* draw the infobox */ /* draw the infobox */
if(sw) if(infobox)
mouse_infobox_draw(sw, c->geometry, c->border); mouse_infobox_draw(&sw, c->geometry, c->border);
} }
/* relase pointer */ /* relase pointer */
mouse_ungrab_pointer(); mouse_ungrab_pointer();
/* free the infobox */ /* free the infobox */
if(sw) if(infobox)
simplewindow_delete(&sw); simplewindow_wipe(&sw);
} }
/** Resize the master column/row of a tiled layout /** Resize the master column/row of a tiled layout
@ -828,7 +828,7 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
/* current tag */ /* current tag */
tag_t *tag; tag_t *tag;
/* the infobox */ /* the infobox */
simple_window_t *sw = NULL; simple_window_t sw;
xcb_window_t root; xcb_window_t root;
tag = tags_get_current(c->screen)[0]; tag = tags_get_current(c->screen)[0];
@ -879,7 +879,7 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
/* create the infobox */ /* create the infobox */
if(infobox) if(infobox)
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry); mouse_infobox_new(&sw, c->phys_screen, c->border, c->geometry);
/* for each motion event */ /* for each motion event */
while(mouse_track_mouse_drag(&mouse_x, &mouse_y)) while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
@ -908,16 +908,16 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
} }
/* draw the infobox */ /* draw the infobox */
if(sw) if(infobox)
mouse_infobox_draw(sw, c->geometry, c->border); mouse_infobox_draw(&sw, c->geometry, c->border);
} }
/* ungrab pointer */ /* ungrab pointer */
mouse_ungrab_pointer(); mouse_ungrab_pointer();
/* free the infobox */ /* free the infobox */
if(sw) if(infobox)
simplewindow_delete(&sw); simplewindow_wipe(&sw);
} }
/** Resize a client with the mouse. /** Resize a client with the mouse.

View file

@ -222,16 +222,16 @@ screen_area_get(int screen, statusbar_array_t *statusbars,
switch(sb->position) switch(sb->position)
{ {
case Top: case Top:
top = MAX(top, (uint16_t) (sb->sw->geometry.y - area.y) + sb->sw->geometry.height); top = MAX(top, (uint16_t) (sb->sw.geometry.y - area.y) + sb->sw.geometry.height);
break; break;
case Bottom: case Bottom:
bottom = MAX(bottom, (uint16_t) (area.y + area.height) - sb->sw->geometry.y); bottom = MAX(bottom, (uint16_t) (area.y + area.height) - sb->sw.geometry.y);
break; break;
case Left: case Left:
left = MAX(left, (uint16_t) (sb->sw->geometry.x - area.x) + sb->sw->geometry.width); left = MAX(left, (uint16_t) (sb->sw.geometry.x - area.x) + sb->sw.geometry.width);
break; break;
case Right: case Right:
right = MAX(right, (uint16_t) (area.x + area.width) - sb->sw->geometry.x); right = MAX(right, (uint16_t) (area.x + area.width) - sb->sw.geometry.x);
break; break;
default: default:
break; break;

View file

@ -41,6 +41,9 @@ statusbar_systray_kickout(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);
/* Who! Check that we're not deleting a statusbar with a systray, because it
* may be its parent. If so, we reparent to root before, otherwise it will
* hurt very much. */
xcb_reparent_window(globalconf.connection, xcb_reparent_window(globalconf.connection,
globalconf.screens[phys_screen].systray.window, globalconf.screens[phys_screen].systray.window,
s->root, -512, -512); s->root, -512, -512);
@ -64,7 +67,7 @@ statusbar_systray_refresh(statusbar_t *statusbar)
uint32_t config_win_vals_off[2] = { -512, -512 }; uint32_t config_win_vals_off[2] = { -512, -512 };
xembed_window_t *em; xembed_window_t *em;
position_t pos; position_t pos;
int phys_screen = statusbar->sw->phys_screen; int phys_screen = statusbar->sw.ctx.phys_screen;
if(statusbar->position if(statusbar->position
&& systray->widget->isvisible && systray->widget->isvisible
@ -83,7 +86,7 @@ statusbar_systray_refresh(statusbar_t *statusbar)
{ {
case Left: case Left:
config_win_vals[0] = systray->area.y; config_win_vals[0] = systray->area.y;
config_win_vals[1] = statusbar->sw->geometry.height - systray->area.x - systray->area.width; config_win_vals[1] = statusbar->sw.geometry.height - systray->area.x - systray->area.width;
config_win_vals[2] = systray->area.height; config_win_vals[2] = systray->area.height;
config_win_vals[3] = systray->area.width; config_win_vals[3] = systray->area.width;
break; break;
@ -101,13 +104,13 @@ statusbar_systray_refresh(statusbar_t *statusbar)
break; break;
} }
/* reparent */ /* reparent */
if(globalconf.screens[phys_screen].systray.parent != statusbar->sw->window) if(globalconf.screens[phys_screen].systray.parent != statusbar->sw.window)
{ {
xcb_reparent_window(globalconf.connection, xcb_reparent_window(globalconf.connection,
globalconf.screens[phys_screen].systray.window, globalconf.screens[phys_screen].systray.window,
statusbar->sw->window, statusbar->sw.window,
config_win_vals[0], config_win_vals[1]); config_win_vals[0], config_win_vals[1]);
globalconf.screens[phys_screen].systray.parent = statusbar->sw->window; globalconf.screens[phys_screen].systray.parent = statusbar->sw.window;
} }
xcb_configure_window(globalconf.connection, xcb_configure_window(globalconf.connection,
globalconf.screens[phys_screen].systray.window, globalconf.screens[phys_screen].systray.window,
@ -134,7 +137,7 @@ statusbar_systray_refresh(statusbar_t *statusbar)
for(em = globalconf.embedded; em; em = em->next) for(em = globalconf.embedded; em; em = em->next)
if(em->phys_screen == phys_screen) if(em->phys_screen == phys_screen)
{ {
if(config_win_vals[1] - config_win_vals[2] >= (uint32_t) statusbar->sw->geometry.y) if(config_win_vals[1] - config_win_vals[2] >= (uint32_t) statusbar->sw.geometry.y)
{ {
xcb_map_window(globalconf.connection, em->win); xcb_map_window(globalconf.connection, em->win);
xcb_configure_window(globalconf.connection, em->win, xcb_configure_window(globalconf.connection, em->win,
@ -157,7 +160,7 @@ statusbar_systray_refresh(statusbar_t *statusbar)
for(em = globalconf.embedded; em; em = em->next) for(em = globalconf.embedded; em; em = em->next)
if(em->phys_screen == phys_screen) if(em->phys_screen == phys_screen)
{ {
if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) statusbar->sw->geometry.y + statusbar->sw->geometry.width) if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) statusbar->sw.geometry.y + statusbar->sw.geometry.width)
{ {
xcb_map_window(globalconf.connection, em->win); xcb_map_window(globalconf.connection, em->win);
xcb_configure_window(globalconf.connection, em->win, xcb_configure_window(globalconf.connection, em->win,
@ -182,7 +185,7 @@ statusbar_systray_refresh(statusbar_t *statusbar)
if(em->phys_screen == phys_screen) if(em->phys_screen == phys_screen)
{ {
/* if(x + width < systray.x + systray.width) */ /* if(x + width < systray.x + systray.width) */
if(config_win_vals[0] + config_win_vals[2] <= (uint32_t) AREA_RIGHT(systray->area) + statusbar->sw->geometry.x) if(config_win_vals[0] + config_win_vals[2] <= (uint32_t) AREA_RIGHT(systray->area) + statusbar->sw.geometry.x)
{ {
xcb_map_window(globalconf.connection, em->win); xcb_map_window(globalconf.connection, em->win);
xcb_configure_window(globalconf.connection, em->win, xcb_configure_window(globalconf.connection, em->win,
@ -218,12 +221,12 @@ statusbar_draw(statusbar_t *statusbar)
if(statusbar->position) if(statusbar->position)
{ {
widget_render(statusbar->widgets, &statusbar->sw->ctx, statusbar->sw->gc, widget_render(statusbar->widgets, &statusbar->sw.ctx, statusbar->sw.gc,
statusbar->sw->pixmap, 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, AWESOME_TYPE_STATUSBAR); statusbar, AWESOME_TYPE_STATUSBAR);
simplewindow_refresh_pixmap(statusbar->sw); simplewindow_refresh_pixmap(&statusbar->sw);
} }
statusbar_systray_refresh(statusbar); statusbar_systray_refresh(statusbar);
@ -240,7 +243,7 @@ statusbar_getbywin(xcb_window_t w)
for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++) for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++)
{ {
statusbar_t *s = globalconf.screens[screen].statusbars.tab[i]; statusbar_t *s = globalconf.screens[screen].statusbars.tab[i];
if(s->sw->window == w) if(s->sw.window == w)
return s; return s;
} }
return NULL; return NULL;
@ -260,18 +263,6 @@ statusbar_refresh(void)
} }
} }
static void
statusbar_clean(statusbar_t *statusbar)
{
/* Who! Check that we're not deleting a statusbar with a systray, because it
* may be its parent. If so, we reparent to root before, otherwise it will
* hurt very much. */
if(statusbar->sw)
statusbar_systray_kickout(statusbar->sw->phys_screen);
simplewindow_delete(&statusbar->sw);
}
/** Update the statusbar position. It deletes every statusbar resources and /** Update the statusbar position. It deletes every statusbar resources and
* create them back. * create them back.
* \param statusbar The statusbar. * \param statusbar The statusbar.
@ -283,7 +274,12 @@ statusbar_position_update(statusbar_t *statusbar)
bool ignore = false; bool ignore = false;
if(statusbar->position == Off) if(statusbar->position == Off)
return statusbar_clean(statusbar); {
xcb_unmap_window(globalconf.connection, statusbar->sw.window);
/* kick out systray if needed */
statusbar_systray_refresh(statusbar);
return;
}
area = screen_area_get(statusbar->screen, NULL, area = screen_area_get(statusbar->screen, NULL,
&globalconf.screens[statusbar->screen].padding, true); &globalconf.screens[statusbar->screen].padding, true);
@ -447,28 +443,31 @@ statusbar_position_update(statusbar_t *statusbar)
break; break;
} }
/* same window size and position ? */ if(!statusbar->sw.window)
if(!statusbar->sw
|| wingeometry.width != statusbar->sw->geometry.width
|| wingeometry.height != statusbar->sw->geometry.height)
{ {
int phys_screen = screen_virttophys(statusbar->screen); int phys_screen = screen_virttophys(statusbar->screen);
statusbar_clean(statusbar); simplewindow_init(&statusbar->sw, phys_screen,
wingeometry.x, wingeometry.y,
statusbar->sw = wingeometry.width, wingeometry.height,
simplewindow_new(phys_screen, 0, 0, 0, statusbar->position,
wingeometry.width, wingeometry.height, 0, &statusbar->colors.fg, &statusbar->colors.bg);
statusbar->position, xcb_map_window(globalconf.connection, statusbar->sw.window);
&statusbar->colors.fg, &statusbar->colors.bg); }
/* same window size and position ? */
simplewindow_move(statusbar->sw, wingeometry.x, wingeometry.y); else
xcb_map_window(globalconf.connection, statusbar->sw->window); {
statusbar->need_update = true; if(wingeometry.width != statusbar->sw.geometry.width
|| wingeometry.height != statusbar->sw.geometry.height)
{
simplewindow_resize(&statusbar->sw, wingeometry.width, wingeometry.height);
statusbar->need_update = true;
}
if(wingeometry.x != statusbar->sw.geometry.x
|| wingeometry.y != statusbar->sw.geometry.y)
simplewindow_move(&statusbar->sw, wingeometry.x, wingeometry.y);
} }
else if(wingeometry.x != statusbar->sw->geometry.x
|| wingeometry.y != statusbar->sw->geometry.y)
simplewindow_move(statusbar->sw, wingeometry.x, wingeometry.y);
/* Set need update */ /* Set need update */
globalconf.screens[statusbar->screen].need_arrange = true; globalconf.screens[statusbar->screen].need_arrange = true;
@ -620,8 +619,6 @@ statusbar_remove(statusbar_t *statusbar)
{ {
position_t p; position_t p;
statusbar_systray_kickout(screen_virttophys(statusbar->screen));
/* save position */ /* save position */
p = statusbar->position; p = statusbar->position;
statusbar->position = Off; statusbar->position = Off;
@ -629,6 +626,10 @@ statusbar_remove(statusbar_t *statusbar)
/* restore position */ /* restore position */
statusbar->position = p; statusbar->position = p;
simplewindow_wipe(&statusbar->sw);
/* sw.window is used to now if the window has been init or not */
statusbar->sw.window = 0;
for(int i = 0; i < globalconf.screens[statusbar->screen].statusbars.len; i++) for(int i = 0; i < globalconf.screens[statusbar->screen].statusbars.len; i++)
if(globalconf.screens[statusbar->screen].statusbars.tab[i] == statusbar) if(globalconf.screens[statusbar->screen].statusbars.tab[i] == statusbar)
{ {
@ -704,8 +705,7 @@ luaA_statusbar_newindex(lua_State *L)
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.fg, buf, len))) if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.fg, buf, len)))
{ {
if((*statusbar)->sw) (*statusbar)->sw.ctx.fg = (*statusbar)->colors.fg;
(*statusbar)->sw->ctx.fg = (*statusbar)->colors.fg;
(*statusbar)->need_update = true; (*statusbar)->need_update = true;
} }
break; break;
@ -713,8 +713,7 @@ luaA_statusbar_newindex(lua_State *L)
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.bg, buf, len))) if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.bg, buf, len)))
{ {
if((*statusbar)->sw) (*statusbar)->sw.ctx.bg = (*statusbar)->colors.bg;
(*statusbar)->sw->ctx.bg = (*statusbar)->colors.bg;
(*statusbar)->need_update = true; (*statusbar)->need_update = true;
} }
break; break;
@ -724,6 +723,8 @@ luaA_statusbar_newindex(lua_State *L)
if(p != (*statusbar)->position) if(p != (*statusbar)->position)
{ {
(*statusbar)->position = p; (*statusbar)->position = p;
simplewindow_wipe(&(*statusbar)->sw);
(*statusbar)->sw.window = 0;
if((*statusbar)->screen != SCREEN_UNDEF) if((*statusbar)->screen != SCREEN_UNDEF)
{ {
for(int i = 0; i < globalconf.screens[(*statusbar)->screen].statusbars.len; i++) for(int i = 0; i < globalconf.screens[(*statusbar)->screen].statusbars.len; i++)

View file

@ -29,7 +29,7 @@
static inline void static inline void
statusbar_delete(statusbar_t **statusbar) statusbar_delete(statusbar_t **statusbar)
{ {
simplewindow_delete(&(*statusbar)->sw); simplewindow_wipe(&(*statusbar)->sw);
widget_node_list_wipe(&(*statusbar)->widgets); widget_node_list_wipe(&(*statusbar)->widgets);
p_delete(&(*statusbar)->name); p_delete(&(*statusbar)->name);
p_delete(statusbar); p_delete(statusbar);

View file

@ -185,7 +185,7 @@ struct titlebar_t
/** Width and height */ /** Width and height */
int width, height; int width, height;
/** Titlebar window */ /** Titlebar window */
simple_window_t *sw; simple_window_t sw;
/** Default colors */ /** Default colors */
struct struct
{ {
@ -219,7 +219,7 @@ struct statusbar_t
/** Ref count */ /** Ref count */
int refcount; int refcount;
/** Window */ /** Window */
simple_window_t *sw; simple_window_t sw;
/** statusbar_t name */ /** statusbar_t name */
char *name; char *name;
/** Bar width */ /** Bar width */

View file

@ -30,7 +30,8 @@
extern awesome_t globalconf; extern awesome_t globalconf;
/** Create a simple window. /** Initialize a simple window.
* \param sw The simple window to initialize.
* \param phys_screen Physical screen number. * \param phys_screen Physical screen number.
* \param x x coordinate. * \param x x coordinate.
* \param y y coordinate. * \param y y coordinate.
@ -40,29 +41,25 @@ extern awesome_t globalconf;
* \param position The rendering position. * \param position The rendering position.
* \param bg Default foreground color. * \param bg Default foreground color.
* \param bg Default background color. * \param bg Default background color.
* \return A pointer to a newly allocated simple window, which must be deleted
* with simplewindow_delete().
*/ */
simple_window_t * void
simplewindow_new(int phys_screen, int x, int y, simplewindow_init(simple_window_t *sw,
unsigned int w, unsigned int h, int phys_screen,
unsigned int border_width, int x, int y,
position_t position, unsigned int w, unsigned int h,
const xcolor_t *fg, const xcolor_t *bg) unsigned int border_width,
position_t position,
const xcolor_t *fg, const xcolor_t *bg)
{ {
simple_window_t *sw;
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, 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_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 };
sw = p_new(simple_window_t, 1);
sw->geometry.x = x; sw->geometry.x = x;
sw->geometry.y = y; sw->geometry.y = y;
sw->geometry.width = w; sw->geometry.width = w;
sw->geometry.height = h; sw->geometry.height = h;
sw->phys_screen = phys_screen;
create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE; create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE;
create_win_val[1] = 1; create_win_val[1] = 1;
@ -104,26 +101,20 @@ simplewindow_new(int phys_screen, int x, int y,
sw->gc = xcb_generate_id(globalconf.connection); sw->gc = xcb_generate_id(globalconf.connection);
xcb_create_gc(globalconf.connection, sw->gc, s->root, gc_mask, gc_values); xcb_create_gc(globalconf.connection, sw->gc, s->root, gc_mask, gc_values);
sw->border_width = border_width; sw->border.width = border_width;
sw->position = position; sw->position = position;
return sw;
} }
/** Destroy a simple window and all its resources. /** Destroy all resources of a simple window.
* \param sw The simple_window_t to delete. * \param sw The simple_window_t to wipe.
*/ */
void void
simplewindow_delete(simple_window_t **sw) simplewindow_wipe(simple_window_t *sw)
{ {
if(*sw) xcb_destroy_window(globalconf.connection, sw->window);
{ xcb_free_pixmap(globalconf.connection, sw->pixmap);
xcb_destroy_window(globalconf.connection, (*sw)->window); xcb_free_gc(globalconf.connection, sw->gc);
xcb_free_pixmap(globalconf.connection, (*sw)->pixmap); draw_context_wipe(&sw->ctx);
xcb_free_gc(globalconf.connection, (*sw)->gc);
draw_context_wipe(&(*sw)->ctx);
p_delete(sw);
}
} }
/** Move a simple window. /** Move a simple window.
@ -147,6 +138,7 @@ static void
simplewindow_draw_context_update(simple_window_t *sw, xcb_screen_t *s) simplewindow_draw_context_update(simple_window_t *sw, xcb_screen_t *s)
{ {
xcolor_t fg = sw->ctx.fg, bg = sw->ctx.bg; xcolor_t fg = sw->ctx.fg, bg = sw->ctx.bg;
int phys_screen = sw->ctx.phys_screen;
draw_context_wipe(&sw->ctx); draw_context_wipe(&sw->ctx);
@ -161,12 +153,12 @@ simplewindow_draw_context_update(simple_window_t *sw, xcb_screen_t *s)
s->root_depth, s->root_depth,
sw->ctx.pixmap, s->root, sw->ctx.pixmap, s->root,
sw->geometry.height, sw->geometry.width); sw->geometry.height, sw->geometry.width);
draw_context_init(&sw->ctx, sw->phys_screen, draw_context_init(&sw->ctx, phys_screen,
sw->geometry.height, sw->geometry.width, sw->geometry.height, sw->geometry.width,
sw->ctx.pixmap, &fg, &bg); sw->ctx.pixmap, &fg, &bg);
break; break;
default: default:
draw_context_init(&sw->ctx, sw->phys_screen, draw_context_init(&sw->ctx, phys_screen,
sw->geometry.width, sw->geometry.height, sw->geometry.width, sw->geometry.height,
sw->pixmap, &fg, &bg); sw->pixmap, &fg, &bg);
break; break;
@ -183,7 +175,7 @@ simplewindow_resize(simple_window_t *sw, int w, int h)
{ {
if(w > 0 && h > 0 && (sw->geometry.width != w || sw->geometry.height != h)) if(w > 0 && h > 0 && (sw->geometry.width != w || sw->geometry.height != h))
{ {
xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->ctx.phys_screen);
uint32_t resize_win_vals[2]; uint32_t resize_win_vals[2];
sw->geometry.width = resize_win_vals[0] = w; sw->geometry.width = resize_win_vals[0] = w;
@ -209,7 +201,7 @@ void
simplewindow_moveresize(simple_window_t *sw, int x, int y, int w, int h) simplewindow_moveresize(simple_window_t *sw, int x, int y, int w, int h)
{ {
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, sw->phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->ctx.phys_screen);
if(sw->geometry.x != x || sw->geometry.y != y) if(sw->geometry.x != x || sw->geometry.y != y)
{ {
@ -261,7 +253,7 @@ simplewindow_border_width_set(simple_window_t *sw, uint32_t border_width)
{ {
xcb_configure_window(globalconf.connection, sw->window, XCB_CONFIG_WINDOW_BORDER_WIDTH, xcb_configure_window(globalconf.connection, sw->window, XCB_CONFIG_WINDOW_BORDER_WIDTH,
&border_width); &border_width);
sw->border_width = border_width; sw->border.width = border_width;
} }
/** Set a simple window border color. /** Set a simple window border color.
@ -273,6 +265,7 @@ simplewindow_border_color_set(simple_window_t *sw, const xcolor_t *color)
{ {
xcb_change_window_attributes(globalconf.connection, sw->window, xcb_change_window_attributes(globalconf.connection, sw->window,
XCB_CW_BORDER_PIXEL, &color->pixel); XCB_CW_BORDER_PIXEL, &color->pixel);
sw->border.color = *color;
} }
// 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

@ -28,10 +28,6 @@
/** A simple window. */ /** A simple window. */
typedef struct simple_window_t typedef struct simple_window_t
{ {
/** Orientation */
/** The physical screen number the window is on. */
int phys_screen;
/** The window object. */ /** The window object. */
xcb_window_t window; xcb_window_t window;
/** The pixmap copied to the window object. */ /** The pixmap copied to the window object. */
@ -40,17 +36,25 @@ typedef struct simple_window_t
xcb_gcontext_t gc; xcb_gcontext_t gc;
/** The window geometry. */ /** The window geometry. */
area_t geometry; area_t geometry;
/** The window border width */ /** The window border */
int border_width; struct
{
/** The window border width */
int width;
/** The window border color */
xcolor_t color;
} border;
/** Draw context */ /** Draw context */
draw_context_t ctx; draw_context_t ctx;
/** Position */ /** Position */
position_t position; position_t position;
} simple_window_t; } simple_window_t;
simple_window_t * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int, void simplewindow_init(simple_window_t *s,
position_t, const xcolor_t *, const xcolor_t *); int, int, int, unsigned int, unsigned int, unsigned int,
void simplewindow_delete(simple_window_t **); position_t, const xcolor_t *, const xcolor_t *);
void simplewindow_wipe(simple_window_t *);
void simplewindow_move(simple_window_t *, int, int); void simplewindow_move(simple_window_t *, int, int);
void simplewindow_resize(simple_window_t *, int, int); void simplewindow_resize(simple_window_t *, int, int);

View file

@ -57,7 +57,7 @@ client_getbytitlebarwin(xcb_window_t win)
client_t *c; client_t *c;
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
if(c->titlebar && c->titlebar->sw && c->titlebar->sw->window == win) if(c->titlebar && c->titlebar->sw.window == win)
return c; return c;
return NULL; return NULL;
@ -69,16 +69,16 @@ client_getbytitlebarwin(xcb_window_t win)
void void
titlebar_draw(client_t *c) titlebar_draw(client_t *c)
{ {
if(!c || !c->titlebar || !c->titlebar->sw || !c->titlebar->position) if(!c || !c->titlebar || !c->titlebar->position)
return; return;
widget_render(c->titlebar->widgets, &c->titlebar->sw->ctx, widget_render(c->titlebar->widgets, &c->titlebar->sw.ctx,
c->titlebar->sw->gc, c->titlebar->sw->pixmap, 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->sw.geometry.x, c->titlebar->sw.geometry.y,
c->titlebar, AWESOME_TYPE_TITLEBAR); c->titlebar, AWESOME_TYPE_TITLEBAR);
simplewindow_refresh_pixmap(c->titlebar->sw); simplewindow_refresh_pixmap(&c->titlebar->sw);
c->titlebar->need_update = false; c->titlebar->need_update = false;
} }
@ -106,36 +106,36 @@ titlebar_geometry_compute(client_t *c, area_t geometry, area_t *res)
return; return;
case Top: case Top:
if(c->titlebar->width) if(c->titlebar->width)
width = MAX(1, MIN(c->titlebar->width, geometry.width - 2 * c->titlebar->border.width)); width = MAX(1, MIN(c->titlebar->width, geometry.width - 2 * c->titlebar->sw.border.width));
else else
width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->border.width); width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->sw.border.width);
switch(c->titlebar->align) switch(c->titlebar->align)
{ {
default: default:
break; break;
case AlignRight: case AlignRight:
x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->border.width; x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->sw.border.width;
break; break;
case AlignCenter: case AlignCenter:
x_offset = (geometry.width - width) / 2; x_offset = (geometry.width - width) / 2;
break; break;
} }
res->x = geometry.x + x_offset; res->x = geometry.x + x_offset;
res->y = geometry.y - c->titlebar->height - 2 * c->titlebar->border.width + c->border; res->y = geometry.y - c->titlebar->height - 2 * c->titlebar->sw.border.width + c->border;
res->width = width; res->width = width;
res->height = c->titlebar->height; res->height = c->titlebar->height;
break; break;
case Bottom: case Bottom:
if(c->titlebar->width) if(c->titlebar->width)
width = MAX(1, MIN(c->titlebar->width, geometry.width - 2 * c->titlebar->border.width)); width = MAX(1, MIN(c->titlebar->width, geometry.width - 2 * c->titlebar->sw.border.width));
else else
width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->border.width); width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->sw.border.width);
switch(c->titlebar->align) switch(c->titlebar->align)
{ {
default: default:
break; break;
case AlignRight: case AlignRight:
x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->border.width; x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->sw.border.width;
break; break;
case AlignCenter: case AlignCenter:
x_offset = (geometry.width - width) / 2; x_offset = (geometry.width - width) / 2;
@ -148,15 +148,15 @@ titlebar_geometry_compute(client_t *c, area_t geometry, area_t *res)
break; break;
case Left: case Left:
if(c->titlebar->width) if(c->titlebar->width)
width = MAX(1, MIN(c->titlebar->width, geometry.height - 2 * c->titlebar->border.width)); width = MAX(1, MIN(c->titlebar->width, geometry.height - 2 * c->titlebar->sw.border.width));
else else
width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->border.width); width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->sw.border.width);
switch(c->titlebar->align) switch(c->titlebar->align)
{ {
default: default:
break; break;
case AlignRight: case AlignRight:
y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->border.width; y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->sw.border.width;
break; break;
case AlignCenter: case AlignCenter:
y_offset = (geometry.height - width) / 2; y_offset = (geometry.height - width) / 2;
@ -169,15 +169,15 @@ titlebar_geometry_compute(client_t *c, area_t geometry, area_t *res)
break; break;
case Right: case Right:
if(c->titlebar->width) if(c->titlebar->width)
width = MAX(1, MIN(c->titlebar->width, geometry.height - 2 * c->titlebar->border.width)); width = MAX(1, MIN(c->titlebar->width, geometry.height - 2 * c->titlebar->sw.border.width));
else else
width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->border.width); width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->sw.border.width);
switch(c->titlebar->align) switch(c->titlebar->align)
{ {
default: default:
break; break;
case AlignRight: case AlignRight:
y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->border.width; y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->sw.border.width;
break; break;
case AlignCenter: case AlignCenter:
y_offset = (geometry.height - width) / 2; y_offset = (geometry.height - width) / 2;
@ -200,6 +200,10 @@ titlebar_init(client_t *c)
int width = 0, height = 0; int width = 0, height = 0;
area_t geom; area_t geom;
/* already had a window? */
if(c->titlebar->sw.window)
simplewindow_wipe(&c->titlebar->sw);
switch(c->titlebar->position) switch(c->titlebar->position)
{ {
default: default:
@ -208,30 +212,29 @@ titlebar_init(client_t *c)
case Top: case Top:
case Bottom: case Bottom:
if(c->titlebar->width) if(c->titlebar->width)
width = MIN(c->titlebar->width, c->geometry.width - 2 * c->titlebar->border.width); width = MIN(c->titlebar->width, c->geometry.width - 2 * c->titlebar->sw.border.width);
else else
width = c->geometry.width + 2 * c->border - 2 * c->titlebar->border.width; width = c->geometry.width + 2 * c->border - 2 * c->titlebar->sw.border.width;
height = c->titlebar->height; height = c->titlebar->height;
break; break;
case Left: case Left:
case Right: case Right:
if(c->titlebar->width) if(c->titlebar->width)
height = MIN(c->titlebar->width, c->geometry.height - 2 * c->titlebar->border.width); height = MIN(c->titlebar->width, c->geometry.height - 2 * c->titlebar->sw.border.width);
else else
height = c->geometry.height + 2 * c->border - 2 * c->titlebar->border.width; height = c->geometry.height + 2 * c->border - 2 * c->titlebar->sw.border.width;
width = c->titlebar->height; width = c->titlebar->height;
break; break;
} }
titlebar_geometry_compute(c, c->geometry, &geom); titlebar_geometry_compute(c, c->geometry, &geom);
c->titlebar->sw = simplewindow_new(c->phys_screen, geom.x, geom.y, simplewindow_init(&c->titlebar->sw, c->phys_screen,
geom.width, geom.height, geom.x, geom.y, geom.width, geom.height,
c->titlebar->border.width, c->titlebar->border.width, c->titlebar->position,
c->titlebar->position, &c->titlebar->colors.fg, &c->titlebar->colors.bg);
&c->titlebar->colors.fg, &c->titlebar->colors.bg);
simplewindow_border_color_set(c->titlebar->sw, &c->titlebar->border.color); simplewindow_border_color_set(&c->titlebar->sw, &c->titlebar->border.color);
client_need_arrange(c); client_need_arrange(c);
@ -302,7 +305,7 @@ luaA_titlebar_newindex(lua_State *L)
size_t len; size_t len;
titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar"); titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
const char *buf, *attr = luaL_checklstring(L, 2, &len); const char *buf, *attr = luaL_checklstring(L, 2, &len);
client_t *c = NULL, **newc; client_t *c = NULL;
int i; int i;
position_t position; position_t position;
@ -310,18 +313,12 @@ luaA_titlebar_newindex(lua_State *L)
{ {
case A_TK_CLIENT: case A_TK_CLIENT:
if(!lua_isnil(L, 3)) if(!lua_isnil(L, 3))
newc = luaA_checkudata(L, 3, "client");
else
newc = NULL;
if(newc)
{ {
client_t **newc = luaA_checkudata(L, 3, "client");
if((*newc)->titlebar) if((*newc)->titlebar)
{ {
simplewindow_delete(&(*newc)->titlebar->sw); xcb_unmap_window(globalconf.connection, (*newc)->titlebar->sw.window);
titlebar_unref(&(*newc)->titlebar); titlebar_unref(&(*newc)->titlebar);
(*newc)->titlebar = NULL;
client_need_arrange(*newc);
} }
/* Attach titlebar to client */ /* Attach titlebar to client */
(*newc)->titlebar = *titlebar; (*newc)->titlebar = *titlebar;
@ -329,16 +326,13 @@ luaA_titlebar_newindex(lua_State *L)
titlebar_init(*newc); titlebar_init(*newc);
c = *newc; c = *newc;
} }
else else if((c = client_getbytitlebar(*titlebar)))
{ {
if((c = client_getbytitlebar(*titlebar))) xcb_unmap_window(globalconf.connection, (*titlebar)->sw.window);
{ /* unref and NULL the ref */
simplewindow_delete(&(*titlebar)->sw); titlebar_unref(&c->titlebar);
/* unref and NULL the ref */ c->titlebar = NULL;
titlebar_unref(&c->titlebar); client_need_arrange(c);
c->titlebar = NULL;
client_need_arrange(c);
}
} }
client_stack(); client_stack();
break; break;
@ -357,16 +351,13 @@ luaA_titlebar_newindex(lua_State *L)
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->border.color, buf, len))) if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->border.color, buf, len)))
if((*titlebar)->sw) simplewindow_border_color_set(&c->titlebar->sw, &c->titlebar->border.color);
xcb_change_window_attributes(globalconf.connection, (*titlebar)->sw->window,
XCB_CW_BORDER_PIXEL, &(*titlebar)->border.color.pixel);
return 0; return 0;
case A_TK_FG: case A_TK_FG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.fg, buf, len))) if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.fg, buf, len)))
{ {
if((*titlebar)->sw) (*titlebar)->sw.ctx.fg = (*titlebar)->colors.fg;
(*titlebar)->sw->ctx.fg = (*titlebar)->colors.fg;
(*titlebar)->need_update = true; (*titlebar)->need_update = true;
} }
return 0; return 0;
@ -374,8 +365,7 @@ luaA_titlebar_newindex(lua_State *L)
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.bg, buf, len))) if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.bg, buf, len)))
{ {
if((*titlebar)->sw) (*titlebar)->sw.ctx.bg = (*titlebar)->colors.bg;
(*titlebar)->sw->ctx.bg = (*titlebar)->colors.bg;
(*titlebar)->need_update = true; (*titlebar)->need_update = true;
} }
break; break;
@ -386,7 +376,6 @@ luaA_titlebar_newindex(lua_State *L)
{ {
(*titlebar)->position = position; (*titlebar)->position = position;
c = client_getbytitlebar(*titlebar); c = client_getbytitlebar(*titlebar);
simplewindow_delete(&c->titlebar->sw);
titlebar_init(c); titlebar_init(c);
} }
break; break;
@ -446,7 +435,7 @@ luaA_titlebar_index(lua_State *L)
luaA_pushcolor(L, &(*titlebar)->colors.bg); luaA_pushcolor(L, &(*titlebar)->colors.bg);
break; break;
case A_TK_POSITION: case A_TK_POSITION:
lua_pushstring(L, position_tostr((*titlebar)->position)); lua_pushstring(L, position_tostr((*titlebar)->position));
break; break;
default: default:
return 0; return 0;

View file

@ -42,25 +42,25 @@ int luaA_titlebar_userdata_new(lua_State *, titlebar_t *);
static inline area_t static inline area_t
titlebar_geometry_add(titlebar_t *t, int border, area_t geometry) titlebar_geometry_add(titlebar_t *t, int border, area_t geometry)
{ {
if(t && t->sw) if(t)
switch(t->position) switch(t->position)
{ {
case Top: case Top:
geometry.y -= t->sw->geometry.height + 2 * t->border.width - border; geometry.y -= t->sw.geometry.height + 2 * t->sw.border.width - border;
geometry.height += t->sw->geometry.height + 2 * t->border.width - border; geometry.height += t->sw.geometry.height + 2 * t->sw.border.width - border;
geometry.width += 2 * border; geometry.width += 2 * border;
break; break;
case Bottom: case Bottom:
geometry.height += t->sw->geometry.height + 2 * t->border.width - border; geometry.height += t->sw.geometry.height + 2 * t->sw.border.width - border;
geometry.width += 2 * border; geometry.width += 2 * border;
break; break;
case Left: case Left:
geometry.x -= t->sw->geometry.width + 2 * t->border.width - border; geometry.x -= t->sw.geometry.width + 2 * t->sw.border.width - border;
geometry.width += t->sw->geometry.width + 2 * t->border.width - border; geometry.width += t->sw.geometry.width + 2 * t->sw.border.width - border;
geometry.height += 2 * border; geometry.height += 2 * border;
break; break;
case Right: case Right:
geometry.width += t->sw->geometry.width + 2 * t->border.width - border; geometry.width += t->sw.geometry.width + 2 * t->sw.border.width - border;
geometry.height += 2 * border; geometry.height += 2 * border;
break; break;
default: default:
@ -84,25 +84,25 @@ titlebar_geometry_add(titlebar_t *t, int border, area_t geometry)
static inline area_t static inline area_t
titlebar_geometry_remove(titlebar_t *t, int border, area_t geometry) titlebar_geometry_remove(titlebar_t *t, int border, area_t geometry)
{ {
if(t && t->sw) if(t)
switch(t->position) switch(t->position)
{ {
case Top: case Top:
geometry.y += t->sw->geometry.height + 2 * t->border.width - border; geometry.y += t->sw.geometry.height + 2 * t->sw.border.width - border;
geometry.height -= t->sw->geometry.height + 2 * t->border.width - border; geometry.height -= t->sw.geometry.height + 2 * t->sw.border.width - border;
geometry.width -= 2 * border; geometry.width -= 2 * border;
break; break;
case Bottom: case Bottom:
geometry.height -= t->sw->geometry.height + 2 * t->border.width - border; geometry.height -= t->sw.geometry.height + 2 * t->sw.border.width - border;
geometry.width -= 2 * border; geometry.width -= 2 * border;
break; break;
case Left: case Left:
geometry.x += t->sw->geometry.width + 2 * t->border.width - border; geometry.x += t->sw.geometry.width + 2 * t->sw.border.width - border;
geometry.width -= t->sw->geometry.width + 2 * t->border.width - border; geometry.width -= t->sw.geometry.width + 2 * t->sw.border.width - border;
geometry.height -= 2 * border; geometry.height -= 2 * border;
break; break;
case Right: case Right:
geometry.width -= t->sw->geometry.width + 2 * t->border.width - border; geometry.width -= t->sw.geometry.width + 2 * t->sw.border.width - border;
geometry.height -= 2 * border; geometry.height -= 2 * border;
break; break;
default: default:
@ -125,11 +125,11 @@ titlebar_update_geometry_floating(client_t *c)
{ {
area_t geom; area_t geom;
if(!c->titlebar || !c->titlebar->sw) if(!c->titlebar)
return; return;
titlebar_geometry_compute(c, c->geometry, &geom); titlebar_geometry_compute(c, c->geometry, &geom);
simplewindow_moveresize(c->titlebar->sw, geom.x, geom.y, geom.width, geom.height); simplewindow_moveresize(&c->titlebar->sw, geom.x, geom.y, geom.width, geom.height);
c->titlebar->need_update = true; c->titlebar->need_update = true;
} }
@ -142,11 +142,11 @@ titlebar_update_geometry_tiled(client_t *c, area_t geometry)
{ {
area_t geom; area_t geom;
if(!c->titlebar || !c->titlebar->sw) if(!c->titlebar)
return; return;
titlebar_geometry_compute(c, geometry, &geom); titlebar_geometry_compute(c, geometry, &geom);
simplewindow_moveresize(c->titlebar->sw, geom.x, geom.y, geom.width, geom.height); simplewindow_moveresize(&c->titlebar->sw, geom.x, geom.y, geom.width, geom.height);
c->titlebar->need_update = true; c->titlebar->need_update = true;
} }

View file

@ -54,7 +54,7 @@ systray_draw(draw_context_t *ctx,
int i = 0; int i = 0;
xembed_window_t *em; xembed_window_t *em;
for(em = globalconf.embedded; em; em = em->next) for(em = globalconf.embedded; em; em = em->next)
if(em->phys_screen == sb->sw->phys_screen) if(em->phys_screen == sb->sw.ctx.phys_screen)
i++; i++;
/** \todo use clas hints */ /** \todo use clas hints */
w->area.width = MIN(i * ctx->height, ctx->width - used); w->area.width = MIN(i * ctx->height, ctx->width - used);
@ -82,7 +82,7 @@ systray_draw(draw_context_t *ctx,
/* set statusbar orientation */ /* set statusbar orientation */
/** \todo stop setting that property on each redraw */ /** \todo stop setting that property on each redraw */
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
globalconf.screens[sb->sw->phys_screen].systray.window, globalconf.screens[sb->sw.ctx.phys_screen].systray.window,
_NET_SYSTEM_TRAY_ORIENTATION, CARDINAL, 32, 1, &orient); _NET_SYSTEM_TRAY_ORIENTATION, CARDINAL, 32, 1, &orient);
return w->area.width; return w->area.width;