examples: Simplify handling events in search-bar
authorMohammed Sadiq <sadiq@sadiqpk.org>
Thu, 14 Jun 2018 17:53:14 +0000 (23:23 +0530)
committerMohammed Sadiq <sadiq@sadiqpk.org>
Thu, 14 Jun 2018 17:53:17 +0000 (23:23 +0530)
In search-bar example, we can use gtk_search_bar_set_key_capture_widget()
which would simplify handling keyboard events.

examples/search-bar.c

index c2a6f2d805b299673924d9245d84f420493268c4..e75056e70fbdc37b7a6b007a4d444b84bd092b05 100644 (file)
@@ -20,7 +20,6 @@ activate_cb (GtkApplication *app,
   GtkWidget *box;
   GtkWidget *entry;
   GtkWidget *menu_button;
-  GtkEventController *controller;
 
   window = gtk_application_window_new (app);
   gtk_widget_show (window);
@@ -41,12 +40,7 @@ activate_cb (GtkApplication *app,
   gtk_box_pack_start (GTK_BOX (box), menu_button);
 
   gtk_search_bar_connect_entry (GTK_SEARCH_BAR (search_bar), GTK_ENTRY (entry));
-
-  controller = gtk_event_controller_key_new ();
-  g_object_set_data_full (G_OBJECT (window), "controller", controller, g_object_unref);
-  g_signal_connect (controller, "key-pressed",
-                    G_CALLBACK (window_key_pressed), search_bar);
-  gtk_widget_add_controller (window, controller);
+  gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (search_bar), window);
 }
 
 gint