Merge branch 'strdup-avoidance' into 'main'

notebook: Use canonical signal names

See merge request GNOME/gtk!4988
This commit is contained in:
Matthias Clasen 2022-08-28 14:05:02 +00:00
commit f24efd175e
10 changed files with 70 additions and 32 deletions

View File

@ -2050,12 +2050,12 @@ connect_completion_signals (GtkEntryCompletion *completion)
GtkEntryBuffer *buffer = gtk_text_get_buffer (text);
controller = completion->entry_key_controller = gtk_event_controller_key_new ();
gtk_event_controller_set_name (controller, "gtk-entry-completion");
gtk_event_controller_set_static_name (controller, "gtk-entry-completion");
g_signal_connect (controller, "key-pressed",
G_CALLBACK (gtk_entry_completion_key_pressed), completion);
gtk_widget_add_controller (GTK_WIDGET (text), controller);
controller = completion->entry_focus_controller = gtk_event_controller_focus_new ();
gtk_event_controller_set_name (controller, "gtk-entry-completion");
gtk_event_controller_set_static_name (controller, "gtk-entry-completion");
g_signal_connect_swapped (controller, "leave", G_CALLBACK (text_focus_out), completion);
gtk_widget_add_controller (GTK_WIDGET (text), controller);

View File

@ -66,6 +66,7 @@ struct _GtkEventControllerPrivate
char *name;
GtkWidget *target;
GdkEvent *event;
unsigned int name_is_static : 1;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkEventController, gtk_event_controller, G_TYPE_OBJECT)
@ -173,8 +174,9 @@ gtk_event_controller_finalize (GObject *object)
{
GtkEventController *self = GTK_EVENT_CONTROLLER (object);
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self);
g_free (priv->name);
if (!priv->name_is_static)
g_free (priv->name);
G_OBJECT_CLASS (gtk_event_controller_parent_class)->finalize (object);
}
@ -571,8 +573,33 @@ gtk_event_controller_set_name (GtkEventController *controller,
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
g_free (priv->name);
if (!priv->name_is_static)
g_free (priv->name);
priv->name = g_strdup (name);
priv->name_is_static = FALSE;
}
/**
* gtk_event_controller_set_static_name:
* @controller: a `GtkEventController`
* @name: (nullable): a name for @controller, must be a static string
*
* Sets a name on the controller that can be used for debugging.
*
* Since: 4.8
*/
void
gtk_event_controller_set_static_name (GtkEventController *controller,
const char *name)
{
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
if (!priv->name_is_static)
g_free (priv->name);
priv->name = (char *)name;
priv->name_is_static = TRUE;
}
GtkWidget *

View File

