Keep more event controller api private

We don't want to expose the GtkCrossingData struct, and manually
feeding events to event controllers is not something we want to
encourage, going forward.
This commit is contained in:
Matthias Clasen 2020-02-20 17:22:03 -05:00
parent 4947b94a41
commit 77aed615e8
8 changed files with 54 additions and 179 deletions

View File

@ -954,16 +954,6 @@ typedef enum
GTK_EVENT_SEQUENCE_DENIED GTK_EVENT_SEQUENCE_DENIED
} GtkEventSequenceState; } GtkEventSequenceState;
typedef enum {
GTK_CROSSING_FOCUS,
GTK_CROSSING_POINTER
} GtkCrossingType;
typedef enum {
GTK_CROSSING_IN,
GTK_CROSSING_OUT
} GtkCrossingDirection;
/** /**
* GtkPanDirection: * GtkPanDirection:
* @GTK_PAN_DIRECTION_LEFT: panned towards the left * @GTK_PAN_DIRECTION_LEFT: panned towards the left

View File

@ -40,37 +40,6 @@ G_BEGIN_DECLS
#define GTK_EVENT_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_EVENT_CONTROLLER, GtkEventControllerClass)) #define GTK_EVENT_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_EVENT_CONTROLLER, GtkEventControllerClass))
typedef struct _GtkCrossingData GtkCrossingData;
/**
* GtkCrossingData:
* @type: the type of crossing event
* @direction: whether this is a focus-in or focus-out event
* @mode: the crossing mode
* @old_target: the old target
* @old_descendent: the direct child of the receiving widget that
* is an ancestor of @old_target, or %NULL if @old_target is not
* a descendent of the receiving widget
* @new_target: the new target
* @new_descendent: the direct child of the receiving widget that
* is an ancestor of @new_target, or %NULL if @new_target is not
* a descendent of the receiving widget
*
* The struct that is passed to gtk_event_controller_handle_crossing().
*
* The @old_target and @new_target fields are set to the old or new
* focus or hover location.
*/
struct _GtkCrossingData {
GtkCrossingType type;
GtkCrossingDirection direction;
GdkCrossingMode mode;
GtkWidget *old_target;
GtkWidget *old_descendent;
GtkWidget *new_target;
GtkWidget *new_descendent;
};
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GType gtk_crossing_data_get_type (void) G_GNUC_CONST; GType gtk_crossing_data_get_type (void) G_GNUC_CONST;
@ -81,17 +50,6 @@ GType gtk_event_controller_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_event_controller_get_widget (GtkEventController *controller); GtkWidget * gtk_event_controller_get_widget (GtkEventController *controller);
GDK_AVAILABLE_IN_ALL
gboolean gtk_event_controller_handle_event (GtkEventController *controller,
GdkEvent *event,
GtkWidget *target,
double x,
double y);
GDK_AVAILABLE_IN_ALL
void gtk_event_controller_handle_crossing (GtkEventController *controller,
const GtkCrossingData *crossing,
double x,
double y);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_event_controller_reset (GtkEventController *controller); void gtk_event_controller_reset (GtkEventController *controller);

View File

