]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkscreen-x11.c
x11: Don't keep an "in_init" variable
[~andy/gtk] / gdk / x11 / gdkscreen-x11.c
index 1faa827ae2f2d3c326cd68d2361c89a8011cd48f..ac0b84319a204c8a6cada9d9a45c97349374a15c 100644 (file)
@@ -1,7 +1,7 @@
  /*
  * gdkscreen-x11.c
- * 
- * Copyright 2001 Sun Microsystems Inc. 
+ *
+ * Copyright 2001 Sun Microsystems Inc.
  *
  * Erwann Chenede <erwann.chenede@sun.com>
  *
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
 
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-#include "gdkscreen.h"
 #include "gdkscreen-x11.h"
-#include "gdkdisplay.h"
 #include "gdkdisplay-x11.h"
-#include "gdkx.h"
-#include "gdkalias.h"
+#include "gdkprivate-x11.h"
+
+#include <glib.h>
+
+#include <stdlib.h>
+#include <string.h>
 
 #include <X11/Xatom.h>
 
@@ -51,8 +47,8 @@
 #include <X11/extensions/Xfixes.h>
 #endif
 
-static void         gdk_screen_x11_dispose     (GObject                  *object);
-static void         gdk_screen_x11_finalize    (GObject                  *object);
+static void         gdk_x11_screen_dispose     (GObject                  *object);
+static void         gdk_x11_screen_finalize    (GObject                  *object);
 static void        init_randr_support         (GdkScreen         *screen);
 static void        deinit_multihead           (GdkScreen         *screen);
 
@@ -64,7 +60,15 @@ enum
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE (GdkScreenX11, _gdk_screen_x11, GDK_TYPE_SCREEN)
+G_DEFINE_TYPE (GdkX11Screen, gdk_x11_screen, GDK_TYPE_SCREEN)
+
+typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
+
+struct _NetWmSupportedAtoms
+{
+  Atom *atoms;
+  gulong n_atoms;
+};
 
 struct _GdkX11Monitor
 {
@@ -76,364 +80,163 @@ struct _GdkX11Monitor
   char *       manufacturer;
 };
 
-static void
-_gdk_screen_x11_class_init (GdkScreenX11Class *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
-  object_class->dispose = gdk_screen_x11_dispose;
-  object_class->finalize = gdk_screen_x11_finalize;
-
-  signals[WINDOW_MANAGER_CHANGED] =
-    g_signal_new (g_intern_static_string ("window_manager_changed"),
-                  G_OBJECT_CLASS_TYPE (object_class),
-                  G_SIGNAL_RUN_LAST,
-                  G_STRUCT_OFFSET (GdkScreenX11Class, window_manager_changed),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__VOID,
-                  G_TYPE_NONE,
-                  0);
-}
 
 static void
-_gdk_screen_x11_init (GdkScreenX11 *screen)
+gdk_x11_screen_init (GdkX11Screen *screen)
 {
 }
 
-/**
- * gdk_screen_get_display:
- * @screen: a #GdkScreen
- *
- * Gets the display to which the @screen belongs.
- * 
- * Returns: the display to which @screen belongs
- *
- * Since: 2.2
- **/
-GdkDisplay *
-gdk_screen_get_display (GdkScreen *screen)
-{
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
-  return GDK_SCREEN_X11 (screen)->display;
-}
-/**
- * gdk_screen_get_width:
- * @screen: a #GdkScreen
- *
- * Gets the width of @screen in pixels
- * 
- * Returns: the width of @screen in pixels.
- *
- * Since: 2.2
- **/
-gint
-gdk_screen_get_width (GdkScreen *screen)
+static GdkDisplay *
+gdk_x11_screen_get_display (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
-
-  return WidthOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
+  return GDK_X11_SCREEN (screen)->display;
 }
 
-/**
- * gdk_screen_get_height:
- * @screen: a #GdkScreen
- *
- * Gets the height of @screen in pixels
- * 
- * Returns: the height of @screen in pixels.
- *
- * Since: 2.2
- **/
-gint
-gdk_screen_get_height (GdkScreen *screen)
+static gint
+gdk_x11_screen_get_width (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
-
-  return HeightOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
+  return WidthOfScreen (GDK_X11_SCREEN (screen)->xscreen);
 }
 
-/**
- * gdk_screen_get_width_mm:
- * @screen: a #GdkScreen
- *
- * Gets the width of @screen in millimeters. 
- * Note that on some X servers this value will not be correct.
- * 
- * Returns: the width of @screen in millimeters.
- *
- * Since: 2.2
- **/
-gint
-gdk_screen_get_width_mm (GdkScreen *screen)
+static gint
+gdk_x11_screen_get_height (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);  
-
-  return WidthMMOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
+  return HeightOfScreen (GDK_X11_SCREEN (screen)->xscreen);
 }
 
-/**
- * gdk_screen_get_height_mm:
- * @screen: a #GdkScreen
- *
- * Returns the height of @screen in millimeters. 
- * Note that on some X servers this value will not be correct.
- * 
- * Returns: the heigth of @screen in millimeters.
- *
- * Since: 2.2
- **/
-gint
-gdk_screen_get_height_mm (GdkScreen *screen)
+static gint
+gdk_x11_screen_get_width_mm (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
-
-  return HeightMMOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
+  return WidthMMOfScreen (GDK_X11_SCREEN (screen)->xscreen);
 }
 
-/**
- * gdk_screen_get_number:
- * @screen: a #GdkScreen
- *
- * Gets the index of @screen among the screens in the display
- * to which it belongs. (See gdk_screen_get_display())
- * 
- * Returns: the index
- *
- * Since: 2.2
- **/
-gint
-gdk_screen_get_number (GdkScreen *screen)
+static gint
+gdk_x11_screen_get_height_mm (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);  
-  
-  return GDK_SCREEN_X11 (screen)->screen_num;
+  return HeightMMOfScreen (GDK_X11_SCREEN (screen)->xscreen);
 }
 
-/**
- * gdk_screen_get_root_window:
- * @screen: a #GdkScreen
- *
- * Gets the root window of @screen. 
- * 
- * Returns: the root window
- *
- * Since: 2.2
- **/
-GdkWindow *
-gdk_screen_get_root_window (GdkScreen *screen)
+static gint
+gdk_x11_screen_get_number (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
-  return GDK_SCREEN_X11 (screen)->root_window;
+  return GDK_X11_SCREEN (screen)->screen_num;
 }
 
-/**
- * gdk_screen_get_default_colormap:
- * @screen: a #GdkScreen
- *
- * Gets the default colormap for @screen.
- * 
- * Returns: the default #GdkColormap.
- *
- * Since: 2.2
- **/
-GdkColormap *
-gdk_screen_get_default_colormap (GdkScreen *screen)
+static GdkWindow *
+gdk_x11_screen_get_root_window (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
-  return GDK_SCREEN_X11 (screen)->default_colormap;
+  return GDK_X11_SCREEN (screen)->root_window;
 }
 
-/**
- * gdk_screen_set_default_colormap:
- * @screen: a #GdkScreen
- * @colormap: a #GdkColormap
- *
- * Sets the default @colormap for @screen.
- *
- * Since: 2.2
- **/
-void
-gdk_screen_set_default_colormap (GdkScreen   *screen,
-                                GdkColormap *colormap)
+static void
+_gdk_x11_screen_events_uninit (GdkScreen *screen)
 {
-  GdkColormap *old_colormap;
-  
-  g_return_if_fail (GDK_IS_SCREEN (screen));
-  g_return_if_fail (GDK_IS_COLORMAP (colormap));
-
-  old_colormap = GDK_SCREEN_X11 (screen)->default_colormap;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
 
-  GDK_SCREEN_X11 (screen)->default_colormap = g_object_ref (colormap);
-  
-  if (old_colormap)
-    g_object_unref (old_colormap);
+  if (x11_screen->xsettings_client)
+    {
+      _gdk_x11_xsettings_client_destroy (x11_screen->xsettings_client);
+      x11_screen->xsettings_client = NULL;
+    }
 }
 
 static void
-gdk_screen_x11_dispose (GObject *object)
+gdk_x11_screen_dispose (GObject *object)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object);
-
-  _gdk_x11_events_uninit_screen (GDK_SCREEN (object));
-
-  if (screen_x11->default_colormap)
-    {
-      g_object_unref (screen_x11->default_colormap);
-      screen_x11->default_colormap = NULL;
-    }
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (object);
+  int i;
 
