1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-04 11:40:22 +00:00

Release xft_data in widget destroy callback to avoid visual distraction

* lwlib/lwlib-int.h (struct _widget_instance) [HAVE_XFT]: Remove nr_xft_data.
* lwlib/lwlib-Xaw.c (find_xft_data, xaw_update_one_widget) [HAVE_XFT]: Loop
while widget member is not NULL instead of using nr_xft_data.
(xaw_destroy_instance) [HAVE_XFT]: Move xft_data release code from here ...
(destroy_xft_data) [HAVE_XFT]: ... to here.
(make_dialog) [HAVE_XFT]: Add destroy_xft_data as destroy callback for dialog.
This commit is contained in:
YAMAMOTO Mitsuharu 2019-04-23 17:27:04 +09:00
parent 6fa8d3c894
commit 085929ca93
2 changed files with 24 additions and 29 deletions

View File

@ -113,6 +113,23 @@ fill_xft_data (struct widget_xft_data *data, Widget widget, XftFont *font)
data->p_width = data->p_height = 0;
}
static void
destroy_xft_data (Widget widget, XtPointer closure, XtPointer call_data)
{
struct widget_xft_data *xft_data = closure;
for (int i = 0; xft_data[i].widget; ++i)
{
if (xft_data[i].xft_draw)
XftDrawDestroy (xft_data[i].xft_draw);
if (xft_data[i].p != None)
XFreePixmap (XtDisplay (widget), xft_data[i].p);
}
if (xft_data[0].xft_font)
XftFontClose (XtDisplay (widget), xft_data[0].xft_font);
xfree (xft_data);
}
static XftFont*
openFont (Widget widget, char *name)
{
@ -230,7 +247,7 @@ find_xft_data (Widget widget)
}
if (!inst || !inst->xft_data || !inst->xft_data[0].xft_font) return 0;
for (nr = 0; data == NULL && nr < inst->nr_xft_data; ++nr)
for (nr = 0; data == NULL && inst->xft_data[nr].widget; ++nr)
{
if (inst->xft_data[nr].widget == widget)
data = &inst->xft_data[nr];
@ -327,10 +344,10 @@ xaw_update_one_widget (widget_instance *instance,
{
int th;
int nr;
for (nr = 0; nr < instance->nr_xft_data; ++nr)
for (nr = 0; instance->xft_data[nr].widget; ++nr)
if (instance->xft_data[nr].widget == widget)
break;
if (nr < instance->nr_xft_data)
if (instance->xft_data[nr].widget)
{
set_text (&instance->xft_data[nr], instance->parent,
val->value, 6);
@ -361,28 +378,6 @@ xaw_update_one_value (widget_instance *instance,
void
xaw_destroy_instance (widget_instance *instance)
{
#ifdef HAVE_XFT
if (instance->xft_data)
{
int i;
for (i = 0; i < instance->nr_xft_data; ++i)
{
if (instance->xft_data[i].xft_draw)
XftDrawDestroy (instance->xft_data[i].xft_draw);
if (instance->xft_data[i].p != None)
{
XtVaSetValues (instance->xft_data[i].widget, XtNbitmap, None,
NULL);
XFreePixmap (XtDisplay (instance->widget),
instance->xft_data[i].p);
}
}
if (instance->xft_data[0].xft_font)
XftFontClose (XtDisplay (instance->widget),
instance->xft_data[0].xft_font);
xfree (instance->xft_data);
}
#endif
if (XtIsSubclass (instance->widget, dialogWidgetClass))
/* Need to destroy the Shell too. */
XtDestroyWidget (XtParent (instance->widget));
@ -569,7 +564,6 @@ make_dialog (char* name,
}
}
instance->xft_data = 0;
instance->nr_xft_data = 0;
if (w)
{
XtResource rec[] =
@ -589,11 +583,13 @@ make_dialog (char* name,
if (xft_font)
{
instance->nr_xft_data = left_buttons + right_buttons + 1;
instance->xft_data = calloc (instance->nr_xft_data,
int nr_xft_data = left_buttons + right_buttons + 1;
instance->xft_data = calloc (nr_xft_data + 1,
sizeof(*instance->xft_data));
fill_xft_data (&instance->xft_data[0], w, xft_font);
XtAddCallback (dialog, XtNdestroyCallback, destroy_xft_data,
instance->xft_data);
}
}

View File

@ -32,7 +32,6 @@ typedef struct _widget_instance
Boolean pop_up_p;
#ifdef HAVE_XFT
struct widget_xft_data *xft_data;
int nr_xft_data;
#endif
struct _widget_info* info;
struct _widget_instance* next;