GtkInspector: Add a function to select the widget under the pointer

This commit is contained in:
Matthias Clasen 2014-07-06 17:03:53 -04:00
parent 2a053cc6c3
commit b0390a3349
2 changed files with 38 additions and 12 deletions

View File

@ -200,6 +200,21 @@ start_flash (GtkInspectorWindow *iw,
gtk_widget_queue_draw (widget);
}
static void
select_widget (GtkInspectorWindow *iw,
GtkWidget *widget)
{
iw->selected_widget = widget;
gtk_notebook_set_current_page (GTK_NOTEBOOK (iw->top_notebook), 0);
gtk_inspector_widget_tree_scan (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree),
gtk_widget_get_toplevel (widget));
gtk_inspector_widget_tree_select_object (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree),
G_OBJECT (widget));
}
static void
on_inspect_widget (GtkWidget *button,
GdkEvent *event,
@ -213,18 +228,8 @@ on_inspect_widget (GtkWidget *button,
widget = find_widget_at_pointer (gdk_event_get_device (event));
if (widget == NULL)
return;
iw->selected_widget = widget;
gtk_notebook_set_current_page (GTK_NOTEBOOK (iw->top_notebook), 0);
gtk_inspector_widget_tree_scan (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree),
gtk_widget_get_toplevel (widget));
gtk_inspector_widget_tree_select_object (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree),
G_OBJECT (widget));
if (widget)
select_widget (iw, widget);
}
static void
@ -401,4 +406,22 @@ gtk_inspector_stop_highlight (GtkWidget *widget)
gtk_widget_queue_draw (widget);
}
void
gtk_inspector_window_select_widget_under_pointer (GtkInspectorWindow *iw)
{
GdkDisplay *display;
GdkDeviceManager *dm;
GdkDevice *device;
GtkWidget *widget;
display = gtk_widget_get_display (GTK_WIDGET (iw));
dm = gdk_display_get_device_manager (display);
device = gdk_device_manager_get_client_pointer (dm);
widget = find_widget_at_pointer (device);
if (widget)
select_widget (iw, widget);
}
/* vim: set et sw=2 ts=2: */

View File

@ -83,6 +83,9 @@ void gtk_inspector_flash_widget (GtkInspectorWindow *iw,
GtkWidget *widget);
void gtk_inspector_start_highlight (GtkWidget *widget);
void gtk_inspector_stop_highlight (GtkWidget *widget);
void gtk_inspector_window_select_widget_under_pointer (GtkInspectorWindow *iw);
G_END_DECLS