[gtk+] inspector: Reshuffle Visual and General tabs



commit 91133fc14c19f139c4e242064482c5636ce27e27
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 12 01:43:03 2014 -0400

    inspector: Reshuffle Visual and General tabs
    
    Move the touchscreen switch to the other debug switches, and
    move the hidpi spin to the other graphical controls. Since the
    Visual tab is getting large, make it scroll. The General tab
    is purely informational again.

 gtk/inspector/general.c  |   74 ----------------------
 gtk/inspector/general.ui |   76 ----------------------
 gtk/inspector/visual.c   |  157 ++++++++++++++++++++++++++++++++++++++++++++--
 gtk/inspector/visual.h   |    6 +-
 gtk/inspector/visual.ui  |   80 ++++++++++++++++++++++-
 5 files changed, 232 insertions(+), 161 deletions(-)
---
diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
index 54002ea..773ef88 100644
--- a/gtk/inspector/general.c
+++ b/gtk/inspector/general.c
@@ -20,7 +20,6 @@
 
 #include "general.h"
 
-#include "gtkadjustment.h"
 #include "gtkdebug.h"
 #include "gtklabel.h"
 #include "gtkscale.h"
@@ -61,9 +60,6 @@ struct _GtkInspectorGeneralPrivate
   GtkWidget *gtk_exe_prefix;
   GtkWidget *gtk_data_prefix;
   GtkWidget *gsettings_schema_dir;
-  GtkWidget *hidpi_spin;
-  GtkWidget *touchscreen_switch;
-  GtkAdjustment *scale_adjustment;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorGeneral, gtk_inspector_general, GTK_TYPE_BOX)
@@ -150,79 +146,12 @@ init_env (GtkInspectorGeneral *gen)
 }
 
 static void
-update_touchscreen (GtkSwitch *sw, GParamSpec *pspec, GtkInspectorGeneral *gen)
-{
-  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);
-}
-
-#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
-static void
-scale_changed (GtkAdjustment *adjustment, GtkInspectorGeneral *gen)
-{
-  GdkDisplay *display;
-  gint scale;
-
-  scale = gtk_adjustment_get_value (adjustment);
-  display = gtk_widget_get_display (GTK_WIDGET (gen));
-  gdk_x11_display_set_window_scale (display, scale);
-}
-#endif
-
-static void
-init_settings (GtkInspectorGeneral *gen)
-{
-#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
-  GdkScreen *screen;
-
-  screen = gtk_widget_get_screen (GTK_WIDGET (gen));
-  if (GDK_IS_X11_SCREEN (screen))
-    {
-      gdouble scale;
-
-      scale = gdk_screen_get_monitor_scale_factor (screen, 0);
-      gtk_adjustment_set_value (gen->priv->scale_adjustment, scale);
-      g_signal_connect (gen->priv->scale_adjustment, "value-changed",
-                        G_CALLBACK (scale_changed), gen);
-    }
-  else
-#endif
-    {
-      gtk_adjustment_set_value (gen->priv->scale_adjustment, 1);
-      gtk_widget_set_sensitive (gen->priv->hidpi_spin, FALSE);
-      gtk_widget_set_tooltip_text (gen->priv->hidpi_spin,
-                                   _("Backend does not support window scaling"));
-    }
-
-  gtk_switch_set_active (GTK_SWITCH (gen->priv->touchscreen_switch), (gtk_get_debug_flags () & 
GTK_DEBUG_TOUCHSCREEN) != 0);
-  g_signal_connect (gen->priv->touchscreen_switch, "notify::active",
-                    G_CALLBACK (update_touchscreen), gen);
-
-  if (g_getenv ("GTK_TEST_TOUCHSCREEN") != 0)
-    {
-      /* hardcoded, nothing we can do */
-      gtk_switch_set_active (GTK_SWITCH (gen->priv->touchscreen_switch), TRUE);
-      gtk_widget_set_sensitive (gen->priv->touchscreen_switch, FALSE);
-      gtk_widget_set_tooltip_text (gen->priv->touchscreen_switch, _("Setting is hardcoded by 
GTK_TEST_TOUCHSCREEN"));
-    }
-}
-
-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);
-  init_settings (gen);
 }
 
 static void
@@ -240,9 +169,6 @@ gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass)
   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);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gsettings_schema_dir);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, hidpi_spin);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, scale_adjustment);
-  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, touchscreen_switch);
 }
 
 // vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/general.ui b/gtk/inspector/general.ui
index b20020a..65de4f6 100644
--- a/gtk/inspector/general.ui
+++ b/gtk/inspector/general.ui
@@ -1,11 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
-  <object class="GtkAdjustment" id="scale_adjustment">
-    <property name="lower">1</property>
-    <property name="upper">2</property>
-    <property name="step-increment">1</property>
-    <property name="page-increment">1</property>
-  </object>
   <template class="GtkInspectorGeneral" parent="GtkBox">
     <property name="orientation">vertical</property>
     <property name="margin">60</property>
