13
0

Define YDK/YTKMM Touch Event API

This commit is contained in:
Robin Gareus 2024-09-16 23:27:59 +02:00
parent 84027120cc
commit 89da2f2c87
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
12 changed files with 306 additions and 1 deletions

View File

@ -229,6 +229,9 @@ gdk_event_mask_get_type (void)
{ GDK_PROXIMITY_OUT_MASK, "GDK_PROXIMITY_OUT_MASK", "proximity-out-mask" },
{ GDK_SUBSTRUCTURE_MASK, "GDK_SUBSTRUCTURE_MASK", "substructure-mask" },
{ GDK_SCROLL_MASK, "GDK_SCROLL_MASK", "scroll-mask" },
{ GDK_TOUCH_BEGIN_MASK, "GDK_TOUCH_BEGIN_MASK", "touch-begin-mask" },
{ GDK_TOUCH_UPDATE_MASK, "GDK_TOUCH_UPDATE_MASK", "touch-update-mask" },
{ GDK_TOUCH_END_MASK, "GDK_TOUCH_END_MASK", "touch-end-mask" },
{ GDK_ALL_EVENTS_MASK, "GDK_ALL_EVENTS_MASK", "all-events-mask" },
{ 0, NULL, NULL }
};

View File

@ -387,6 +387,14 @@ gdk_event_new (GdkEventType type)
new_event->button.x_root = 0.;
new_event->button.y_root = 0.;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
new_event->touch.x = 0.;
new_event->touch.y = 0.;
new_event->touch.x_root = 0.;
new_event->touch.y_root = 0.;
break;
case GDK_SCROLL:
new_event->scroll.x = 0.;
new_event->scroll.y = 0.;
@ -596,6 +604,10 @@ gdk_event_get_time (const GdkEvent *event)
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
return event->button.time;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
return event->touch.time;
case GDK_SCROLL:
return event->scroll.time;
case GDK_KEY_PRESS:
@ -674,6 +686,11 @@ gdk_event_get_state (const GdkEvent *event,
case GDK_BUTTON_RELEASE:
*state = event->button.state;
return TRUE;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
*state = event->touch.state;
return TRUE;
case GDK_SCROLL:
*state = event->scroll.state;
return TRUE;
@ -770,6 +787,12 @@ gdk_event_get_coords (const GdkEvent *event,
x = event->motion.x;
y = event->motion.y;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
x = event->touch.x;
y = event->touch.y;
break;
default:
fetched = FALSE;
break;
@ -820,6 +843,12 @@ gdk_event_get_root_coords (const GdkEvent *event,
x = event->button.x_root;
y = event->button.y_root;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
x = event->touch.x_root;
y = event->touch.y_root;
break;
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
x = event->crossing.x_root;

View File

@ -9887,6 +9887,9 @@ static const guint type_masks[] = {
0, /* GDK_OWNER_CHANGE = 34 */
0, /* GDK_GRAB_BROKEN = 35 */
0, /* GDK_DAMAGE = 36 */
GDK_TOUCH_BEGIN_MASK, /* GDK_TOUCH_BEGIN = 37 */
GDK_TOUCH_UPDATE_MASK, /* GDK_TOUCH_UPDATE = 38 */
GDK_TOUCH_END_MASK, /* GDK_TOUCH_END = 39 */
};
G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
@ -9929,6 +9932,14 @@ is_motion_type (GdkEventType type)
type == GDK_LEAVE_NOTIFY;
}
static gboolean
is_touch_type (GdkEventType type)
{
return type == GDK_TOUCH_BEGIN ||
type == GDK_TOUCH_UPDATE ||
type == GDK_TOUCH_END;
}
static GdkWindowObject *
find_common_ancestor (GdkWindowObject *win1,
GdkWindowObject *win2)
@ -10873,6 +10884,19 @@ proxy_button_event (GdkEvent *source_event,
event->scroll.delta_y = source_event->scroll.delta_y;
return TRUE;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
convert_toplevel_coords_to_window (event_win,
toplevel_x, toplevel_y,
&event->touch.x, &event->touch.y);
event->touch.sequence = source_event->touch.sequence;
event->touch.deviceid = source_event->touch.deviceid;
event->touch.x_root = source_event->touch.x_root;
event->touch.y_root = source_event->touch.y_root;
event->touch.state = state;
return TRUE;
default:
return FALSE;
}
@ -11057,7 +11081,8 @@ _gdk_windowing_got_event (GdkDisplay *display,
return;
if (!(is_button_type (event->type) ||
is_motion_type (event->type)) ||
is_motion_type (event->type) ||
is_touch_type (event->type)) ||
event_private->window_type == GDK_WINDOW_ROOT)
return;
@ -11147,6 +11172,9 @@ _gdk_windowing_got_event (GdkDisplay *display,
else if (is_button_type (event->type))
unlink_event = proxy_button_event (event,
serial);
else if (is_touch_type (event->type))
unlink_event = proxy_button_event (event,
serial);
if (event->type == GDK_BUTTON_RELEASE &&
!event->any.send_event)

View File

@ -50,6 +50,7 @@ typedef struct _GdkEventNoExpose GdkEventNoExpose;
typedef struct _GdkEventVisibility GdkEventVisibility;
typedef struct _GdkEventMotion GdkEventMotion;
typedef struct _GdkEventButton GdkEventButton;
typedef struct _GdkEventTouch GdkEventTouch;
typedef struct _GdkEventScroll GdkEventScroll;
typedef struct _GdkEventKey GdkEventKey;
typedef struct _GdkEventFocus GdkEventFocus;
@ -152,6 +153,9 @@ typedef enum
GDK_OWNER_CHANGE = 34,
GDK_GRAB_BROKEN = 35,
GDK_DAMAGE = 36,
GDK_TOUCH_BEGIN = 37,
GDK_TOUCH_UPDATE = 38,
GDK_TOUCH_END = 39,
GDK_EVENT_LAST /* helper variable for decls */
} GdkEventType;
@ -181,6 +185,9 @@ typedef enum
GDK_PROXIMITY_OUT_MASK = 1 << 19,
GDK_SUBSTRUCTURE_MASK = 1 << 20,
GDK_SCROLL_MASK = 1 << 21,
GDK_TOUCH_BEGIN_MASK = 1 << 22,
GDK_TOUCH_UPDATE_MASK = 1 << 23,
GDK_TOUCH_END_MASK = 1 << 24,
GDK_ALL_EVENTS_MASK = 0x3FFFFE
} GdkEventMask;
@ -325,6 +332,21 @@ struct _GdkEventButton
gdouble x_root, y_root;
};
struct _GdkEventTouch
{
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
gdouble x;
gdouble y;
guint state;
guint sequence;
guint flags;
guint deviceid;
gdouble x_root, y_root;
};
struct _GdkEventScroll
{
GdkEventType type;
@ -500,6 +522,7 @@ union _GdkEvent
GdkEventVisibility visibility;
GdkEventMotion motion;
GdkEventButton button;
GdkEventTouch touch;
GdkEventScroll scroll;
GdkEventKey key;
GdkEventCrossing crossing;

View File

@ -92,6 +92,9 @@ enum EventType
OWNER_CHANGE,
GRAB_BROKEN,
DAMAGE,
TOUCH_BEGIN,
TOUCH_UPDATE,
TOUCH_END,
EVENT_LAST
};

