From 75d49675f39158755401b560afb99651b17895d1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 15 May 2014 00:06:43 -0400 Subject: [PATCH] inspector: Add a general information tab It is useful to see the GTK+ version, and the various paths that affect GTK+ operation at runtime. --- gtk/inspector/Makefile.am | 2 + gtk/inspector/general.c | 170 ++++++++++++++++ gtk/inspector/general.h | 53 +++++ gtk/inspector/general.ui | 269 ++++++++++++++++++++++++++ gtk/inspector/init.c | 2 + gtk/inspector/inspector.gresource.xml | 1 + gtk/inspector/window.ui | 11 ++ po/POTFILES.in | 1 + 8 files changed, 509 insertions(+) create mode 100644 gtk/inspector/general.c create mode 100644 gtk/inspector/general.h create mode 100644 gtk/inspector/general.ui diff --git a/gtk/inspector/Makefile.am b/gtk/inspector/Makefile.am index ee32cf3bfb..e2770d1f82 100644 --- a/gtk/inspector/Makefile.am +++ b/gtk/inspector/Makefile.am @@ -25,6 +25,8 @@ libgtkinspector_la_SOURCES = \ css-editor.c \ data-list.h \ data-list.c \ + general.h \ + general.c \ init.h \ init.c \ inspect-button.c \ diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c new file mode 100644 index 0000000000..8321ecb23c --- /dev/null +++ b/gtk/inspector/general.c @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2014 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "general.h" + +#include "gtkprivate.h" + +#ifdef GDK_WINDOWING_X11 +#include "x11/gdkx.h" +#endif + +#ifdef GDK_WINDOWING_WIN32 +#include "win32/gdkwin32.h" +#endif + +#ifdef GDK_WINDOWING_QUARTZ +#include "quartz/gdkquartz.h" +#endif + +#ifdef GDK_WINDOWING_WAYLAND +#include "wayland/gdkwayland.h" +#endif + +#ifdef GDK_WINDOWING_BROADWAY +#include "broadway/gdkbroadway.h" +#endif + + +struct _GtkInspectorGeneralPrivate +{ + GtkWidget *gtk_version; + GtkWidget *gdk_backend; + + GtkWidget *prefix; + GtkWidget *xdg_data_home; + GtkWidget *xdg_data_dirs; + GtkWidget *gtk_path; + GtkWidget *gtk_exe_prefix; + GtkWidget *gtk_data_prefix; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorGeneral, gtk_inspector_general, GTK_TYPE_BOX) + +static void +init_version (GtkInspectorGeneral *gen) +{ + const gchar *backend; + GdkDisplay *display; + + display = gtk_widget_get_display (GTK_WIDGET (gen)); + +#ifdef GDK_WINDOWING_X11 + if (GDK_IS_X11_DISPLAY (display)) + backend = "X11"; + else +#endif +#ifdef GDK_WINDOWING_WAYLAND + if (GDK_IS_WAYLAND_DISPLAY (display)) + backend = "Wayland"; + else +#endif +#ifdef GDK_WINDOWING_BROADWAY + if (GDK_IS_BROADWAY_DISPLAY (display)) + backend = "Broadway"; + else +#endif +#ifdef GDK_WINDOWING_WIN32 + if (GDK_IS_WIN32_DISPLAY (display)) + backend = "Windows"; + else +#endif +#ifdef GDK_WINDOWING_QUARTZ + if (GDK_IS_QUARTZ_DISPLAY (display)) + backend = "Quartz"; + else +#endif + backend = "Unknown"; + + gtk_label_set_text (GTK_LABEL (gen->priv->gtk_version), GTK_VERSION); + gtk_label_set_text (GTK_LABEL (gen->priv->gdk_backend), backend); +} + +static void +set_monospace_font (GtkWidget *w) +{ + PangoFontDescription *font_desc; + font_desc = pango_font_description_from_string ("monospace"); + gtk_widget_override_font (w, font_desc); + pango_font_description_free (font_desc); +} + +static void +set_path_label (GtkWidget *w, + const gchar *var) +{ + const gchar *v; + + v = g_getenv (var); +g_print ("%s %s\n", var, v); + if (v) + { + set_monospace_font (w); + gtk_label_set_text (GTK_LABEL (w), v); + } + else + { + GtkWidget *r; + r = gtk_widget_get_ancestor (w, GTK_TYPE_LIST_BOX_ROW); + gtk_widget_hide (r); + } +} + +static void +init_env (GtkInspectorGeneral *gen) +{ + set_monospace_font (gen->priv->prefix); + gtk_label_set_text (GTK_LABEL (gen->priv->prefix), _gtk_get_data_prefix ()); + set_path_label (gen->priv->xdg_data_home, "XDG_DATA_HOME"); + set_path_label (gen->priv->xdg_data_dirs, "XDG_DATA_DIRS"); + set_path_label (gen->priv->gtk_path, "GTK_PATH"); + set_path_label (gen->priv->gtk_exe_prefix, "GTK_EXE_PREFIX"); + set_path_label (gen->priv->gtk_data_prefix, "GTK_DATA_PREFIX"); +} + +static void +gtk_inspector_general_init (GtkInspectorGeneral *gen) +{ + gen->priv = gtk_inspector_general_get_instance_private (gen); + gtk_widget_init_template (GTK_WIDGET (gen)); + init_version (gen); + init_env (gen); +} + +static void +gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/general.ui"); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_version); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gdk_backend); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, prefix); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, xdg_data_home); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, xdg_data_dirs); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_path); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_exe_prefix); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_data_prefix); +} + +GtkWidget * +gtk_inspector_general_new (void) +{ + return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_GENERAL, NULL)); +} + +// vim: set et sw=2 ts=2: diff --git a/gtk/inspector/general.h b/gtk/inspector/general.h new file mode 100644 index 0000000000..b3ef154b34 --- /dev/null +++ b/gtk/inspector/general.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef _GTK_INSPECTOR_GENERAL_H_ +#define _GTK_INSPECTOR_GENERAL_H_ + +#include + +#define GTK_TYPE_INSPECTOR_GENERAL (gtk_inspector_general_get_type()) +#define GTK_INSPECTOR_GENERAL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_GENERAL, GtkInspectorGeneral)) +#define GTK_INSPECTOR_GENERAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_GENERAL, GtkInspectorGeneralClass)) +#define GTK_INSPECTOR_IS_GENERAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_GENERAL)) +#define GTK_INSPECTOR_IS_GENERAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_GENERAL)) +#define GTK_INSPECTOR_GENERAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_GENERAL, GtkInspectorGeneralClass)) + + +typedef struct _GtkInspectorGeneralPrivate GtkInspectorGeneralPrivate; + +typedef struct _GtkInspectorGeneral +{ + GtkBox parent; + GtkInspectorGeneralPrivate *priv; +} GtkInspectorGeneral; + +typedef struct _GtkInspectorGeneralClass +{ + GtkBoxClass parent; +} GtkInspectorGeneralClass; + +G_BEGIN_DECLS + +GType gtk_inspector_general_get_type (void); +GtkWidget *gtk_inspector_general_new (void); + +G_END_DECLS + +#endif // _GTK_INSPECTOR_GENERAL_H_ + +// vim: set et sw=2 ts=2: diff --git a/gtk/inspector/general.ui b/gtk/inspector/general.ui new file mode 100644 index 0000000000..ce4aee0617 --- /dev/null +++ b/gtk/inspector/general.ui @@ -0,0 +1,269 @@ + + + + + horizontal + + + + + + + + + + + + + horizontal + + + + + +--> + diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c index 4621c71034..4ea5b759a5 100644 --- a/gtk/inspector/init.c +++ b/gtk/inspector/init.c @@ -27,6 +27,7 @@ #include "classes-list.h" #include "css-editor.h" #include "data-list.h" +#include "general.h" #include "object-hierarchy.h" #include "property-cell-renderer.h" #include "prop-list.h" @@ -52,6 +53,7 @@ gtk_inspector_init (void) g_type_ensure (GTK_TYPE_INSPECTOR_CLASSES_LIST); g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR); g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST); + g_type_ensure (GTK_TYPE_INSPECTOR_GENERAL); g_type_ensure (GTK_TYPE_INSPECTOR_OBJECT_HIERARCHY); g_type_ensure (GTK_TYPE_INSPECTOR_PROPERTY_CELL_RENDERER); g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST); diff --git a/gtk/inspector/inspector.gresource.xml b/gtk/inspector/inspector.gresource.xml index 9282da6216..a9e3f72540 100644 --- a/gtk/inspector/inspector.gresource.xml +++ b/gtk/inspector/inspector.gresource.xml @@ -6,6 +6,7 @@ classes-list.ui css-editor.ui data-list.ui + general.ui object-hierarchy.ui prop-list.ui signals-list.ui diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui index 2234a06ffd..7e2687024b 100644 --- a/gtk/inspector/window.ui +++ b/gtk/inspector/window.ui @@ -231,6 +231,17 @@ Custom CSS + + + True + + + + + True + General + + diff --git a/po/POTFILES.in b/po/POTFILES.in index c93ff681d5..3aa86b223e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -275,6 +275,7 @@ gtk/inspector/classes-list.ui.h gtk/inspector/css-editor.c gtk/inspector/css-editor.ui.h gtk/inspector/data-list.ui.h +gtk/inspector/general.ui.h gtk/inspector/inspect-button.c gtk/inspector/object-hierarchy.ui.h gtk/inspector/prop-list.ui.h