[gtk+/wip/carlosg/event-delivery: 103/119] gtkexpander: Remove event window
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/carlosg/event-delivery: 103/119] gtkexpander: Remove event window
- Date: Wed, 26 Apr 2017 13:48:34 +0000 (UTC)
commit d65f4bde8dca7056824f4c7f673302acfb9caf6e
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Apr 3 00:33:56 2017 +0200
gtkexpander: Remove event window
Detect presses/releases inside the label area instead.
gtk/gtkexpander.c | 135 ++++++++++++++++-------------------------------------
1 files changed, 41 insertions(+), 94 deletions(-)
---
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index 836bde9..cc88fea 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -144,7 +144,6 @@ enum
struct _GtkExpanderPrivate
{
GtkWidget *label_widget;
- GdkWindow *event_window;
GtkCssGadget *gadget;
GtkWidget *title_widget;
@@ -161,6 +160,7 @@ struct _GtkExpanderPrivate
guint prelight : 1;
guint label_fill : 1;
guint resize_toplevel : 1;
+ guint pressed_in_title : 1;
};
static void gtk_expander_set_property (GObject *object,
@@ -173,12 +173,8 @@ static void gtk_expander_get_property (GObject *object,
GParamSpec *pspec);
static void gtk_expander_destroy (GtkWidget *widget);
-static void gtk_expander_realize (GtkWidget *widget);
-static void gtk_expander_unrealize (GtkWidget *widget);
static void gtk_expander_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void gtk_expander_map (GtkWidget *widget);
-static void gtk_expander_unmap (GtkWidget *widget);
static void gtk_expander_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
@@ -225,6 +221,11 @@ static void gtk_expander_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
/* Gestures */
+static void gesture_multipress_pressed_cb (GtkGestureMultiPress *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ GtkExpander *expander);
static void gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
gint n_press,
gdouble x,
@@ -262,11 +263,7 @@ gtk_expander_class_init (GtkExpanderClass *klass)
gobject_class->get_property = gtk_expander_get_property;
widget_class->destroy = gtk_expander_destroy;
- widget_class->realize = gtk_expander_realize;
- widget_class->unrealize = gtk_expander_unrealize;
widget_class->size_allocate = gtk_expander_size_allocate;
- widget_class->map = gtk_expander_map;
- widget_class->unmap = gtk_expander_unmap;
widget_class->snapshot = gtk_expander_snapshot;
widget_class->enter_notify_event = gtk_expander_enter_notify;
widget_class->leave_notify_event = gtk_expander_leave_notify;
@@ -370,7 +367,6 @@ gtk_expander_init (GtkExpander *expander)
gtk_widget_set_has_window (GTK_WIDGET (expander), FALSE);
priv->label_widget = NULL;
- priv->event_window = NULL;
priv->spacing = 0;
priv->expanded = FALSE;
@@ -403,6 +399,8 @@ gtk_expander_init (GtkExpander *expander)
GDK_BUTTON_PRIMARY);
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture),
FALSE);
+ g_signal_connect (priv->multipress_gesture, "pressed",
+ G_CALLBACK (gesture_multipress_pressed_cb), expander);
g_signal_connect (priv->multipress_gesture, "released",
G_CALLBACK (gesture_multipress_released_cb), expander);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture),
@@ -525,39 +523,6 @@ gtk_expander_destroy (GtkWidget *widget)
}
static void
-gtk_expander_realize (GtkWidget *widget)
-{
- GtkAllocation allocation;
- GtkExpanderPrivate *priv;
-
- priv = GTK_EXPANDER (widget)->priv;
-
- GTK_WIDGET_CLASS (gtk_expander_parent_class)->realize (widget);
-
- gtk_widget_get_allocation (widget, &allocation);
-
- priv->event_window = gdk_window_new_input (gtk_widget_get_window (widget),
- GDK_ALL_EVENTS_MASK,
- &allocation);
- gtk_widget_register_window (widget, priv->event_window);
-}
-
-static void
-gtk_expander_unrealize (GtkWidget *widget)
-{
- GtkExpanderPrivate *priv = GTK_EXPANDER (widget)->priv;
-
- if (priv->event_window)
- {
- gtk_widget_unregister_window (widget, priv->event_window);
- gdk_window_destroy (priv->event_window);
- priv->event_window = NULL;
- }
-
- GTK_WIDGET_CLASS (gtk_expander_parent_class)->unrealize (widget);
-}
-
-static void
gtk_expander_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
@@ -572,47 +537,37 @@ gtk_expander_size_allocate (GtkWidget *widget,
&clip);
gtk_widget_set_clip (widget, &clip);
-
- if (gtk_widget_get_realized (widget))
- {
- GtkAllocation title_allocation;
-
- gtk_widget_get_allocation (priv->title_widget, &title_allocation);
- gdk_window_move_resize (priv->event_window,
- title_allocation.x, title_allocation.y,
- title_allocation.width, title_allocation.height);
- }
}
static void
-gtk_expander_map (GtkWidget *widget)
+gtk_expander_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
- GtkExpanderPrivate *priv = GTK_EXPANDER (widget)->priv;
-
- gtk_widget_map (priv->title_widget);
-
- GTK_WIDGET_CLASS (gtk_expander_parent_class)->map (widget);
-
- if (priv->event_window)
- gdk_window_show (priv->event_window);
+ gtk_css_gadget_snapshot (GTK_EXPANDER (widget)->priv->gadget, snapshot);
}
static void
-gtk_expander_unmap (GtkWidget *widget)
+gesture_multipress_pressed_cb (GtkGestureMultiPress *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ GtkExpander *expander)
{
- GtkExpanderPrivate *priv = GTK_EXPANDER (widget)->priv;
+ GtkExpanderPrivate *priv = expander->priv;
+ GtkAllocation title_allocation, allocation;
- if (priv->event_window)
- gdk_window_hide (priv->event_window);
+ gtk_widget_get_allocation (GTK_WIDGET (expander), &allocation);
+ gtk_widget_get_allocation (priv->title_widget, &title_allocation);
+ /* Coordinates are in the widget coordinate system, so transform
+ * the title_allocation to it.
+ */
+ title_allocation.x -= allocation.x;
+ title_allocation.y -= allocation.y;
- GTK_WIDGET_CLASS (gtk_expander_parent_class)->unmap (widget);
-}
-
-static void
-gtk_expander_snapshot (GtkWidget *widget,
- GtkSnapshot *snapshot)
-{
- gtk_css_gadget_snapshot (GTK_EXPANDER (widget)->priv->gadget, snapshot);
+ priv->pressed_in_title = (x >= title_allocation.x &&
+ x < title_allocation.x + title_allocation.width &&
+ y >= title_allocation.y &&
+ y < title_allocation.y + title_allocation.height);
}
static void
@@ -622,7 +577,7 @@ gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
gdouble y,
GtkExpander *expander)
{
- if (expander->priv->prelight)
+ if (expander->priv->pressed_in_title)
gtk_widget_activate (GTK_WIDGET (expander));
}
@@ -664,18 +619,14 @@ gtk_expander_enter_notify (GtkWidget *widget,
{
GtkExpander *expander = GTK_EXPANDER (widget);
- if (event->window == expander->priv->event_window &&
- event->detail != GDK_NOTIFY_INFERIOR)
- {
- expander->priv->prelight = TRUE;
+ expander->priv->prelight = TRUE;
- update_node_state (expander);
+ update_node_state (expander);
- if (expander->priv->label_widget)
- gtk_widget_set_state_flags (expander->priv->label_widget,
- GTK_STATE_FLAG_PRELIGHT,
- FALSE);
- }
+ if (expander->priv->label_widget)
+ gtk_widget_set_state_flags (expander->priv->label_widget,
+ GTK_STATE_FLAG_PRELIGHT,
+ FALSE);
return FALSE;
}
@@ -686,17 +637,13 @@ gtk_expander_leave_notify (GtkWidget *widget,
{
GtkExpander *expander = GTK_EXPANDER (widget);
- if (event->window == expander->priv->event_window &&
- event->detail != GDK_NOTIFY_INFERIOR)
- {
- expander->priv->prelight = FALSE;
+ expander->priv->prelight = FALSE;
- update_node_state (expander);
+ update_node_state (expander);
- if (expander->priv->label_widget)
- gtk_widget_unset_state_flags (expander->priv->label_widget,
- GTK_STATE_FLAG_PRELIGHT);
- }
+ if (expander->priv->label_widget)
+ gtk_widget_unset_state_flags (expander->priv->label_widget,
+ GTK_STATE_FLAG_PRELIGHT);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]