From 1a55f59f23421683fd0d480392ce9398f645ee76 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 6 Feb 2020 16:55:34 +0000 Subject: [PATCH] testgtk: Port keyval example to shortcut controllers --- tests/testgtk.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/testgtk.c b/tests/testgtk.c index 47bd34d851..1f6b8c8439 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -1603,14 +1603,15 @@ create_listbox (GtkWidget *widget) static GtkWidget * -accel_button_new (GtkAccelGroup *accel_group, - const gchar *text, - const gchar *accel) +accel_button_new (const gchar *text, + const gchar *accel) { guint keyval; GdkModifierType modifiers; GtkWidget *button; GtkWidget *label; + GtkEventController *controller; + GtkShortcut *shortcut; if (!gtk_accelerator_parse (accel, &keyval, &modifiers)) { @@ -1618,12 +1619,17 @@ accel_button_new (GtkAccelGroup *accel_group, } button = gtk_button_new (); - gtk_widget_add_accelerator (button, "activate", accel_group, - keyval, modifiers, GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); + controller = gtk_shortcut_controller_new (); + gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller), GTK_SHORTCUT_SCOPE_GLOBAL); + gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE); + shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (keyval, modifiers), + gtk_activate_action_new ()); + gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut); + g_object_unref (shortcut); + gtk_widget_add_controller (button, controller); label = gtk_accel_label_new (text); - gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), button); - gtk_widget_show (label); + gtk_accel_label_set_accel (GTK_ACCEL_LABEL (label), keyval, modifiers); gtk_container_add (GTK_CONTAINER (button), label); @@ -1638,7 +1644,6 @@ create_key_lookup (GtkWidget *widget) if (!window) { - GtkAccelGroup *accel_group = gtk_accel_group_new (); GtkWidget *button; GtkWidget *content_area; @@ -1653,8 +1658,6 @@ create_key_lookup (GtkWidget *widget) */ gtk_window_set_default_size (GTK_WINDOW (window), 300, -1); - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); - content_area = gtk_dialog_get_content_area (GTK_DIALOG (window)); button = gtk_button_new_with_mnemonic ("Button 1 (_a)"); @@ -1667,23 +1670,23 @@ create_key_lookup (GtkWidget *widget) gtk_container_add (GTK_CONTAINER (content_area), button); button = gtk_button_new_with_mnemonic ("Button 6 (_b)"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 7", "b"); + button = accel_button_new ("Button 7", "b"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 8", "d"); + button = accel_button_new ("Button 8", "d"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 9", "Cyrillic_ve"); + button = accel_button_new ("Button 9", "Cyrillic_ve"); gtk_container_add (GTK_CONTAINER (content_area), button); button = gtk_button_new_with_mnemonic ("Button 10 (_1)"); gtk_container_add (GTK_CONTAINER (content_area), button); button = gtk_button_new_with_mnemonic ("Button 11 (_!)"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 12", "a"); + button = accel_button_new ("Button 12", "a"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 13", "a"); + button = accel_button_new ("Button 13", "a"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 14", "a"); + button = accel_button_new ("Button 14", "a"); gtk_container_add (GTK_CONTAINER (content_area), button); - button = accel_button_new (accel_group, "Button 15", "b"); + button = accel_button_new ("Button 15", "b"); gtk_container_add (GTK_CONTAINER (content_area), button); window_ptr = &window;