@@ -284,74 +278,6 @@
         </child>
       </object>
     </child>
-    <child>
-      <object class="GtkFrame" id="settings_frame">
-        <property name="visible">True</property>
-        <property name="halign">center</property>
-        <child>
-          <object class="GtkListBox">
-            <property name="visible">True</property>
-            <property name="selection-mode">none</property>
-            <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
-                <property name="margin">10</property>
-                <property name="spacing">40</property>
-                <child>
-                  <object class="GtkLabel" id="hidpi_label">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Window scaling</property>
-                    <property name="halign">start</property>
-                    <property name="valign">baseline</property>
-                    <property name="xalign">0.0</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSpinButton" id="hidpi_spin">
-                    <property name="visible">True</property>
-                    <property name="halign">end</property>
-                    <property name="valign">baseline</property>
-                    <property name="adjustment">scale_adjustment</property>
-                    <property name="snap-to-ticks">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
-                <property name="margin">10</property>
-                <property name="spacing">40</property>
-                <child>
-                  <object class="GtkLabel" id="touchscreen_label">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Simulate touchscreen</property>
-                    <property name="halign">start</property>
-                    <property name="valign">baseline</property>
-                    <property name="xalign">0.0</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSwitch" id="touchscreen_switch">
-                    <property name="visible">True</property>
-                    <property name="halign">end</property>
-                    <property name="valign">baseline</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
   </template>
   <object class="GtkSizeGroup">
     <property name="mode">horizontal</property>
@@ -365,7 +291,6 @@
       <widget name="gtk_exe_prefix_label"/>
       <widget name="gtk_data_prefix_label"/>
       <widget name="gsettings_schema_dir_label"/>
-      <widget name="touchscreen_label"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup">
@@ -373,7 +298,6 @@
     <widgets>
       <widget name="version_frame"/>
       <widget name="env_frame"/>
-      <widget name="settings_frame"/>
     </widgets>
   </object>
 </interface>
diff --git a/gtk/inspector/visual.c b/gtk/inspector/visual.c
index a665b5b..9af4853 100644
--- a/gtk/inspector/visual.c
+++ b/gtk/inspector/visual.c
@@ -20,6 +20,8 @@
 
 #include "visual.h"
 
+#include "gtkadjustment.h"
+#include "gtkbox.h"
 #include "gtkcomboboxtext.h"
 #include "gtkdebug.h"
 #include "gtkprivate.h"
@@ -27,19 +29,30 @@
 #include "gtkswitch.h"
 #include "gtkwindow.h"
 
+#ifdef GDK_WINDOWING_X11
+#include "x11/gdkx.h"
+#endif
+
 struct _GtkInspectorVisualPrivate
 {
+  GtkWidget *visual_box;
+  GtkWidget *theme_combo;
+  GtkWidget *dark_switch;
+  GtkWidget *icon_combo;
   GtkWidget *direction_combo;
+  GtkWidget *hidpi_spin;
+  GtkAdjustment *scale_adjustment;
+
+  GtkWidget *debug_box;
   GtkWidget *updates_switch;
   GtkWidget *baselines_switch;
   GtkWidget *pixelcache_switch;
+  GtkWidget *touchscreen_switch;
 
-  GtkWidget *theme_combo;
-  GtkWidget *dark_switch;
-  GtkWidget *icon_combo;
+  GtkAdjustment *focus_adjustment;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorVisual, gtk_inspector_visual, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorVisual, gtk_inspector_visual, GTK_TYPE_SCROLLED_WINDOW)
 
 static void
 fix_direction_recurse (GtkWidget *widget,
@@ -325,6 +338,116 @@ icons_changed (GtkComboBox        *c,
   g_free (theme);
 }
 
+#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
+static void
+scale_changed (GtkAdjustment *adjustment, GtkInspectorVisual *vis)
+{
+  GdkDisplay *display;
+  gint scale;
+
+  scale = gtk_adjustment_get_value (adjustment);
+  display = gtk_widget_get_display (GTK_WIDGET (vis));
+  gdk_x11_display_set_window_scale (display, scale);
+}
+#endif
+
+static void
+init_scale (GtkInspectorVisual *vis)
+{
+#if defined (GDK_WINDOWING_X11) && defined (HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE)
+  GdkScreen *screen;
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (vis));
+  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"));
+    }
+}
+
+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;
+  else if (direction == GTK_DIR_UP &&
+           widget == vis->priv->debug_box)
+    next = vis->priv->visual_box;
+  else 
+    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;
+}
+
 static void
 gtk_inspector_visual_init (GtkInspectorVisual *vis)
 {
@@ -334,12 +457,32 @@ gtk_inspector_visual_init (GtkInspectorVisual *vis)
   init_theme (vis);
   init_dark (vis);
   init_icons (vis);
+  init_scale (vis);
+  init_touchscreen (vis);
+}
+
+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);
 }
 
 static void
 gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed = gtk_inspector_visual_constructed;
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/visual.ui");
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, updates_switch);
@@ -349,6 +492,11 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, dark_switch);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, theme_combo);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, icon_combo);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, hidpi_spin);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, scale_adjustment);
+  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);
 
   gtk_widget_class_bind_template_callback (widget_class, updates_activate);
   gtk_widget_class_bind_template_callback (widget_class, direction_changed);
