widget: add detach callbacks
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
5d063874b1
commit
4ba2e22bae
|
@ -335,6 +335,8 @@ luaA_statusbar_widget_remove(lua_State *L)
|
||||||
wnext = w->next;
|
wnext = w->next;
|
||||||
if(w->widget == *widget)
|
if(w->widget == *widget)
|
||||||
{
|
{
|
||||||
|
if((*widget)->detach)
|
||||||
|
(*widget)->detach(*widget, *sb);
|
||||||
widget_unref(widget);
|
widget_unref(widget);
|
||||||
widget_node_list_detach(&(*sb)->widgets, w);
|
widget_node_list_detach(&(*sb)->widgets, w);
|
||||||
p_delete(&w);
|
p_delete(&w);
|
||||||
|
|
|
@ -97,6 +97,8 @@ struct widget_t
|
||||||
widget_constructor_t *type;
|
widget_constructor_t *type;
|
||||||
/** Widget destructor */
|
/** Widget destructor */
|
||||||
widget_destructor_t *destructor;
|
widget_destructor_t *destructor;
|
||||||
|
/** Widget detach function */
|
||||||
|
void (*detach)(widget_t *, void *);
|
||||||
/** Draw function */
|
/** Draw function */
|
||||||
int (*draw)(draw_context_t *, int, widget_node_t *, int, int, void *);
|
int (*draw)(draw_context_t *, int, widget_node_t *, int, int, void *);
|
||||||
/** Index function */
|
/** Index function */
|
||||||
|
|
|
@ -388,6 +388,8 @@ luaA_titlebar_widget_remove(lua_State *L)
|
||||||
wnext = w->next;
|
wnext = w->next;
|
||||||
if(w->widget == *widget)
|
if(w->widget == *widget)
|
||||||
{
|
{
|
||||||
|
if((*widget)->detach)
|
||||||
|
(*widget)->detach(*widget, *tb);
|
||||||
widget_unref(widget);
|
widget_unref(widget);
|
||||||
widget_node_list_detach(&(*tb)->widgets, w);
|
widget_node_list_detach(&(*tb)->widgets, w);
|
||||||
p_delete(&w);
|
p_delete(&w);
|
||||||
|
|
|
@ -251,6 +251,23 @@ taglist_destructor(widget_t *widget)
|
||||||
p_delete(&d);
|
p_delete(&d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Taglist detach function.
|
||||||
|
* \param widget The widget which is detaching.
|
||||||
|
* \param object The object we are leaving.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
taglist_detach(widget_t *widget, void *object)
|
||||||
|
{
|
||||||
|
taglist_data_t *d = widget->data;
|
||||||
|
taglist_drawn_area_t *tda;
|
||||||
|
|
||||||
|
if((tda = taglist_drawn_area_getbyobj(d->drawn_area, object)))
|
||||||
|
{
|
||||||
|
taglist_drawn_area_list_detach(&d->drawn_area, tda);
|
||||||
|
taglist_drawn_area_delete(&tda);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Create a brand new taglist widget.
|
/** Create a brand new taglist widget.
|
||||||
* \param align Widget alignment.
|
* \param align Widget alignment.
|
||||||
* \return A taglist widget.
|
* \return A taglist widget.
|
||||||
|
@ -269,6 +286,7 @@ taglist_new(alignment_t align)
|
||||||
w->draw = taglist_draw;
|
w->draw = taglist_draw;
|
||||||
w->button_press = taglist_button_press;
|
w->button_press = taglist_button_press;
|
||||||
w->destructor = taglist_destructor;
|
w->destructor = taglist_destructor;
|
||||||
|
w->detach = taglist_detach;
|
||||||
|
|
||||||
w->data = d = p_new(taglist_data_t, 1);
|
w->data = d = p_new(taglist_data_t, 1);
|
||||||
d->label = LUA_REFNIL;
|
d->label = LUA_REFNIL;
|
||||||
|
|
|
@ -125,7 +125,6 @@ tasklist_draw(draw_context_t *ctx, int screen,
|
||||||
|
|
||||||
if(!(odata = tasklist_object_data_getbyobj(d->objects_data, p)))
|
if(!(odata = tasklist_object_data_getbyobj(d->objects_data, p)))
|
||||||
{
|
{
|
||||||
/** \todo delete this when the widget is removed from the object */
|
|
||||||
odata = p_new(tasklist_object_data_t, 1);
|
odata = p_new(tasklist_object_data_t, 1);
|
||||||
odata->object = p;
|
odata->object = p;
|
||||||
tasklist_object_data_list_push(&d->objects_data, odata);
|
tasklist_object_data_list_push(&d->objects_data, odata);
|
||||||
|
@ -351,6 +350,23 @@ tasklist_destructor(widget_t *widget)
|
||||||
p_delete(&d);
|
p_delete(&d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Tasklist detach function.
|
||||||
|
* \param widget The widget which is detaching.
|
||||||
|
* \param object The object we are leaving.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
tasklist_detach(widget_t *widget, void *object)
|
||||||
|
{
|
||||||
|
tasklist_data_t *d = widget->data;
|
||||||
|
tasklist_object_data_t *od;
|
||||||
|
|
||||||
|
if((od = tasklist_object_data_getbyobj(d->objects_data, object)))
|
||||||
|
{
|
||||||
|
tasklist_object_data_list_detach(&d->objects_data, od);
|
||||||
|
tasklist_object_data_delete(&od);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Create a new widget tasklist.
|
/** Create a new widget tasklist.
|
||||||
* \param align The widget alignment, which is flex anyway.
|
* \param align The widget alignment, which is flex anyway.
|
||||||
* \return A brand new tasklist widget.
|
* \return A brand new tasklist widget.
|
||||||
|
@ -370,6 +386,7 @@ tasklist_new(alignment_t align __attribute__ ((unused)))
|
||||||
w->newindex = luaA_tasklist_newindex;
|
w->newindex = luaA_tasklist_newindex;
|
||||||
w->data = d = p_new(tasklist_data_t, 1);
|
w->data = d = p_new(tasklist_data_t, 1);
|
||||||
w->destructor = tasklist_destructor;
|
w->destructor = tasklist_destructor;
|
||||||
|
w->detach = tasklist_detach;
|
||||||
|
|
||||||
d->show_icons = true;
|
d->show_icons = true;
|
||||||
d->label = LUA_REFNIL;
|
d->label = LUA_REFNIL;
|
||||||
|
|
Loading…
Reference in New Issue