View File

@ -91,6 +91,9 @@ enum EventMask
PROXIMITY_OUT_MASK = 1 << 19,
SUBSTRUCTURE_MASK = 1 << 20,
SCROLL_MASK = 1 << 21,
TOUCH_BEGIN_MASK = 1 << 22,
TOUCH_UPDATE_MASK = 1 << 23,
TOUCH_END_MASK = 1 << 24,
ALL_EVENTS_MASK = 0x3FFFFE
};

View File

@ -1599,6 +1599,7 @@ gtk_main_do_event (GdkEvent *event)
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_TOUCH_BEGIN:
gtk_propagate_event (grab_widget, event);
break;
@ -1636,6 +1637,8 @@ gtk_main_do_event (GdkEvent *event)
/* else fall through */
case GDK_MOTION_NOTIFY:
case GDK_BUTTON_RELEASE:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT:
gtk_propagate_event (grab_widget, event);

View File

@ -197,6 +197,9 @@ enum {
KEYNAV_FAILED,
DRAG_FAILED,
DAMAGE_EVENT,
TOUCH_BEGIN,
TOUCH_UPDATE,
TOUCH_END,
LAST_SIGNAL
};
@ -537,6 +540,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->drag_drop = NULL;
klass->drag_data_received = NULL;
klass->screen_changed = NULL;
klass->touch_begin_event = NULL;
klass->touch_update_event = NULL;
klass->touch_end_event = NULL;
klass->can_activate_accel = gtk_widget_real_can_activate_accel;
klass->grab_broken_event = NULL;
klass->query_tooltip = gtk_widget_real_query_tooltip;
@ -2377,6 +2383,39 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_TYPE_NONE, 1,
GDK_TYPE_SCREEN);
/* YTK Touch */
widget_signals[TOUCH_BEGIN] =
g_signal_new (I_("touch-start"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, touch_begin_event),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
widget_signals[TOUCH_UPDATE] =
g_signal_new (I_("touch-update"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, touch_update_event),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
widget_signals[TOUCH_END] =
g_signal_new (I_("touch-end"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, touch_end_event),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GtkWidget::can-activate-accel:
* @widget: the object which received the signal
@ -5001,6 +5040,15 @@ gtk_widget_event_internal (GtkWidget *widget,
case GDK_DAMAGE:
signal_num = DAMAGE_EVENT;
break;
case GDK_TOUCH_BEGIN:
signal_num = TOUCH_BEGIN;
break;
case GDK_TOUCH_END:
signal_num = TOUCH_END;
break;
case GDK_TOUCH_UPDATE:
signal_num = TOUCH_UPDATE;
break;
default:
g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
signal_num = -1;

View File

@ -726,6 +726,12 @@ struct _GtkWidgetClass
GdkEventAny *event);
gboolean (* window_state_event) (GtkWidget *widget,
GdkEventWindowState *event);
gboolean (* touch_begin_event) (GtkWidget *widget,
GdkEventTouch *event);
gboolean (* touch_update_event) (GtkWidget *widget,
GdkEventTouch *event);
gboolean (* touch_end_event) (GtkWidget *widget,
GdkEventTouch *event);
/* selection */
void (* selection_get) (GtkWidget *widget,

View File

@ -3395,6 +3395,9 @@ void Widget_Class::class_init_function(void* g_class, void* class_data)
klass->drag_motion = &drag_motion_callback;
klass->drag_drop = &drag_drop_callback;
klass->drag_data_received = &drag_data_received_callback;
klass->touch_begin_event = &touch_begin_callback;
klass->touch_update_event = &touch_update_callback;
klass->touch_end_event = &touch_end_callback;
#ifdef GTKMM_ATKMM_ENABLED
#ifndef GTKMM_DISABLE_DEPRECATED
@ -4344,6 +4347,120 @@ gboolean Widget_Class::button_release_event_callback(GtkWidget* self, GdkEventBu
typedef gboolean RType;
return RType();
}
gboolean Widget_Class::touch_begin_callback(GtkWidget* self, GdkEventTouch* p0)
{
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
Glib::ObjectBase::_get_current_wrapper((GObject*)self));
// Non-gtkmmproc-generated custom classes implicitly call the default
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
// generated classes can use this optimisation, which avoids the unnecessary
// parameter conversions if there is no possibility of the virtual function
// being overridden:
if(obj_base && obj_base->is_derived_())
{
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
if(obj) // This can be NULL during destruction.
{
try // Trap C++ exceptions which would normally be lost because this is a C callback.
{
// Call the virtual member method, which derived classes might override.
return static_cast<int>(obj->on_touch_begin_event(p0));
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
}
BaseClassType *const base = static_cast<BaseClassType*>(
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
);
// Call the original underlying C function:
if(base && base->touch_begin_event)
return (*base->touch_begin_event)(self, p0);
typedef gboolean RType;
return RType();
}
gboolean Widget_Class::touch_update_callback(GtkWidget* self, GdkEventTouch* p0)
{
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
Glib::ObjectBase::_get_current_wrapper((GObject*)self));
// Non-gtkmmproc-generated custom classes implicitly call the default
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
// generated classes can use this optimisation, which avoids the unnecessary
// parameter conversions if there is no possibility of the virtual function
// being overridden:
if(obj_base && obj_base->is_derived_())
{
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
if(obj) // This can be NULL during destruction.
{
try // Trap C++ exceptions which would normally be lost because this is a C callback.
{
// Call the virtual member method, which derived classes might override.
return static_cast<int>(obj->on_touch_update_event(p0));
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
}
BaseClassType *const base = static_cast<BaseClassType*>(
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
);
// Call the original underlying C function:
if(base && base->touch_update_event)
return (*base->touch_update_event)(self, p0);
typedef gboolean RType;
return RType();
}
gboolean Widget_Class::touch_end_callback(GtkWidget* self, GdkEventTouch* p0)
{
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
Glib::ObjectBase::_get_current_wrapper((GObject*)self));
// Non-gtkmmproc-generated custom classes implicitly call the default
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
// generated classes can use this optimisation, which avoids the unnecessary
// parameter conversions if there is no possibility of the virtual function
// being overridden:
if(obj_base && obj_base->is_derived_())
{
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
if(obj) // This can be NULL during destruction.
{
try // Trap C++ exceptions which would normally be lost because this is a C callback.
{
// Call the virtual member method, which derived classes might override.
return static_cast<int>(obj->on_touch_end_event(p0));
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
}
BaseClassType *const base = static_cast<BaseClassType*>(
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
);
// Call the original underlying C function:
if(base && base->touch_end_event)
return (*base->touch_end_event)(self, p0);
typedef gboolean RType;
return RType();
}
gboolean Widget_Class::scroll_event_callback(GtkWidget* self, GdkEventScroll* p0)
{
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
@ -7516,6 +7633,42 @@ bool Gtk::Widget::on_button_release_event(GdkEventButton* event)
typedef bool RType;
return RType();
}
bool Gtk::Widget::on_touch_begin_event(GdkEventTouch* event)
{
BaseClassType *const base = static_cast<BaseClassType*>(
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
);
if(base && base->touch_begin_event)
return (*base->touch_begin_event)(gobj(),event);
typedef bool RType;
return RType();
}
bool Gtk::Widget::on_touch_update_event(GdkEventTouch* event)
{
BaseClassType *const base = static_cast<BaseClassType*>(
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
);
if(base && base->touch_update_event)
return (*base->touch_update_event)(gobj(),event);
typedef bool RType;
return RType();
}
bool Gtk::Widget::on_touch_end_event(GdkEventTouch* event)
{
BaseClassType *const base = static_cast<BaseClassType*>(
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
);
if(base && base->touch_end_event)
return (*base->touch_end_event)(gobj(),event);
typedef bool RType;
return RType();
}
bool Gtk::Widget::on_scroll_event(GdkEventScroll* event)
{
BaseClassType *const base = static_cast<BaseClassType*>(

View File

@ -90,6 +90,9 @@ protected:
static gboolean drag_motion_callback(GtkWidget* self, GdkDragContext* p0, gint p1, gint p2, guint p3);
static gboolean drag_drop_callback(GtkWidget* self, GdkDragContext* p0, gint p1, gint p2, guint p3);
static void drag_data_received_callback(GtkWidget* self, GdkDragContext* p0, gint p1, gint p2, GtkSelectionData* p3, guint p4, guint p5);
static gboolean touch_begin_callback(GtkWidget*, GdkEventTouch*);
static gboolean touch_update_callback(GtkWidget*, GdkEventTouch*);
static gboolean touch_end_callback(GtkWidget*, GdkEventTouch*);
#ifdef GTKMM_ATKMM_ENABLED
#ifndef GTKMM_DISABLE_DEPRECATED

View File

@ -490,6 +490,9 @@ protected:
virtual bool on_drag_drop(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time);
/// This is a default handler for the signal signal_drag_data_received().
virtual void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const SelectionData& selection_data, guint info, guint time);
virtual bool on_touch_begin_event(GdkEventTouch* event);
virtual bool on_touch_update_event(GdkEventTouch* event);
virtual bool on_touch_end_event(GdkEventTouch* event);
#ifdef GTKMM_ATKMM_ENABLED
/// This is a default handler for the signal signal_get_accessible().
virtual Glib::RefPtr<Atk::Object> on_get_accessible();