diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2013-04-04 16:08:35 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2013-04-04 16:08:35 -0400 |
commit | 9c5ee628e3c669fef579f13c848000fca5379c80 (patch) | |
tree | bd0ef6d0456dac8ad66f7b5290473660dd872b56 | |
parent | b61e1d03b42723e13cf7dd05a26c9bd92dbac0ce (diff) | |
download | nautilus-9c5ee628e3c669fef579f13c848000fca5379c80.tar.gz |
query-editor: avoid focus change hack when focusing the search entry
Code was very fragile and didn't work when the window wasn't initially
realized, such as when launching a search from the Shell provider.
We can get the same effect by moving the cursor at the end of the entry
after the focus has been set.
https://bugzilla.gnome.org/show_bug.cgi?id=697224
-rw-r--r-- | src/nautilus-query-editor.c | 68 |
1 files changed, 3 insertions, 65 deletions
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c index 023e011f4..7c75f4b67 100644 --- a/src/nautilus-query-editor.c +++ b/src/nautilus-query-editor.c @@ -108,70 +108,6 @@ static NautilusQueryEditorRowOps row_type[] = { G_DEFINE_TYPE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE_BOX); -/* taken from gtk/gtktreeview.c */ -static void -send_focus_change (GtkWidget *widget, - GdkDevice *device, - gboolean in) -{ - GdkDeviceManager *device_manager; - GList *devices, *d; - - device_manager = gdk_display_get_device_manager (gtk_widget_get_display (widget)); - devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER); - devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE)); - devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING)); - - for (d = devices; d; d = d->next) { - GdkDevice *dev = d->data; - GdkEvent *fevent; - GdkWindow *window; - - if (gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD) - continue; - - window = gtk_widget_get_window (widget); - - /* Skip non-master keyboards that haven't - * selected for events from this window - */ - if (gdk_device_get_device_type (dev) != GDK_DEVICE_TYPE_MASTER && - !gdk_window_get_device_events (window, dev)) - continue; - - fevent = gdk_event_new (GDK_FOCUS_CHANGE); - - fevent->focus_change.type = GDK_FOCUS_CHANGE; - fevent->focus_change.window = g_object_ref (window); - fevent->focus_change.in = in; - gdk_event_set_device (fevent, device); - - gtk_widget_send_focus_change (widget, fevent); - - gdk_event_free (fevent); - } - - g_list_free (devices); -} - -static void -entry_focus_hack (GtkWidget *entry, - GdkDevice *device) -{ - GtkEntryClass *entry_class; - GtkWidgetClass *entry_parent_class; - - /* Grab focus will select all the text. We don't want that to happen, so we - * call the parent instance and bypass the selection change. This is probably - * really non-kosher. */ - entry_class = g_type_class_peek (GTK_TYPE_ENTRY); - entry_parent_class = g_type_class_peek_parent (entry_class); - (entry_parent_class->grab_focus) (entry); - - /* send focus-in event */ - send_focus_change (entry, device, TRUE); -} - gboolean nautilus_query_editor_handle_event (NautilusQueryEditor *editor, GdkEventKey *event) @@ -262,7 +198,9 @@ nautilus_query_editor_grab_focus (GtkWidget *widget) NautilusQueryEditor *editor = NAUTILUS_QUERY_EDITOR (widget); if (gtk_widget_get_visible (widget)) { - entry_focus_hack (editor->details->entry, gtk_get_current_event_device ()); + /* avoid selecting the entry text */ + gtk_widget_grab_focus (editor->details->entry); + gtk_editable_set_position (GTK_EDITABLE (editor->details->entry), -1); } } |