[gtk+] Introduce API to get the preferred visual



commit 2b95d1a34ed7cd70ea3eaaa9b7d8add200b5a9d2
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 22 18:48:45 2014 -0500

    Introduce API to get the preferred visual
    
    Unless GDK_RGBA=0 is set, this will be the RGBA visual.
    The new function is called gdk_screen_get_preferred_visual().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=630217

 docs/reference/gdk/gdk3-sections.txt |    1 +
 docs/reference/gtk/running.sgml      |    9 +++++++++
 gdk/gdkscreen.c                      |   30 ++++++++++++++++++++++++++++++
 gdk/gdkscreen.h                      |    2 ++
 gdk/gdkscreenprivate.h               |    1 +
 gtk/gtkwidget.c                      |    9 +++++++--
 6 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index d23183a..f3a35e5 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -195,6 +195,7 @@ GdkScreen
 gdk_screen_get_default
 gdk_screen_get_system_visual
 gdk_screen_get_rgba_visual
+gdk_screen_get_preferred_visual
 gdk_screen_is_composited
 gdk_screen_get_root_window
 gdk_screen_get_display
diff --git a/docs/reference/gtk/running.sgml b/docs/reference/gtk/running.sgml
index 8065e19..c7d2d9b 100644
--- a/docs/reference/gtk/running.sgml
+++ b/docs/reference/gtk/running.sgml
@@ -479,6 +479,15 @@ nevertheless.
 </formalpara>
 
 <formalpara>
+  <title><envar>GDK_RGBA</envar></title>
+
+  <para>
+    Since 3.12, this environment variable can be used to prevent
+    using RGBA visuals on the X11 backend by setting GDK_RGBA=0.
+  </para>
+</formalpara>
+
+<formalpara>
   <title><envar>XDG_DATA_HOME</envar>, <envar>XDG_DATA_DIRS</envar></title>
 
   <para>
diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c
index 743b850..113d2a4 100644
--- a/gdk/gdkscreen.c
+++ b/gdk/gdkscreen.c
@@ -913,6 +913,36 @@ gdk_screen_get_rgba_visual (GdkScreen *screen)
 }
 
 /**
+ * gdk_screen_get_preferred_visual:
+ * @screen: a #GdkScreen
+ *
+ * Returns the visual that is preferred when creating windows.
+ *
+ * This will be the visual returned by gdk_screen_get_rgba_visual()
+ * unless that is not available, or unless the environment
+ * variable <envar>GDK_RGBA</envar> is set to 0.
+ *
+ * Return value: (transfer none): the preferred visual to use
+ *     for windows
+ *
+ * Since: 3.12
+ */
+GdkVisual *
+gdk_screen_get_preferred_visual (GdkScreen *screen)
+{
+  GdkVisual *visual;
+
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
+
+  visual = gdk_screen_get_rgba_visual (screen);
+
+  if (visual == NULL || g_strcmp0 (g_getenv ("GDK_RGBA"), "0") == 0)
+    visual = gdk_screen_get_system_visual (screen);
+
+  return visual;
+}
+
+/**
  * gdk_screen_is_composited:
  * @screen: a #GdkScreen
  *
diff --git a/gdk/gdkscreen.h b/gdk/gdkscreen.h
index dde5524..57d6132 100644
--- a/gdk/gdkscreen.h
+++ b/gdk/gdkscreen.h
@@ -45,6 +45,8 @@ GDK_AVAILABLE_IN_ALL
 GdkVisual *  gdk_screen_get_system_visual     (GdkScreen   *screen);
 GDK_AVAILABLE_IN_ALL
 GdkVisual *  gdk_screen_get_rgba_visual       (GdkScreen   *screen);
+GDK_AVAILABLE_IN_3_12
+GdkVisual *  gdk_screen_get_preferred_visual  (GdkScreen   *screen);
 GDK_AVAILABLE_IN_ALL
 gboolean     gdk_screen_is_composited         (GdkScreen   *screen);
 
diff --git a/gdk/gdkscreenprivate.h b/gdk/gdkscreenprivate.h
index 23cf1bd..b73a092 100644
--- a/gdk/gdkscreenprivate.h
+++ b/gdk/gdkscreenprivate.h
@@ -66,6 +66,7 @@ struct _GdkScreenClass
   GList *      (* list_visuals)          (GdkScreen *screen);
   GdkVisual *  (* get_system_visual)     (GdkScreen *screen);
   GdkVisual *  (* get_rgba_visual)       (GdkScreen *screen);
+  GdkVisual *  (* get_preferred_visual)  (GdkScreen *screen);
   gboolean     (* is_composited)         (GdkScreen *screen);
   gchar *      (* make_display_name)     (GdkScreen *screen);
   GdkWindow *  (* get_active_window)     (GdkScreen *screen);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 29157c0..6deeb6e 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -10863,9 +10863,14 @@ gtk_widget_get_visual (GtkWidget *widget)
           g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
                      gtk_widget_get_name (widget));
         }
-    }
 
-  return gdk_screen_get_system_visual (screen);
+  visual = gdk_screen_get_rgba_visual (screen);
+
+  if (visual == NULL ||
+      g_strcmp0 (g_getenv ("GDK_RGBA"), "0") != 0)
+    visual = gdk_screen_get_system_visual (screen);
+
+  return visual;
 }
 
 /**


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