@@ -356,7 +504,6 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, pixelcache_activate);
   gtk_widget_class_bind_template_callback (widget_class, theme_changed);
   gtk_widget_class_bind_template_callback (widget_class, icons_changed);
-
 }
 
 // vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/visual.h b/gtk/inspector/visual.h
index 593be52..90df94f 100644
--- a/gtk/inspector/visual.h
+++ b/gtk/inspector/visual.h
@@ -18,7 +18,7 @@
 #ifndef _GTK_INSPECTOR_VISUAL_H_
 #define _GTK_INSPECTOR_VISUAL_H_
 
-#include <gtk/gtkbox.h>
+#include <gtk/gtkscrolledwindow.h>
 
 #define GTK_TYPE_INSPECTOR_VISUAL            (gtk_inspector_visual_get_type())
 #define GTK_INSPECTOR_VISUAL(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_VISUAL, 
GtkInspectorVisual))
@@ -32,13 +32,13 @@ typedef struct _GtkInspectorVisualPrivate GtkInspectorVisualPrivate;
 
 typedef struct _GtkInspectorVisual
 {
-  GtkBox parent;
+  GtkScrolledWindow parent;
   GtkInspectorVisualPrivate *priv;
 } GtkInspectorVisual;
 
 typedef struct _GtkInspectorVisualClass
 {
-  GtkBoxClass parent;
+  GtkScrolledWindowClass parent;
 } GtkInspectorVisualClass;
 
 G_BEGIN_DECLS
diff --git a/gtk/inspector/visual.ui b/gtk/inspector/visual.ui
index 5233c94..499bc4a 100644
--- a/gtk/inspector/visual.ui
+++ b/gtk/inspector/visual.ui
@@ -1,6 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
-  <template class="GtkInspectorVisual" parent="GtkBox">
+  <object class="GtkAdjustment" id="scale_adjustment">
+    <property name="lower">1</property>
+    <property name="upper">2</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">1</property>
+  </object>
+  <template class="GtkInspectorVisual" parent="GtkScrolledWindow">
+    <property name="hscrollbar-policy">never</property>
+    <property name="vscrollbar-policy">automatic</property>
+    <child>
+      <object class="GtkBox">
+    <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <property name="margin">60</property>
     <property name="spacing">10</property>
@@ -9,9 +20,12 @@
         <property name="visible">True</property>
         <property name="halign">center</property>
         <child>
-          <object class="GtkListBox">
+          <object class="GtkListBox" id="visual_box">
             <property name="visible">True</property>
             <property name="selection-mode">none</property>
+            <style>
+              <class name="view"/>
+            </style>
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
@@ -127,6 +141,35 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <property name="margin">10</property>
+                <property name="spacing">40</property>
+                <child>
+                  <object class="GtkLabel" id="hidpi_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Window scaling</property>
+                    <property name="halign">start</property>
+                    <property name="valign">baseline</property>
+                    <property name="xalign">0.0</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="hidpi_spin">
+                    <property name="visible">True</property>
+                    <property name="halign">end</property>
+                    <property name="valign">baseline</property>
+                    <property name="adjustment">scale_adjustment</property>
+                    <property name="snap-to-ticks">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
       </object>
@@ -136,7 +179,7 @@
         <property name="visible">True</property>
         <property name="halign">center</property>
         <child>
-          <object class="GtkListBox">
+          <object class="GtkListBox" id="debug_box">
             <property name="visible">True</property>
             <property name="selection-mode">none</property>
             <child>
@@ -223,10 +266,39 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <property name="margin">10</property>
+                <property name="spacing">40</property>
+                <child>
+                  <object class="GtkLabel" id="touchscreen_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Simulate touchscreen</property>
+                    <property name="halign">start</property>
+                    <property name="valign">baseline</property>
+                    <property name="xalign">0.0</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSwitch" id="touchscreen_switch">
+                    <property name="visible">True</property>
+                    <property name="halign">end</property>
+                    <property name="valign">baseline</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
       </object>
     </child>
+      </object>
+    </child>
   </template>
   <object class="GtkSizeGroup">
     <property name="mode">horizontal</property>
@@ -235,9 +307,11 @@
       <widget name="dark_label"/>
       <widget name="icon_label"/>
       <widget name="direction_label"/>
+      <widget name="hidpi_label"/>
       <widget name="updates_label"/>
       <widget name="baselines_label"/>
       <widget name="pixelcache_label"/>
+      <widget name="touchscreen_label"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]