Package: gtk

Function gtk-search-bar-handle-event

Lambda List

gtk-search-bar-handle-event (search-bar event)

Arguments

search-bar -- a gtk-search-bar widget
event -- a gdk-event containing key press events

Return Value

+gdk-event-stop+ if the key press event resulted in text being entered in the search entry, and revealing the search bar if necessary, +gdk-event-propagate+ otherwise.

Details

This function should be called when the toplevel window which contains the search bar received a key event.

If the key event is handled by the search bar, the bar will be shown, the entry populated with the entered text and +gdk-event-stop+ will be returned. The caller should ensure that events are not propagated further.

If no entry has been connected to the search bar, using the function gtk-search-bar-connect-entry, this function will return immediately with a warning.

Example

Showing the search bar on key presses
 static gboolean
 on_key_press_event (GtkWidget *widget,
                     GdkEvent  *event,
                     gpointer   user_data)
 {
   GtkSearchBar *bar = GTK_SEARCH_BAR (user_data);
   return gtk_search_bar_handle_event (bar, event);
 }

static void create_toplevel (void) { GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); GtkWindow *search_bar = gtk_search_bar_new ();

// Add more widgets to the window...

g_signal_connect (window, "key-press-event", G_CALLBACK (on_key_press_event), search_bar); }
 

See also

2020-6-1