-  if (screen_x11->system_colormap)
+  for (i = 0; i < 32; ++i)
     {
-      g_object_unref (screen_x11->system_colormap);
-      screen_x11->system_colormap = NULL;
+      if (x11_screen->subwindow_gcs[i])
+        {
+          XFreeGC (x11_screen->xdisplay, x11_screen->subwindow_gcs[i]);
+          x11_screen->subwindow_gcs[i] = 0;
+        }
     }
 
-  if (screen_x11->rgba_colormap)
-    {
-      g_object_unref (screen_x11->rgba_colormap);
-      screen_x11->rgba_colormap = NULL;
-    }
+  _gdk_x11_screen_events_uninit (GDK_SCREEN (object));
 
-  if (screen_x11->root_window)
-    _gdk_window_destroy (screen_x11->root_window, TRUE);
+  if (x11_screen->root_window)
+    _gdk_window_destroy (x11_screen->root_window, TRUE);
 
-  G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->dispose (object);
+  G_OBJECT_CLASS (gdk_x11_screen_parent_class)->dispose (object);
 
-  screen_x11->xdisplay = NULL;
-  screen_x11->xscreen = NULL;
-  screen_x11->screen_num = -1;
-  screen_x11->xroot_window = None;
-  screen_x11->wmspec_check_window = None;
+  x11_screen->xdisplay = NULL;
+  x11_screen->xscreen = NULL;
+  x11_screen->screen_num = -1;
+  x11_screen->xroot_window = None;
+  x11_screen->wmspec_check_window = None;
 }
 
 static void
-gdk_screen_x11_finalize (GObject *object)
+gdk_x11_screen_finalize (GObject *object)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (object);
   gint          i;
 
-  if (screen_x11->root_window)
-    g_object_unref (screen_x11->root_window);
-
-  if (screen_x11->renderer)
-    g_object_unref (screen_x11->renderer);
+  if (x11_screen->root_window)
+    g_object_unref (x11_screen->root_window);
 
   /* Visual Part */
-  for (i = 0; i < screen_x11->nvisuals; i++)
-    g_object_unref (screen_x11->visuals[i]);
-  g_free (screen_x11->visuals);
-  g_hash_table_destroy (screen_x11->visual_hash);
-
-  g_free (screen_x11->window_manager_name);
+  for (i = 0; i < x11_screen->nvisuals; i++)
+    g_object_unref (x11_screen->visuals[i]);
+  g_free (x11_screen->visuals);
+  g_hash_table_destroy (x11_screen->visual_hash);
 
-  g_hash_table_destroy (screen_x11->colormap_hash);
+  g_free (x11_screen->window_manager_name);
 
   deinit_multihead (GDK_SCREEN (object));
   
-  G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gdk_x11_screen_parent_class)->finalize (object);
 }
 
-/**
- * gdk_screen_get_n_monitors:
- * @screen: a #GdkScreen.
- *
- * Returns the number of monitors which @screen consists of.
- *
- * Returns: number of monitors which @screen consists of.
- *
- * Since: 2.2
- **/
-gint 
-gdk_screen_get_n_monitors (GdkScreen *screen)
+static gint
+gdk_x11_screen_get_n_monitors (GdkScreen *screen)
 {
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
-  
-  return GDK_SCREEN_X11 (screen)->n_monitors;
+  return GDK_X11_SCREEN (screen)->n_monitors;
 }
 
-static GdkX11Monitor *
-get_monitor (GdkScreen *screen,
-            int        monitor_num)
+static gint
+gdk_x11_screen_get_primary_monitor (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11;
-
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-  
-  screen_x11 = GDK_SCREEN_X11 (screen);
-  
-  g_return_val_if_fail (monitor_num < screen_x11->n_monitors, NULL);
-  g_return_val_if_fail (monitor_num >= 0, NULL);
-  
-  return &(screen_x11->monitors[monitor_num]);
+  return GDK_X11_SCREEN (screen)->primary_monitor;
 }
 
-/**
- * gdk_screen_get_monitor_width_mm:
- * @screen: a #GdkScreen
- * @monitor_num: number of the monitor
- *
- * Gets the width in millimeters of the specified monitor, if available.
- *
- * Returns: the width of the monitor, or -1 if not available
- *
- * Since: 2.14
- */
-gint
-gdk_screen_get_monitor_width_mm        (GdkScreen *screen,
-                                gint       monitor_num)
+static gint
+gdk_x11_screen_get_monitor_width_mm (GdkScreen *screen,
+                                     gint       monitor_num)
 {
-  return get_monitor (screen, monitor_num)->width_mm;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+
+  return x11_screen->monitors[monitor_num].width_mm;
 }
 
-/**
- * gdk_screen_get_monitor_height_mm:
- * @screen: a #GdkScreen
- * @monitor_num: number of the monitor
- *
- * Gets the height in millimeters of the specified monitor. 
- *
- * Returns: the height of the monitor, or -1 if not available
- *
- * Since: 2.14
- */
-gint
-gdk_screen_get_monitor_height_mm (GdkScreen *screen,
-                                  gint       monitor_num)
+static gint
+gdk_x11_screen_get_monitor_height_mm (GdkScreen *screen,
+                                     gint       monitor_num)
 {
-  return get_monitor (screen, monitor_num)->height_mm;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+
+  return x11_screen->monitors[monitor_num].height_mm;
 }
 
-/**
- * gdk_screen_get_monitor_plug_name:
- * @screen: a #GdkScreen
- * @monitor_num: number of the monitor
- *
- * Returns the output name of the specified monitor. 
- * Usually something like VGA, DVI, or TV, not the actual
- * product name of the display device.
- * 
- * Returns: a newly-allocated string containing the name of the monitor,
- *   or %NULL if the name cannot be determined
- *
- * Since: 2.14
- */
-gchar *
-gdk_screen_get_monitor_plug_name (GdkScreen *screen,
-                                 gint       monitor_num)
+static gchar *
+gdk_x11_screen_get_monitor_plug_name (GdkScreen *screen,
+                                     gint       monitor_num)
 {
-  return g_strdup (get_monitor (screen, monitor_num)->output_name);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+
+  return g_strdup (x11_screen->monitors[monitor_num].output_name);
 }
 
 /**
  * gdk_x11_screen_get_monitor_output:
- * @screen: a #GdkScreen
- * @monitor_num: number of the monitor 
+ * @screen: (type GdkX11Screen): a #GdkScreen
+ * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
  *
  * Gets the XID of the specified output/monitor.
- * If the X server does not support version 1.2 of the RANDR 
+ * If the X server does not support version 1.2 of the RANDR
  * extension, 0 is returned.
  *
  * Returns: the XID of the monitor
@@ -444,139 +247,198 @@ XID
 gdk_x11_screen_get_monitor_output (GdkScreen *screen,
                                    gint       monitor_num)
 {
-  return get_monitor (screen, monitor_num)->output;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), None);
+  g_return_val_if_fail (monitor_num >= 0, None);
+  g_return_val_if_fail (monitor_num < x11_screen->n_monitors, None);
+
+  return x11_screen->monitors[monitor_num].output;
 }
 
-/**
- * gdk_screen_get_monitor_geometry:
- * @screen : a #GdkScreen.
- * @monitor_num: the monitor number. 
- * @dest : a #GdkRectangle to be filled with the monitor geometry
- *
- * Retrieves the #GdkRectangle representing the size and position of 
- * the individual monitor within the entire screen area.
- * 
- * Note that the size of the entire screen area can be retrieved via 
- * gdk_screen_get_width() and gdk_screen_get_height().
- *
- * Since: 2.2
- **/
-void 
-gdk_screen_get_monitor_geometry (GdkScreen    *screen,
-                                gint          monitor_num,
-                                GdkRectangle *dest)
+static void
+gdk_x11_screen_get_monitor_geometry (GdkScreen    *screen,
+                                    gint          monitor_num,
+                                    GdkRectangle *dest)
 {
-  if (dest) 
-    {
-      GdkX11Monitor *monitor = get_monitor (screen, monitor_num);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
 
-      *dest = monitor->geometry;
-    }
+  if (dest)
+    *dest = x11_screen->monitors[monitor_num].geometry;
 }
 
