2014-05-11 01:19:21 +00:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-07-10 14:33:27 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-11 01:19:21 +00:00
|
|
|
#include "visual.h"
|
|
|
|
|
2014-07-12 05:43:03 +00:00
|
|
|
#include "gtkadjustment.h"
|
|
|
|
#include "gtkbox.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkcomboboxtext.h"
|
|
|
|
#include "gtkdebug.h"
|
2014-05-16 10:02:00 +00:00
|
|
|
#include "gtkprivate.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtkswitch.h"
|
|
|
|
#include "gtkwindow.h"
|
2014-11-07 19:17:41 +00:00
|
|
|
#include "gtkcssproviderprivate.h"
|
2014-05-16 10:02:00 +00:00
|
|
|
|
2014-07-12 05:43:03 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
#include "x11/gdkx.h"
|
|
|
|
#endif
|
|
|
|
|
2014-11-07 14:27:56 +00:00
|
|
|
#include "gdk/gdk-private.h"
|
2014-11-07 12:11:38 +00:00
|
|
|
|
2014-05-11 01:19:21 +00:00
|
|
|
struct _GtkInspectorVisualPrivate
|
|
|
|
{
|
2014-07-12 05:43:03 +00:00
|
|
|
GtkWidget *visual_box;
|
|
|
|
GtkWidget *theme_combo;
|
|
|
|
GtkWidget *dark_switch;
|
|
|
|
GtkWidget *icon_combo;
|
2014-12-13 04:14:34 +00:00
|
|
|
GtkWidget *cursor_combo;
|
|
|
|
GtkWidget *cursor_size_spin;
|
2014-05-11 01:19:21 +00:00
|
|
|
GtkWidget *direction_combo;
|
2014-07-19 23:15:58 +00:00
|
|
|
GtkWidget *font_button;
|
2014-07-12 05:43:03 +00:00
|
|
|
GtkWidget *hidpi_spin;
|
2014-08-04 22:03:37 +00:00
|
|
|
GtkWidget *animation_switch;
|
2014-07-12 05:43:03 +00:00
|
|
|
GtkAdjustment *scale_adjustment;
|
2014-12-13 04:14:34 +00:00
|
|
|
GtkAdjustment *cursor_size_adjustment;
|
2014-07-12 05:43:03 +00:00
|
|
|
|
|
|
|
GtkWidget *debug_box;
|
2014-11-10 20:07:52 +00:00
|
|
|
GtkWidget *rendering_mode_combo;
|
2014-05-15 02:53:32 +00:00
|
|
|
GtkWidget *updates_switch;
|
2014-05-11 01:19:21 +00:00
|
|
|
GtkWidget *baselines_switch;
|
2014-07-12 05:43:03 +00:00
|
|
|
GtkWidget *touchscreen_switch;
|
2014-05-11 01:19:21 +00:00
|
|
|
|
2014-11-07 04:29:49 +00:00
|
|
|
GtkWidget *gl_box;
|
|
|
|
GtkWidget *gl_combo;
|
|
|
|
GtkWidget *software_gl_switch;
|
|
|
|
GtkWidget *software_surface_switch;
|
|
|
|
GtkWidget *texture_rectangle_switch;
|
|
|
|
|
2014-07-12 05:43:03 +00:00
|
|
|
GtkAdjustment *focus_adjustment;
|
2014-05-15 02:53:32 +00:00
|
|
|
};
|
2014-05-11 01:19:21 +00:00
|
|
|
|
2014-07-12 05:43:03 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorVisual, gtk_inspector_visual, GTK_TYPE_SCROLLED_WINDOW)
|
2014-05-11 01:19:21 +00:00
|
|
|
|
|
|
|
static void
|
2014-05-15 02:53:32 +00:00
|
|
|
fix_direction_recurse (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2014-05-11 01:19:21 +00:00
|
|
|
{
|
|
|
|
GtkTextDirection dir = GPOINTER_TO_INT (data);
|
|
|
|
|
|
|
|
g_object_ref (widget);
|
|
|
|
|
|
|
|
gtk_widget_set_direction (widget, dir);
|
|
|
|
if (GTK_IS_CONTAINER (widget))
|
|
|
|
gtk_container_forall (GTK_CONTAINER (widget), fix_direction_recurse, data);
|
|
|
|
|
|
|
|
g_object_unref (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTextDirection initial_direction;
|
|
|
|
|
|
|
|
static void
|
|
|
|
fix_direction (GtkWidget *iw)
|
|
|
|
{
|
|
|
|
fix_direction_recurse (iw, GINT_TO_POINTER (initial_direction));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
direction_changed (GtkComboBox *combo)
|
|
|
|
{
|
|
|
|
GtkWidget *iw;
|
|
|
|
const gchar *direction;
|
|
|
|
|
|
|
|
iw = gtk_widget_get_toplevel (GTK_WIDGET (combo));
|
|
|
|
fix_direction (iw);
|
|
|
|
|
|
|
|
direction = gtk_combo_box_get_active_id (combo);
|
|
|
|
if (g_strcmp0 (direction, "ltr") == 0)
|
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
|
|
|
|
else
|
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_direction (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
const gchar *direction;
|
|
|
|
|
|
|
|
initial_direction = gtk_widget_get_default_direction ();
|
|
|
|
if (initial_direction == GTK_TEXT_DIR_LTR)
|
|
|
|
direction = "ltr";
|
|
|
|
else
|
|
|
|
direction = "rtl";
|
|
|
|
gtk_combo_box_set_active_id (GTK_COMBO_BOX (vis->priv->direction_combo), direction);
|
|
|
|
}
|
|
|
|
|
2014-05-15 20:11:14 +00:00
|
|
|
static void
|
|
|
|
redraw_everything (void)
|
|
|
|
{
|
|
|
|
GList *toplevels;
|
|
|
|
toplevels = gtk_window_list_toplevels ();
|
|
|
|
g_list_foreach (toplevels, (GFunc) gtk_widget_queue_draw, NULL);
|
|
|
|
g_list_free (toplevels);
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:52:03 +00:00
|
|
|
static void
|
2014-05-15 02:53:32 +00:00
|
|
|
updates_activate (GtkSwitch *sw)
|
|
|
|
{
|
2014-11-10 20:24:08 +00:00
|
|
|
gboolean updates;
|
|
|
|
|
|
|
|
updates = gtk_switch_get_active (sw);
|
|
|
|
GDK_PRIVATE_CALL (gdk_display_set_debug_updates) (gdk_display_get_default (), updates);
|
2014-05-15 20:11:14 +00:00
|
|
|
redraw_everything ();
|
2014-05-15 02:53:32 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 20:24:08 +00:00
|
|
|
static void
|
|
|
|
init_updates (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
gboolean updates;
|
|
|
|
|
|
|
|
updates = GDK_PRIVATE_CALL (gdk_display_get_debug_updates) (gdk_display_get_default ());
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (vis->priv->updates_switch), updates);
|
|
|
|
}
|
|
|
|
|
2014-05-11 01:19:21 +00:00
|
|
|
static void
|
|
|
|
baselines_activate (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
guint flags;
|
|
|
|
|
|
|
|
flags = gtk_get_debug_flags ();
|
|
|
|
|
|
|
|
if (gtk_switch_get_active (sw))
|
|
|
|
flags |= GTK_DEBUG_BASELINES;
|
|
|
|
else
|
|
|
|
flags &= ~GTK_DEBUG_BASELINES;
|
|
|
|
|
|
|
|
gtk_set_debug_flags (flags);
|
2014-05-15 20:11:14 +00:00
|
|
|
redraw_everything ();
|
2014-05-11 01:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pixelcache_activate (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
guint flags;
|
|
|
|
|
|
|
|
flags = gtk_get_debug_flags ();
|
|
|
|
|
|
|
|
if (gtk_switch_get_active (sw))
|
|
|
|
flags |= GTK_DEBUG_PIXEL_CACHE;
|
|
|
|
else
|
|
|
|
flags &= ~GTK_DEBUG_PIXEL_CACHE;
|
|
|
|
|
|
|
|
gtk_set_debug_flags (flags);
|
2014-05-15 20:11:14 +00:00
|
|
|
/* FIXME: this doesn't work, because it is redrawing
|
|
|
|
* _from_ the cache. We need to recurse over the tree
|
|
|
|
* and invalidate the pixel cache of every widget that
|
|
|
|
* has one.
|
|
|
|
*/
|
|
|
|
redraw_everything ();
|
2014-05-11 01:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-15 02:53:32 +00:00
|
|
|
fill_gtk (const gchar *path,
|
|
|
|
GHashTable *t)
|
|
|
|
{
|
|
|
|
const gchar *dir_entry;
|
|
|
|
GDir *dir = g_dir_open (path, 0, NULL);
|
|
|
|
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((dir_entry = g_dir_read_name (dir)))
|
|
|
|
{
|
|
|
|
gchar *filename = g_build_filename (path, dir_entry, "gtk-3.0", "gtk.css", NULL);
|
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR) &&
|
|
|
|
!g_hash_table_contains (t, dir_entry))
|
|
|
|
g_hash_table_add (t, g_strdup (dir_entry));
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 10:02:00 +00:00
|
|
|
static gchar*
|
|
|
|
get_data_path (const gchar *subdir)
|
|
|
|
{
|
|
|
|
gchar *base_datadir, *full_datadir;
|
|
|
|
#if defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
|
2014-11-07 19:17:41 +00:00
|
|
|
base_datadir = g_strdup (_gtk_get_datadir ());
|
2014-05-16 10:02:00 +00:00
|
|
|
#else
|
|
|
|
base_datadir = g_strdup (GTK_DATADIR);
|
|
|
|
#endif
|
|
|
|
full_datadir = g_build_filename (base_datadir, subdir, NULL);
|
|
|
|
g_free (base_datadir);
|
|
|
|
return full_datadir;
|
|
|
|
}
|
|
|
|
|
2014-05-15 02:53:32 +00:00
|
|
|
static void
|
|
|
|
init_theme (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GHashTable *t;
|
|
|
|
GHashTableIter iter;
|
2015-01-09 20:28:53 +00:00
|
|
|
gchar *theme, *path;
|
2014-05-15 02:53:32 +00:00
|
|
|
|
|
|
|
t = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2014-10-30 16:50:09 +00:00
|
|
|
/* Builtin themes */
|
2014-06-14 04:15:09 +00:00
|
|
|
g_hash_table_add (t, g_strdup ("Adwaita"));
|
2014-10-30 16:50:09 +00:00
|
|
|
g_hash_table_add (t, g_strdup ("HighContrast"));
|
2014-07-21 18:01:46 +00:00
|
|
|
g_hash_table_add (t, g_strdup ("Raleigh"));
|
2014-05-16 10:02:00 +00:00
|
|
|
|
2014-11-07 19:17:41 +00:00
|
|
|
path = _gtk_css_provider_get_theme_dir ();
|
|
|
|
fill_gtk (path, t);
|
|
|
|
g_free (path);
|
2014-05-15 02:53:32 +00:00
|
|
|
|
|
|
|
path = g_build_filename (g_get_user_data_dir (), "themes", NULL);
|
|
|
|
fill_gtk (path, t);
|
|
|
|
g_free (path);
|
|
|
|
|
2014-11-07 19:17:41 +00:00
|
|
|
path = g_build_filename (g_get_home_dir (), ".themes", NULL);
|
2014-10-21 18:30:07 +00:00
|
|
|
fill_gtk (path, t);
|
|
|
|
g_free (path);
|
|
|
|
|
2014-05-15 02:53:32 +00:00
|
|
|
g_hash_table_iter_init (&iter, t);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&theme, NULL))
|
2015-01-09 20:28:53 +00:00
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (vis->priv->theme_combo), theme, theme);
|
2014-05-15 02:53:32 +00:00
|
|
|
g_hash_table_destroy (t);
|
|
|
|
|
2015-01-09 20:28:53 +00:00
|
|
|
g_object_bind_property (gtk_settings_get_default (), "gtk-theme-name",
|
|
|
|
vis->priv->theme_combo, "active-id",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2014-07-10 14:33:27 +00:00
|
|
|
|
|
|
|
if (g_getenv ("GTK_THEME") != NULL)
|
|
|
|
{
|
|
|
|
/* theme is hardcoded, nothing we can do */
|
|
|
|
gtk_widget_set_sensitive (vis->priv->theme_combo, FALSE);
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->theme_combo , _("Theme is hardcoded by GTK_THEME"));
|
|
|
|
}
|
2014-05-15 02:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_dark (GtkInspectorVisual *vis)
|
|
|
|
{
|
2014-09-14 12:36:41 +00:00
|
|
|
g_object_bind_property (gtk_settings_get_default (), "gtk-application-prefer-dark-theme",
|
|
|
|
vis->priv->dark_switch, "active",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2014-07-10 14:33:27 +00:00
|
|
|
|
|
|
|
if (g_getenv ("GTK_THEME") != NULL)
|
|
|
|
{
|
|
|
|
/* theme is hardcoded, nothing we can do */
|
|
|
|
gtk_widget_set_sensitive (vis->priv->dark_switch, FALSE);
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->dark_switch, _("Theme is hardcoded by GTK_THEME"));
|
|
|
|
}
|
2014-05-15 02:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_icons (const gchar *path,
|
|
|
|
GHashTable *t)
|
|
|
|
{
|
|
|
|
const gchar *dir_entry;
|
|
|
|
GDir *dir;
|
|
|
|
|
|
|
|
dir = g_dir_open (path, 0, NULL);
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((dir_entry = g_dir_read_name (dir)))
|
|
|
|
{
|
|
|
|
gchar *filename = g_build_filename (path, dir_entry, "index.theme", NULL);
|
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR) &&
|
|
|
|
g_strcmp0 (dir_entry, "hicolor") != 0 &&
|
|
|
|
!g_hash_table_contains (t, dir_entry))
|
|
|
|
g_hash_table_add (t, g_strdup (dir_entry));
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_icons (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GHashTable *t;
|
|
|
|
GHashTableIter iter;
|
2015-01-09 20:28:53 +00:00
|
|
|
gchar *theme, *path;
|
2014-05-15 02:53:32 +00:00
|
|
|
|
|
|
|
t = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
2015-01-09 20:28:53 +00:00
|
|
|
path = get_data_path ("icons");
|
|
|
|
fill_icons (path, t);
|
|
|
|
g_free (path);
|
2014-05-16 10:02:00 +00:00
|
|
|
|
2014-05-15 02:53:32 +00:00
|
|
|
path = g_build_filename (g_get_user_data_dir (), "icons", NULL);
|
|
|
|
fill_icons (path, t);
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, t);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&theme, NULL))
|
|
|
|
{
|
2015-01-09 20:28:53 +00:00
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (vis->priv->icon_combo), theme, theme);
|
2014-05-15 02:53:32 +00:00
|
|
|
}
|
|
|
|
g_hash_table_destroy (t);
|
|
|
|
|
2015-01-09 20:28:53 +00:00
|
|
|
g_object_bind_property (gtk_settings_get_default (), "gtk-icon-theme-name",
|
|
|
|
vis->priv->icon_combo, "active-id",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2014-05-15 02:53:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 04:14:34 +00:00
|
|
|
static void
|
|
|
|
fill_cursors (const gchar *path,
|
|
|
|
GHashTable *t)
|
|
|
|
{
|
|
|
|
const gchar *dir_entry;
|
|
|
|
GDir *dir;
|
|
|
|
|
|
|
|
dir = g_dir_open (path, 0, NULL);
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((dir_entry = g_dir_read_name (dir)))
|
|
|
|
{
|
|
|
|
gchar *filename = g_build_filename (path, dir_entry, "cursors", NULL);
|
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_DIR) &&
|
|
|
|
!g_hash_table_contains (t, dir_entry))
|
|
|
|
g_hash_table_add (t, g_strdup (dir_entry));
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_cursors (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GHashTable *t;
|
|
|
|
GHashTableIter iter;
|
2015-01-17 01:37:36 +00:00
|
|
|
gchar *theme, *path;
|
2014-12-13 04:14:34 +00:00
|
|
|
|
|
|
|
t = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
2015-01-09 20:28:53 +00:00
|
|
|
path = get_data_path ("icons");
|
|
|
|
fill_cursors (path, t);
|
|
|
|
g_free (path);
|
2014-12-13 04:14:34 +00:00
|
|
|
|
|
|
|
path = g_build_filename (g_get_user_data_dir (), "icons", NULL);
|
|
|
|
fill_cursors (path, t);
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, t);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&theme, NULL))
|
|
|
|
{
|
2015-01-09 20:28:53 +00:00
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (vis->priv->cursor_combo), theme, theme);
|
2014-12-13 04:14:34 +00:00
|
|
|
}
|
|
|
|
g_hash_table_destroy (t);
|
|
|
|
|
2015-01-09 20:28:53 +00:00
|
|
|
g_object_bind_property (gtk_settings_get_default (), "gtk-cursor-theme-name",
|
|
|
|
vis->priv->cursor_combo, "active-id",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2014-12-13 04:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cursor_size_changed (GtkAdjustment *adjustment, GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
|
|
|
|
size = gtk_adjustment_get_value (adjustment);
|
|
|
|
g_object_set (gtk_settings_get_default (), "gtk-cursor-theme-size", size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_cursor_size (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
|
|
|
|
g_object_get (gtk_settings_get_default (), "gtk-cursor-theme-size", &size, NULL);
|
|
|
|
if (size == 0)
|
|
|
|
size = gdk_display_get_default_cursor_size (gdk_display_get_default ());
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (vis->priv->scale_adjustment, (gdouble)size);
|
|
|
|
g_signal_connect (vis->priv->cursor_size_adjustment, "value-changed",
|
|
|
|
G_CALLBACK (cursor_size_changed), vis);
|
|
|
|
}
|
|
|
|
|
2014-07-19 23:15:58 +00:00
|
|
|
static void
|
|
|
|
init_font (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
g_object_bind_property (gtk_settings_get_default (), "gtk-font-name",
|
|
|
|
vis->priv->font_button, "font-name",
|
|
|
|
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
|
|
|
|
}
|
|
|
|
|
2014-10-25 19:23:16 +00:00
|
|
|
#if defined (GDK_WINDOWING_X11)
|
2014-07-12 05:43:03 +00:00
|
|
|
static void
|
|
|
|
scale_changed (GtkAdjustment *adjustment, GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
gint scale;
|
|
|
|
|
|
|
|
scale = gtk_adjustment_get_value (adjustment);
|
2014-10-24 19:55:31 +00:00
|
|
|
display = gdk_display_get_default ();
|
2014-07-12 05:43:03 +00:00
|
|
|
gdk_x11_display_set_window_scale (display, scale);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_scale (GtkInspectorVisual *vis)
|
|
|
|
{
|
2014-10-25 19:23:16 +00:00
|
|
|
#if defined (GDK_WINDOWING_X11)
|
2014-07-12 05:43:03 +00:00
|
|
|
GdkScreen *screen;
|
|
|
|
|
2014-10-24 19:55:31 +00:00
|
|
|
screen = gdk_screen_get_default ();
|
2014-07-12 05:43:03 +00:00
|
|
|
if (GDK_IS_X11_SCREEN (screen))
|
|
|
|
{
|
|
|
|
gdouble scale;
|
|
|
|
|
|
|
|
scale = gdk_screen_get_monitor_scale_factor (screen, 0);
|
|
|
|
gtk_adjustment_set_value (vis->priv->scale_adjustment, scale);
|
|
|
|
g_signal_connect (vis->priv->scale_adjustment, "value-changed",
|
|
|
|
G_CALLBACK (scale_changed), vis);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (vis->priv->scale_adjustment, 1);
|
|
|
|
gtk_widget_set_sensitive (vis->priv->hidpi_spin, FALSE);
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->hidpi_spin,
|
|
|
|
_("Backend does not support window scaling"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 22:03:37 +00:00
|
|
|
static void
|
|
|
|
init_animation (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
g_object_bind_property (gtk_settings_get_default (), "gtk-enable-animations",
|
|
|
|
vis->priv->animation_switch, "active",
|
|
|
|
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
|
|
|
|
}
|
|
|
|
|
2014-07-12 05:43:03 +00:00
|
|
|
static void
|
|
|
|
update_touchscreen (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
GtkDebugFlag flags;
|
|
|
|
|
|
|
|
flags = gtk_get_debug_flags ();
|
|
|
|
|
|
|
|
if (gtk_switch_get_active (sw))
|
|
|
|
flags |= GTK_DEBUG_TOUCHSCREEN;
|
|
|
|
else
|
|
|
|
flags &= ~GTK_DEBUG_TOUCHSCREEN;
|
|
|
|
|
|
|
|
gtk_set_debug_flags (flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_touchscreen (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (vis->priv->touchscreen_switch), (gtk_get_debug_flags () & GTK_DEBUG_TOUCHSCREEN) != 0);
|
|
|
|
g_signal_connect (vis->priv->touchscreen_switch, "notify::active",
|
|
|
|
G_CALLBACK (update_touchscreen), NULL);
|
|
|
|
|
|
|
|
if (g_getenv ("GTK_TEST_TOUCHSCREEN") != 0)
|
|
|
|
{
|
|
|
|
/* hardcoded, nothing we can do */
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (vis->priv->touchscreen_switch), TRUE);
|
|
|
|
gtk_widget_set_sensitive (vis->priv->touchscreen_switch, FALSE);
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->touchscreen_switch, _("Setting is hardcoded by GTK_TEST_TOUCHSCREEN"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
keynav_failed (GtkWidget *widget, GtkDirectionType direction, GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GtkWidget *next;
|
|
|
|
gdouble value, lower, upper, page;
|
|
|
|
|
|
|
|
if (direction == GTK_DIR_DOWN &&
|
|
|
|
widget == vis->priv->visual_box)
|
|
|
|
next = vis->priv->debug_box;
|
2014-11-07 04:29:49 +00:00
|
|
|
else if (direction == GTK_DIR_DOWN &&
|
|
|
|
widget == vis->priv->debug_box)
|
|
|
|
next = vis->priv->gl_box;
|
2014-07-12 05:43:03 +00:00
|
|
|
else if (direction == GTK_DIR_UP &&
|
|
|
|
widget == vis->priv->debug_box)
|
|
|
|
next = vis->priv->visual_box;
|
2014-11-07 04:29:49 +00:00
|
|
|
else if (direction == GTK_DIR_UP &&
|
|
|
|
widget == vis->priv->gl_box)
|
|
|
|
next = vis->priv->debug_box;
|
2015-01-09 20:28:53 +00:00
|
|
|
else
|
2014-07-12 05:43:03 +00:00
|
|
|
next = NULL;
|
|
|
|
|
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
gtk_widget_child_focus (next, direction);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = gtk_adjustment_get_value (vis->priv->focus_adjustment);
|
|
|
|
lower = gtk_adjustment_get_lower (vis->priv->focus_adjustment);
|
|
|
|
upper = gtk_adjustment_get_upper (vis->priv->focus_adjustment);
|
|
|
|
page = gtk_adjustment_get_page_size (vis->priv->focus_adjustment);
|
|
|
|
|
|
|
|
if (direction == GTK_DIR_UP && value > lower)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (vis->priv->focus_adjustment, lower);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (direction == GTK_DIR_DOWN && value < upper - page)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (vis->priv->focus_adjustment, upper - page);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-11-07 04:29:49 +00:00
|
|
|
static void
|
|
|
|
init_gl (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GdkGLFlags flags;
|
|
|
|
|
2014-11-07 14:27:56 +00:00
|
|
|
flags = GDK_PRIVATE_CALL (gdk_gl_get_flags) ();
|
2014-11-07 04:29:49 +00:00
|
|
|
|
|
|
|
if (flags & GDK_GL_ALWAYS)
|
|
|
|
gtk_combo_box_set_active_id (GTK_COMBO_BOX (vis->priv->gl_combo), "always");
|
|
|
|
else if (flags & GDK_GL_DISABLE)
|
|
|
|
gtk_combo_box_set_active_id (GTK_COMBO_BOX (vis->priv->gl_combo), "disable");
|
|
|
|
else
|
|
|
|
gtk_combo_box_set_active_id (GTK_COMBO_BOX (vis->priv->gl_combo), "maybe");
|
|
|
|
gtk_widget_set_sensitive (vis->priv->gl_combo, FALSE);
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->gl_combo,
|
2014-11-08 01:10:12 +00:00
|
|
|
_("Not settable at runtime.\nUse GDK_GL=always or GDK_GL=disable instead"));
|
2014-11-07 04:29:49 +00:00
|
|
|
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (vis->priv->software_gl_switch),
|
|
|
|
flags & GDK_GL_SOFTWARE_DRAW_GL);
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (vis->priv->software_surface_switch),
|
|
|
|
flags & GDK_GL_SOFTWARE_DRAW_SURFACE);
|
|
|
|
gtk_switch_set_active (GTK_SWITCH (vis->priv->texture_rectangle_switch),
|
|
|
|
flags & GDK_GL_TEXTURE_RECTANGLE);
|
|
|
|
|
|
|
|
if (flags & GDK_GL_DISABLE)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (vis->priv->software_gl_switch, FALSE);
|
|
|
|
gtk_widget_set_sensitive (vis->priv->software_surface_switch, FALSE);
|
|
|
|
gtk_widget_set_sensitive (vis->priv->texture_rectangle_switch, FALSE);
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->software_gl_switch, _("GL rendering is disabled"));
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->software_surface_switch, _("GL rendering is disabled"));
|
|
|
|
gtk_widget_set_tooltip_text (vis->priv->texture_rectangle_switch, _("GL rendering is disabled"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 20:07:52 +00:00
|
|
|
static void
|
|
|
|
init_rendering_mode (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GdkRenderingMode mode;
|
|
|
|
|
|
|
|
mode = GDK_PRIVATE_CALL (gdk_display_get_rendering_mode) (gdk_display_get_default ());
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (vis->priv->rendering_mode_combo), mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rendering_mode_changed (GtkComboBox *c,
|
|
|
|
GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
GdkRenderingMode mode;
|
|
|
|
|
|
|
|
mode = gtk_combo_box_get_active (c);
|
|
|
|
GDK_PRIVATE_CALL (gdk_display_set_rendering_mode) (gdk_display_get_default (), mode);
|
|
|
|
}
|
|
|
|
|
2014-11-07 04:29:49 +00:00
|
|
|
static void
|
|
|
|
update_gl_flag (GtkSwitch *sw,
|
|
|
|
GdkGLFlags flag)
|
|
|
|
{
|
|
|
|
GdkGLFlags flags;
|
|
|
|
|
2014-11-07 14:27:56 +00:00
|
|
|
flags = GDK_PRIVATE_CALL (gdk_gl_get_flags) ();
|
2014-11-07 04:29:49 +00:00
|
|
|
|
|
|
|
if (gtk_switch_get_active (sw))
|
|
|
|
flags |= flag;
|
|
|
|
else
|
|
|
|
flags &= ~flag;
|
|
|
|
|
2014-11-07 14:27:56 +00:00
|
|
|
GDK_PRIVATE_CALL (gdk_gl_set_flags) (flags);
|
2014-11-07 04:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
software_gl_activate (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
update_gl_flag (sw, GDK_GL_SOFTWARE_DRAW_GL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
software_surface_activate (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
update_gl_flag (sw, GDK_GL_SOFTWARE_DRAW_SURFACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
texture_rectangle_activate (GtkSwitch *sw)
|
|
|
|
{
|
|
|
|
update_gl_flag (sw, GDK_GL_TEXTURE_RECTANGLE);
|
|
|
|
}
|
|
|
|
|
2014-05-15 02:53:32 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_visual_init (GtkInspectorVisual *vis)
|
|
|
|
{
|
|
|
|
vis->priv = gtk_inspector_visual_get_instance_private (vis);
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (vis));
|
|
|
|
init_direction (vis);
|
|
|
|
init_theme (vis);
|
|
|
|
init_dark (vis);
|
|
|
|
init_icons (vis);
|
2014-12-13 04:14:34 +00:00
|
|
|
init_cursors (vis);
|
|
|
|
init_cursor_size (vis);
|
2014-07-19 23:15:58 +00:00
|
|
|
init_font (vis);
|
2014-07-12 05:43:03 +00:00
|
|
|
init_scale (vis);
|
2014-11-10 20:07:52 +00:00
|
|
|
init_rendering_mode (vis);
|
2014-11-10 20:24:08 +00:00
|
|
|
init_updates (vis);
|
2014-08-04 22:03:37 +00:00
|
|
|
init_animation (vis);
|
2014-07-12 05:43:03 +00:00
|
|
|
init_touchscreen (vis);
|
2014-11-07 04:29:49 +00:00
|
|
|
init_gl (vis);
|
2014-07-12 05:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_visual_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (object);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_visual_parent_class)->constructed (object);
|
|
|
|
|
|
|
|
vis->priv->focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (vis));
|
|
|
|
gtk_container_set_focus_vadjustment (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (vis))),
|
|
|
|
vis->priv->focus_adjustment);
|
|
|
|
|
|
|
|
g_signal_connect (vis->priv->visual_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
|
|
|
|
g_signal_connect (vis->priv->debug_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
|
2014-11-07 04:29:49 +00:00
|
|
|
g_signal_connect (vis->priv->gl_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
|
2014-05-11 01:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-07-12 05:43:03 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructed = gtk_inspector_visual_constructed;
|
2014-05-11 01:19:21 +00:00
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/visual.ui");
|
2014-11-10 20:07:52 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, rendering_mode_combo);
|
2014-05-11 01:19:21 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, updates_switch);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, direction_combo);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, baselines_switch);
|
2014-05-15 02:53:32 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, theme_combo);
|
2014-12-13 04:14:34 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, dark_switch);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, cursor_combo);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, cursor_size_spin);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, cursor_size_adjustment);
|
2014-05-15 02:53:32 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, icon_combo);
|
2014-07-12 05:43:03 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, hidpi_spin);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, scale_adjustment);
|
2014-12-13 04:14:34 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, animation_switch);
|
2014-07-12 05:43:03 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, touchscreen_switch);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, visual_box);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, debug_box);
|
2014-07-19 23:15:58 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, font_button);
|
2014-11-07 04:29:49 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, gl_box);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, gl_combo);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, software_gl_switch);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, software_surface_switch);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, texture_rectangle_switch);
|
2014-05-15 02:53:32 +00:00
|
|
|
|
2014-05-11 01:19:21 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, updates_activate);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, direction_changed);
|
2014-11-10 20:07:52 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, rendering_mode_changed);
|
2014-05-11 01:19:21 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, baselines_activate);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, pixelcache_activate);
|
2014-11-07 04:29:49 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, software_gl_activate);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, software_surface_activate);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, texture_rectangle_activate);
|
2014-05-11 01:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|