wibox: handle widget_node_t as array rather than list
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
4eb096e236
commit
569ea75409
32
event.c
32
event.c
|
@ -87,10 +87,9 @@ event_handle_mouse_button(client_t *c,
|
||||||
* \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 width, int height, int16_t *x, int16_t *y)
|
widget_getbycoords(position_t position, widget_node_array_t *widgets, int width, int height, int16_t *x, int16_t *y)
|
||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
widget_node_t *w;
|
|
||||||
|
|
||||||
/* Need to transform coordinates like it was top/bottom */
|
/* Need to transform coordinates like it was top/bottom */
|
||||||
switch(position)
|
switch(position)
|
||||||
|
@ -109,11 +108,14 @@ widget_getbycoords(position_t position, widget_node_t *widgets, int width, int h
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(w = widgets; w; w = w->next)
|
for(int i = 0; i < widgets->len; i++)
|
||||||
|
{
|
||||||
|
widget_node_t *w = &widgets->tab[i];
|
||||||
if(w->widget->isvisible &&
|
if(w->widget->isvisible &&
|
||||||
*x >= w->area.x && *x < w->area.x + w->area.width
|
*x >= w->area.x && *x < w->area.x + w->area.width
|
||||||
&& *y >= w->area.y && *y < w->area.y + w->area.height)
|
&& *y >= w->area.y && *y < w->area.y + w->area.height)
|
||||||
return w;
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +150,7 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
|
||||||
ev->event_x -= wibox->sw.geometry.x;
|
ev->event_x -= wibox->sw.geometry.x;
|
||||||
ev->event_y -= wibox->sw.geometry.y;
|
ev->event_y -= wibox->sw.geometry.y;
|
||||||
}
|
}
|
||||||
if((w = widget_getbycoords(wibox->position, wibox->widgets,
|
if((w = widget_getbycoords(wibox->position, &wibox->widgets,
|
||||||
wibox->sw.geometry.width,
|
wibox->sw.geometry.width,
|
||||||
wibox->sw.geometry.height,
|
wibox->sw.geometry.height,
|
||||||
&ev->event_x, &ev->event_y)))
|
&ev->event_x, &ev->event_y)))
|
||||||
|
@ -331,21 +333,21 @@ event_handle_destroynotify(void *data __attribute__ ((unused)),
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
event_handle_widget_motionnotify(void *object,
|
event_handle_widget_motionnotify(void *object,
|
||||||
widget_node_t **mouse_over,
|
widget_t **mouse_over,
|
||||||
widget_node_t *w)
|
widget_node_t *w)
|
||||||
{
|
{
|
||||||
if(w != *mouse_over)
|
if(w->widget != *mouse_over)
|
||||||
{
|
{
|
||||||
if(*mouse_over)
|
if(*mouse_over)
|
||||||
{
|
{
|
||||||
/* call mouse leave function on old widget */
|
/* call mouse leave function on old widget */
|
||||||
luaA_wibox_userdata_new(globalconf.L, object);
|
luaA_wibox_userdata_new(globalconf.L, object);
|
||||||
luaA_dofunction(globalconf.L, (*mouse_over)->widget->mouse_leave, 1, 0);
|
luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
|
||||||
}
|
}
|
||||||
if(w)
|
if(w)
|
||||||
{
|
{
|
||||||
/* call mouse enter function on new widget and register it */
|
/* call mouse enter function on new widget and register it */
|
||||||
*mouse_over = w;
|
*mouse_over = w->widget;
|
||||||
luaA_wibox_userdata_new(globalconf.L, object);
|
luaA_wibox_userdata_new(globalconf.L, object);
|
||||||
luaA_dofunction(globalconf.L, w->widget->mouse_enter, 1, 0);
|
luaA_dofunction(globalconf.L, w->widget->mouse_enter, 1, 0);
|
||||||
}
|
}
|
||||||
|
@ -365,14 +367,12 @@ event_handle_motionnotify(void *data __attribute__ ((unused)),
|
||||||
wibox_t *wibox = wibox_getbywin(ev->event);
|
wibox_t *wibox = wibox_getbywin(ev->event);
|
||||||
widget_node_t *w;
|
widget_node_t *w;
|
||||||
|
|
||||||
if(wibox)
|
if(wibox
|
||||||
{
|
&& (w = widget_getbycoords(wibox->position, &wibox->widgets,
|
||||||
w = widget_getbycoords(wibox->position, wibox->widgets,
|
wibox->sw.geometry.width,
|
||||||
wibox->sw.geometry.width,
|
wibox->sw.geometry.height,
|
||||||
wibox->sw.geometry.height,
|
&ev->event_x, &ev->event_y)))
|
||||||
&ev->event_x, &ev->event_y);
|
|
||||||
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
|
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
|
||||||
{
|
{
|
||||||
/* call mouse leave function on widget the mouse was over */
|
/* call mouse leave function on widget the mouse was over */
|
||||||
luaA_wibox_userdata_new(globalconf.L, wibox);
|
luaA_wibox_userdata_new(globalconf.L, wibox);
|
||||||
luaA_dofunction(globalconf.L, wibox->mouse_over->widget->mouse_leave, 1, 0);
|
luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
20
structs.h
20
structs.h
|
@ -84,6 +84,8 @@ typedef widget_t *(widget_constructor_t)(alignment_t);
|
||||||
typedef void (widget_destructor_t)(widget_t *);
|
typedef void (widget_destructor_t)(widget_t *);
|
||||||
typedef struct awesome_t awesome_t;
|
typedef struct awesome_t awesome_t;
|
||||||
|
|
||||||
|
ARRAY_TYPE(widget_node_t, widget_node)
|
||||||
|
|
||||||
/** Wibox type */
|
/** Wibox type */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -104,10 +106,10 @@ typedef struct
|
||||||
/** Screen */
|
/** Screen */
|
||||||
int screen;
|
int screen;
|
||||||
/** Widget list */
|
/** Widget list */
|
||||||
widget_node_t *widgets;
|
widget_node_array_t widgets;
|
||||||
luaA_ref widgets_table;
|
luaA_ref widgets_table;
|
||||||
/** Widget the mouse is over */
|
/** Widget the mouse is over */
|
||||||
widget_node_t *mouse_over;
|
widget_t *mouse_over;
|
||||||
/** Need update */
|
/** Need update */
|
||||||
bool need_update;
|
bool need_update;
|
||||||
} wibox_t;
|
} wibox_t;
|
||||||
|
@ -185,22 +187,8 @@ struct widget_node_t
|
||||||
widget_t *widget;
|
widget_t *widget;
|
||||||
/** The area where the widget was drawn */
|
/** The area where the widget was drawn */
|
||||||
area_t area;
|
area_t area;
|
||||||
/** Next and previous widget in the list */
|
|
||||||
widget_node_t *prev, *next;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Delete a widget node structure.
|
|
||||||
* \param node The node to destroy.
|
|
||||||
*/
|
|
||||||
static inline void
|
|
||||||
widget_node_delete(widget_node_t **node)
|
|
||||||
{
|
|
||||||
widget_unref(&(*node)->widget);
|
|
||||||
p_delete(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
DO_SLIST(widget_node_t, widget_node, widget_node_delete)
|
|
||||||
|
|
||||||
/* Strut */
|
/* Strut */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
14
wibox.c
14
wibox.c
|
@ -114,12 +114,12 @@ wibox_systray_kickout(int phys_screen)
|
||||||
static void
|
static void
|
||||||
wibox_systray_refresh(wibox_t *wibox)
|
wibox_systray_refresh(wibox_t *wibox)
|
||||||
{
|
{
|
||||||
widget_node_t *systray;
|
|
||||||
|
|
||||||
if(wibox->screen == SCREEN_UNDEF)
|
if(wibox->screen == SCREEN_UNDEF)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(systray = wibox->widgets; systray; systray = systray->next)
|
for(int i = 0; i < wibox->widgets.len; i++)
|
||||||
|
{
|
||||||
|
widget_node_t *systray = &wibox->widgets.tab[i];
|
||||||
if(systray->widget->type == systray_new)
|
if(systray->widget->type == systray_new)
|
||||||
{
|
{
|
||||||
uint32_t config_back[] = { wibox->sw.ctx.bg.pixel };
|
uint32_t config_back[] = { wibox->sw.ctx.bg.pixel };
|
||||||
|
@ -263,6 +263,7 @@ wibox_systray_refresh(wibox_t *wibox)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the wibox position. It deletes every wibox resources and
|
/** Update the wibox position. It deletes every wibox resources and
|
||||||
|
@ -447,7 +448,7 @@ wibox_delete(wibox_t **wibox)
|
||||||
{
|
{
|
||||||
simplewindow_wipe(&(*wibox)->sw);
|
simplewindow_wipe(&(*wibox)->sw);
|
||||||
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->widgets_table);
|
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->widgets_table);
|
||||||
widget_node_list_wipe(&(*wibox)->widgets);
|
widget_node_array_wipe(&(*wibox)->widgets);
|
||||||
p_delete(wibox);
|
p_delete(wibox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,7 +482,7 @@ wibox_draw(wibox_t *wibox)
|
||||||
{
|
{
|
||||||
if(wibox->isvisible)
|
if(wibox->isvisible)
|
||||||
{
|
{
|
||||||
widget_render(wibox->widgets, &wibox->sw.ctx, wibox->sw.gc,
|
widget_render(&wibox->widgets, &wibox->sw.ctx, wibox->sw.gc,
|
||||||
wibox->sw.pixmap,
|
wibox->sw.pixmap,
|
||||||
wibox->screen, wibox->sw.orientation,
|
wibox->screen, wibox->sw.orientation,
|
||||||
wibox->sw.geometry.x, wibox->sw.geometry.y,
|
wibox->sw.geometry.x, wibox->sw.geometry.y,
|
||||||
|
@ -697,7 +698,8 @@ luaA_wibox_new(lua_State *L)
|
||||||
static void
|
static void
|
||||||
wibox_widgets_table_build(lua_State *L, wibox_t *wibox)
|
wibox_widgets_table_build(lua_State *L, wibox_t *wibox)
|
||||||
{
|
{
|
||||||
widget_node_list_wipe(&wibox->widgets);
|
widget_node_array_wipe(&wibox->widgets);
|
||||||
|
widget_node_array_init(&wibox->widgets);
|
||||||
luaA_table2widgets(L, &wibox->widgets);
|
luaA_table2widgets(L, &wibox->widgets);
|
||||||
wibox->mouse_over = NULL;
|
wibox->mouse_over = NULL;
|
||||||
wibox->need_update = true;
|
wibox->need_update = true;
|
||||||
|
|
47
widget.c
47
widget.c
|
@ -87,7 +87,7 @@ widget_common_button(widget_node_t *w,
|
||||||
* \param widgets The linked list of widget node.
|
* \param widgets The linked list of widget node.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
luaA_table2widgets(lua_State *L, widget_node_t **widgets)
|
luaA_table2widgets(lua_State *L, widget_node_array_t *widgets)
|
||||||
{
|
{
|
||||||
if(lua_istable(L, -1))
|
if(lua_istable(L, -1))
|
||||||
{
|
{
|
||||||
|
@ -103,9 +103,10 @@ luaA_table2widgets(lua_State *L, widget_node_t **widgets)
|
||||||
widget_t **widget = luaA_toudata(L, -1, "widget");
|
widget_t **widget = luaA_toudata(L, -1, "widget");
|
||||||
if(widget)
|
if(widget)
|
||||||
{
|
{
|
||||||
widget_node_t *w = p_new(widget_node_t, 1);
|
widget_node_t w;
|
||||||
w->widget = widget_ref(widget);
|
p_clear(&w, 1);
|
||||||
widget_node_list_append(widgets, w);
|
w.widget = widget_ref(widget);
|
||||||
|
widget_node_array_append(widgets, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,13 +124,12 @@ luaA_table2widgets(lua_State *L, widget_node_t **widgets)
|
||||||
* \todo Remove GC.
|
* \todo Remove GC.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_pixmap_t rotate_px,
|
widget_render(widget_node_array_t *widgets, draw_context_t *ctx, xcb_gcontext_t gc, xcb_pixmap_t rotate_px,
|
||||||
int screen, orientation_t orientation,
|
int screen, orientation_t orientation,
|
||||||
int x, int y, wibox_t *wibox)
|
int x, int y, wibox_t *wibox)
|
||||||
{
|
{
|
||||||
xcb_pixmap_t rootpix;
|
xcb_pixmap_t rootpix;
|
||||||
xcb_screen_t *s;
|
xcb_screen_t *s;
|
||||||
widget_node_t *w;
|
|
||||||
int left = 0, right = 0;
|
int left = 0, right = 0;
|
||||||
char *data;
|
char *data;
|
||||||
xcb_get_property_reply_t *prop_r;
|
xcb_get_property_reply_t *prop_r;
|
||||||
|
@ -183,28 +183,28 @@ widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_
|
||||||
|
|
||||||
draw_rectangle(ctx, rectangle, 1.0, true, &ctx->bg);
|
draw_rectangle(ctx, rectangle, 1.0, true, &ctx->bg);
|
||||||
|
|
||||||
for(w = wnode; w; w = w->next)
|
for(int i = 0; i < widgets->len; i++)
|
||||||
if(w->widget->align == AlignLeft && w->widget->isvisible)
|
if(widgets->tab[i].widget->align == AlignLeft && widgets->tab[i].widget->isvisible)
|
||||||
left += w->widget->draw(ctx, screen, w, left, (left + right), wibox);
|
left += widgets->tab[i].widget->draw(ctx, screen, &widgets->tab[i], left, (left + right), wibox);
|
||||||
|
|
||||||
/* renders right widget from last to first */
|
/* renders right widget from last to first */
|
||||||
for(w = *widget_node_list_last(&wnode); w; w = w->prev)
|
for(int i = widgets->len - 1; i; i--)
|
||||||
if(w->widget->align == AlignRight && w->widget->isvisible)
|
if(widgets->tab[i].widget->align == AlignRight && widgets->tab[i].widget->isvisible)
|
||||||
right += w->widget->draw(ctx, screen, w, right, (left + right), wibox);
|
right += widgets->tab[i].widget->draw(ctx, screen, &widgets->tab[i], right, (left + right), wibox);
|
||||||
|
|
||||||
/* \todo rewrite this */
|
/* \todo rewrite this */
|
||||||
int flex = 0;
|
int flex = 0;
|
||||||
for(w = wnode; w; w = w->next)
|
for(int i = 0; i < widgets->len; i++)
|
||||||
if(w->widget->align == AlignFlex && w->widget->isvisible)
|
if(widgets->tab[i].widget->align == AlignFlex && widgets->tab[i].widget->isvisible)
|
||||||
flex++;
|
flex++;
|
||||||
|
|
||||||
if(flex)
|
if(flex)
|
||||||
{
|
{
|
||||||
int length = (ctx->width - (left + right)) / flex;
|
int length = (ctx->width - (left + right)) / flex;
|
||||||
|
|
||||||
for(w = wnode; w; w = w->next)
|
for(int i = 0; i < widgets->len; i++)
|
||||||
if(w->widget->align == AlignFlex && w->widget->isvisible)
|
if(widgets->tab[i].widget->align == AlignFlex && widgets->tab[i].widget->isvisible)
|
||||||
left += w->widget->draw(ctx, screen, w, left, (left + right) + length * --flex , wibox);
|
left += widgets->tab[i].widget->draw(ctx, screen, &widgets->tab[i], left, (left + right) + length * --flex , wibox);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(orientation)
|
switch(orientation)
|
||||||
|
@ -249,10 +249,9 @@ widget_invalidate_cache(int screen, int flags)
|
||||||
for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
|
for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
|
||||||
{
|
{
|
||||||
wibox_t *wibox = globalconf.screens[screen].wiboxes.tab[i];
|
wibox_t *wibox = globalconf.screens[screen].wiboxes.tab[i];
|
||||||
widget_node_t *widget;
|
|
||||||
|
|
||||||
for(widget = wibox->widgets; widget; widget = widget->next)
|
for(int j = 0; j < wibox->widgets.len; j++)
|
||||||
if(widget->widget->cache_flags & flags)
|
if(wibox->widgets.tab[j].widget->cache_flags & flags)
|
||||||
{
|
{
|
||||||
wibox->need_update = true;
|
wibox->need_update = true;
|
||||||
break;
|
break;
|
||||||
|
@ -272,8 +271,8 @@ widget_invalidate_bywidget(widget_t *widget)
|
||||||
{
|
{
|
||||||
wibox_t *wibox = globalconf.screens[screen].wiboxes.tab[i];
|
wibox_t *wibox = globalconf.screens[screen].wiboxes.tab[i];
|
||||||
if(!wibox->need_update)
|
if(!wibox->need_update)
|
||||||
for(widget_node_t *witer = wibox->widgets; witer; witer = witer->next)
|
for(int j = 0; j < wibox->widgets.len; j++)
|
||||||
if(witer->widget == widget)
|
if(wibox->widgets.tab[j].widget == widget)
|
||||||
{
|
{
|
||||||
wibox->need_update = true;
|
wibox->need_update = true;
|
||||||
break;
|
break;
|
||||||
|
@ -282,8 +281,8 @@ widget_invalidate_bywidget(widget_t *widget)
|
||||||
|
|
||||||
for(client_t *c = globalconf.clients; c; c = c->next)
|
for(client_t *c = globalconf.clients; c; c = c->next)
|
||||||
if(c->titlebar && !c->titlebar->need_update)
|
if(c->titlebar && !c->titlebar->need_update)
|
||||||
for(widget_node_t *witer = c->titlebar->widgets; witer; witer = witer->next)
|
for(int j = 0; j < c->titlebar->widgets.len; j++)
|
||||||
if(witer->widget == widget)
|
if(c->titlebar->widgets.tab[j].widget == widget)
|
||||||
{
|
{
|
||||||
c->titlebar->need_update = true;
|
c->titlebar->need_update = true;
|
||||||
break;
|
break;
|
||||||
|
|
15
widget.h
15
widget.h
|
@ -29,10 +29,10 @@
|
||||||
void widget_invalidate_cache(int, int);
|
void widget_invalidate_cache(int, int);
|
||||||
int widget_calculate_offset(int, int, int, int);
|
int widget_calculate_offset(int, int, int, int);
|
||||||
void widget_common_new(widget_t *);
|
void widget_common_new(widget_t *);
|
||||||
void widget_render(widget_node_t *, draw_context_t *, xcb_gcontext_t, xcb_drawable_t, int, orientation_t, int, int, wibox_t *);
|
void widget_render(widget_node_array_t *, draw_context_t *, xcb_gcontext_t, xcb_drawable_t, int, orientation_t, int, int, wibox_t *);
|
||||||
|
|
||||||
int luaA_widget_userdata_new(lua_State *, widget_t *);
|
int luaA_widget_userdata_new(lua_State *, widget_t *);
|
||||||
void luaA_table2widgets(lua_State *, widget_node_t **);
|
void luaA_table2widgets(lua_State *, widget_node_array_t *);
|
||||||
|
|
||||||
void widget_invalidate_bywidget(widget_t *);
|
void widget_invalidate_bywidget(widget_t *);
|
||||||
|
|
||||||
|
@ -42,6 +42,17 @@ widget_constructor_t graph_new;
|
||||||
widget_constructor_t systray_new;
|
widget_constructor_t systray_new;
|
||||||
widget_constructor_t imagebox_new;
|
widget_constructor_t imagebox_new;
|
||||||
|
|
||||||
|
/** Delete a widget node structure.
|
||||||
|
* \param node The node to destroy.
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
widget_node_delete(widget_node_t *node)
|
||||||
|
{
|
||||||
|
widget_unref(&node->widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARRAY_FUNCS(widget_node_t, widget_node, widget_node_delete)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 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
|
||||||
|
|
Loading…
Reference in New Issue