-/**
- * gdk_screen_get_rgba_colormap:
- * @screen: a #GdkScreen.
- * 
- * Gets a colormap to use for creating windows or pixmaps with an
- * alpha channel. The windowing system on which GTK+ is running
- * may not support this capability, in which case %NULL will
- * be returned. Even if a non-%NULL value is returned, its
- * possible that the window's alpha channel won't be honored
- * when displaying the window on the screen: in particular, for
- * X an appropriate windowing manager and compositing manager
- * must be running to provide appropriate display.
- *
- * This functionality is not implemented in the Windows backend.
- *
- * For setting an overall opacity for a top-level window, see
- * gdk_window_set_opacity().
+static int
+get_current_desktop (GdkScreen *screen)
+{
+  Display *display;
+  Window win;
+  Atom current_desktop, type;
+  int format;
+  unsigned long n_items, bytes_after;
+  unsigned char *data_return = NULL;
+  int workspace = 0;
 
- * Return value: a colormap to use for windows with an alpha channel
- *   or %NULL if the capability is not available.
- *
- * Since: 2.8
- **/
-GdkColormap *
-gdk_screen_get_rgba_colormap (GdkScreen *screen)
+  if (!gdk_x11_screen_supports_net_wm_hint (screen,
+                                            gdk_atom_intern_static_string ("_NET_CURRENT_DESKTOP")))
+    return workspace;
+
+  display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
+  win = XRootWindow (display, GDK_SCREEN_XNUMBER (screen));
+
+  current_desktop = XInternAtom (display, "_NET_CURRENT_DESKTOP", True);
+
+  XGetWindowProperty (display,
+                      win,
+                      current_desktop,
+                      0, G_MAXLONG,
+                      False, XA_CARDINAL,
+                      &type, &format, &n_items, &bytes_after,
+                      &data_return);
+
+  if (type == XA_CARDINAL && format == 32 && n_items > 0)
+    workspace = (int) data_return[0];
+
+  if (data_return)
+    XFree (data_return);
+
+  return workspace;
+}
+
+static void
+get_work_area (GdkScreen    *screen,
+               GdkRectangle *area)
 {
-  GdkScreenX11 *screen_x11;
+  Atom            workarea;
+  Atom            type;
+  Window          win;
+  int             format;
+  gulong          num;
+  gulong          leftovers;
+  gulong          max_len = 4 * 32;
+  guchar         *ret_workarea;
+  long           *workareas;
+  int             result;
+  int             disp_screen;
+  int             desktop;
+  Display        *display;
+
+  display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
+  disp_screen = GDK_SCREEN_XNUMBER (screen);
+  workarea = XInternAtom (display, "_NET_WORKAREA", True);
+
+  /* Defaults in case of error */
+  area->x = 0;
+  area->y = 0;
+  area->width = gdk_screen_get_width (screen);
+  area->height = gdk_screen_get_height (screen);
 
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
+  if (!gdk_x11_screen_supports_net_wm_hint (screen,
+                                            gdk_atom_intern_static_string ("_NET_WORKAREA")))
+    return;
 
-  screen_x11 = GDK_SCREEN_X11 (screen);
+  if (workarea == None)
+    return;
 
-  if (!screen_x11->rgba_visual)
-    return NULL;
+  win = XRootWindow (display, disp_screen);
+  result = XGetWindowProperty (display,
+                               win,
+                               workarea,
+                               0,
+                               max_len,
+                               False,
+                               AnyPropertyType,
+                               &type,
+                               &format,
+                               &num,
+                               &leftovers,
+                               &ret_workarea);
+  if (result != Success ||
+      type == None ||
+      format == 0 ||
+      leftovers ||
+      num % 4 != 0)
+    return;
 
-  if (!screen_x11->rgba_colormap)
-    screen_x11->rgba_colormap = gdk_colormap_new (screen_x11->rgba_visual,
-                                                 FALSE);
-  
-  return screen_x11->rgba_colormap;
+  desktop = get_current_desktop (screen);
+
+  workareas = (long *) ret_workarea;
+  area->x = workareas[desktop * 4];
+  area->y = workareas[desktop * 4 + 1];
+  area->width = workareas[desktop * 4 + 2];
+  area->height = workareas[desktop * 4 + 3];
+
+  XFree (ret_workarea);
 }
 
-/**
- * gdk_screen_get_rgba_visual:
- * @screen: a #GdkScreen
- * 
- * Gets a visual to use for creating windows or pixmaps with an
- * alpha channel. See the docs for gdk_screen_get_rgba_colormap()
- * for caveats.
- * 
- * Return value: a visual to use for windows with an alpha channel
- *   or %NULL if the capability is not available.
- *
- * Since: 2.8
- **/
-GdkVisual *
-gdk_screen_get_rgba_visual (GdkScreen *screen)
+static void
+gdk_x11_screen_get_monitor_workarea (GdkScreen    *screen,
+                                     gint          monitor_num,
+                                     GdkRectangle *dest)
 {
-  GdkScreenX11 *screen_x11;
+  GdkRectangle workarea;
 
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
+  gdk_x11_screen_get_monitor_geometry (screen, monitor_num, dest);
 
-  screen_x11 = GDK_SCREEN_X11 (screen);
+  /* The EWMH constrains workarea to be a rectangle, so it
+   * can't adequately deal with L-shaped monitor arrangements.
+   * As a workaround, we ignore the workarea for anything
+   * but the primary monitor. Since that is where the 'desktop
+   * chrome' usually lives, this works ok in practice.
+   */
+  if (monitor_num == GDK_X11_SCREEN (screen)->primary_monitor)
+    {
+      get_work_area (screen, &workarea);
+      if (gdk_rectangle_intersect (dest, &workarea, &workarea))
+        *dest = workarea;
+    }
+}
+
+static GdkVisual *
+gdk_x11_screen_get_rgba_visual (GdkScreen *screen)
+{
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
 
-  return screen_x11->rgba_visual;
+  return x11_screen->rgba_visual;
 }
 
 /**
  * gdk_x11_screen_get_xscreen:
- * @screen: a #GdkScreen.
- * @returns: an Xlib <type>Screen*</type>
+ * @screen: (type GdkX11Screen): a #GdkScreen
  *
  * Returns the screen of a #GdkScreen.
  *
+ * Returns: (transfer none): an Xlib <type>Screen*</type>
+ *
  * Since: 2.2
  */
 Screen *
 gdk_x11_screen_get_xscreen (GdkScreen *screen)
 {
-  return GDK_SCREEN_X11 (screen)->xscreen;
+  return GDK_X11_SCREEN (screen)->xscreen;
 }
 
 /**
  * gdk_x11_screen_get_screen_number:
- * @screen: a #GdkScreen.
- * @returns: the position of @screen among the screens of
- *   its display.
+ * @screen: (type GdkX11Screen): a #GdkScreen
  *
  * Returns the index of a #GdkScreen.
  *
+ * Returns: the position of @screen among the screens
+ *     of its display
+ *
  * Since: 2.2
  */
 int
 gdk_x11_screen_get_screen_number (GdkScreen *screen)
 {
-  return GDK_SCREEN_X11 (screen)->screen_num;
+  return GDK_X11_SCREEN (screen)->screen_num;
 }
 
 static gboolean
 check_is_composited (GdkDisplay *display,
-                    GdkScreenX11 *screen_x11)
+                    GdkX11Screen *x11_screen)
 {
-  Atom xselection = gdk_x11_atom_to_xatom_for_display (display, screen_x11->cm_selection_atom);
+  Atom xselection = gdk_x11_atom_to_xatom_for_display (display, x11_screen->cm_selection_atom);
   Window xwindow;
   
   xwindow = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), xselection);
