2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-05-07 04:13:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
#include "window.h"
|
2018-04-04 10:38:09 +00:00
|
|
|
|
|
|
|
#include "highlightoverlay.h"
|
2014-10-11 01:40:53 +00:00
|
|
|
#include "object-tree.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-10-10 20:06:37 +00:00
|
|
|
#include "gtkstack.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkmain.h"
|
2018-01-19 09:16:15 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2018-06-26 12:56:28 +00:00
|
|
|
#include "gtkgesturemultipress.h"
|
|
|
|
#include "gtkeventcontrollermotion.h"
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
2019-02-23 21:51:51 +00:00
|
|
|
#include "gtkroot.h"
|
2018-01-19 09:16:15 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
static GtkWidget *
|
|
|
|
find_widget_at_pointer (GdkDevice *device)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-03 20:43:04 +00:00
|
|
|
GtkWidget *widget = NULL;
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkSurface *pointer_surface;
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
pointer_surface = gdk_device_get_surface_at_position (device, NULL, NULL);
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
if (pointer_surface)
|
2019-02-23 21:51:51 +00:00
|
|
|
widget = gtk_root_get_for_surface (pointer_surface);
|
2014-05-03 20:43:04 +00:00
|
|
|
|
|
|
|
if (widget)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2017-06-26 09:48:33 +00:00
|
|
|
double x, y;
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2018-03-20 14:21:12 +00:00
|
|
|
gdk_surface_get_device_position_double (gtk_widget_get_surface (widget),
|
2017-06-26 09:48:33 +00:00
|
|
|
device, &x, &y, NULL);
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2018-08-12 11:30:15 +00:00
|
|
|
widget = gtk_widget_pick (widget, x, y);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2017-11-04 23:49:18 +00:00
|
|
|
return widget;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
clear_flash (GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2018-04-04 10:38:09 +00:00
|
|
|
if (iw->flash_overlay)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
2018-04-04 10:38:09 +00:00
|
|
|
gtk_inspector_window_remove_overlay (iw, iw->flash_overlay);
|
|
|
|
g_clear_object (&iw->flash_overlay);
|
2014-05-03 20:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
start_flash (GtkInspectorWindow *iw,
|
|
|
|
GtkWidget *widget)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
2014-12-01 14:38:26 +00:00
|
|
|
clear_flash (iw);
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
iw->flash_count = 1;
|
2018-04-04 10:38:09 +00:00
|
|
|
iw->flash_overlay = gtk_highlight_overlay_new (widget);
|
|
|
|
gtk_inspector_window_add_overlay (iw, iw->flash_overlay);
|
2014-05-03 20:43:04 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:03:53 +00:00
|
|
|
static void
|
|
|
|
select_widget (GtkInspectorWindow *iw,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *wt = GTK_INSPECTOR_OBJECT_TREE (iw->object_tree);
|
2014-10-04 02:12:54 +00:00
|
|
|
|
2014-07-06 21:03:53 +00:00
|
|
|
iw->selected_widget = widget;
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_inspector_object_tree_select_object (wt, G_OBJECT (widget));
|
2014-07-06 21:03:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
static void
|
2019-02-24 04:06:00 +00:00
|
|
|
on_inspect_widget (GtkInspectorWindow *iw,
|
|
|
|
GdkEvent *event)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2018-03-20 14:21:12 +00:00
|
|
|
gdk_surface_raise (gtk_widget_get_surface (GTK_WIDGET (iw)));
|
2014-06-05 00:29:10 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
clear_flash (iw);
|
2014-05-03 20:43:04 +00:00
|
|
|
|
|
|
|
widget = find_widget_at_pointer (gdk_event_get_device (event));
|
|
|
|
|
2014-07-06 21:03:53 +00:00
|
|
|
if (widget)
|
|
|
|
select_widget (iw, widget);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
on_highlight_widget (GtkWidget *button,
|
|
|
|
GdkEvent *event,
|
|
|
|
GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-03 20:43:04 +00:00
|
|
|
GtkWidget *widget;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
widget = find_widget_at_pointer (gdk_event_get_device (event));
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
if (widget == NULL)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
/* This window isn't in-process. Ignore it. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
if (gtk_widget_get_toplevel (widget) == GTK_WIDGET (iw))
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
/* Don't hilight things in the inspector window */
|
2014-05-03 20:43:04 +00:00
|
|
|
return;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 10:38:09 +00:00
|
|
|
if (iw->flash_overlay &&
|
|
|
|
gtk_highlight_overlay_get_widget (GTK_HIGHLIGHT_OVERLAY (iw->flash_overlay)) == widget)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
|
|
|
/* Already selected */
|
|
|
|
return;
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
clear_flash (iw);
|
|
|
|
start_flash (iw, widget);
|
2014-05-03 20:43:04 +00:00
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-10-28 03:51:17 +00:00
|
|
|
static void
|
|
|
|
deemphasize_window (GtkWidget *window)
|
|
|
|
{
|
2016-10-29 02:37:20 +00:00
|
|
|
GdkDisplay *display;
|
2014-10-28 03:51:17 +00:00
|
|
|
|
2016-10-29 02:37:20 +00:00
|
|
|
display = gtk_widget_get_display (window);
|
|
|
|
if (gdk_display_is_composited (display))
|
2014-10-28 03:51:17 +00:00
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_t *region;
|
|
|
|
|
|
|
|
gtk_widget_set_opacity (window, 0.3);
|
|
|
|
rect.x = rect.y = rect.width = rect.height = 0;
|
|
|
|
region = cairo_region_create_rectangle (&rect);
|
|
|
|
gtk_widget_input_shape_combine_region (window, region);
|
|
|
|
cairo_region_destroy (region);
|
|
|
|
}
|
|
|
|
else
|
2018-03-20 14:21:12 +00:00
|
|
|
gdk_surface_lower (gtk_widget_get_surface (window));
|
2014-10-28 03:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reemphasize_window (GtkWidget *window)
|
|
|
|
{
|
2016-10-29 02:37:20 +00:00
|
|
|
GdkDisplay *display;
|
2014-10-28 03:51:17 +00:00
|
|
|
|
2016-10-29 02:37:20 +00:00
|
|
|
display = gtk_widget_get_display (window);
|
|
|
|
if (gdk_display_is_composited (display))
|
2014-10-28 03:51:17 +00:00
|
|
|
{
|
|
|
|
gtk_widget_set_opacity (window, 1.0);
|
|
|
|
gtk_widget_input_shape_combine_region (window, NULL);
|
|
|
|
}
|
|
|
|
else
|
2018-03-20 14:21:12 +00:00
|
|
|
gdk_surface_raise (gtk_widget_get_surface (window));
|
2014-10-28 03:51:17 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
static gboolean handle_event (GtkInspectorWindow *iw, GdkEvent *event);
|
|
|
|
|
2018-06-26 12:56:28 +00:00
|
|
|
static void
|
2019-02-24 04:06:00 +00:00
|
|
|
handle_button_event (GtkInspectorWindow *iw,
|
|
|
|
GdkEvent *event)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
2019-02-24 04:06:00 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (iw, handle_event, NULL);
|
2018-06-26 12:56:28 +00:00
|
|
|
reemphasize_window (GTK_WIDGET (iw));
|
2019-02-24 04:06:00 +00:00
|
|
|
on_inspect_widget (iw, event);
|
|
|
|
}
|
2018-06-26 12:56:28 +00:00
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
static void
|
|
|
|
handle_motion_event (GtkInspectorWindow *iw,
|
|
|
|
GdkEvent *event)
|
|
|
|
{
|
|
|
|
on_highlight_widget (NULL, event, iw);
|
2018-06-26 12:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-24 04:06:00 +00:00
|
|
|
handle_key_event (GtkInspectorWindow *iw,
|
|
|
|
GdkEvent *event)
|
2018-06-26 12:56:28 +00:00
|
|
|
{
|
2019-02-24 04:06:00 +00:00
|
|
|
guint keyval = 0;
|
2018-06-26 12:56:28 +00:00
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
gdk_event_get_keyval (event, &keyval);
|
|
|
|
if (keyval == GDK_KEY_Escape)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (iw, handle_event, NULL);
|
|
|
|
reemphasize_window (GTK_WIDGET (iw));
|
|
|
|
clear_flash (iw);
|
|
|
|
}
|
2018-06-26 12:56:28 +00:00
|
|
|
}
|
2014-10-28 03:51:17 +00:00
|
|
|
|
2018-06-26 12:56:28 +00:00
|
|
|
static gboolean
|
2019-02-24 04:06:00 +00:00
|
|
|
handle_event (GtkInspectorWindow *iw, GdkEvent *event)
|
2018-06-26 12:56:28 +00:00
|
|
|
{
|
2019-02-24 04:06:00 +00:00
|
|
|
switch ((int)gdk_event_get_event_type (event))
|
2018-06-26 12:56:28 +00:00
|
|
|
{
|
2019-02-24 04:06:00 +00:00
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
case GDK_KEY_RELEASE:
|
|
|
|
handle_key_event (iw, event);
|
|
|
|
break;
|
2018-06-26 12:56:28 +00:00
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
handle_motion_event (iw, event);
|
|
|
|
break;
|
2018-06-26 12:56:28 +00:00
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
handle_button_event (iw, event);
|
|
|
|
break;
|
2018-06-26 12:56:28 +00:00
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
default:;
|
2014-06-13 02:29:31 +00:00
|
|
|
}
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
return TRUE;
|
2017-05-06 14:44:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
void
|
2014-09-06 00:52:03 +00:00
|
|
|
gtk_inspector_on_inspect (GtkWidget *button,
|
|
|
|
GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2019-02-24 04:06:00 +00:00
|
|
|
g_signal_connect (iw, "event", G_CALLBACK (handle_event), NULL);
|
2014-10-28 03:51:17 +00:00
|
|
|
deemphasize_window (GTK_WIDGET (iw));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
static gboolean
|
2014-05-07 03:24:20 +00:00
|
|
|
on_flash_timeout (GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
iw->flash_count++;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2018-04-04 10:38:09 +00:00
|
|
|
gtk_highlight_overlay_set_color (GTK_HIGHLIGHT_OVERLAY (iw->flash_overlay),
|
|
|
|
&(GdkRGBA) {
|
|
|
|
0.0, 0.0, 1.0,
|
|
|
|
(iw && iw->flash_count % 2 == 0) ? 0.0 : 0.2
|
|
|
|
});
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
if (iw->flash_count == 6)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
2018-04-04 10:38:09 +00:00
|
|
|
clear_flash (iw);
|
2014-05-07 03:24:20 +00:00
|
|
|
iw->flash_cnx = 0;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_flash_widget (GtkInspectorWindow *iw,
|
|
|
|
GtkWidget *widget)
|
2014-05-03 20:43:04 +00:00
|
|
|
{
|
|
|
|
if (!gtk_widget_get_visible (widget) || !gtk_widget_get_mapped (widget))
|
|
|
|
return;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-12-01 14:38:26 +00:00
|
|
|
if (iw->flash_cnx != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (iw->flash_cnx);
|
|
|
|
iw->flash_cnx = 0;
|
|
|
|
}
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
start_flash (iw, widget);
|
|
|
|
iw->flash_cnx = g_timeout_add (150, (GSourceFunc) on_flash_timeout, iw);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:03:53 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_window_select_widget_under_pointer (GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
GdkDevice *device;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2014-10-24 19:55:31 +00:00
|
|
|
display = gdk_display_get_default ();
|
2015-12-16 18:28:53 +00:00
|
|
|
device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
|
2014-07-06 21:03:53 +00:00
|
|
|
|
|
|
|
widget = find_widget_at_pointer (device);
|
|
|
|
|
|
|
|
if (widget)
|
|
|
|
select_widget (iw, widget);
|
|
|
|
}
|
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
/* vim: set et sw=2 ts=2: */
|