aboutsummaryrefslogtreecommitdiff
path: root/src/stardict-view.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-03 18:17:04 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-03 18:17:04 +0200
commit832842bf81fbc194b75c9440e2944aa2390bf427 (patch)
treeeecb354b2e4dda9818edb5c60c197ab9e5e14516 /src/stardict-view.c
parent49072f9d01504dcd1670811b80d6b11bb8c6e1a9 (diff)
downloadtdv-832842bf81fbc194b75c9440e2944aa2390bf427.tar.gz
tdv-832842bf81fbc194b75c9440e2944aa2390bf427.tar.xz
tdv-832842bf81fbc194b75c9440e2944aa2390bf427.zip
sdgui: don't reload on size-allocate
We could annoyingly get these events on window de/focus.
Diffstat (limited to 'src/stardict-view.c')
-rw-r--r--src/stardict-view.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/stardict-view.c b/src/stardict-view.c
index cc7935b..d073b16 100644
--- a/src/stardict-view.c
+++ b/src/stardict-view.c
@@ -316,6 +316,13 @@ adjust_for_height (StardictView *self)
self->entries = g_list_concat (self->entries, g_list_reverse (append));
gtk_widget_queue_draw (widget);
+
+ // Also handling this for adjust_for_offset(), which calls this.
+ PangoLayout *selection = g_weak_ref_get (&self->selection);
+ if (selection)
+ g_object_unref (selection);
+ else
+ self->selection_begin = self->selection_end = -1;
}
static void
@@ -365,7 +372,6 @@ reload (StardictView *self)
{
GtkWidget *widget = GTK_WIDGET (self);
- // FIXME: this invalidates the selection, we'd need better identification
g_list_free_full (self->entries, (GDestroyNotify) view_entry_destroy);
self->entries = NULL;
gtk_widget_queue_draw (widget);
@@ -590,7 +596,28 @@ stardict_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
GTK_WIDGET_CLASS (stardict_view_parent_class)
->size_allocate (widget, allocation);
- reload (STARDICT_VIEW (widget));
+ StardictView *self = STARDICT_VIEW (widget);
+ if (!gtk_widget_get_realized (widget) || !self->dict)
+ return;
+
+ PangoLayout *selection = g_weak_ref_get (&self->selection), **origin = NULL;
+ for (GList *iter = self->entries; iter; iter = iter->next)
+ {
+ ViewEntry *ve = iter->data;
+ if (selection && selection == ve->word_layout)
+ origin = &ve->word_layout;
+ if (selection && selection == ve->definition_layout)
+ origin = &ve->definition_layout;
+ }
+ if (selection)
+ g_object_unref (selection);
+
+ for (GList *iter = self->entries; iter; iter = iter->next)
+ view_entry_rebuild_layouts (iter->data, widget);
+ if (origin)
+ g_weak_ref_set (&self->selection, *origin);
+
+ adjust_for_offset (self);
}
static void