From: YAMAMOTO Mitsuharu Date: Tue, 23 Apr 2019 08:27:04 +0000 (+0900) Subject: Release xft_data in widget destroy callback to avoid visual distraction X-Git-Tag: emacs-27.0.90~3129 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=085929ca9309a170b5b4252448f1291e3db2b594;p=emacs.git 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. --- diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c index 9655076da9d..a00f8aa73f9 100644 --- a/lwlib/lwlib-Xaw.c +++ b/lwlib/lwlib-Xaw.c @@ -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); } } diff --git a/lwlib/lwlib-int.h b/lwlib/lwlib-int.h index e21fa1f1714..28b1fb9508d 100644 --- a/lwlib/lwlib-int.h +++ b/lwlib/lwlib-int.h @@ -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;