@@ -613,7 +475,7 @@ static gboolean
 init_fake_xinerama (GdkScreen *screen)
 {
 #ifdef G_ENABLE_DEBUG
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   XSetWindowAttributes atts;
   Window win;
   gint w, h;
@@ -624,36 +486,36 @@ init_fake_xinerama (GdkScreen *screen)
   /* Fake Xinerama mode by splitting the screen into 4 monitors.
    * Also draw a little cross to make the monitor boundaries visible.
    */
-  w = WidthOfScreen (screen_x11->xscreen);
-  h = HeightOfScreen (screen_x11->xscreen);
-
-  screen_x11->n_monitors = 4;
-  screen_x11->monitors = g_new0 (GdkX11Monitor, 4);
-  init_monitor_geometry (&screen_x11->monitors[0], 0, 0, w / 2, h / 2);
-  init_monitor_geometry (&screen_x11->monitors[1], w / 2, 0, w / 2, h / 2);
-  init_monitor_geometry (&screen_x11->monitors[2], 0, h / 2, w / 2, h / 2);
-  init_monitor_geometry (&screen_x11->monitors[3], w / 2, h / 2, w / 2, h / 2);
+  w = WidthOfScreen (x11_screen->xscreen);
+  h = HeightOfScreen (x11_screen->xscreen);
+
+  x11_screen->n_monitors = 4;
+  x11_screen->monitors = g_new0 (GdkX11Monitor, 4);
+  init_monitor_geometry (&x11_screen->monitors[0], 0, 0, w / 2, h / 2);
+  init_monitor_geometry (&x11_screen->monitors[1], w / 2, 0, w / 2, h / 2);
+  init_monitor_geometry (&x11_screen->monitors[2], 0, h / 2, w / 2, h / 2);
+  init_monitor_geometry (&x11_screen->monitors[3], w / 2, h / 2, w / 2, h / 2);
   
   atts.override_redirect = 1;
   atts.background_pixel = WhitePixel(GDK_SCREEN_XDISPLAY (screen), 
-                                    screen_x11->screen_num);
+                                    x11_screen->screen_num);
   win = XCreateWindow(GDK_SCREEN_XDISPLAY (screen), 
-                     screen_x11->xroot_window, 0, h / 2, w, 1, 0, 
+                     x11_screen->xroot_window, 0, h / 2, w, 1, 0, 
                      DefaultDepth(GDK_SCREEN_XDISPLAY (screen), 
-                                  screen_x11->screen_num),
+                                  x11_screen->screen_num),
                      InputOutput, 
                      DefaultVisual(GDK_SCREEN_XDISPLAY (screen), 
-                                   screen_x11->screen_num),
+                                   x11_screen->screen_num),
                      CWOverrideRedirect|CWBackPixel, 
                      &atts);
   XMapRaised(GDK_SCREEN_XDISPLAY (screen), win); 
   win = XCreateWindow(GDK_SCREEN_XDISPLAY (screen), 
-                     screen_x11->xroot_window, w/2 , 0, 1, h, 0, 
+                     x11_screen->xroot_window, w/2 , 0, 1, h, 0, 
                      DefaultDepth(GDK_SCREEN_XDISPLAY (screen), 
-                                  screen_x11->screen_num),
+                                  x11_screen->screen_num),
                      InputOutput, 
                      DefaultVisual(GDK_SCREEN_XDISPLAY (screen), 
-                                   screen_x11->screen_num),
+                                   x11_screen->screen_num),
                      CWOverrideRedirect|CWBackPixel, 
                      &atts);
   XMapRaised(GDK_SCREEN_XDISPLAY (screen), win);
@@ -678,6 +540,7 @@ free_monitors (GdkX11Monitor *monitors,
   g_free (monitors);
 }
 
+#ifdef HAVE_RANDR
 static int
 monitor_compare_function (GdkX11Monitor *monitor1,
                           GdkX11Monitor *monitor2)
@@ -702,16 +565,19 @@ monitor_compare_function (GdkX11Monitor *monitor1,
 
   return 0;
 }
+#endif
 
 static gboolean
 init_randr13 (GdkScreen *screen)
 {
 #ifdef HAVE_RANDR
   GdkDisplay *display = gdk_screen_get_display (screen);
-  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   Display *dpy = GDK_SCREEN_XDISPLAY (screen);
   XRRScreenResources *resources;
+  RROutput primary_output;
+  RROutput first_output = None;
   int i;
   GArray *monitors;
   gboolean randr12_compat = FALSE;
@@ -719,11 +585,11 @@ init_randr13 (GdkScreen *screen)
   if (!display_x11->have_randr13)
       return FALSE;
 
-  resources = XRRGetScreenResourcesCurrent (screen_x11->xdisplay,
-                                           screen_x11->xroot_window);
+  resources = XRRGetScreenResourcesCurrent (x11_screen->xdisplay,
+                                           x11_screen->xroot_window);
   if (!resources)
     return FALSE;
-  
+
   monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
                                 resources->noutput);
 
@@ -733,7 +599,7 @@ init_randr13 (GdkScreen *screen)
        XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
 
       /* Non RandR1.2 X driver have output name "default" */
-      randr12_compat |= !g_strcmp0(output->name, "default");
+      randr12_compat |= !g_strcmp0 (output->name, "default");
 
       if (output->connection == RR_Disconnected)
         {
@@ -766,6 +632,9 @@ init_randr13 (GdkScreen *screen)
       XRRFreeOutputInfo (output);
     }
 
+  if (resources->noutput > 0)
+    first_output = resources->outputs[0];
+
   XRRFreeScreenResources (resources);
 
   /* non RandR 1.2 X driver doesn't return any usable multihead data */
@@ -781,12 +650,38 @@ init_randr13 (GdkScreen *screen)
 
   g_array_sort (monitors,
                 (GCompareFunc) monitor_compare_function);
-  screen_x11->n_monitors = monitors->len;
-  screen_x11->monitors = (GdkX11Monitor *)g_array_free (monitors, FALSE);
+  x11_screen->n_monitors = monitors->len;
+  x11_screen->monitors = (GdkX11Monitor *)g_array_free (monitors, FALSE);
+
+  x11_screen->primary_monitor = 0;
+
+  primary_output = XRRGetOutputPrimary (x11_screen->xdisplay,
+                                        x11_screen->xroot_window);
+
+  for (i = 0; i < x11_screen->n_monitors; ++i)
+    {
+      if (x11_screen->monitors[i].output == primary_output)
+       {
+         x11_screen->primary_monitor = i;
+         break;
+       }
 
-  return screen_x11->n_monitors > 0;
+      /* No RandR1.3+ available or no primary set, fall back to prefer LVDS as primary if present */
+      if (primary_output == None &&
+          g_ascii_strncasecmp (x11_screen->monitors[i].output_name, "LVDS", 4) == 0)
+       {
+         x11_screen->primary_monitor = i;
+         break;
+       }
+
+      /* No primary specified and no LVDS found */
+      if (x11_screen->monitors[i].output == first_output)
+       x11_screen->primary_monitor = i;
+    }
+
+  return x11_screen->n_monitors > 0;
 #endif
-  
+
   return FALSE;
 }
 
@@ -796,7 +691,7 @@ init_solaris_xinerama (GdkScreen *screen)
 #ifdef HAVE_SOLARIS_XINERAMA
   Display *dpy = GDK_SCREEN_XDISPLAY (screen);
   int screen_no = gdk_screen_get_number (screen);
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   XRectangle monitors[MAXFRAMEBUFFERS];
   unsigned char hints[16];
   gint result;
@@ -816,16 +711,18 @@ init_solaris_xinerama (GdkScreen *screen)
       return FALSE;
     }
 
