/* Ignores (x, y) on input, translates event coordinates to * allocation relative (x, y) of the returned widget. */ static GtkWidget * find_topmost_widget_coords_from_event (GdkEvent *event, gint *x, gint *y) { GtkAllocation allocation; gint tx, ty; gdouble dx, dy; GtkWidget *tmp; gdk_event_get_coords (event, &dx, &dy); /* Returns coordinates relative to tmp's allocation. */ tmp = _gtk_widget_find_at_coords (event->any.window, dx, dy, &tx, &ty); if (!tmp) return NULL; /* Make sure the pointer can actually be on the widget returned. */ gtk_widget_get_allocation (tmp, &allocation); if (tx < 0 || tx >= allocation.width || ty < 0 || ty >= allocation.height) return NULL; if (x) *x = tx; if (y) *y = ty; return tmp; }
/* Ignores (x, y) on input, translates event coordinates to * allocation relative (x, y) of the returned widget. */ static GtkWidget * find_topmost_widget_coords_from_event (GdkEvent *event, gint *x, gint *y) { GtkAllocation allocation; gint tx, ty; gdouble dx, dy; GtkWidget *tmp; gdk_event_get_coords (event, &dx, &dy); /* Returns coordinates relative to tmp's allocation. */ tmp = _gtk_widget_find_at_coords (event->any.window, dx, dy, &tx, &ty); if (!tmp) return NULL; /* Make sure the pointer can actually be on the widget returned. */ gtk_widget_get_allocation (tmp, &allocation); allocation.x = 0; allocation.y = 0; if (GTK_IS_WINDOW (tmp)) { GtkBorder border; _gtk_window_get_shadow_width (GTK_WINDOW (tmp), &border); allocation.x = border.left; allocation.y = border.top; allocation.width -= border.left + border.right; allocation.height -= border.top + border.bottom; } if (tx < allocation.x || tx >= allocation.width || ty < allocation.y || ty >= allocation.height) return NULL; if (x) *x = tx; if (y) *y = ty; return tmp; }
static void gtk_tooltip_show_tooltip (GdkDisplay *display) { gint x, y; GdkScreen *screen; GdkWindow *window; GtkWidget *tooltip_widget; GtkTooltip *tooltip; gboolean has_tooltip; gboolean return_value = FALSE; tooltip = g_object_get_data (G_OBJECT (display), "gdk-display-current-tooltip"); if (tooltip->keyboard_mode_enabled) { x = y = -1; tooltip_widget = tooltip->keyboard_widget; } else { GdkDevice *device; gint tx, ty; window = tooltip->last_window; if (!GDK_IS_WINDOW (window)) return; device = gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display)); gdk_window_get_device_position (window, device, &x, &y, NULL); gdk_window_get_root_coords (window, x, y, &tx, &ty); tooltip->last_x = tx; tooltip->last_y = ty; tooltip_widget = _gtk_widget_find_at_coords (window, x, y, &x, &y); } if (!tooltip_widget) return; g_object_get (tooltip_widget, "has-tooltip", &has_tooltip, NULL); return_value = gtk_tooltip_run_requery (&tooltip_widget, tooltip, &x, &y); if (!return_value) return; if (!tooltip->current_window) { if (gtk_widget_get_tooltip_window (tooltip_widget)) tooltip->current_window = gtk_widget_get_tooltip_window (tooltip_widget); else tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window); } screen = gtk_widget_get_screen (tooltip_widget); /* FIXME: should use tooltip->current_window iso tooltip->window */ if (screen != gtk_widget_get_screen (tooltip->window)) { g_signal_handlers_disconnect_by_func (display, gtk_tooltip_display_closed, tooltip); gtk_window_set_screen (GTK_WINDOW (tooltip->window), screen); g_signal_connect (display, "closed", G_CALLBACK (gtk_tooltip_display_closed), tooltip); } gtk_tooltip_position (tooltip, display, tooltip_widget); /* Now a tooltip is visible again on the display, make sure browse * mode is enabled. */ tooltip->browse_mode_enabled = TRUE; if (tooltip->browse_mode_timeout_id) { g_source_remove (tooltip->browse_mode_timeout_id); tooltip->browse_mode_timeout_id = 0; } }