[gtk+/multitouch: 20/129] gtk: Add a GdkDevice parameter to ::press-and-hold
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/multitouch: 20/129] gtk: Add a GdkDevice parameter to ::press-and-hold
- Date: Sat, 18 Feb 2012 17:07:59 +0000 (UTC)
commit 80e08d1b1bca2597c9d047b0f7bfcddab8c6a5c1
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Nov 1 12:30:40 2011 +0100
gtk: Add a GdkDevice parameter to ::press-and-hold
This would be useful when popping up menus, just so we
know what device to trigger it for.
gtk/gtkmarshalers.list | 2 +-
gtk/gtkwidget.c | 11 ++++++--
gtk/gtkwidget.h | 1 +
tests/testpressandhold.c | 61 ++++++++++------------------------------------
4 files changed, 23 insertions(+), 52 deletions(-)
---
diff --git a/gtk/gtkmarshalers.list b/gtk/gtkmarshalers.list
index 9b8195b..a21caff 100644
--- a/gtk/gtkmarshalers.list
+++ b/gtk/gtkmarshalers.list
@@ -27,7 +27,6 @@ BOOLEAN:ENUM
BOOLEAN:ENUM,BOOLEAN
BOOLEAN:ENUM,DOUBLE
BOOLEAN:ENUM,INT
-BOOLEAN:ENUM,INT,INT
BOOLEAN:OBJECT
BOOLEAN:OBJECT,UINT,FLAGS
BOOLEAN:OBJECT,INT,INT,UINT
@@ -37,6 +36,7 @@ BOOLEAN:OBJECT,BOXED,BOXED
BOOLEAN:OBJECT,OBJECT,OBJECT
BOOLEAN:OBJECT,STRING,STRING
BOOLEAN:OBJECT,ENUM
+BOOLEAN:OBJECT,ENUM,INT,INT
BOOLEAN:INT
BOOLEAN:INT,INT
BOOLEAN:INT,INT,INT
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 388d526..876e228 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3118,8 +3118,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, press_and_hold),
_gtk_boolean_handled_accumulator, NULL,
- _gtk_marshal_BOOLEAN__ENUM_INT_INT,
- G_TYPE_BOOLEAN, 3,
+ _gtk_marshal_BOOLEAN__OBJECT_ENUM_INT_INT,
+ G_TYPE_BOOLEAN, 4,
+ GDK_TYPE_DEVICE,
GTK_TYPE_PRESS_AND_HOLD_ACTION,
G_TYPE_INT,
G_TYPE_INT);
@@ -6949,6 +6950,7 @@ gtk_widget_press_and_hold_cancel (GtkWidget *widget)
g_signal_emit (widget, widget_signals[PRESS_AND_HOLD],
0,
+ data->device,
GTK_PRESS_AND_HOLD_CANCEL,
-1, -1,
&return_value);
@@ -7037,6 +7039,7 @@ gtk_widget_press_and_hold_timeout (gpointer user_data)
/* Done, clean up and emit the trigger signal */
g_signal_emit (widget, widget_signals[PRESS_AND_HOLD],
0,
+ data->device,
GTK_PRESS_AND_HOLD_TRIGGER,
data->current_x, data->current_y,
&return_value);
@@ -7135,6 +7138,7 @@ gtk_widget_press_and_hold_begin_animation_timeout (gpointer user_data)
static gboolean
gtk_widget_press_and_hold_query (GtkWidget *widget,
+ GdkDevice *device,
gint x,
gint y)
{
@@ -7142,6 +7146,7 @@ gtk_widget_press_and_hold_query (GtkWidget *widget,
g_signal_emit (widget, widget_signals[PRESS_AND_HOLD],
0,
+ device,
GTK_PRESS_AND_HOLD_QUERY,
x, y,
&return_value);
@@ -7161,7 +7166,7 @@ gtk_widget_press_and_hold_start (GtkWidget *widget,
data = gtk_widget_get_press_and_hold_data (widget);
- if (gtk_widget_press_and_hold_query (widget, event->x, event->y))
+ if (gtk_widget_press_and_hold_query (widget, data->device, event->x, event->y))
{
gint timeout, begin_ani_timeout;
GdkScreen *screen;
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index a214b38..32fc5bb 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -435,6 +435,7 @@ struct _GtkWidgetClass
void (* captured_event) (GtkWidget *widget,
GdkEvent *event);
gboolean (* press_and_hold) (GtkWidget *widget,
+ GdkDevice *device,
GtkPressAndHoldAction action,
gint x,
gint y);
diff --git a/tests/testpressandhold.c b/tests/testpressandhold.c
index e4fe8c4..dda44c6 100644
--- a/tests/testpressandhold.c
+++ b/tests/testpressandhold.c
@@ -23,42 +23,12 @@
#include <gtk/gtk.h>
-struct CoordData
-{
- gint x;
- gint y;
- GtkWidget *widget;
-};
-
-static void
-popup_position_func (GtkMenu *menu,
- gint *x,
- gint *y,
- gboolean *push_in,
- gpointer user_data)
-{
- GtkRequisition req;
- GdkScreen *screen;
- struct CoordData *data = user_data;
-
- screen = gtk_widget_get_screen (data->widget);
- gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
-
- *x = data->x;
- *y = data->y;
-
- *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
- *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
-}
-
static void
press_and_hold_show_menu (GtkWidget *widget,
- gint x,
- gint y)
+ GdkDevice *device)
{
GtkWidget *menu;
GtkWidget *item;
- struct CoordData data;
menu = gtk_menu_new ();
@@ -74,34 +44,29 @@ press_and_hold_show_menu (GtkWidget *widget,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
- data.widget = widget;
- gdk_window_get_origin (gtk_widget_get_window (widget), &data.x, &data.y);
- data.x += x;
- data.y += y;
-
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- popup_position_func,
- &data,
- 1,
- GDK_CURRENT_TIME);
+ gtk_menu_popup_for_device (GTK_MENU (menu), device,
+ NULL, NULL, NULL, NULL, NULL,
+ 1,
+ GDK_CURRENT_TIME);
}
static gboolean
press_and_hold (GtkWidget *widget,
- GtkPressAndHoldAction action,
- gint x,
- gint y,
- gboolean keyboard)
+ GdkDevice *device,
+ GtkPressAndHoldAction action,
+ gint x,
+ gint y,
+ gpointer user_data)
{
switch (action)
{
case GTK_PRESS_AND_HOLD_QUERY:
g_print ("press-and-hold-query on %s\n", gtk_widget_get_name (widget));
- return TRUE;
+ break;
case GTK_PRESS_AND_HOLD_TRIGGER:
g_print ("press-and-hold-trigger on %s\n", gtk_widget_get_name (widget));
- press_and_hold_show_menu (widget, x, y);
+ press_and_hold_show_menu (widget, device);
break;
case GTK_PRESS_AND_HOLD_CANCEL:
@@ -109,7 +74,7 @@ press_and_hold (GtkWidget *widget,
break;
}
- return FALSE;
+ return TRUE;
}
static GtkTreeModel *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]