[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 085929c: Release xft_data in widget destroy callbac
From: |
YAMAMOTO Mitsuharu |
Subject: |
[Emacs-diffs] master 085929c: Release xft_data in widget destroy callback to avoid visual distraction |
Date: |
Tue, 23 Apr 2019 04:27:54 -0400 (EDT) |
branch: master
commit 085929ca9309a170b5b4252448f1291e3db2b594
Author: YAMAMOTO Mitsuharu <address@hidden>
Commit: YAMAMOTO Mitsuharu <address@hidden>
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.
---
lwlib/lwlib-Xaw.c | 52 ++++++++++++++++++++++++----------------------------
lwlib/lwlib-int.h | 1 -
2 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c
index 9655076..a00f8aa 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 e21fa1f..28b1fb9 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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 085929c: Release xft_data in widget destroy callback to avoid visual distraction,
YAMAMOTO Mitsuharu <=