forked from AuroraMiddleware/gtk
motion controller: Add getters for crossing event targets
This information can be needed in signal handlers, so make it available.
This commit is contained in:
parent
ecd6446d08
commit
17f4211e4f
@ -6684,6 +6684,8 @@ gtk_event_controller_scroll_get_type
|
||||
<TITLE>GtkEventControllerMotion</TITLE>
|
||||
GtkEventControllerMotion
|
||||
gtk_event_controller_motion_new
|
||||
gtk_event_controller_motion_get_pointer_origin
|
||||
gtk_event_controller_motion_get_pointer_target
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GTK_TYPE_EVENT_CONTROLLER_MOTION
|
||||
|
@ -29,7 +29,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtkwidget.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkeventcontrollerprivate.h"
|
||||
#include "gtkeventcontrollermotion.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
@ -39,6 +40,8 @@ struct _GtkEventControllerMotion
|
||||
{
|
||||
GtkEventController parent_instance;
|
||||
|
||||
const GdkEvent *current_event;
|
||||
|
||||
guint is_pointer_focus : 1;
|
||||
guint contains_pointer_focus : 1;
|
||||
};
|
||||
@ -132,7 +135,11 @@ gtk_event_controller_motion_handle_event (GtkEventController *controller,
|
||||
|
||||
update_pointer_focus (motion, TRUE, detail);
|
||||
|
||||
motion->current_event = event;
|
||||
|
||||
g_signal_emit (controller, signals[ENTER], 0, x, y, mode, detail);
|
||||
|
||||
motion->current_event = NULL;
|
||||
}
|
||||
else if (type == GDK_LEAVE_NOTIFY)
|
||||
{
|
||||
@ -144,13 +151,18 @@ gtk_event_controller_motion_handle_event (GtkEventController *controller,
|
||||
|
||||
update_pointer_focus (motion, FALSE, detail);
|
||||
|
||||
motion->current_event = event;
|
||||
|
||||
g_signal_emit (controller, signals[LEAVE], 0, mode, detail);
|
||||
|
||||
motion->current_event = NULL;
|
||||
}
|
||||
else if (type == GDK_MOTION_NOTIFY)
|
||||
{
|
||||
double x, y;
|
||||
|
||||
gdk_event_get_coords (event, &x, &y);
|
||||
|
||||
g_signal_emit (controller, signals[MOTION], 0, x, y);
|
||||
}
|
||||
|
||||
@ -300,3 +312,56 @@ gtk_event_controller_motion_new (void)
|
||||
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_event_controller_motion_get_pointer_origin:
|
||||
* @controller: a #GtkEventControllerMotion
|
||||
*
|
||||
* Returns the widget that contained the pointer before.
|
||||
*
|
||||
* This function can only be used in handlers for the
|
||||
* #GtkEventControllerMotion::enter and
|
||||
* #GtkEventControllerMotion::leave signals.
|
||||
*
|
||||
* Returns: (transfer none): the previous pointer focus
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_event_controller_motion_get_pointer_origin (GtkEventControllerMotion *controller)
|
||||
{
|
||||
GtkWidget *origin;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (controller), NULL);
|
||||
g_return_val_if_fail (controller->current_event != NULL, NULL);
|
||||
|
||||
if (gdk_event_get_event_type (controller->current_event) == GDK_ENTER_NOTIFY)
|
||||
origin = (GtkWidget *)gdk_event_get_related_target (controller->current_event);
|
||||
else
|
||||
origin = (GtkWidget *)gdk_event_get_target (controller->current_event);
|
||||
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_event_controller_motion_get_pointer_target:
|
||||
* @controller: a #GtkEventControllerMotion
|
||||
*
|
||||
* Returns the widget that will contain the pointer afterwards.
|
||||
*
|
||||
* This function can only be used in handlers for the
|
||||
* #GtkEventControllerMotion::enter and
|
||||
* #GtkEventControllerMotion::leave signals.
|
||||
*
|
||||
* Returns: (transfer none): the next pointer focus
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_event_controller_motion_get_pointer_target (GtkEventControllerMotion *controller)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (controller), NULL);
|
||||
g_return_val_if_fail (controller->current_event != NULL, NULL);
|
||||
|
||||
if (gdk_event_get_event_type (controller->current_event) == GDK_ENTER_NOTIFY)
|
||||
return (GtkWidget *)gdk_event_get_target (controller->current_event);
|
||||
else
|
||||
return (GtkWidget *)gdk_event_get_related_target (controller->current_event);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,11 @@ GType gtk_event_controller_motion_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkEventController *gtk_event_controller_motion_new (void);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_event_controller_motion_get_pointer_origin (GtkEventControllerMotion *controller);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_event_controller_motion_get_pointer_target (GtkEventControllerMotion *controller);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_EVENT_CONTROLLER_MOTION_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user