-  screen_x11->monitors = g_new0 (GdkX11Monitor, n_monitors);
-  screen_x11->n_monitors = n_monitors;
+  x11_screen->monitors = g_new0 (GdkX11Monitor, n_monitors);
+  x11_screen->n_monitors = n_monitors;
 
   for (i = 0; i < n_monitors; i++)
     {
-      init_monitor_geometry (&screen_x11->monitors[i],
+      init_monitor_geometry (&x11_screen->monitors[i],
                             monitors[i].x, monitors[i].y,
                             monitors[i].width, monitors[i].height);
     }
-  
+
+  x11_screen->primary_monitor = 0;
+
   return TRUE;
 #endif /* HAVE_SOLARIS_XINERAMA */
 
@@ -837,7 +734,7 @@ init_xfree_xinerama (GdkScreen *screen)
 {
 #ifdef HAVE_XFREE_XINERAMA
   Display *dpy = GDK_SCREEN_XDISPLAY (screen);
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   XineramaScreenInfo *monitors;
   int i, n_monitors;
   
@@ -860,33 +757,202 @@ init_xfree_xinerama (GdkScreen *screen)
       return FALSE;
     }
 
-  screen_x11->n_monitors = n_monitors;
-  screen_x11->monitors = g_new0 (GdkX11Monitor, n_monitors);
+  x11_screen->n_monitors = n_monitors;
+  x11_screen->monitors = g_new0 (GdkX11Monitor, n_monitors);
   
   for (i = 0; i < n_monitors; ++i)
     {
-      init_monitor_geometry (&screen_x11->monitors[i],
+      init_monitor_geometry (&x11_screen->monitors[i],
                             monitors[i].x_org, monitors[i].y_org,
                             monitors[i].width, monitors[i].height);
     }
   
   XFree (monitors);
   
+  x11_screen->primary_monitor = 0;
+
   return TRUE;
 #endif /* HAVE_XFREE_XINERAMA */
   
   return FALSE;
 }
 
+static gboolean
+init_solaris_xinerama_indices (GdkX11Screen *x11_screen)
+{
+#ifdef HAVE_SOLARIS_XINERAMA
+  XRectangle    x_monitors[MAXFRAMEBUFFERS];
+  unsigned char hints[16];
+  gint          result;
+  gint          monitor_num;
+  gint          x_n_monitors;
+  gint          i;
+
+  if (!XineramaGetState (x11_screen->xdisplay, x11_screen->screen_num))
+    return FALSE;
+
+  result = XineramaGetInfo (x11_screen->xdisplay, x11_screen->screen_num,
+                            x_monitors, hints, &x_n_monitors);
+
+  if (result == 0)
+    return FALSE;
+
+
+  for (monitor_num = 0; monitor_num < x11_screen->n_monitors; ++monitor_num)
+    {
+      for (i = 0; i < x_n_monitors; ++i)
+        {
+          if (x11_screen->monitors[monitor_num].geometry.x == x_monitors[i].x &&
+             x11_screen->monitors[monitor_num].geometry.y == x_monitors[i].y &&
+             x11_screen->monitors[monitor_num].geometry.width == x_monitors[i].width &&
+             x11_screen->monitors[monitor_num].geometry.height == x_monitors[i].height)
+           {
+             g_hash_table_insert (x11_screen->xinerama_matches,
+                                  GINT_TO_POINTER (monitor_num),
+                                  GINT_TO_POINTER (i));
+           }
+        }
+    }
+  return TRUE;
+#endif /* HAVE_SOLARIS_XINERAMA */
+
+  return FALSE;
+}
+
+static gboolean
+init_xfree_xinerama_indices (GdkX11Screen *x11_screen)
+{
+#ifdef HAVE_XFREE_XINERAMA
+  XineramaScreenInfo *x_monitors;
+  gint                monitor_num;
+  gint                x_n_monitors;
+  gint                i;
+
+  if (!XineramaIsActive (x11_screen->xdisplay))
+    return FALSE;
+
+  x_monitors = XineramaQueryScreens (x11_screen->xdisplay, &x_n_monitors);
+  if (x_n_monitors <= 0 || x_monitors == NULL)
+    {
+      if (x_monitors)
+       XFree (x_monitors);
+
+      return FALSE;
+    }
+
+  for (monitor_num = 0; monitor_num < x11_screen->n_monitors; ++monitor_num)
+    {
+      for (i = 0; i < x_n_monitors; ++i)
+        {
+          if (x11_screen->monitors[monitor_num].geometry.x == x_monitors[i].x_org &&
+             x11_screen->monitors[monitor_num].geometry.y == x_monitors[i].y_org &&
+             x11_screen->monitors[monitor_num].geometry.width == x_monitors[i].width &&
+             x11_screen->monitors[monitor_num].geometry.height == x_monitors[i].height)
+           {
+             g_hash_table_insert (x11_screen->xinerama_matches,
+                                  GINT_TO_POINTER (monitor_num),
+                                  GINT_TO_POINTER (i));
+           }
+        }
+    }
+  XFree (x_monitors);
+  return TRUE;
+#endif /* HAVE_XFREE_XINERAMA */
+
+  return FALSE;
+}
+
+static void
+init_xinerama_indices (GdkX11Screen *x11_screen)
+{
+  int opcode, firstevent, firsterror;
+
+  x11_screen->xinerama_matches = g_hash_table_new (g_direct_hash, g_direct_equal);
+  if (XQueryExtension (x11_screen->xdisplay, "XINERAMA",
+                      &opcode, &firstevent, &firsterror))
+    {
+      x11_screen->xinerama_matches = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+      /* Solaris Xinerama first, then XFree/Xorg Xinerama
+       * to match the order in init_multihead()
+       */
+      if (init_solaris_xinerama_indices (x11_screen) == FALSE)
+        init_xfree_xinerama_indices (x11_screen);
+    }
+}
+
+gint
+_gdk_x11_screen_get_xinerama_index (GdkScreen *screen,
+                                   gint       monitor_num)
+{
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+  gpointer val;
+
+  g_return_val_if_fail (monitor_num < x11_screen->n_monitors, -1);
+
+  if (x11_screen->xinerama_matches == NULL)
+    init_xinerama_indices (x11_screen);
+
+  if (g_hash_table_lookup_extended (x11_screen->xinerama_matches, GINT_TO_POINTER (monitor_num), NULL, &val))
+    return (GPOINTER_TO_INT(val));
+
+  return -1;
+}
+
+void
+_gdk_x11_screen_get_edge_monitors (GdkScreen *screen,
+                                   gint      *top,
+                                   gint      *bottom,
+                                   gint      *left,
+                                   gint      *right)
+{
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+  gint          top_most_pos = HeightOfScreen (GDK_X11_SCREEN (screen)->xscreen);
+  gint          left_most_pos = WidthOfScreen (GDK_X11_SCREEN (screen)->xscreen);
+  gint          bottom_most_pos = 0;
+  gint          right_most_pos = 0;
+  gint          monitor_num;
+
+  for (monitor_num = 0; monitor_num < x11_screen->n_monitors; monitor_num++)
+    {
+      gint monitor_x = x11_screen->monitors[monitor_num].geometry.x;
+      gint monitor_y = x11_screen->monitors[monitor_num].geometry.y;
+      gint monitor_max_x = monitor_x + x11_screen->monitors[monitor_num].geometry.width;
+      gint monitor_max_y = monitor_y + x11_screen->monitors[monitor_num].geometry.height;
+
+      if (left && left_most_pos > monitor_x)
+       {
+         left_most_pos = monitor_x;
+         *left = monitor_num;
+       }
+      if (right && right_most_pos < monitor_max_x)
+       {
+         right_most_pos = monitor_max_x;
+         *right = monitor_num;
+       }
+      if (top && top_most_pos > monitor_y)
+       {
+         top_most_pos = monitor_y;
+         *top = monitor_num;
+       }
+      if (bottom && bottom_most_pos < monitor_max_y)
+       {
+         bottom_most_pos = monitor_max_y;
+         *bottom = monitor_num;
+       }
+    }
+}
+
 static void
 deinit_multihead (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
 
-  free_monitors (screen_x11->monitors, screen_x11->n_monitors);
+  free_monitors (x11_screen->monitors, x11_screen->n_monitors);
+  g_clear_pointer (&x11_screen->xinerama_matches, g_hash_table_destroy);
 
-  screen_x11->n_monitors = 0;
-  screen_x11->monitors = NULL;
+  x11_screen->n_monitors = 0;
+  x11_screen->monitors = NULL;
 }
 
 static gboolean
@@ -933,7 +999,7 @@ compare_monitors (GdkX11Monitor *monitors1, gint n_monitors1,
 static void
 init_multihead (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   int opcode, firstevent, firsterror;
 
   /* There are four different implementations of multihead support: 
@@ -962,12 +1028,13 @@ init_multihead (GdkScreen *screen)
     }
 
   /* No multihead support of any kind for this screen */
-  screen_x11->n_monitors = 1;
-  screen_x11->monitors = g_new0 (GdkX11Monitor, 1);
+  x11_screen->n_monitors = 1;
+  x11_screen->monitors = g_new0 (GdkX11Monitor, 1);
+  x11_screen->primary_monitor = 0;
 
-  init_monitor_geometry (screen_x11->monitors, 0, 0,
-                        WidthOfScreen (screen_x11->xscreen),
-                        HeightOfScreen (screen_x11->xscreen));
+  init_monitor_geometry (x11_screen->monitors, 0, 0,
+                        WidthOfScreen (x11_screen->xscreen),
+                        HeightOfScreen (x11_screen->xscreen));
 }
 
 GdkScreen *
@@ -975,26 +1042,26 @@ _gdk_x11_screen_new (GdkDisplay *display,
                     gint        screen_number) 
 {
   GdkScreen *screen;
-  GdkScreenX11 *screen_x11;
-  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
-
-  screen = g_object_new (GDK_TYPE_SCREEN_X11, NULL);
-
-  screen_x11 = GDK_SCREEN_X11 (screen);
-  screen_x11->display = display;
-  screen_x11->xdisplay = display_x11->xdisplay;
-  screen_x11->xscreen = ScreenOfDisplay (display_x11->xdisplay, screen_number);
-  screen_x11->screen_num = screen_number;
-  screen_x11->xroot_window = RootWindow (display_x11->xdisplay,screen_number);
-  screen_x11->wmspec_check_window = None;
+  GdkX11Screen *x11_screen;
+  GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
+
+  screen = g_object_new (GDK_TYPE_X11_SCREEN, NULL);
+
+  x11_screen = GDK_X11_SCREEN (screen);
+  x11_screen->display = display;
+  x11_screen->xdisplay = display_x11->xdisplay;
+  x11_screen->xscreen = ScreenOfDisplay (display_x11->xdisplay, screen_number);
+  x11_screen->screen_num = screen_number;
+  x11_screen->xroot_window = RootWindow (display_x11->xdisplay,screen_number);
+  x11_screen->wmspec_check_window = None;
   /* we want this to be always non-null */
-  screen_x11->window_manager_name = g_strdup ("unknown");
+  x11_screen->window_manager_name = g_strdup ("unknown");
   
   init_multihead (screen);
   init_randr_support (screen);
   
-  _gdk_visual_init (screen);
-  _gdk_windowing_window_init (screen);
+  _gdk_x11_screen_init_visuals (screen);
+  _gdk_x11_screen_init_root_window (screen);
   
   return screen;
 }
@@ -1007,78 +1074,67 @@ _gdk_x11_screen_new (GdkDisplay *display,
 void
 _gdk_x11_screen_setup (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
 
-  screen_x11->cm_selection_atom = make_cm_atom (screen_x11->screen_num);
-  gdk_display_request_selection_notification (screen_x11->display,
-                                             screen_x11->cm_selection_atom);
-  screen_x11->is_composited = check_is_composited (screen_x11->display, screen_x11);
+  x11_screen->cm_selection_atom = make_cm_atom (x11_screen->screen_num);
+  gdk_display_request_selection_notification (x11_screen->display,
+                                             x11_screen->cm_selection_atom);
+  x11_screen->is_composited = check_is_composited (x11_screen->display, x11_screen);
 }
 
-/**
- * gdk_screen_is_composited:
- * @screen: a #GdkScreen
- * 
- * Returns whether windows with an RGBA visual can reasonably
- * be expected to have their alpha channel drawn correctly on
- * the screen.
- *
- * On X11 this function returns whether a compositing manager is
- * compositing @screen.
- * 
- * Return value: Whether windows with RGBA visuals can reasonably be
- * expected to have their alpha channels drawn correctly on the screen.
- * 
- * Since: 2.10
- **/
-gboolean
-gdk_screen_is_composited (GdkScreen *screen)
+static gboolean
+gdk_x11_screen_is_composited (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
 
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
-
-  screen_x11 = GDK_SCREEN_X11 (screen);
-
-  return screen_x11->is_composited;
+  return x11_screen->is_composited;
 }
 
 static void
-init_randr_support (GdkScreen * screen)
+init_randr_support (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
-  
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+
+  /* NB: This is also needed for XSettings, so don't remove. */
   XSelectInput (GDK_SCREEN_XDISPLAY (screen),
-               screen_x11->xroot_window,
-               StructureNotifyMask);
+                x11_screen->xroot_window,
+                StructureNotifyMask);
 
 #ifdef HAVE_RANDR
+  if (!GDK_X11_DISPLAY (gdk_screen_get_display (screen))->have_randr12)
+    return;
+
   XRRSelectInput (GDK_SCREEN_XDISPLAY (screen),
-                 screen_x11->xroot_window,
-                 RRScreenChangeNotifyMask      |
-                 RRCrtcChangeNotifyMask        |
-                 RROutputPropertyNotifyMask);
+                  x11_screen->xroot_window,
+                  RRScreenChangeNotifyMask
+                  | RRCrtcChangeNotifyMask
+                  | RROutputPropertyNotifyMask);
 #endif
 }
 
 static void
 process_monitors_change (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   gint          n_monitors;
+  gint          primary_monitor;
   GdkX11Monitor        *monitors;
   gboolean changed;
 
-  n_monitors = screen_x11->n_monitors;
-  monitors = screen_x11->monitors;
+  primary_monitor = x11_screen->primary_monitor;
+  n_monitors = x11_screen->n_monitors;
+  monitors = x11_screen->monitors;
 
-  screen_x11->n_monitors = 0;
-  screen_x11->monitors = NULL;
+  x11_screen->n_monitors = 0;
+  x11_screen->monitors = NULL;
 
   init_multihead (screen);
 
-  changed = !compare_monitors (monitors, n_monitors,
-                               screen_x11->monitors, screen_x11->n_monitors);
+  changed =
+    !compare_monitors (monitors, n_monitors,
+                      x11_screen->monitors, x11_screen->n_monitors) ||
+    x11_screen->primary_monitor != primary_monitor;
+
 
   free_monitors (monitors, n_monitors);
 
@@ -1091,13 +1147,15 @@ _gdk_x11_screen_size_changed (GdkScreen *screen,
                              XEvent    *event)
 {
   gint width, height;
-  GdkDisplayX11 *display_x11;
+#ifdef HAVE_RANDR
+  GdkX11Display *display_x11;
+#endif
 
   width = gdk_screen_get_width (screen);
   height = gdk_screen_get_height (screen);
 
 #ifdef HAVE_RANDR
-  display_x11 = GDK_DISPLAY_X11 (gdk_screen_get_display (screen));
+  display_x11 = GDK_X11_DISPLAY (gdk_screen_get_display (screen));
 
   if (display_x11->have_randr13 && event->type == ConfigureNotify)
     return;
@@ -1108,7 +1166,7 @@ _gdk_x11_screen_size_changed (GdkScreen *screen,
     {
       XConfigureEvent *rcevent = (XConfigureEvent *) event;
       Screen       *xscreen = gdk_x11_screen_get_xscreen (screen);
-      
+
       xscreen->width   = rcevent->width;
       xscreen->height  = rcevent->height;
     }
@@ -1135,17 +1193,17 @@ _gdk_x11_screen_process_owner_change (GdkScreen *screen,
 {
 #ifdef HAVE_XFIXES
   XFixesSelectionNotifyEvent *selection_event = (XFixesSelectionNotifyEvent *)event;
-  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
-  Atom xcm_selection_atom = gdk_x11_atom_to_xatom_for_display (screen_x11->display,
-                                                              screen_x11->cm_selection_atom);
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+  Atom xcm_selection_atom = gdk_x11_atom_to_xatom_for_display (x11_screen->display,
+                                                              x11_screen->cm_selection_atom);
 
   if (selection_event->selection == xcm_selection_atom)
     {
       gboolean composited = selection_event->owner != None;
 
-      if (composited != screen_x11->is_composited)
+      if (composited != x11_screen->is_composited)
        {
-         screen_x11->is_composited = composited;
+         x11_screen->is_composited = composited;
 
          g_signal_emit_by_name (screen, "composited-changed");
        }
@@ -1153,34 +1211,13 @@ _gdk_x11_screen_process_owner_change (GdkScreen *screen,
 #endif
 }
 
-/**
- * _gdk_windowing_substitute_screen_number:
- * @display_name : The name of a display, in the form used by 
- *                 gdk_display_open (). If %NULL a default value
- *                 will be used. On X11, this is derived from the DISPLAY
- *                 environment variable.
- * @screen_number : The number of a screen within the display
- *                  referred to by @display_name.
- *
- * Modifies a @display_name to make @screen_number the default
- * screen when the display is opened.
- *
- * Return value: a newly allocated string holding the resulting
- *   display name. Free with g_free().
- */
-gchar * 
-_gdk_windowing_substitute_screen_number (const gchar *display_name,
-                                        gint         screen_number)
+static gchar *
+substitute_screen_number (const gchar *display_name,
+                          gint         screen_number)
 {
   GString *str;
   gchar   *p;
 
-  if (!display_name)
-    display_name = getenv ("DISPLAY");
-
-  if (!display_name)
-    return NULL;
-
   str = g_string_new (display_name);
 
   p = strrchr (str->str, '.');
@@ -1192,57 +1229,21 @@ _gdk_windowing_substitute_screen_number (const gchar *display_name,
   return g_string_free (str, FALSE);
 }
 
-/**
- * gdk_screen_make_display_name:
- * @screen: a #GdkScreen
- * 
- * Determines the name to pass to gdk_display_open() to get
- * a #GdkDisplay with this screen as the default screen.
- * 
- * Return value: a newly allocated string, free with g_free()
- *
- * Since: 2.2
- **/
-gchar *
-gdk_screen_make_display_name (GdkScreen *screen)
+static gchar *
+gdk_x11_screen_make_display_name (GdkScreen *screen)
 {
   const gchar *old_display;
 
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
   old_display = gdk_display_get_name (gdk_screen_get_display (screen));
 
-  return _gdk_windowing_substitute_screen_number (old_display, 
-                                                 gdk_screen_get_number (screen));
+  return substitute_screen_number (old_display,
+                                   gdk_screen_get_number (screen));
 }
 
-/**
- * gdk_screen_get_active_window
- * @screen: a #GdkScreen
- *
- * Returns the screen's currently active window.
- *
- * On X11, this is done by inspecting the _NET_ACTIVE_WINDOW property
- * on the root window, as described in the <ulink
- * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
- * Manager Hints</ulink>. If there is no currently currently active
- * window, or the window manager does not support the
- * _NET_ACTIVE_WINDOW hint, this function returns %NULL.
- *
- * On other platforms, this function may return %NULL, depending on whether
- * it is implementable on that platform.
- *
- * The returned window should be unrefed using g_object_unref() when
- * no longer needed.
- *
- * Return value: the currently active window, or %NULL.
- *
- * Since: 2.10
- **/
-GdkWindow *
-gdk_screen_get_active_window (GdkScreen *screen)
+static GdkWindow *
+gdk_x11_screen_get_active_window (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   GdkWindow *ret = NULL;
   Atom type_return;
   gint format_return;
@@ -1250,16 +1251,12 @@ gdk_screen_get_active_window (GdkScreen *screen)
   gulong bytes_after_return;
   guchar *data = NULL;
 
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
   if (!gdk_x11_screen_supports_net_wm_hint (screen,
                                             gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
     return NULL;
 
-  screen_x11 = GDK_SCREEN_X11 (screen);
-
-  if (XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
-                         gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
+  if (XGetWindowProperty (x11_screen->xdisplay, x11_screen->xroot_window,
+                         gdk_x11_get_xatom_by_name_for_display (x11_screen->display,
                                                                 "_NET_ACTIVE_WINDOW"),
                          0, 1, False, XA_WINDOW, &type_return,
                          &format_return, &nitems_return,
@@ -1268,12 +1265,12 @@ gdk_screen_get_active_window (GdkScreen *screen)
     {
       if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
         {
-          GdkNativeWindow window = *(GdkNativeWindow *) data;
+          Window window = *(Window *) data;
 
           if (window != None)
             {
-              ret = gdk_window_foreign_new_for_display (screen_x11->display,
-                                                        *(GdkNativeWindow *) data);
+              ret = gdk_x11_window_foreign_new_for_display (x11_screen->display,
+                                                            window);
             }
         }
     }
@@ -1284,35 +1281,10 @@ gdk_screen_get_active_window (GdkScreen *screen)
   return ret;
 }
 
-/**
- * gdk_screen_get_window_stack
- * @screen: a #GdkScreen
- *
- * Returns a #GList of #GdkWindow<!-- -->s representing the current
- * window stack.
- *
- * On X11, this is done by inspecting the _NET_CLIENT_LIST_STACKING
- * property on the root window, as described in the <ulink
- * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
- * Manager Hints</ulink>. If the window manager does not support the
- * _NET_CLIENT_LIST_STACKING hint, this function returns %NULL.
- *
- * On other platforms, this function may return %NULL, depending on whether
- * it is implementable on that platform.
- *
- * The returned list is newly allocated and owns references to the
- * windows it contains, so it should be freed using g_list_free() and
- * its windows unrefed using g_object_unref() when no longer needed.
- *
- * Return value: a list of #GdkWindow<!-- -->s for the current window stack,
- *               or %NULL.
- *
- * Since: 2.10
- **/
-GList *
-gdk_screen_get_window_stack (GdkScreen *screen)
+static GList *
+gdk_x11_screen_get_window_stack (GdkScreen *screen)
 {
-  GdkScreenX11 *screen_x11;
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
   GList *ret = NULL;
   Atom type_return;
   gint format_return;
@@ -1320,16 +1292,12 @@ gdk_screen_get_window_stack (GdkScreen *screen)
   gulong bytes_after_return;
   guchar *data = NULL;
 
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
   if (!gdk_x11_screen_supports_net_wm_hint (screen,
                                             gdk_atom_intern_static_string ("_NET_CLIENT_LIST_STACKING")))
     return NULL;
 
-  screen_x11 = GDK_SCREEN_X11 (screen);
-
-  if (XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
-                         gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
+  if (XGetWindowProperty (x11_screen->xdisplay, x11_screen->xroot_window,
+                         gdk_x11_get_xatom_by_name_for_display (x11_screen->display,
                                                                 "_NET_CLIENT_LIST_STACKING"),
                          0, G_MAXLONG, False, XA_WINDOW, &type_return,
                          &format_return, &nitems_return,
@@ -1345,8 +1313,8 @@ gdk_screen_get_window_stack (GdkScreen *screen)
 
           for (i = 0; i < nitems_return; i++)
             {
-              win = gdk_window_foreign_new_for_display (screen_x11->display,
-                                                        (GdkNativeWindow)stack[i]);
+              win = gdk_x11_window_foreign_new_for_display (x11_screen->display,
+                                                            (Window)stack[i]);
 
               if (win != NULL)
                 ret = g_list_append (ret, win);
@@ -1360,5 +1328,353 @@ gdk_screen_get_window_stack (GdkScreen *screen)
   return ret;
 }
 
-#define __GDK_SCREEN_X11_C__
-#include "gdkaliasdef.c"
+static gboolean
+gdk_x11_screen_get_setting (GdkScreen   *screen,
+                           const gchar *name,
+                           GValue      *value)
+{
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+  const GValue *setting;
+
+  setting = _gdk_x11_xsettings_client_get_setting (x11_screen->xsettings_client, name);
+  if (setting == NULL)
+    goto out;
+
+  if (!g_value_type_transformable (G_VALUE_TYPE (setting), G_VALUE_TYPE (value)))
+    {
+      g_warning ("Cannot transform xsetting %s of type %s to type %s\n",
+                name,
+                g_type_name (G_VALUE_TYPE (setting)),
+                g_type_name (G_VALUE_TYPE (value)));
+      goto out;
+    }
+
+  g_value_transform (setting, value);
+
+  return TRUE;
+
+ out:
+  return _gdk_x11_get_xft_setting (screen, name, value);
+}
+
+static void
+cleanup_atoms(gpointer data)
+{
+  NetWmSupportedAtoms *supported_atoms = data;
+  if (supported_atoms->atoms)
+      XFree (supported_atoms->atoms);
+  g_free (supported_atoms);
+}
+
+static Window
+get_net_supporting_wm_check (GdkX11Screen *screen,
+                             Window        window)
+{
+  GdkDisplay *display;
+  Atom type;
+  gint format;
+  gulong n_items;
+  gulong bytes_after;
+  guchar *data;
+  Window value;
+
+  display = screen->display;
+  type = None;
+  data = NULL;
+  value = None;
+
+  gdk_x11_display_error_trap_push (display);
+  XGetWindowProperty (screen->xdisplay, window,
+                     gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
+                     0, G_MAXLONG, False, XA_WINDOW, &type, &format,
+                     &n_items, &bytes_after, &data);
+  gdk_x11_display_error_trap_pop_ignored (display);
+
+  if (type == XA_WINDOW)
+    value = *(Window *)data;
+
+  if (data)
+    XFree (data);
+
+  return value;
+}
+
+static void
+fetch_net_wm_check_window (GdkScreen *screen)
+{
+  GdkX11Screen *x11_screen;
+  GdkDisplay *display;
+  Window window;
+  GTimeVal tv;
+  gint error;
+
+  x11_screen = GDK_X11_SCREEN (screen);
+  display = x11_screen->display;
+
+  g_return_if_fail (GDK_X11_DISPLAY (display)->trusted_client);
+
+  if (x11_screen->wmspec_check_window != None)
+    return; /* already have it */
+
+  g_get_current_time (&tv);
+
+  if (ABS  (tv.tv_sec - x11_screen->last_wmspec_check_time) < 15)
+    return; /* we've checked recently */
+
+  window = get_net_supporting_wm_check (x11_screen, x11_screen->xroot_window);
+  if (window == None)
+    return;
+
+  if (window != get_net_supporting_wm_check (x11_screen, window))
+    return;
+
+  gdk_x11_display_error_trap_push (display);
+
+  /* Find out if this WM goes away, so we can reset everything. */
+  XSelectInput (x11_screen->xdisplay, window, StructureNotifyMask);
+
+  error = gdk_x11_display_error_trap_pop (display);
+  if (!error)
+    {
+      /* We check the window property again because after XGetWindowProperty()
+       * and before XSelectInput() the window may have been recycled in such a
+       * way that XSelectInput() doesn't fail but the window is no longer what
+       * we want.
+       */
+      if (window != get_net_supporting_wm_check (x11_screen, window))
+        return;
+
+      x11_screen->wmspec_check_window = window;
+      x11_screen->last_wmspec_check_time = tv.tv_sec;
+      x11_screen->need_refetch_net_supported = TRUE;
+      x11_screen->need_refetch_wm_name = TRUE;
+
+      /* Careful, reentrancy */
+      _gdk_x11_screen_window_manager_changed (screen);
+    }
+}
+
+/**
+ * gdk_x11_screen_supports_net_wm_hint:
+ * @screen: (type GdkX11Screen): the relevant #GdkScreen.
+ * @property: a property atom.
+ *
+ * This function is specific to the X11 backend of GDK, and indicates
+ * whether the window manager supports a certain hint from the
+ * Extended Window Manager Hints Specification. You can find this
+ * specification on
+ * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
+ *
+ * When using this function, keep in mind that the window manager
+ * can change over time; so you shouldn't use this function in
+ * a way that impacts persistent application state. A common bug
+ * is that your application can start up before the window manager
+ * does when the user logs in, and before the window manager starts
+ * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
+ * You can monitor the window_manager_changed signal on #GdkScreen to detect
+ * a window manager change.
+ *
+ * Return value: %TRUE if the window manager supports @property
+ *
+ * Since: 2.2
+ **/
+gboolean
+gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
+                                    GdkAtom    property)
+{
+  gulong i;
+  GdkX11Screen *x11_screen;
+  NetWmSupportedAtoms *supported_atoms;
+  GdkDisplay *display;
+
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+
+  x11_screen = GDK_X11_SCREEN (screen);
+  display = x11_screen->display;
+
+  if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
+    return FALSE;
+
+  supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
+  if (!supported_atoms)
+    {
+      supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
+      g_object_set_data_full (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms, cleanup_atoms);
+    }
+
+  fetch_net_wm_check_window (screen);
+
+  if (x11_screen->wmspec_check_window == None)
+    return FALSE;
+
+  if (x11_screen->need_refetch_net_supported)
+    {
+      /* WM has changed since we last got the supported list,
+       * refetch it.
+       */
+      Atom type;
+      gint format;
+      gulong bytes_after;
+
+      x11_screen->need_refetch_net_supported = FALSE;
+
+      if (supported_atoms->atoms)
+        XFree (supported_atoms->atoms);
+
+      supported_atoms->atoms = NULL;
+      supported_atoms->n_atoms = 0;
+
+      XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), x11_screen->xroot_window,
+                          gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
+                          0, G_MAXLONG, False, XA_ATOM, &type, &format,
+                          &supported_atoms->n_atoms, &bytes_after,
+                          (guchar **)&supported_atoms->atoms);
+
+      if (type != XA_ATOM)
+        return FALSE;
+    }
+
+  if (supported_atoms->atoms == NULL)
+    return FALSE;
+
+  i = 0;
+  while (i < supported_atoms->n_atoms)
+    {
+      if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
+        return TRUE;
+
+      ++i;
+    }
+
+  return FALSE;
+}
+
+void
+_gdk_x11_screen_init_events (GdkScreen *screen)
+{
+  GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
+
+  x11_screen->xsettings_client = _gdk_x11_xsettings_client_new (screen);
+}
+
+/**
+ * gdk_x11_screen_get_window_manager_name:
+ * @screen: (type GdkX11Screen): a #GdkScreen
+ *
+ * Returns the name of the window manager for @screen.
+ *
+ * Return value: the name of the window manager screen @screen, or
+ * "unknown" if the window manager is unknown. The string is owned by GDK
+ * and should not be freed.
+ *
+ * Since: 2.2
+ **/
+const char*
+gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
+{
+  GdkX11Screen *x11_screen;
+  GdkDisplay *display;
+
+  x11_screen = GDK_X11_SCREEN (screen);
+  display = x11_screen->display;
+
+  if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
+    return x11_screen->window_manager_name;
+
+  fetch_net_wm_check_window (screen);
+
+  if (x11_screen->need_refetch_wm_name)
+    {
+      /* Get the name of the window manager */
+      x11_screen->need_refetch_wm_name = FALSE;
+
+      g_free (x11_screen->window_manager_name);
+      x11_screen->window_manager_name = g_strdup ("unknown");
+
+      if (x11_screen->wmspec_check_window != None)
+        {
+          Atom type;
+          gint format;
+          gulong n_items;
+          gulong bytes_after;
+          gchar *name;
+
+          name = NULL;
+
+          gdk_x11_display_error_trap_push (display);
+
+          XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
+                              x11_screen->wmspec_check_window,
+                              gdk_x11_get_xatom_by_name_for_display (display,
+                                                                     "_NET_WM_NAME"),
+                              0, G_MAXLONG, False,
+                              gdk_x11_get_xatom_by_name_for_display (display,
+                                                                     "UTF8_STRING"),
+                              &type, &format,
+                              &n_items, &bytes_after,
+                              (guchar **)&name);
+
+          gdk_x11_display_error_trap_pop_ignored (display);
+
+          if (name != NULL)
+            {
+              g_free (x11_screen->window_manager_name);
+              x11_screen->window_manager_name = g_strdup (name);
+              XFree (name);
+            }
+        }
+    }
+
+  return GDK_X11_SCREEN (screen)->window_manager_name;
+}
+
+static void
+gdk_x11_screen_class_init (GdkX11ScreenClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GdkScreenClass *screen_class = GDK_SCREEN_CLASS (klass);
+
+  object_class->dispose = gdk_x11_screen_dispose;
+  object_class->finalize = gdk_x11_screen_finalize;
+
+  screen_class->get_display = gdk_x11_screen_get_display;
+  screen_class->get_width = gdk_x11_screen_get_width;
+  screen_class->get_height = gdk_x11_screen_get_height;
+  screen_class->get_width_mm = gdk_x11_screen_get_width_mm;
+  screen_class->get_height_mm = gdk_x11_screen_get_height_mm;
+  screen_class->get_number = gdk_x11_screen_get_number;
+  screen_class->get_root_window = gdk_x11_screen_get_root_window;
+  screen_class->get_n_monitors = gdk_x11_screen_get_n_monitors;
+  screen_class->get_primary_monitor = gdk_x11_screen_get_primary_monitor;
+  screen_class->get_monitor_width_mm = gdk_x11_screen_get_monitor_width_mm;
+  screen_class->get_monitor_height_mm = gdk_x11_screen_get_monitor_height_mm;
+  screen_class->get_monitor_plug_name = gdk_x11_screen_get_monitor_plug_name;
+  screen_class->get_monitor_geometry = gdk_x11_screen_get_monitor_geometry;
+  screen_class->get_monitor_workarea = gdk_x11_screen_get_monitor_workarea;
+  screen_class->get_system_visual = _gdk_x11_screen_get_system_visual;
+  screen_class->get_rgba_visual = gdk_x11_screen_get_rgba_visual;
+  screen_class->is_composited = gdk_x11_screen_is_composited;
+  screen_class->make_display_name = gdk_x11_screen_make_display_name;
+  screen_class->get_active_window = gdk_x11_screen_get_active_window;
+  screen_class->get_window_stack = gdk_x11_screen_get_window_stack;
+  screen_class->get_setting = gdk_x11_screen_get_setting;
+  screen_class->visual_get_best_depth = _gdk_x11_screen_visual_get_best_depth;
+  screen_class->visual_get_best_type = _gdk_x11_screen_visual_get_best_type;
+  screen_class->visual_get_best = _gdk_x11_screen_visual_get_best;
+  screen_class->visual_get_best_with_depth = _gdk_x11_screen_visual_get_best_with_depth;
+  screen_class->visual_get_best_with_type = _gdk_x11_screen_visual_get_best_with_type;
+  screen_class->visual_get_best_with_both = _gdk_x11_screen_visual_get_best_with_both;
+  screen_class->query_depths = _gdk_x11_screen_query_depths;
+  screen_class->query_visual_types = _gdk_x11_screen_query_visual_types;
+  screen_class->list_visuals = _gdk_x11_screen_list_visuals;
+
+  signals[WINDOW_MANAGER_CHANGED] =
+    g_signal_new (g_intern_static_string ("window-manager-changed"),
+                  G_OBJECT_CLASS_TYPE (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GdkX11ScreenClass, window_manager_changed),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+}