2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
* Copyright (c) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* 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-07 04:13:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
#include <stdlib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2019-12-07 15:00:41 +00:00
|
|
|
#include "init.h"
|
2014-05-05 03:47:11 +00:00
|
|
|
#include "window.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "prop-list.h"
|
2021-08-19 16:38:27 +00:00
|
|
|
#include "clipboard.h"
|
2018-09-11 00:25:37 +00:00
|
|
|
#include "controllers.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "css-editor.h"
|
2015-03-02 23:02:25 +00:00
|
|
|
#include "css-node-tree.h"
|
2014-10-11 01:40:53 +00:00
|
|
|
#include "object-tree.h"
|
2014-05-21 01:44:48 +00:00
|
|
|
#include "size-groups.h"
|
2020-07-27 17:29:21 +00:00
|
|
|
#include "a11y.h"
|
2014-05-14 00:36:02 +00:00
|
|
|
#include "actions.h"
|
2020-03-16 00:48:31 +00:00
|
|
|
#include "shortcuts.h"
|
2020-06-30 18:50:01 +00:00
|
|
|
#include "list-data.h"
|
2014-06-05 12:31:06 +00:00
|
|
|
#include "menu.h"
|
2014-07-19 06:47:36 +00:00
|
|
|
#include "misc-info.h"
|
2014-12-21 00:24:08 +00:00
|
|
|
#include "magnifier.h"
|
2016-10-30 05:11:38 +00:00
|
|
|
#include "recorder.h"
|
2020-06-30 19:17:14 +00:00
|
|
|
#include "tree-data.h"
|
2019-12-07 17:07:12 +00:00
|
|
|
#include "visual.h"
|
2019-12-07 17:30:15 +00:00
|
|
|
#include "general.h"
|
2019-12-07 17:31:10 +00:00
|
|
|
#include "logs.h"
|
2014-05-14 00:36:02 +00:00
|
|
|
|
2022-09-24 03:11:41 +00:00
|
|
|
#include "gdkdebugprivate.h"
|
2020-04-17 12:37:45 +00:00
|
|
|
#include "gdkmarshalers.h"
|
2018-10-05 20:07:07 +00:00
|
|
|
#include "gskrendererprivate.h"
|
2014-10-11 02:34:32 +00:00
|
|
|
#include "gtkbutton.h"
|
2018-10-05 20:07:07 +00:00
|
|
|
#include "gtkcsswidgetnodeprivate.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkmodulesprivate.h"
|
|
|
|
#include "gtkprivate.h"
|
2019-05-26 18:02:55 +00:00
|
|
|
#include "gtknative.h"
|
2014-10-11 02:34:32 +00:00
|
|
|
#include "gtkstack.h"
|
2014-07-12 03:45:18 +00:00
|
|
|
#include "gtkwindowgroup.h"
|
2019-04-02 23:07:51 +00:00
|
|
|
#include "gtkrevealer.h"
|
2019-04-05 19:15:16 +00:00
|
|
|
#include "gtklayoutmanager.h"
|
2019-05-07 22:04:41 +00:00
|
|
|
#include "gtkcssprovider.h"
|
2020-05-13 18:25:22 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2019-05-07 22:04:41 +00:00
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
enum {
|
|
|
|
PROP_INSPECTED_DISPLAY = 1,
|
|
|
|
NUM_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[NUM_PROPERTIES];
|
|
|
|
|
2020-04-17 12:37:45 +00:00
|
|
|
enum {
|
|
|
|
EVENT,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2021-08-07 09:58:46 +00:00
|
|
|
|
|
|
|
/* Fast way of knowing that further checks are necessary because at least
|
|
|
|
* one inspector window has been constructed. */
|
|
|
|
static gboolean any_inspector_window_constructed = FALSE;
|
|
|
|
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
static gboolean
|
|
|
|
set_selected_object (GtkInspectorWindow *iw,
|
|
|
|
GObject *selected)
|
2014-05-05 03:47:11 +00:00
|
|
|
{
|
2014-12-01 14:37:05 +00:00
|
|
|
GList *l;
|
2018-08-29 14:19:37 +00:00
|
|
|
char *title;
|
2014-12-01 14:37:05 +00:00
|
|
|
|
2014-05-10 16:26:22 +00:00
|
|
|
if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected))
|
2014-10-25 01:14:16 +00:00
|
|
|
return FALSE;
|
2014-05-10 16:26:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
title = gtk_inspector_get_object_title (selected);
|
2016-03-07 01:41:28 +00:00
|
|
|
gtk_label_set_label (GTK_LABEL (iw->object_title), title);
|
2018-08-29 14:19:37 +00:00
|
|
|
g_free (title);
|
2016-03-07 01:41:28 +00:00
|
|
|
|
2019-04-05 19:15:16 +00:00
|
|
|
gtk_inspector_prop_list_set_layout_child (GTK_INSPECTOR_PROP_LIST (iw->layout_prop_list), selected);
|
2014-07-19 06:47:36 +00:00
|
|
|
gtk_inspector_misc_info_set_object (GTK_INSPECTOR_MISC_INFO (iw->misc_info), selected);
|
2015-03-02 23:02:25 +00:00
|
|
|
gtk_inspector_css_node_tree_set_object (GTK_INSPECTOR_CSS_NODE_TREE (iw->widget_css_node_tree), selected);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_inspector_size_groups_set_object (GTK_INSPECTOR_SIZE_GROUPS (iw->size_groups), selected);
|
2020-06-30 19:17:14 +00:00
|
|
|
gtk_inspector_tree_data_set_object (GTK_INSPECTOR_TREE_DATA (iw->tree_data), selected);
|
2020-06-30 18:50:01 +00:00
|
|
|
gtk_inspector_list_data_set_object (GTK_INSPECTOR_LIST_DATA (iw->list_data), selected);
|
2014-05-14 00:36:02 +00:00
|
|
|
gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
|
2020-03-16 00:48:31 +00:00
|
|
|
gtk_inspector_shortcuts_set_object (GTK_INSPECTOR_SHORTCUTS (iw->shortcuts), selected);
|
2014-06-05 12:31:06 +00:00
|
|
|
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
|
2018-09-11 00:25:37 +00:00
|
|
|
gtk_inspector_controllers_set_object (GTK_INSPECTOR_CONTROLLERS (iw->controllers), selected);
|
2014-12-21 00:24:08 +00:00
|
|
|
gtk_inspector_magnifier_set_object (GTK_INSPECTOR_MAGNIFIER (iw->magnifier), selected);
|
2020-07-27 17:29:21 +00:00
|
|
|
gtk_inspector_a11y_set_object (GTK_INSPECTOR_A11Y (iw->a11y), selected);
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2014-12-01 14:37:05 +00:00
|
|
|
for (l = iw->extra_pages; l != NULL; l = l->next)
|
|
|
|
g_object_set (l->data, "object", selected, NULL);
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_object_activated (GtkInspectorObjectTree *wt,
|
|
|
|
GObject *selected,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
2020-07-06 20:53:54 +00:00
|
|
|
if (GTK_IS_WIDGET (selected))
|
|
|
|
gtk_inspector_window_set_object (iw, selected, CHILD_KIND_WIDGET, 0);
|
|
|
|
else
|
|
|
|
gtk_inspector_window_set_object (iw, selected, CHILD_KIND_OTHER, 0);
|
2014-10-11 02:34:32 +00:00
|
|
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-details");
|
2014-10-25 01:14:16 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "details");
|
2014-10-11 02:34:32 +00:00
|
|
|
}
|
2014-05-31 03:21:13 +00:00
|
|
|
|
2014-10-11 02:34:32 +00:00
|
|
|
static void
|
|
|
|
on_object_selected (GtkInspectorObjectTree *wt,
|
|
|
|
GObject *selected,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
2014-10-25 01:52:23 +00:00
|
|
|
gtk_widget_set_sensitive (iw->object_details_button, selected != NULL);
|
2014-05-10 16:26:22 +00:00
|
|
|
if (GTK_IS_WIDGET (selected))
|
|
|
|
gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
static void
|
|
|
|
notify_node (GtkInspectorCssNodeTree *cnt,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
GtkCssNode *node;
|
|
|
|
GtkWidget *widget = NULL;
|
|
|
|
|
|
|
|
for (node = gtk_inspector_css_node_tree_get_node (cnt);
|
|
|
|
node != NULL;
|
|
|
|
node = gtk_css_node_get_parent (node))
|
|
|
|
{
|
|
|
|
if (!GTK_IS_CSS_WIDGET_NODE (node))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
widget = gtk_css_widget_node_get_widget (GTK_CSS_WIDGET_NODE (node));
|
|
|
|
if (widget != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (widget)
|
|
|
|
gtk_inspector_flash_widget (iw, widget);
|
|
|
|
}
|
|
|
|
|
2014-10-11 02:34:32 +00:00
|
|
|
static void
|
2014-10-25 01:14:16 +00:00
|
|
|
close_object_details (GtkWidget *button, GtkInspectorWindow *iw)
|
2014-10-11 02:34:32 +00:00
|
|
|
{
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-tree");
|
2014-10-25 01:14:16 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "list");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
open_object_details (GtkWidget *button, GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
GObject *selected;
|
|
|
|
|
|
|
|
selected = gtk_inspector_object_tree_get_selected (GTK_INSPECTOR_OBJECT_TREE (iw->object_tree));
|
2021-12-15 02:52:20 +00:00
|
|
|
|
2020-07-06 20:53:54 +00:00
|
|
|
gtk_inspector_window_set_object (iw, selected, CHILD_KIND_WIDGET, 0);
|
2014-10-25 01:14:16 +00:00
|
|
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-details");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "details");
|
2014-10-11 02:34:32 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
static gboolean
|
|
|
|
translate_visible_child_name (GBinding *binding,
|
|
|
|
const GValue *from,
|
|
|
|
GValue *to,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw = user_data;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = g_value_get_string (from);
|
|
|
|
|
|
|
|
if (gtk_stack_get_child_by_name (GTK_STACK (iw->object_start_stack), name))
|
|
|
|
g_value_set_string (to, name);
|
|
|
|
else
|
|
|
|
g_value_set_string (to, "empty");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:53:54 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
ChildKind kind;
|
|
|
|
guint position;
|
|
|
|
} ChildData;
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_window_init (GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-12-01 14:37:05 +00:00
|
|
|
GIOExtensionPoint *extension_point;
|
|
|
|
GList *l, *extensions;
|
|
|
|
|
2020-07-06 20:53:54 +00:00
|
|
|
iw->objects = g_array_new (FALSE, FALSE, sizeof (ChildData));
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (iw));
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
g_object_bind_property_full (iw->object_details, "visible-child-name",
|
|
|
|
iw->object_start_stack, "visible-child-name",
|
|
|
|
G_BINDING_SYNC_CREATE,
|
|
|
|
translate_visible_child_name,
|
|
|
|
NULL,
|
|
|
|
iw,
|
|
|
|
NULL);
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_window_group_add_window (gtk_window_group_new (), GTK_WINDOW (iw));
|
2014-12-01 14:37:05 +00:00
|
|
|
|
|
|
|
extension_point = g_io_extension_point_lookup ("gtk-inspector-page");
|
|
|
|
extensions = g_io_extension_point_get_extensions (extension_point);
|
|
|
|
|
|
|
|
for (l = extensions; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
GIOExtension *extension = l->data;
|
|
|
|
GType type;
|
|
|
|
GtkWidget *widget;
|
2014-12-09 23:22:12 +00:00
|
|
|
const char *name;
|
2014-12-01 14:37:05 +00:00
|
|
|
char *title;
|
2014-12-09 23:22:12 +00:00
|
|
|
GtkWidget *button;
|
|
|
|
gboolean use_picker;
|
2014-12-01 14:37:05 +00:00
|
|
|
|
|
|
|
type = g_io_extension_get_type (extension);
|
|
|
|
|
|
|
|
widget = g_object_new (type, NULL);
|
|
|
|
|
|
|
|
iw->extra_pages = g_list_prepend (iw->extra_pages, widget);
|
|
|
|
|
2014-12-09 23:22:12 +00:00
|
|
|
name = g_io_extension_get_name (extension);
|
2014-12-01 14:37:05 +00:00
|
|
|
g_object_get (widget, "title", &title, NULL);
|
2014-12-09 23:22:12 +00:00
|
|
|
|
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (widget), "use-picker"))
|
|
|
|
g_object_get (widget, "use-picker", &use_picker, NULL);
|
|
|
|
else
|
|
|
|
use_picker = FALSE;
|
|
|
|
|
|
|
|
if (use_picker)
|
|
|
|
{
|
2017-01-20 07:02:48 +00:00
|
|
|
button = gtk_button_new_from_icon_name ("find-location-symbolic");
|
2015-10-23 20:13:30 +00:00
|
|
|
gtk_widget_set_focus_on_click (button, FALSE);
|
2014-12-09 23:22:12 +00:00
|
|
|
gtk_widget_set_halign (button, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (gtk_inspector_on_inspect), iw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
button = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
|
|
|
|
gtk_stack_add_titled (GTK_STACK (iw->top_stack), widget, name, title);
|
|
|
|
gtk_stack_add_named (GTK_STACK (iw->button_stack), button, name);
|
|
|
|
|
|
|
|
g_free (title);
|
2014-12-01 14:37:05 +00:00
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 10:34:23 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_window_constructed (GObject *object)
|
|
|
|
{
|
2014-09-26 13:49:47 +00:00
|
|
|
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
|
2014-06-27 22:43:59 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_window_parent_class)->constructed (object);
|
2014-09-26 13:49:47 +00:00
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
g_object_set_data (G_OBJECT (iw->inspected_display), "-gtk-inspector", iw);
|
2021-08-07 09:58:46 +00:00
|
|
|
any_inspector_window_constructed = TRUE;
|
2019-12-07 16:49:30 +00:00
|
|
|
|
|
|
|
gtk_inspector_object_tree_set_display (GTK_INSPECTOR_OBJECT_TREE (iw->object_tree), iw->inspected_display);
|
2019-12-07 16:48:39 +00:00
|
|
|
gtk_inspector_css_editor_set_display (GTK_INSPECTOR_CSS_EDITOR (iw->css_editor), iw->inspected_display);
|
2019-12-07 17:07:12 +00:00
|
|
|
gtk_inspector_visual_set_display (GTK_INSPECTOR_VISUAL (iw->visual), iw->inspected_display);
|
2019-12-07 17:30:15 +00:00
|
|
|
gtk_inspector_general_set_display (GTK_INSPECTOR_GENERAL (iw->general), iw->inspected_display);
|
2021-08-19 16:38:27 +00:00
|
|
|
gtk_inspector_clipboard_set_display (GTK_INSPECTOR_CLIPBOARD (iw->clipboard), iw->inspected_display);
|
2019-12-07 17:31:10 +00:00
|
|
|
gtk_inspector_logs_set_display (GTK_INSPECTOR_LOGS (iw->logs), iw->inspected_display);
|
2019-12-07 17:42:37 +00:00
|
|
|
gtk_inspector_css_node_tree_set_display (GTK_INSPECTOR_CSS_NODE_TREE (iw->widget_css_node_tree), iw->inspected_display);
|
2014-05-07 10:34:23 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 21:19:50 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_window_dispose (GObject *object)
|
|
|
|
{
|
2019-12-07 15:54:10 +00:00
|
|
|
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (iw->inspected_display), "-gtk-inspector", NULL);
|
2019-04-02 21:19:50 +00:00
|
|
|
|
2019-12-25 00:42:14 +00:00
|
|
|
g_clear_object (&iw->flash_overlay);
|
2020-07-06 20:53:54 +00:00
|
|
|
g_clear_pointer (&iw->objects, g_array_unref);
|
2019-12-25 00:42:14 +00:00
|
|
|
|
2022-07-07 13:09:35 +00:00
|
|
|
gtk_widget_dispose_template (GTK_WIDGET (iw), GTK_TYPE_INSPECTOR_WINDOW);
|
2022-07-06 12:53:22 +00:00
|
|
|
|
2019-04-02 21:19:50 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_window_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
static void
|
|
|
|
object_details_changed (GtkWidget *combo,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_center_stack), "title");
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:53:54 +00:00
|
|
|
static void
|
|
|
|
go_up_cb (GtkWidget *button,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
if (iw->objects->len > 1)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_pop_object (iw);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (iw->objects->len > 0)
|
|
|
|
{
|
|
|
|
ChildData *data = &g_array_index (iw->objects, ChildData, 0);
|
|
|
|
GtkWidget *widget = (GtkWidget *)data->object;
|
|
|
|
if (GTK_IS_WIDGET (widget) && gtk_widget_get_parent (widget))
|
|
|
|
{
|
|
|
|
GObject *obj = G_OBJECT (gtk_widget_get_parent (widget));
|
|
|
|
gtk_inspector_window_replace_object (iw, obj, CHILD_KIND_WIDGET, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
go_down_cb (GtkWidget *button,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
ChildData *data;
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
if (iw->objects->len < 1)
|
|
|
|
{
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
object = data->object;
|
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (object))
|
|
|
|
{
|
|
|
|
GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (object));
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_push_object (iw, G_OBJECT (child), CHILD_KIND_WIDGET, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (G_IS_LIST_MODEL (object))
|
|
|
|
{
|
|
|
|
GObject *item = g_list_model_get_item (G_LIST_MODEL (object), 0);
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_push_object (iw, item, CHILD_KIND_LISTITEM, 0);
|
|
|
|
g_object_unref (item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
go_previous_cb (GtkWidget *button,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
ChildData *data;
|
|
|
|
GObject *object;
|
|
|
|
GObject *parent;
|
|
|
|
|
|
|
|
if (iw->objects->len < 1)
|
|
|
|
{
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iw->objects->len > 1)
|
|
|
|
{
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 2);
|
|
|
|
parent = data->object;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parent = NULL;
|
|
|
|
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
object = data->object;
|
|
|
|
|
|
|
|
switch (data->kind)
|
|
|
|
{
|
|
|
|
case CHILD_KIND_WIDGET:
|
|
|
|
{
|
|
|
|
GtkWidget *sibling = gtk_widget_get_prev_sibling (GTK_WIDGET (object));
|
|
|
|
if (sibling)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_replace_object (iw, (GObject*)sibling, CHILD_KIND_WIDGET, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHILD_KIND_LISTITEM:
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
|
|
|
|
if (parent && data->position > 0)
|
|
|
|
item = g_list_model_get_item (G_LIST_MODEL (parent), data->position - 1);
|
|
|
|
else
|
|
|
|
item = NULL;
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_replace_object (iw, item, CHILD_KIND_LISTITEM, data->position - 1);
|
|
|
|
g_object_unref (item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHILD_KIND_CONTROLLER:
|
|
|
|
case CHILD_KIND_PROPERTY:
|
|
|
|
case CHILD_KIND_OTHER:
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
go_next_cb (GtkWidget *button,
|
|
|
|
GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
ChildData *data;
|
|
|
|
GObject *object;
|
|
|
|
GObject *parent;
|
|
|
|
|
|
|
|
if (iw->objects->len < 1)
|
|
|
|
{
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iw->objects->len > 1)
|
|
|
|
{
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 2);
|
|
|
|
parent = data->object;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parent = NULL;
|
|
|
|
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
object = data->object;
|
|
|
|
|
|
|
|
switch (data->kind)
|
|
|
|
{
|
|
|
|
case CHILD_KIND_WIDGET:
|
|
|
|
{
|
|
|
|
GtkWidget *sibling = gtk_widget_get_next_sibling (GTK_WIDGET (object));
|
|
|
|
if (sibling)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_replace_object (iw, (GObject*)sibling, CHILD_KIND_WIDGET, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHILD_KIND_LISTITEM:
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
|
|
|
|
if (parent &&
|
|
|
|
data->position + 1 < g_list_model_get_n_items (G_LIST_MODEL (parent)))
|
|
|
|
item = g_list_model_get_item (G_LIST_MODEL (parent), data->position + 1);
|
|
|
|
else
|
|
|
|
item = NULL;
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_replace_object (iw, item, CHILD_KIND_LISTITEM, data->position + 1);
|
|
|
|
g_object_unref (item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHILD_KIND_CONTROLLER:
|
|
|
|
case CHILD_KIND_PROPERTY:
|
|
|
|
case CHILD_KIND_OTHER:
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
}
|
|
|
|
|
2018-01-14 21:07:12 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_window_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GskRenderer *renderer;
|
2019-05-07 22:04:41 +00:00
|
|
|
GtkCssProvider *provider;
|
2018-01-14 21:07:12 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_window_parent_class)->realize (widget);
|
|
|
|
|
2019-05-26 18:02:55 +00:00
|
|
|
renderer = gtk_native_get_renderer (GTK_NATIVE (widget));
|
2018-01-14 21:07:12 +00:00
|
|
|
gsk_renderer_set_debug_flags (renderer, 0);
|
2019-05-07 22:04:41 +00:00
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
|
|
|
gtk_css_provider_load_from_resource (provider, "/org/gtk/libgtk/inspector/inspector.css");
|
|
|
|
gtk_style_context_add_provider_for_display (gtk_widget_get_display (widget),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
800);
|
|
|
|
g_object_unref (provider);
|
2018-01-14 21:07:12 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_window_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_INSPECTED_DISPLAY:
|
|
|
|
iw->inspected_display = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_window_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_INSPECTED_DISPLAY:
|
|
|
|
g_value_set_object (value, iw->inspected_display);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 22:56:25 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_inspector_window_enable_debugging (GtkWindow *window,
|
|
|
|
gboolean toggle)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 10:34:23 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-05-05 03:47:11 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2020-05-13 22:56:25 +00:00
|
|
|
GtkWindowClass *window_class = GTK_WINDOW_CLASS (klass);
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-05-07 10:34:23 +00:00
|
|
|
object_class->constructed = gtk_inspector_window_constructed;
|
2019-04-02 21:19:50 +00:00
|
|
|
object_class->dispose = gtk_inspector_window_dispose;
|
2019-12-07 15:54:10 +00:00
|
|
|
object_class->set_property = gtk_inspector_window_set_property;
|
|
|
|
object_class->get_property = gtk_inspector_window_get_property;
|
2020-05-13 22:56:25 +00:00
|
|
|
|
2018-01-14 21:07:12 +00:00
|
|
|
widget_class->realize = gtk_inspector_window_realize;
|
2014-05-07 10:34:23 +00:00
|
|
|
|
2020-05-13 22:56:25 +00:00
|
|
|
window_class->enable_debugging = gtk_inspector_window_enable_debugging;
|
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
properties[PROP_INSPECTED_DISPLAY] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("inspected-display", NULL, NULL,
|
2019-12-07 15:54:10 +00:00
|
|
|
GDK_TYPE_DISPLAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
|
|
|
|
2020-04-17 12:37:45 +00:00
|
|
|
signals[EVENT] = g_signal_new (g_intern_static_string ("event"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
g_signal_accumulator_true_handled,
|
|
|
|
NULL,
|
|
|
|
_gdk_marshal_BOOLEAN__POINTER,
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
1,
|
|
|
|
GDK_TYPE_EVENT);
|
|
|
|
g_signal_set_va_marshaller (signals[EVENT],
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
_gdk_marshal_BOOLEAN__POINTERv);
|
2019-02-24 04:06:00 +00:00
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/window.ui");
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-10-10 20:06:37 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, top_stack);
|
2014-12-01 14:37:05 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, button_stack);
|
2014-10-11 02:34:32 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_stack);
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_tree);
|
2014-10-11 02:34:32 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_details);
|
2016-03-07 01:41:28 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_start_stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_center_stack);
|
2014-10-25 01:14:16 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_buttons);
|
2014-10-25 01:52:23 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_details_button);
|
2014-10-11 04:23:21 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, select_object);
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, prop_list);
|
2019-04-05 19:15:16 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, layout_prop_list);
|
2015-03-02 23:02:25 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_css_node_tree);
|
2016-10-29 19:11:23 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_recorder);
|
2016-03-07 01:41:28 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_title);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, size_groups);
|
2020-06-30 19:17:14 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, tree_data);
|
2020-06-30 18:50:01 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, list_data);
|
2014-05-14 00:36:02 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions);
|
2020-03-16 00:48:31 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, shortcuts);
|
2014-06-05 12:31:06 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
|
2014-07-19 06:47:36 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
|
2018-09-11 00:25:37 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, controllers);
|
2014-12-21 00:24:08 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, magnifier);
|
2020-07-27 17:29:21 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, a11y);
|
2019-04-02 23:07:51 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, sidebar_revealer);
|
2019-12-07 16:48:39 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, css_editor);
|
2019-12-07 17:07:12 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, visual);
|
2019-12-07 17:30:15 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, general);
|
2021-08-19 16:38:27 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, clipboard);
|
2019-12-07 17:31:10 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, logs);
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2020-07-06 20:53:54 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, go_up_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, go_down_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, go_previous_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, list_position_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, go_next_button);
|
|
|
|
|
2014-09-06 00:52:03 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, gtk_inspector_on_inspect);
|
2014-10-11 02:34:32 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_object_activated);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_object_selected);
|
2014-10-25 01:14:16 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, open_object_details);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, close_object_details);
|
2016-03-07 01:41:28 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, object_details_changed);
|
2018-10-05 20:07:07 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, notify_node);
|
2020-07-06 20:53:54 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, go_previous_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, go_up_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, go_down_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, go_next_cb);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 17:36:36 +00:00
|
|
|
static GdkDisplay *
|
|
|
|
get_inspector_display (void)
|
2014-10-24 19:55:31 +00:00
|
|
|
{
|
2022-06-21 00:30:47 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
const char *name;
|
2014-10-24 19:55:31 +00:00
|
|
|
|
2022-06-21 00:30:47 +00:00
|
|
|
name = g_getenv ("GTK_INSPECTOR_DISPLAY");
|
|
|
|
display = gdk_display_open (name);
|
2014-10-24 19:55:31 +00:00
|
|
|
|
2022-06-21 00:30:47 +00:00
|
|
|
if (display)
|
|
|
|
g_debug ("Using display %s for GtkInspector", name);
|
|
|
|
else
|
|
|
|
g_message ("Failed to open display %s", name);
|
2014-10-24 19:55:31 +00:00
|
|
|
|
|
|
|
if (!display)
|
|
|
|
{
|
|
|
|
display = gdk_display_open (NULL);
|
|
|
|
if (display)
|
|
|
|
g_debug ("Using default display for GtkInspector");
|
|
|
|
else
|
|
|
|
g_message ("Failed to separate connection to default display");
|
|
|
|
}
|
|
|
|
|
2017-03-17 15:12:45 +00:00
|
|
|
|
|
|
|
if (display)
|
|
|
|
{
|
2021-05-11 01:25:08 +00:00
|
|
|
GdkDebugFlags flags;
|
2017-03-17 15:12:45 +00:00
|
|
|
|
|
|
|
name = g_getenv ("GTK_INSPECTOR_RENDERER");
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (display), "gsk-renderer",
|
|
|
|
g_strdup (name), g_free);
|
2018-01-12 00:48:27 +00:00
|
|
|
|
2021-05-11 01:25:08 +00:00
|
|
|
flags = gdk_display_get_debug_flags (gdk_display_get_default ());
|
|
|
|
|
|
|
|
gdk_display_set_debug_flags (display, flags & (GDK_DEBUG_GL_GLES | GDK_DEBUG_GL_GLX));
|
2018-01-12 00:48:27 +00:00
|
|
|
gtk_set_display_debug_flags (display, 0);
|
2017-03-17 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 19:55:31 +00:00
|
|
|
if (!display)
|
|
|
|
display = gdk_display_get_default ();
|
|
|
|
|
2019-04-06 18:19:40 +00:00
|
|
|
if (display == gdk_display_get_default ())
|
|
|
|
g_message ("Using default display for GtkInspector; expect some spillover");
|
|
|
|
|
2017-10-31 17:36:36 +00:00
|
|
|
return display;
|
2014-10-24 19:55:31 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
static GtkInspectorWindow *
|
|
|
|
gtk_inspector_window_new (GdkDisplay *display)
|
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw;
|
|
|
|
|
|
|
|
iw = g_object_new (GTK_TYPE_INSPECTOR_WINDOW,
|
|
|
|
"display", get_inspector_display (),
|
|
|
|
"inspected-display", display,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return iw;
|
|
|
|
}
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
GtkWidget *
|
2019-12-07 15:54:10 +00:00
|
|
|
gtk_inspector_window_get (GdkDisplay *display)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2019-12-07 15:54:10 +00:00
|
|
|
GtkWidget *iw;
|
|
|
|
|
2019-12-07 15:00:41 +00:00
|
|
|
gtk_inspector_init ();
|
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
iw = GTK_WIDGET (g_object_get_data (G_OBJECT (display), "-gtk-inspector"));
|
|
|
|
|
|
|
|
if (!iw)
|
2021-12-15 02:52:20 +00:00
|
|
|
iw = GTK_WIDGET (gtk_inspector_window_new (display));
|
2019-12-07 15:54:10 +00:00
|
|
|
|
|
|
|
return iw;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 10:38:09 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_window_add_overlay (GtkInspectorWindow *iw,
|
|
|
|
GtkInspectorOverlay *overlay)
|
|
|
|
{
|
|
|
|
iw->overlays = g_list_prepend (iw->overlays, g_object_ref (overlay));
|
|
|
|
|
|
|
|
gtk_inspector_overlay_queue_draw (overlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_window_remove_overlay (GtkInspectorWindow *iw,
|
|
|
|
GtkInspectorOverlay *overlay)
|
|
|
|
{
|
|
|
|
GList *item;
|
|
|
|
|
|
|
|
item = g_list_find (iw->overlays, overlay);
|
|
|
|
if (item == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_inspector_overlay_queue_draw (overlay);
|
|
|
|
|
|
|
|
iw->overlays = g_list_delete_link (iw->overlays, item);
|
2019-12-25 00:42:14 +00:00
|
|
|
g_object_unref (overlay);
|
2018-04-04 10:38:09 +00:00
|
|
|
}
|
|
|
|
|
2016-10-30 05:11:38 +00:00
|
|
|
static GtkInspectorWindow *
|
|
|
|
gtk_inspector_window_get_for_display (GdkDisplay *display)
|
|
|
|
{
|
|
|
|
return g_object_get_data (G_OBJECT (display), "-gtk-inspector");
|
|
|
|
}
|
|
|
|
|
2018-04-03 19:09:35 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gtk_inspector_prepare_render (GtkWidget *widget,
|
|
|
|
GskRenderer *renderer,
|
|
|
|
GdkSurface *surface,
|
|
|
|
const cairo_region_t *region,
|
2021-03-09 22:42:59 +00:00
|
|
|
GskRenderNode *root,
|
|
|
|
GskRenderNode *widget_node)
|
2016-10-30 05:11:38 +00:00
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw;
|
|
|
|
|
|
|
|
iw = gtk_inspector_window_get_for_display (gtk_widget_get_display (widget));
|
|
|
|
if (iw == NULL)
|
2021-03-09 22:42:59 +00:00
|
|
|
return root;
|
2016-10-30 05:11:38 +00:00
|
|
|
|
|
|
|
/* sanity check for single-display GDK backends */
|
|
|
|
if (GTK_WIDGET (iw) == widget)
|
2021-03-09 22:42:59 +00:00
|
|
|
return root;
|
2016-10-30 05:11:38 +00:00
|
|
|
|
|
|
|
gtk_inspector_recorder_record_render (GTK_INSPECTOR_RECORDER (iw->widget_recorder),
|
|
|
|
widget,
|
2016-11-20 02:52:56 +00:00
|
|
|
renderer,
|
2018-03-21 10:49:14 +00:00
|
|
|
surface,
|
2016-10-30 05:11:38 +00:00
|
|
|
region,
|
2021-03-09 22:42:59 +00:00
|
|
|
root);
|
2018-04-03 19:09:35 +00:00
|
|
|
|
2018-04-04 10:38:09 +00:00
|
|
|
if (iw->overlays)
|
|
|
|
{
|
|
|
|
GtkSnapshot *snapshot;
|
|
|
|
GList *l;
|
2020-05-20 07:22:41 +00:00
|
|
|
double native_x, native_y;
|
2018-04-04 10:38:09 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
snapshot = gtk_snapshot_new ();
|
2021-03-09 22:42:59 +00:00
|
|
|
gtk_snapshot_append_node (snapshot, root);
|
2018-04-04 10:38:09 +00:00
|
|
|
|
2020-05-20 07:22:41 +00:00
|
|
|
gtk_native_get_surface_transform (GTK_NATIVE (widget), &native_x, &native_y);
|
|
|
|
|
2020-05-13 18:25:22 +00:00
|
|
|
gtk_snapshot_save (snapshot);
|
2020-05-20 07:22:41 +00:00
|
|
|
gtk_snapshot_translate (snapshot, &(graphene_point_t) { native_x, native_y });
|
2020-05-13 18:25:22 +00:00
|
|
|
|
2018-04-04 10:38:09 +00:00
|
|
|
for (l = iw->overlays; l; l = l->next)
|
|
|
|
{
|
2021-03-09 22:42:59 +00:00
|
|
|
gtk_inspector_overlay_snapshot (l->data, snapshot, widget_node, widget);
|
2018-04-04 10:38:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 18:25:22 +00:00
|
|
|
gtk_snapshot_restore (snapshot);
|
|
|
|
|
2021-03-09 22:42:59 +00:00
|
|
|
gsk_render_node_unref (root);
|
|
|
|
root = gtk_snapshot_free_to_node (snapshot);
|
2018-04-04 10:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 22:42:59 +00:00
|
|
|
return root;
|
2016-10-30 05:11:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
gboolean
|
|
|
|
gtk_inspector_is_recording (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw;
|
|
|
|
|
2021-08-07 09:58:46 +00:00
|
|
|
if (!any_inspector_window_constructed)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
iw = gtk_inspector_window_get_for_display (gtk_widget_get_display (widget));
|
|
|
|
if (iw == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* sanity check for single-display GDK backends */
|
|
|
|
if (GTK_WIDGET (iw) == widget)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gtk_inspector_recorder_is_recording (GTK_INSPECTOR_RECORDER (iw->widget_recorder));
|
|
|
|
}
|
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
gboolean
|
|
|
|
gtk_inspector_handle_event (GdkEvent *event)
|
|
|
|
{
|
|
|
|
GtkInspectorWindow *iw;
|
|
|
|
gboolean handled = FALSE;
|
|
|
|
|
2021-08-07 09:58:46 +00:00
|
|
|
if (!any_inspector_window_constructed)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-02-24 04:06:00 +00:00
|
|
|
iw = gtk_inspector_window_get_for_display (gdk_event_get_display (event));
|
|
|
|
if (iw == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-12-15 02:52:20 +00:00
|
|
|
gtk_inspector_recorder_record_event (GTK_INSPECTOR_RECORDER (iw->widget_recorder),
|
|
|
|
gtk_get_event_widget (event),
|
|
|
|
event);
|
|
|
|
|
2020-04-17 12:37:45 +00:00
|
|
|
g_signal_emit (iw, signals[EVENT], 0, event, &handled);
|
2019-02-24 04:06:00 +00:00
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2019-12-07 15:54:10 +00:00
|
|
|
GdkDisplay *
|
|
|
|
gtk_inspector_window_get_inspected_display (GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
return iw->inspected_display;
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:53:54 +00:00
|
|
|
static void
|
|
|
|
update_go_button (GtkWidget *button,
|
|
|
|
gboolean enabled,
|
|
|
|
const char *tooltip)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (button, enabled);
|
|
|
|
gtk_widget_set_tooltip_text (button, tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_go_buttons (GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
GObject *parent;
|
|
|
|
GObject *object;
|
|
|
|
ChildKind kind;
|
|
|
|
guint position;
|
|
|
|
|
|
|
|
if (iw->objects->len > 1)
|
|
|
|
{
|
|
|
|
ChildData *data = &g_array_index (iw->objects, ChildData, iw->objects->len - 2);
|
|
|
|
parent = data->object;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iw->objects->len > 0)
|
|
|
|
{
|
|
|
|
ChildData *data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
object = data->object;
|
|
|
|
kind = data->kind;
|
|
|
|
position = data->position;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
object = NULL;
|
|
|
|
kind = CHILD_KIND_OTHER;
|
2021-04-13 00:56:19 +00:00
|
|
|
position = 0;
|
2020-07-06 20:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
text = g_strdup_printf ("Go to %s", G_OBJECT_TYPE_NAME (parent));
|
|
|
|
update_go_button (iw->go_up_button, TRUE, text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
update_go_button (iw->go_up_button, GTK_IS_WIDGET (object) && !GTK_IS_ROOT (object), "Parent widget");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (kind)
|
|
|
|
{
|
|
|
|
case CHILD_KIND_WIDGET:
|
2020-08-01 06:56:34 +00:00
|
|
|
update_go_button (iw->go_down_button,
|
|
|
|
GTK_IS_WIDGET (object) &>k_widget_get_first_child (GTK_WIDGET (object)) != NULL,
|
|
|
|
"First child");
|
|
|
|
update_go_button (iw->go_previous_button,
|
|
|
|
GTK_IS_WIDGET (object) && gtk_widget_get_prev_sibling (GTK_WIDGET (object)) != NULL,
|
|
|
|
"Previous sibling");
|
|
|
|
update_go_button (iw->go_next_button,
|
|
|
|
GTK_IS_WIDGET (object) && gtk_widget_get_next_sibling (GTK_WIDGET (object)) != NULL,
|
|
|
|
"Next sibling");
|
2022-11-28 18:43:36 +00:00
|
|
|
gtk_widget_set_visible (iw->list_position_label, FALSE);
|
2020-07-06 20:53:54 +00:00
|
|
|
break;
|
|
|
|
case CHILD_KIND_LISTITEM:
|
|
|
|
update_go_button (iw->go_down_button, FALSE, NULL);
|
|
|
|
update_go_button (iw->go_previous_button, position > 0, "Previous list item");
|
|
|
|
update_go_button (iw->go_next_button, position + 1 < g_list_model_get_n_items (G_LIST_MODEL (parent)), "Next list item");
|
|
|
|
{
|
|
|
|
char *text = g_strdup_printf ("%u", position);
|
|
|
|
gtk_label_set_label (GTK_LABEL (iw->list_position_label), text);
|
|
|
|
g_free (text);
|
2022-11-28 18:43:36 +00:00
|
|
|
gtk_widget_set_visible (iw->list_position_label, TRUE);
|
2020-07-06 20:53:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CHILD_KIND_PROPERTY:
|
|
|
|
case CHILD_KIND_CONTROLLER:
|
|
|
|
case CHILD_KIND_OTHER:
|
|
|
|
update_go_button (iw->go_down_button, FALSE, NULL);
|
|
|
|
update_go_button (iw->go_previous_button, FALSE, NULL);
|
|
|
|
update_go_button (iw->go_next_button, FALSE, NULL);
|
2022-11-28 18:43:36 +00:00
|
|
|
gtk_widget_set_visible (iw->list_position_label, FALSE);
|
2020-07-06 20:53:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_object_details (GtkInspectorWindow *iw,
|
|
|
|
GObject *object,
|
|
|
|
const char *tab)
|
|
|
|
{
|
|
|
|
set_selected_object (iw, object);
|
|
|
|
|
|
|
|
if (tab)
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_details), tab);
|
|
|
|
if (!gtk_stack_get_visible_child_name (GTK_STACK (iw->object_details)))
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_details), "properties");
|
|
|
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-details");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "details");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_window_push_object (GtkInspectorWindow *iw,
|
|
|
|
GObject *object,
|
|
|
|
ChildKind kind,
|
|
|
|
guint position)
|
|
|
|
{
|
|
|
|
ChildData data;
|
|
|
|
|
|
|
|
data.kind = kind;
|
|
|
|
data.object = object;
|
|
|
|
data.position = position;
|
|
|
|
g_array_append_val (iw->objects, data);
|
|
|
|
show_object_details (iw, object, "properties");
|
|
|
|
update_go_buttons (iw);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_window_pop_object (GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
ChildData *data;
|
|
|
|
const char *tabs[] = {
|
|
|
|
"properties",
|
|
|
|
"controllers",
|
|
|
|
"properties",
|
|
|
|
"list-data",
|
|
|
|
"misc",
|
|
|
|
};
|
|
|
|
const char *tab;
|
|
|
|
|
|
|
|
if (iw->objects->len < 2)
|
|
|
|
{
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (iw));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
tab = tabs[data->kind];
|
|
|
|
g_array_remove_index (iw->objects, iw->objects->len - 1);
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
show_object_details (iw, data->object, tab);
|
|
|
|
update_go_buttons (iw);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_window_replace_object (GtkInspectorWindow *iw,
|
|
|
|
GObject *object,
|
|
|
|
ChildKind kind,
|
|
|
|
guint position)
|
|
|
|
{
|
|
|
|
ChildData *data;
|
|
|
|
|
|
|
|
data = &g_array_index (iw->objects, ChildData, iw->objects->len - 1);
|
|
|
|
g_assert (data->kind == kind);
|
|
|
|
data->object = object;
|
|
|
|
data->position = position;
|
|
|
|
show_object_details (iw, object, NULL);
|
|
|
|
update_go_buttons (iw);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_window_set_object (GtkInspectorWindow *iw,
|
|
|
|
GObject *object,
|
|
|
|
ChildKind kind,
|
|
|
|
guint position)
|
|
|
|
{
|
|
|
|
g_array_set_size (iw->objects, 0);
|
|
|
|
gtk_inspector_window_push_object (iw, object, kind, position);
|
|
|
|
update_go_buttons (iw);
|
|
|
|
}
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
// vim: set et sw=2 ts=2:
|
2019-12-07 15:54:10 +00:00
|
|
|
|