@ -46,8 +46,6 @@ struct _GtkEventControllerFocus
{ {
GtkEventController parent_instance; GtkEventController parent_instance;
const GtkCrossingData *current_crossing;
guint is_focus : 1; guint is_focus : 1;
guint contains_focus : 1; guint contains_focus : 1;
}; };
@ -148,16 +146,8 @@ gtk_event_controller_focus_handle_crossing (GtkEventController *controller,
double x, double x,
double y) double y)
{ {
GtkEventControllerFocus *focus = GTK_EVENT_CONTROLLER_FOCUS (controller); if (crossing->type == GTK_CROSSING_FOCUS)
if (crossing->type != GTK_CROSSING_FOCUS)
return;
focus->current_crossing = crossing;
update_focus (controller, crossing); update_focus (controller, crossing);
focus->current_crossing = NULL;
} }
static void static void
@ -295,64 +285,6 @@ gtk_event_controller_focus_new (void)
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_FOCUS, NULL); return g_object_new (GTK_TYPE_EVENT_CONTROLLER_FOCUS, NULL);
} }
/**
* gtk_event_controller_focus_get_focus_origin:
* @controller: a #GtkEventControllerFocus
*
* Returns the widget that was holding focus before.
*
* This function can only be used in handlers for the
* #GtkEventControllerFocus::focus-in and #GtkEventControllerFocus::focus-out signals.
*
* Returns: (transfer none): the previous focus
*/
GtkWidget *
gtk_event_controller_focus_get_focus_origin (GtkEventControllerFocus *controller)
{
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_FOCUS (controller), NULL);
g_return_val_if_fail (controller->current_crossing != NULL, NULL);
return controller->current_crossing->old_target;
}
/**
* gtk_event_controller_focus_get_focus_target:
* @controller: a #GtkEventControllerFocus
*
* Returns the widget that will be holding focus afterwards.
*
* This function can only be used in handlers for the
* #GtkEventControllerFocus::focus-in and #GtkEventControllerFocus::focus-out signals.
*
* Returns: (transfer none): the next focus
*/
GtkWidget *
gtk_event_controller_focus_get_focus_target (GtkEventControllerFocus *controller)
{
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_FOCUS (controller), NULL);
g_return_val_if_fail (controller->current_crossing != NULL, NULL);
return controller->current_crossing->new_target;
}
GtkWidget *
gtk_event_controller_focus_get_old_focus_child (GtkEventControllerFocus *controller)
{
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_FOCUS (controller), NULL);
g_return_val_if_fail (controller->current_crossing != NULL, NULL);
return controller->current_crossing->old_descendent;
}
GtkWidget *
gtk_event_controller_focus_get_new_focus_child (GtkEventControllerFocus *controller)
{
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_FOCUS (controller), NULL);
g_return_val_if_fail (controller->current_crossing != NULL, NULL);
return controller->current_crossing->new_descendent;
}
/** /**
* gtk_event_controller_focus_contains_focus: * gtk_event_controller_focus_contains_focus:
* @self: a #GtkEventControllerFocus * @self: a #GtkEventControllerFocus

View File

@ -46,15 +46,6 @@ GType gtk_event_controller_focus_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkEventController *gtk_event_controller_focus_new (void); GtkEventController *gtk_event_controller_focus_new (void);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_event_controller_focus_get_focus_origin (GtkEventControllerFocus *controller);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_event_controller_focus_get_focus_target (GtkEventControllerFocus *controller);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_event_controller_focus_get_old_focus_child (GtkEventControllerFocus *controller);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_event_controller_focus_get_new_focus_child (GtkEventControllerFocus *controller);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_event_controller_focus_contains_focus (GtkEventControllerFocus *self); gboolean gtk_event_controller_focus_contains_focus (GtkEventControllerFocus *self);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@ -303,48 +303,6 @@ gtk_event_controller_motion_new (void)
NULL); 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 or
* #GtkEventControllerMotion::leave signals.
*
* Returns: (transfer none): the previous pointer focus
*/
GtkWidget *
gtk_event_controller_motion_get_pointer_origin (GtkEventControllerMotion *controller)
{
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (controller), NULL);
g_return_val_if_fail (controller->current_crossing != NULL, NULL);
return controller->current_crossing->old_target;
}
/**
* 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 or
* #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_crossing != NULL, NULL);
return controller->current_crossing->new_target;
}
/** /**
* gtk_event_controller_motion_contains_pointer: * gtk_event_controller_motion_contains_pointer:
* @self: a #GtkEventControllerMotion * @self: a #GtkEventControllerMotion

View File

@ -45,11 +45,6 @@ GType gtk_event_controller_motion_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkEventController *gtk_event_controller_motion_new (void); 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);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_event_controller_motion_contains_pointer (GtkEventControllerMotion *self); gboolean gtk_event_controller_motion_contains_pointer (GtkEventControllerMotion *self);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@ -22,6 +22,47 @@
#include "gtkeventcontroller.h" #include "gtkeventcontroller.h"
typedef enum {
GTK_CROSSING_FOCUS,
GTK_CROSSING_POINTER
} GtkCrossingType;
typedef enum {
GTK_CROSSING_IN,
GTK_CROSSING_OUT
} GtkCrossingDirection;
typedef struct _GtkCrossingData GtkCrossingData;
/**
* GtkCrossingData:
* @type: the type of crossing event
* @direction: whether this is a focus-in or focus-out event
* @mode: the crossing mode
* @old_target: the old target
* @old_descendent: the direct child of the receiving widget that
* is an ancestor of @old_target, or %NULL if @old_target is not
* a descendent of the receiving widget
* @new_target: the new target
* @new_descendent: the direct child of the receiving widget that
* is an ancestor of @new_target, or %NULL if @new_target is not
* a descendent of the receiving widget
*
* The struct that is passed to gtk_event_controller_handle_crossing().
*
* The @old_target and @new_target fields are set to the old or new
* focus or hover location.
*/
struct _GtkCrossingData {
GtkCrossingType type;
GtkCrossingDirection direction;
GdkCrossingMode mode;
GtkWidget *old_target;
GtkWidget *old_descendent;
GtkWidget *new_target;
GtkWidget *new_descendent;
};
struct _GtkEventController struct _GtkEventController
{ {
GObject parent_instance; GObject parent_instance;
@ -58,4 +99,14 @@ struct _GtkEventControllerClass
GtkWidget *gtk_event_controller_get_target (GtkEventController *controller); GtkWidget *gtk_event_controller_get_target (GtkEventController *controller);
gboolean gtk_event_controller_handle_event (GtkEventController *controller,
GdkEvent *event,
GtkWidget *target,
double x,
double y);
void gtk_event_controller_handle_crossing (GtkEventController *controller,
const GtkCrossingData *crossing,
double x,
double y);
#endif /* __GTK_EVENT_CONTROLLER_PRIVATE_H__ */ #endif /* __GTK_EVENT_CONTROLLER_PRIVATE_H__ */

View File

@ -30,7 +30,7 @@
#include "gtkactionmuxerprivate.h" #include "gtkactionmuxerprivate.h"
#include "gtkcontainer.h" #include "gtkcontainer.h"
#include "gtkcsstypesprivate.h" #include "gtkcsstypesprivate.h"
#include "gtkeventcontroller.h" #include "gtkeventcontrollerprivate.h"
#include "gtklistlistmodelprivate.h" #include "gtklistlistmodelprivate.h"
#include "gtkrootprivate.h" #include "gtkrootprivate.h"
#include "gtksizerequestcacheprivate.h" #include "gtksizerequestcacheprivate.h"