[nautilus] query-editor: fixup event handling code



commit b6d0261485934dd9ecbf8d72e4d1232d4199d7cb
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jul 14 16:23:36 2012 -0400

    query-editor: fixup event handling code
    
    - We shouldn't try to realize the entry again if it's realized already
    - Since gdk_event_copy() refs the event's GdkWindow, and
      gdk_event_free() unrefs it, we should make sure to unref the original
      window first, and add a reference to the GdkWindow we replace in the
      event, or we will trigger criticals when unrealizing the toplevel.

 src/nautilus-query-editor.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 56752f4..6f67fb9 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -198,6 +198,9 @@ nautilus_query_editor_handle_event (NautilusQueryEditor *editor,
 	const char *new_text;
 
 	editor->details->got_preedit = FALSE;
+	if (!gtk_widget_get_realized (editor->details->entry)) {
+		gtk_widget_realize (editor->details->entry);
+	}
 
 	old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->details->entry)));
 
@@ -205,9 +208,9 @@ nautilus_query_editor_handle_event (NautilusQueryEditor *editor,
 			       G_CALLBACK (entry_preedit_changed_cb), editor);
 
 	new_event = gdk_event_copy ((GdkEvent *) event);
-	((GdkEventKey *) new_event)->window = gtk_widget_get_window (editor->details->entry);
-
-	gtk_widget_realize (editor->details->entry);
+	g_object_unref (((GdkEventKey *) new_event)->window);
+	((GdkEventKey *) new_event)->window = g_object_ref
+		(gtk_widget_get_window (editor->details->entry));
 	retval = gtk_widget_event (editor->details->entry, new_event);
 	gdk_event_free (new_event);
 
@@ -217,9 +220,7 @@ nautilus_query_editor_handle_event (NautilusQueryEditor *editor,
 	text_changed = strcmp (old_text, new_text) != 0;
 	g_free (old_text);
 
-	handled = (editor->details->got_preedit
-		   || (retval && text_changed));
-
+	handled = (editor->details->got_preedit) || (retval && text_changed);
 	editor->details->got_preedit = FALSE;
 
 	return handled;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]