From 832842bf81fbc194b75c9440e2944aa2390bf427 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sat, 3 Sep 2022 18:17:04 +0200 Subject: sdgui: don't reload on size-allocate We could annoyingly get these events on window de/focus. --- src/stardict-view.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/stardict-view.c') 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 -- cgit v1.2.3-70-g09d2