mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-10 12:40:10 +00:00
tooltip: Use GdkEvent API
And at the same time, reshuffle things slightly to avoid creating synthetic events.
This commit is contained in:
parent
96daf93821
commit
853602bf63
@ -146,7 +146,10 @@ static void gtk_tooltip_display_closed (GdkDisplay *display,
|
|||||||
static void gtk_tooltip_set_last_window (GtkTooltip *tooltip,
|
static void gtk_tooltip_set_last_window (GtkTooltip *tooltip,
|
||||||
GdkWindow *window);
|
GdkWindow *window);
|
||||||
|
|
||||||
static void gtk_tooltip_handle_event_internal (GdkEvent *event);
|
static void gtk_tooltip_handle_event_internal (GdkEventType event_type,
|
||||||
|
GdkWindow *window,
|
||||||
|
gdouble dx,
|
||||||
|
gdouble dy);
|
||||||
|
|
||||||
static inline GQuark tooltip_quark (void)
|
static inline GQuark tooltip_quark (void)
|
||||||
{
|
{
|
||||||
@ -414,7 +417,6 @@ gtk_tooltip_trigger_tooltip_query (GdkDisplay *display)
|
|||||||
{
|
{
|
||||||
gint x, y;
|
gint x, y;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
GdkEvent event;
|
|
||||||
GdkDevice *device;
|
GdkDevice *device;
|
||||||
|
|
||||||
/* Trigger logic as if the mouse moved */
|
/* Trigger logic as if the mouse moved */
|
||||||
@ -423,17 +425,7 @@ gtk_tooltip_trigger_tooltip_query (GdkDisplay *display)
|
|||||||
if (!window)
|
if (!window)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
event.type = GDK_MOTION_NOTIFY;
|
gtk_tooltip_handle_event_internal (GDK_MOTION_NOTIFY, window, x, y);
|
||||||
event.motion.window = window;
|
|
||||||
event.motion.x = x;
|
|
||||||
event.motion.y = y;
|
|
||||||
event.motion.is_hint = FALSE;
|
|
||||||
|
|
||||||
gdk_window_get_root_coords (window, x, y, &x, &y);
|
|
||||||
event.motion.x_root = x;
|
|
||||||
event.motion.y_root = y;
|
|
||||||
|
|
||||||
gtk_tooltip_handle_event_internal (&event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private functions */
|
/* private functions */
|
||||||
@ -678,20 +670,18 @@ _gtk_widget_find_at_coords (GdkWindow *window,
|
|||||||
* allocation relative (x, y) of the returned widget.
|
* allocation relative (x, y) of the returned widget.
|
||||||
*/
|
*/
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
find_topmost_widget_coords_from_event (GdkEvent *event,
|
find_topmost_widget_coords (GdkWindow *window,
|
||||||
gint *x,
|
gdouble dx,
|
||||||
gint *y)
|
gdouble dy,
|
||||||
|
gint *x,
|
||||||
|
gint *y)
|
||||||
{
|
{
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
gint tx, ty;
|
gint tx, ty;
|
||||||
gdouble dx, dy;
|
|
||||||
GtkWidget *tmp;
|
GtkWidget *tmp;
|
||||||
|
|
||||||
gdk_event_get_coords (event, &dx, &dy);
|
|
||||||
|
|
||||||
/* Returns coordinates relative to tmp's allocation. */
|
/* Returns coordinates relative to tmp's allocation. */
|
||||||
tmp = _gtk_widget_find_at_coords (gdk_event_get_window (event),
|
tmp = _gtk_widget_find_at_coords (window, dx, dy, &tx, &ty);
|
||||||
dx, dy, &tx, &ty);
|
|
||||||
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1391,30 +1381,41 @@ tooltips_enabled (GdkEvent *event)
|
|||||||
void
|
void
|
||||||
_gtk_tooltip_handle_event (GdkEvent *event)
|
_gtk_tooltip_handle_event (GdkEvent *event)
|
||||||
{
|
{
|
||||||
|
GdkEventType event_type;
|
||||||
|
GdkWindow *window;
|
||||||
|
gdouble dx, dy;
|
||||||
|
|
||||||
if (!tooltips_enabled (event))
|
if (!tooltips_enabled (event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gtk_tooltip_handle_event_internal (event);
|
event_type = gdk_event_get_event_type (event);
|
||||||
|
window = gdk_event_get_window (event);
|
||||||
|
gdk_event_get_coords (event, &dx, &dy);
|
||||||
|
|
||||||
|
gtk_tooltip_handle_event_internal (event_type, window, dx, dy);
|
||||||
|
|
||||||
|
/* Always poll for a next motion event */
|
||||||
|
gdk_event_request_motions ((GdkEventMotion *) event);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_tooltip_handle_event_internal (GdkEvent *event)
|
gtk_tooltip_handle_event_internal (GdkEventType event_type,
|
||||||
|
GdkWindow *window,
|
||||||
|
gdouble dx,
|
||||||
|
gdouble dy)
|
||||||
{
|
{
|
||||||
gint x, y;
|
gint x, y;
|
||||||
GtkWidget *has_tooltip_widget;
|
GtkWidget *has_tooltip_widget;
|
||||||
GdkDisplay *display;
|
GdkDisplay *display;
|
||||||
GtkTooltip *current_tooltip;
|
GtkTooltip *current_tooltip;
|
||||||
|
|
||||||
/* Returns coordinates relative to has_tooltip_widget's allocation. */
|
has_tooltip_widget = find_topmost_widget_coords (window, dx, dy, &x, &y);
|
||||||
has_tooltip_widget = find_topmost_widget_coords_from_event (event, &x, &y);
|
display = gdk_window_get_display (window);
|
||||||
display = gdk_window_get_display (gdk_event_get_window (event));
|
|
||||||
current_tooltip = g_object_get_qdata (G_OBJECT (display), quark_current_tooltip);
|
current_tooltip = g_object_get_qdata (G_OBJECT (display), quark_current_tooltip);
|
||||||
|
|
||||||
if (current_tooltip)
|
if (current_tooltip)
|
||||||
{
|
gtk_tooltip_set_last_window (current_tooltip, window);
|
||||||
gtk_tooltip_set_last_window (current_tooltip,
|
|
||||||
gdk_event_get_window (event));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current_tooltip && current_tooltip->keyboard_mode_enabled)
|
if (current_tooltip && current_tooltip->keyboard_mode_enabled)
|
||||||
{
|
{
|
||||||
@ -1436,9 +1437,6 @@ gtk_tooltip_handle_event_internal (GdkEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always poll for a next motion event */
|
|
||||||
gdk_event_request_motions ((GdkEventMotion *) event);
|
|
||||||
|
|
||||||
/* Hide the tooltip when there's no new tooltip widget */
|
/* Hide the tooltip when there's no new tooltip widget */
|
||||||
if (!has_tooltip_widget)
|
if (!has_tooltip_widget)
|
||||||
{
|
{
|
||||||
@ -1448,7 +1446,7 @@ gtk_tooltip_handle_event_internal (GdkEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (gdk_event_get_event_type (event))
|
switch (event_type)
|
||||||
{
|
{
|
||||||
case GDK_BUTTON_PRESS:
|
case GDK_BUTTON_PRESS:
|
||||||
case GDK_2BUTTON_PRESS:
|
case GDK_2BUTTON_PRESS:
|
||||||
@ -1477,7 +1475,7 @@ gtk_tooltip_handle_event_internal (GdkEvent *event)
|
|||||||
&x, &y);
|
&x, &y);
|
||||||
|
|
||||||
/* Leave notify should override the query function */
|
/* Leave notify should override the query function */
|
||||||
hide_tooltip = (gdk_event_get_event_type (event) == GDK_LEAVE_NOTIFY);
|
hide_tooltip = (event_type == GDK_LEAVE_NOTIFY);
|
||||||
|
|
||||||
/* Is the pointer above another widget now? */
|
/* Is the pointer above another widget now? */
|
||||||
if (GTK_TOOLTIP_VISIBLE (current_tooltip))
|
if (GTK_TOOLTIP_VISIBLE (current_tooltip))
|
||||||
@ -1507,8 +1505,7 @@ gtk_tooltip_handle_event_internal (GdkEvent *event)
|
|||||||
G_CALLBACK (gtk_tooltip_display_closed),
|
G_CALLBACK (gtk_tooltip_display_closed),
|
||||||
current_tooltip);
|
current_tooltip);
|
||||||
|
|
||||||
gtk_tooltip_set_last_window (current_tooltip,
|
gtk_tooltip_set_last_window (current_tooltip, window);
|
||||||
gdk_event_get_window (event));
|
|
||||||
|
|
||||||
gtk_tooltip_start_delay (display);
|
gtk_tooltip_start_delay (display);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user