[libadwaita/wip/exalm/tab-overview: 13/15] tab-item: Move item activate handling to AdwTabBox
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/tab-overview: 13/15] tab-item: Move item activate handling to AdwTabBox
- Date: Tue, 12 Oct 2021 08:51:31 +0000 (UTC)
commit 08e9d516ce7662ede0ac6e13c3be7ecf0d1aeb4e
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sat Aug 21 20:43:45 2021 +0500
tab-item: Move item activate handling to AdwTabBox
We'll need to handle it differently for overview.
Also a bunch of stuff about press vs release
src/adw-tab-box.c | 11 ++++++++++
src/adw-tab-item.c | 20 ++++++++++--------
src/adw-tab-list-base-private.h | 4 ++++
src/adw-tab-list-base.c | 46 ++++++++++++++++++++++++-----------------
4 files changed, 53 insertions(+), 28 deletions(-)
---
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index d4009c09..3147d18d 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -28,6 +28,16 @@ adw_tab_box_tabs_have_visible_focus (AdwTabListBase *base)
return adw_tab_bar_tabs_have_visible_focus (self->tab_bar);
}
+static void
+adw_tab_box_activate_item (AdwTabListBase *base,
+ AdwTabItem *item)
+{
+ AdwTabPage *page = adw_tab_item_get_page (item);
+ GtkWidget *child = adw_tab_page_get_child (page);
+
+ gtk_widget_grab_focus (child);
+}
+
static void
adw_tab_box_class_init (AdwTabBoxClass *klass)
{
@@ -35,6 +45,7 @@ adw_tab_box_class_init (AdwTabBoxClass *klass)
AdwTabListBaseClass *base_class = ADW_TAB_LIST_BASE_CLASS (klass);
base_class->tabs_have_visible_focus = adw_tab_box_tabs_have_visible_focus;
+ base_class->activate_item = adw_tab_box_activate_item;
base_class->item_type = ADW_TYPE_TAB;
diff --git a/src/adw-tab-item.c b/src/adw-tab-item.c
index e9234f27..ba02ffec 100644
--- a/src/adw-tab-item.c
+++ b/src/adw-tab-item.c
@@ -40,6 +40,7 @@ enum {
static GParamSpec *props[LAST_PROP];
enum {
+ SIGNAL_ACTIVATE,
SIGNAL_EXTRA_DRAG_DROP,
SIGNAL_LAST_SIGNAL,
};
@@ -106,15 +107,7 @@ static gboolean
activate_cb (AdwTabItem *self,
GVariant *args)
{
- AdwTabItemPrivate *priv = adw_tab_item_get_instance_private (self);
- GtkWidget *child;
-
- if (!priv->page || !priv->view)
- return GDK_EVENT_PROPAGATE;
-
- child = adw_tab_page_get_child (priv->page);
-
- gtk_widget_grab_focus (child);
+ g_signal_emit (self, signals[SIGNAL_ACTIVATE], 0);
return GDK_EVENT_STOP;
}
@@ -294,6 +287,15 @@ adw_tab_item_class_init (AdwTabItemClass *klass)
1,
G_TYPE_VALUE);
+ signals[SIGNAL_ACTIVATE] =
+ g_signal_new ("activate",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 0);
+
g_object_class_install_properties (object_class, LAST_PROP, props);
gtk_widget_class_add_binding (widget_class, GDK_KEY_space, 0, (GtkShortcutFunc) activate_cb, NULL);
diff --git a/src/adw-tab-list-base-private.h b/src/adw-tab-list-base-private.h
index 892f5346..8b0317e4 100644
--- a/src/adw-tab-list-base-private.h
+++ b/src/adw-tab-list-base-private.h
@@ -13,6 +13,7 @@
#endif
#include <gtk/gtk.h>
+#include "adw-tab-item-private.h"
#include "adw-tab-view.h"
G_BEGIN_DECLS
@@ -28,6 +29,9 @@ struct _AdwTabListBaseClass
GType item_type;
gboolean (*tabs_have_visible_focus) (AdwTabListBase *self);
+
+ void (*activate_item) (AdwTabListBase *self,
+ AdwTabItem *item);
};
void adw_tab_list_base_set_view (AdwTabListBase *self,
diff --git a/src/adw-tab-list-base.c b/src/adw-tab-list-base.c
index 198e2a46..30ad5463 100644
--- a/src/adw-tab-list-base.c
+++ b/src/adw-tab-list-base.c
@@ -647,17 +647,10 @@ add_reorder_bindings (GtkWidgetClass *widget_class,
}
static void
-activate_tab (AdwTabListBase *self)
+item_activated_cb (AdwTabListBase *self,
+ AdwTabItem *item)
{
- AdwTabListBasePrivate *priv = adw_tab_list_base_get_instance_private (self);
- GtkWidget *child;
-
- if (!priv->selected_tab || !priv->selected_tab->page)
- return;
-
- child = adw_tab_page_get_child (priv->selected_tab->page);
-
- gtk_widget_grab_focus (child);
+ ADW_TAB_LIST_BASE_GET_CLASS (self)->activate_item (self, item);
}
/* Scrolling */
@@ -670,15 +663,20 @@ update_visible (AdwTabListBase *self)
GList *l;
double value, page_size;
- if (!priv->adjustment)
+ // TODO
+ if (!priv->adjustment) {
+ for (l = priv->tabs; l; l = l->next) {
+ TabInfo *info = l->data;
+
+ adw_tab_item_set_fully_visible (info->tab, TRUE);
+ }
+
return;
+ }
value = gtk_adjustment_get_value (priv->adjustment);
page_size = gtk_adjustment_get_page_size (priv->adjustment);
- if (!priv->adjustment)
- return;
-
for (l = priv->tabs; l; l = l->next) {
TabInfo *info = l->data;
int pos;
@@ -1725,6 +1723,9 @@ create_tab_info (AdwTabListBase *self,
priv->extra_drag_types,
priv->extra_drag_n_types);
+ g_signal_connect_object (info->tab, "activate", G_CALLBACK (item_activated_cb),
+ self, G_CONNECT_SWAPPED);
+
gtk_widget_set_parent (GTK_WIDGET (info->tab), GTK_WIDGET (self));
g_signal_connect_object (info->tab, "extra-drag-drop", G_CALLBACK (extra_drag_drop_cb), self, 0);
@@ -2849,7 +2850,7 @@ handle_click (AdwTabListBase *self,
if (can_grab_focus)
gtk_widget_grab_focus (GTK_WIDGET (info->tab));
else
- activate_tab (self);
+ gtk_widget_grab_focus (adw_tab_page_get_child (info->page));
}
static void
@@ -2916,9 +2917,7 @@ released_cb (AdwTabListBase *self,
{
AdwTabListBasePrivate *priv = adw_tab_list_base_get_instance_private (self);
TabInfo *info;
-
- if (!is_touchscreen (gesture))
- return;
+ guint button;
x += gtk_adjustment_get_value (priv->adjustment);
@@ -2930,7 +2929,16 @@ released_cb (AdwTabListBase *self,
return;
}
- handle_click (self, info, gesture);
+ button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
+
+ if (button != GDK_BUTTON_PRIMARY)
+ return;
+
+ if (is_touchscreen (gesture))
+ handle_click (self, info, gesture);
+
+ if (adw_tab_item_get_fully_visible (info->tab))
+ ADW_TAB_LIST_BASE_GET_CLASS (self)->activate_item (self, info->tab);
}
/* Overrides */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]