static void drawing_area_hierarchy_changed (GtkWidget *widget, GtkWidget *previous_toplevel) { DrawingArea *area = (DrawingArea *) widget; GSimpleActionGroup *action_group; GSimpleAction *action; GtkWidget *toplevel; gint i; if (previous_toplevel && area->pad_controller) { gtk_widget_remove_controller (previous_toplevel, GTK_EVENT_CONTROLLER (area->pad_controller)); area->pad_controller = NULL; } toplevel = gtk_widget_get_toplevel (GTK_WIDGET (area)); if (!GTK_IS_WINDOW (toplevel)) return; action_group = g_simple_action_group_new (); area->pad_controller = gtk_pad_controller_new (G_ACTION_GROUP (action_group), NULL); for (i = 0; i < G_N_ELEMENTS (pad_actions); i++) { if (pad_actions[i].type == GTK_PAD_ACTION_BUTTON) { action = g_simple_action_new (pad_actions[i].action_name, NULL); g_object_set_data (G_OBJECT (action), "color", (gpointer) pad_colors[i]); g_signal_connect (action, "activate", G_CALLBACK (on_pad_button_activate), area); } else { action = g_simple_action_new_stateful (pad_actions[i].action_name, G_VARIANT_TYPE_DOUBLE, NULL); g_signal_connect (action, "activate", G_CALLBACK (on_pad_knob_change), area); } g_action_map_add_action (G_ACTION_MAP (action_group), G_ACTION (action)); g_object_unref (action); } gtk_pad_controller_set_action_entries (area->pad_controller, pad_actions, G_N_ELEMENTS (pad_actions)); gtk_widget_add_controller (toplevel, GTK_EVENT_CONTROLLER (area->pad_controller)); }
static void drawing_area_unroot (GtkWidget *widget) { DrawingArea *area = (DrawingArea *) widget; GtkWidget *toplevel; toplevel = gtk_widget_get_toplevel (widget); if (area->pad_controller) { gtk_widget_remove_controller (toplevel, GTK_EVENT_CONTROLLER (area->pad_controller)); area->pad_controller = NULL; } GTK_WIDGET_CLASS (drawing_area_parent_class)->unroot (widget); }