mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
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
5 changed files with 64 additions and 64 deletions
32
event.c
32
event.c
|
@ -87,10 +87,9 @@ event_handle_mouse_button(client_t *c,
|
|||
* \return A widget node.
|
||||
*/
|
||||
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;
|
||||
widget_node_t *w;
|
||||
|
||||
/* Need to transform coordinates like it was top/bottom */
|
||||
switch(position)
|
||||
|
@ -109,11 +108,14 @@ widget_getbycoords(position_t position, widget_node_t *widgets, int width, int h
|
|||
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 &&
|
||||
*x >= w->area.x && *x < w->area.x + w->area.width
|
||||
&& *y >= w->area.y && *y < w->area.y + w->area.height)
|
||||
return w;
|
||||
}
|
||||
|
||||
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_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.height,
|
||||
&ev->event_x, &ev->event_y)))
|
||||
|
@ -331,21 +333,21 @@ event_handle_destroynotify(void *data __attribute__ ((unused)),
|
|||
*/
|
||||
static void
|
||||
event_handle_widget_motionnotify(void *object,
|
||||
widget_node_t **mouse_over,
|
||||
widget_t **mouse_over,
|
||||
widget_node_t *w)
|
||||
{
|
||||
if(w != *mouse_over)
|
||||
if(w->widget != *mouse_over)
|
||||
{
|
||||
if(*mouse_over)
|
||||
{
|
||||
/* call mouse leave function on old widget */
|
||||
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)
|
||||
{
|
||||
/* 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_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);
|
||||
widget_node_t *w;
|
||||
|
||||
if(wibox)
|
||||
{
|
||||
w = widget_getbycoords(wibox->position, wibox->widgets,
|
||||
wibox->sw.geometry.width,
|
||||
wibox->sw.geometry.height,
|
||||
&ev->event_x, &ev->event_y);
|
||||
if(wibox
|
||||
&& (w = widget_getbycoords(wibox->position, &wibox->widgets,
|
||||
wibox->sw.geometry.width,
|
||||
wibox->sw.geometry.height,
|
||||
&ev->event_x, &ev->event_y)))
|
||||
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
|
|||
{
|
||||
/* call mouse leave function on widget the mouse was over */
|
||||
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;
|
||||
|
|
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 struct awesome_t awesome_t;
|
||||
|
||||
ARRAY_TYPE(widget_node_t, widget_node)
|
||||
|
||||
/** Wibox type */
|
||||
typedef struct
|
||||
{
|
||||
|
@ -104,10 +106,10 @@ typedef struct
|
|||
/** Screen */
|
||||
int screen;
|
||||
/** Widget list */
|
||||
widget_node_t *widgets;
|
||||
widget_node_array_t widgets;
|
||||
luaA_ref widgets_table;
|
||||
/** Widget the mouse is over */
|
||||
widget_node_t *mouse_over;
|
||||
widget_t *mouse_over;
|
||||
/** Need update */
|
||||
bool need_update;
|
||||
} wibox_t;
|
||||
|
@ -185,22 +187,8 @@ struct widget_node_t
|
|||
widget_t *widget;
|
||||
/** The area where the widget was drawn */
|
||||
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 */
|
||||
typedef struct
|
||||
{
|
||||
|
|
14
wibox.c
14
wibox.c
|
@ -114,12 +114,12 @@ wibox_systray_kickout(int phys_screen)
|
|||
static void
|
||||
wibox_systray_refresh(wibox_t *wibox)
|
||||
{
|
||||
widget_node_t *systray;
|
||||
|
||||
if(wibox->screen == SCREEN_UNDEF)
|
||||
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)
|
||||
{
|
||||
uint32_t config_back[] = { wibox->sw.ctx.bg.pixel };
|
||||
|
@ -263,6 +263,7 @@ wibox_systray_refresh(wibox_t *wibox)
|
|||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Update the wibox position. It deletes every wibox resources and
|
||||
|
@ -447,7 +448,7 @@ wibox_delete(wibox_t **wibox)
|
|||
{
|
||||
simplewindow_wipe(&(*wibox)->sw);
|
||||
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->widgets_table);
|
||||
widget_node_list_wipe(&(*wibox)->widgets);
|
||||
widget_node_array_wipe(&(*wibox)->widgets);
|
||||
p_delete(wibox);
|
||||
}
|
||||
|
||||
|
@ -481,7 +482,7 @@ wibox_draw(wibox_t *wibox)
|
|||
{
|
||||
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->screen, wibox->sw.orientation,
|
||||
wibox->sw.geometry.x, wibox->sw.geometry.y,
|
||||
|
@ -697,7 +698,8 @@ luaA_wibox_new(lua_State *L)
|
|||
static void
|
||||
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);
|
||||
wibox->mouse_over = NULL;
|
||||
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.
|
||||
*/
|
||||
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))
|
||||
{
|
||||
|
@ -103,9 +103,10 @@ luaA_table2widgets(lua_State *L, widget_node_t **widgets)
|
|||
widget_t **widget = luaA_toudata(L, -1, "widget");
|
||||
if(widget)
|
||||
{
|
||||
widget_node_t *w = p_new(widget_node_t, 1);
|
||||
w->widget = widget_ref(widget);
|
||||
widget_node_list_append(widgets, w);
|
||||
widget_node_t w;
|
||||
p_clear(&w, 1);
|
||||
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.
|
||||
*/
|
||||
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 x, int y, wibox_t *wibox)
|
||||
{
|
||||
xcb_pixmap_t rootpix;
|
||||
xcb_screen_t *s;
|
||||
widget_node_t *w;
|
||||
int left = 0, right = 0;
|
||||
char *data;
|
||||
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);
|
||||
|
||||
for(w = wnode; w; w = w->next)
|
||||
if(w->widget->align == AlignLeft && w->widget->isvisible)
|
||||
left += w->widget->draw(ctx, screen, w, left, (left + right), wibox);
|
||||
for(int i = 0; i < widgets->len; i++)
|
||||
if(widgets->tab[i].widget->align == AlignLeft && widgets->tab[i].widget->isvisible)
|
||||
left += widgets->tab[i].widget->draw(ctx, screen, &widgets->tab[i], left, (left + right), wibox);
|
||||
|
||||
/* renders right widget from last to first */
|
||||
for(w = *widget_node_list_last(&wnode); w; w = w->prev)
|
||||
if(w->widget->align == AlignRight && w->widget->isvisible)
|
||||
right += w->widget->draw(ctx, screen, w, right, (left + right), wibox);
|
||||
for(int i = widgets->len - 1; i; i--)
|
||||
if(widgets->tab[i].widget->align == AlignRight && widgets->tab[i].widget->isvisible)
|
||||
right += widgets->tab[i].widget->draw(ctx, screen, &widgets->tab[i], right, (left + right), wibox);
|
||||
|
||||
/* \todo rewrite this */
|
||||
int flex = 0;
|
||||
for(w = wnode; w; w = w->next)
|
||||
if(w->widget->align == AlignFlex && w->widget->isvisible)
|
||||
for(int i = 0; i < widgets->len; i++)
|
||||
if(widgets->tab[i].widget->align == AlignFlex && widgets->tab[i].widget->isvisible)
|
||||
flex++;
|
||||
|
||||
if(flex)
|
||||
{
|
||||
int length = (ctx->width - (left + right)) / flex;
|
||||
|
||||
for(w = wnode; w; w = w->next)
|
||||
if(w->widget->align == AlignFlex && w->widget->isvisible)
|
||||
left += w->widget->draw(ctx, screen, w, left, (left + right) + length * --flex , wibox);
|
||||
for(int i = 0; i < widgets->len; i++)
|
||||
if(widgets->tab[i].widget->align == AlignFlex && widgets->tab[i].widget->isvisible)
|
||||
left += widgets->tab[i].widget->draw(ctx, screen, &widgets->tab[i], left, (left + right) + length * --flex , wibox);
|
||||
}
|
||||
|
||||
switch(orientation)
|
||||
|
@ -249,10 +249,9 @@ widget_invalidate_cache(int screen, int flags)
|
|||
for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
|
||||
{
|
||||
wibox_t *wibox = globalconf.screens[screen].wiboxes.tab[i];
|
||||
widget_node_t *widget;
|
||||
|
||||
for(widget = wibox->widgets; widget; widget = widget->next)
|
||||
if(widget->widget->cache_flags & flags)
|
||||
for(int j = 0; j < wibox->widgets.len; j++)
|
||||
if(wibox->widgets.tab[j].widget->cache_flags & flags)
|
||||
{
|
||||
wibox->need_update = true;
|
||||
break;
|
||||
|
@ -272,8 +271,8 @@ widget_invalidate_bywidget(widget_t *widget)
|
|||
{
|
||||
wibox_t *wibox = globalconf.screens[screen].wiboxes.tab[i];
|
||||
if(!wibox->need_update)
|
||||
for(widget_node_t *witer = wibox->widgets; witer; witer = witer->next)
|
||||
if(witer->widget == widget)
|
||||
for(int j = 0; j < wibox->widgets.len; j++)
|
||||
if(wibox->widgets.tab[j].widget == widget)
|
||||
{
|
||||
wibox->need_update = true;
|
||||
break;
|
||||
|
@ -282,8 +281,8 @@ widget_invalidate_bywidget(widget_t *widget)
|
|||
|
||||
for(client_t *c = globalconf.clients; c; c = c->next)
|
||||
if(c->titlebar && !c->titlebar->need_update)
|
||||
for(widget_node_t *witer = c->titlebar->widgets; witer; witer = witer->next)
|
||||
if(witer->widget == widget)
|
||||
for(int j = 0; j < c->titlebar->widgets.len; j++)
|
||||
if(c->titlebar->widgets.tab[j].widget == widget)
|
||||
{
|
||||
c->titlebar->need_update = true;
|
||||
break;
|
||||
|
|
15
widget.h
15
widget.h
|
@ -29,10 +29,10 @@
|
|||
void widget_invalidate_cache(int, int);
|
||||
int widget_calculate_offset(int, int, int, int);
|
||||
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 *);
|
||||
void luaA_table2widgets(lua_State *, widget_node_t **);
|
||||
void luaA_table2widgets(lua_State *, widget_node_array_t *);
|
||||
|
||||
void widget_invalidate_bywidget(widget_t *);
|
||||
|
||||
|
@ -42,6 +42,17 @@ widget_constructor_t graph_new;
|
|||
widget_constructor_t systray_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
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
Loading…
Reference in a new issue