@ -68,6 +68,9 @@ const char * gtk_event_controller_get_name (GtkEventControll
GDK_AVAILABLE_IN_ALL
void gtk_event_controller_set_name (GtkEventController *controller,
const char *name);
GDK_AVAILABLE_IN_4_8
void gtk_event_controller_set_static_name (GtkEventController *controller,
const char *name);
GDK_AVAILABLE_IN_ALL
GdkEvent * gtk_event_controller_get_current_event (GtkEventController *controller);

View File

@ -588,7 +588,7 @@ gtk_im_context_wayland_set_client_widget (GtkIMContext *context,
GtkGesture *gesture;
gesture = gtk_gesture_click_new ();
gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (gesture), "wayland-im-context-click");
gtk_event_controller_set_static_name (GTK_EVENT_CONTROLLER (gesture), "wayland-im-context-click");
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
GTK_PHASE_CAPTURE);
g_signal_connect (gesture, "pressed",

View File

@ -976,11 +976,11 @@ add_tab_bindings (GtkWidgetClass *widget_class,
{
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Tab, modifiers,
"move_focus_out",
"move-focus-out",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Tab, modifiers,
"move_focus_out",
"move-focus-out",
"(i)", direction);
}
@ -993,11 +993,11 @@ add_arrow_bindings (GtkWidgetClass *widget_class,
gtk_widget_class_add_binding_signal (widget_class,
keysym, GDK_CONTROL_MASK,
"move_focus_out",
"move-focus-out",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class,
keypad_keysym, GDK_CONTROL_MASK,
"move_focus_out",
"move-focus-out",
"(i)", direction);
}
@ -1011,11 +1011,11 @@ add_reorder_bindings (GtkWidgetClass *widget_class,
gtk_widget_class_add_binding_signal (widget_class,
keysym, GDK_ALT_MASK,
"reorder_tab",
"reorder-tab",
"(ib)", direction, move_to_last);
gtk_widget_class_add_binding_signal (widget_class,
keypad_keysym, GDK_ALT_MASK,
"reorder_tab",
"reorder-tab",
"(ib)", direction, move_to_last);
}

View File

@ -595,7 +595,7 @@ struct _GtkSignalAction
{
GtkShortcutAction parent_instance;
char *name;
const char *name; /* interned */
};
struct _GtkSignalActionClass
@ -616,9 +616,7 @@ G_DEFINE_TYPE (GtkSignalAction, gtk_signal_action, GTK_TYPE_SHORTCUT_ACTION)
static void
gtk_signal_action_finalize (GObject *gobject)
{
GtkSignalAction *self = GTK_SIGNAL_ACTION (gobject);
g_free (self->name);
//GtkSignalAction *self = GTK_SIGNAL_ACTION (gobject);
G_OBJECT_CLASS (gtk_signal_action_parent_class)->finalize (gobject);
}
@ -899,7 +897,7 @@ gtk_signal_action_set_property (GObject *gobject,
switch (prop_id)
{
case SIGNAL_PROP_SIGNAL_NAME:
self->name = g_value_dup_string (value);
self->name = g_intern_string (g_value_get_string (value));
break;
default:
@ -974,11 +972,21 @@ gtk_signal_action_init (GtkSignalAction *self)
GtkShortcutAction *
gtk_signal_action_new (const char *signal_name)
{
GtkShortcutAction *action;
const char *name = "signal-name";
GValue value = G_VALUE_INIT;
g_return_val_if_fail (signal_name != NULL, NULL);
return g_object_new (GTK_TYPE_SIGNAL_ACTION,
"signal-name", signal_name,
NULL);
g_value_init (&value, G_TYPE_STRING);
g_value_set_static_string (&value, signal_name);
action = GTK_SHORTCUT_ACTION (g_object_new_with_properties (GTK_TYPE_SIGNAL_ACTION,
1, &name, &value));
g_value_unset (&value);
return action;
}
/**

View File

@ -51,13 +51,13 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget)
model = gtk_flatten_list_model_new (G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER)));
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-bubble");
gtk_event_controller_set_static_name (controller, "gtk-shortcut-manager-bubble");
gtk_widget_add_controller (widget, controller);
model = gtk_flatten_list_model_new (G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER)));
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-capture");
gtk_event_controller_set_static_name (controller, "gtk-shortcut-manager-capture");
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
gtk_widget_add_controller (widget, controller);
}

View File

@ -1856,7 +1856,7 @@ gtk_text_init (GtkText *self)
GTK_TEXT_CONTENT (priv->selection_content)->self = self;
target = gtk_drop_target_new (G_TYPE_STRING, GDK_ACTION_COPY | GDK_ACTION_MOVE);
gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (target), "gtk-text-drop-target");
gtk_event_controller_set_static_name (GTK_EVENT_CONTROLLER (target), "gtk-text-drop-target");
g_signal_connect (target, "accept", G_CALLBACK (gtk_text_drag_accept), self);
g_signal_connect (target, "enter", G_CALLBACK (gtk_text_drag_motion), self);
g_signal_connect (target, "motion", G_CALLBACK (gtk_text_drag_motion), self);
@ -1881,7 +1881,7 @@ gtk_text_init (GtkText *self)
G_CALLBACK (gtk_text_delete_surrounding_cb), self);
priv->drag_gesture = gtk_gesture_drag_new ();
gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (priv->drag_gesture), "gtk-text-drag-gesture");
gtk_event_controller_set_static_name (GTK_EVENT_CONTROLLER (priv->drag_gesture), "gtk-text-drag-gesture");
g_signal_connect (priv->drag_gesture, "drag-update",
G_CALLBACK (gtk_text_drag_gesture_update), self);
g_signal_connect (priv->drag_gesture, "drag-end",
@ -1891,7 +1891,7 @@ gtk_text_init (GtkText *self)
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (priv->drag_gesture));
gesture = gtk_gesture_click_new ();
gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (gesture), "gtk-text-click-gesture");
gtk_event_controller_set_static_name (GTK_EVENT_CONTROLLER (gesture), "gtk-text-click-gesture");
g_signal_connect (gesture, "pressed",
G_CALLBACK (gtk_text_click_gesture_pressed), self);
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
@ -1899,14 +1899,14 @@ gtk_text_init (GtkText *self)
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
controller = gtk_event_controller_motion_new ();
gtk_event_controller_set_name (controller, "gtk-text-motion-controller");
gtk_event_controller_set_static_name (controller, "gtk-text-motion-controller");
g_signal_connect (controller, "motion",
G_CALLBACK (gtk_text_motion_controller_motion), self);
gtk_widget_add_controller (GTK_WIDGET (self), controller);
priv->key_controller = gtk_event_controller_key_new ();
gtk_event_controller_set_propagation_phase (priv->key_controller, GTK_PHASE_TARGET);
gtk_event_controller_set_name (priv->key_controller, "gtk-text-key-controller");
gtk_event_controller_set_static_name (priv->key_controller, "gtk-text-key-controller");
g_signal_connect (priv->key_controller, "key-pressed",
G_CALLBACK (gtk_text_key_controller_key_pressed), self);
g_signal_connect_swapped (priv->key_controller, "im-update",
@ -1916,7 +1916,7 @@ gtk_text_init (GtkText *self)
gtk_widget_add_controller (GTK_WIDGET (self), priv->key_controller);
priv->focus_controller = gtk_event_controller_focus_new ();
gtk_event_controller_set_name (priv->focus_controller, "gtk-text-focus-controller");
gtk_event_controller_set_static_name (priv->focus_controller, "gtk-text-focus-controller");
g_signal_connect (priv->focus_controller, "notify::is-focus",
G_CALLBACK (gtk_text_focus_changed), self);
gtk_widget_add_controller (GTK_WIDGET (self), priv->focus_controller);

View File

@ -2362,7 +2362,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
if (g_list_model_get_n_items (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts)) > 0)
{
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts));
gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
gtk_event_controller_set_static_name (controller, "gtk-widget-class-shortcuts");
gtk_widget_add_controller (widget, controller);
}

View File

@ -1683,7 +1683,7 @@ gtk_window_init (GtkWindow *window)
gtk_widget_add_controller (widget, controller);
controller = gtk_event_controller_legacy_new ();
gtk_event_controller_set_name (controller, "gtk-window-toplevel-focus");
gtk_event_controller_set_static_name (controller, "gtk-window-toplevel-focus");
g_signal_connect_swapped (controller, "event",
G_CALLBACK (gtk_window_handle_focus), window);
gtk_widget_add_controller (widget, controller);
@ -1694,7 +1694,7 @@ gtk_window_init (GtkWindow *window)
shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (MENU_BAR_ACCEL, 0),
gtk_callback_action_new (gtk_window_activate_menubar, NULL, NULL));
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_event_controller_set_name (controller, "gtk-window-menubar-accel");
gtk_event_controller_set_static_name (controller, "gtk-window-menubar-accel");
gtk_widget_add_controller (widget, controller);
priv->menubar_controller = controller;
@ -2797,7 +2797,7 @@ gtk_window_set_application (GtkWindow *window,
app_accels = gtk_application_get_application_accels (priv->application);
priv->application_shortcut_controller = gtk_shortcut_controller_new_for_model (gtk_application_accels_get_shortcuts (app_accels));
gtk_event_controller_set_name (priv->application_shortcut_controller, "gtk-application-shortcuts");
gtk_event_controller_set_static_name (priv->application_shortcut_controller, "gtk-application-shortcuts");
gtk_event_controller_set_propagation_phase (priv->application_shortcut_controller, GTK_PHASE_CAPTURE);
gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (priv->application_shortcut_controller), GTK_SHORTCUT_SCOPE_GLOBAL);
gtk_widget_add_controller (GTK_WIDGET (window), priv->application_shortcut_controller);