[libadwaita/wip/exalm/tab-overview: 6/15] tab: Create event controllers programmatically
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/tab-overview: 6/15] tab: Create event controllers programmatically
- Date: Tue, 12 Oct 2021 08:51:31 +0000 (UTC)
commit 4f7db80cbe6414bb24f85d24743af23af3822986
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sat Aug 21 02:48:25 2021 +0500
tab: Create event controllers programmatically
Next we'll split all but the widgetry into a base class, we want
controllers to be shared.
src/adw-tab.c | 20 +++++++++++++++-----
src/adw-tab.ui | 11 -----------
2 files changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/src/adw-tab.c b/src/adw-tab.c
index c295c3b5..4f323c6c 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -824,12 +824,8 @@ adw_tab_class_init (AdwTabClass *klass)
gtk_widget_class_bind_template_child (widget_class, AdwTab, indicator_icon);
gtk_widget_class_bind_template_child (widget_class, AdwTab, indicator_btn);
gtk_widget_class_bind_template_child (widget_class, AdwTab, close_btn);
- gtk_widget_class_bind_template_child (widget_class, AdwTab, drop_target);
gtk_widget_class_bind_template_callback (widget_class, close_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, indicator_clicked_cb);
- gtk_widget_class_bind_template_callback (widget_class, motion_cb);
- gtk_widget_class_bind_template_callback (widget_class, leave_cb);
- gtk_widget_class_bind_template_callback (widget_class, drop_cb);
gtk_widget_class_add_binding (widget_class, GDK_KEY_space, 0, (GtkShortcutFunc) activate_cb, NULL);
gtk_widget_class_add_binding (widget_class, GDK_KEY_KP_Space, 0, (GtkShortcutFunc) activate_cb, NULL);
@@ -843,9 +839,16 @@ adw_tab_class_init (AdwTabClass *klass)
static void
adw_tab_init (AdwTab *self)
{
+ GtkEventController *controller;
+
g_type_ensure (ADW_TYPE_FADING_LABEL);
gtk_widget_init_template (GTK_WIDGET (self));
+
+ controller = gtk_event_controller_motion_new ();
+ g_signal_connect_swapped (controller, "motion", G_CALLBACK (motion_cb), self);
+ g_signal_connect_swapped (controller, "leave", G_CALLBACK (leave_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), controller);
}
AdwTab *
@@ -1034,6 +1037,13 @@ adw_tab_setup_extra_drop_target (AdwTab *self,
g_return_if_fail (ADW_IS_TAB (self));
g_return_if_fail (n_types == 0 || types != NULL);
- gtk_drop_target_set_actions (self->drop_target, actions);
+ if (!self->drop_target) {
+ self->drop_target = gtk_drop_target_new (G_TYPE_INVALID, actions);
+ g_signal_connect_swapped (self->drop_target, "drop", G_CALLBACK (drop_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (self->drop_target));
+ } else {
+ gtk_drop_target_set_actions (self->drop_target, actions);
+ }
+
gtk_drop_target_set_gtypes (self->drop_target, types, n_types);
}
diff --git a/src/adw-tab.ui b/src/adw-tab.ui
index 9e868cd6..ef11e4b8 100644
--- a/src/adw-tab.ui
+++ b/src/adw-tab.ui
@@ -4,17 +4,6 @@
<template class="AdwTab" parent="GtkWidget">
<property name="focusable">True</property>
<property name="overflow">hidden</property>
- <child>
- <object class="GtkEventControllerMotion">
- <signal name="motion" handler="motion_cb" swapped="true"/>
- <signal name="leave" handler="leave_cb" swapped="true"/>
- </object>
- </child>
- <child>
- <object class="GtkDropTarget" id="drop_target">
- <signal name="drop" handler="drop_cb" swapped="true"/>
- </object>
- </child>
<child>
<object class="GtkButton" id="indicator_btn">
<property name="can-focus">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]