[mutter/wip/carlosg/input-in-backends: 236/241] clutter: Move X11 input to src/backends/x11



commit 7eb01e1250638b5065c338b9d393c2391f6f4802
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 22 13:53:00 2019 +0100

    clutter: Move X11 input to src/backends/x11
    
    The end goal is to have all clutter backend code in src/backends. Input
    is the larger chunk of it, which is now part of our specific
    MutterClutterBackendX11, this extends to device manager, input devices,
    tools and keymap.
    
    This was supposed to be nice and incremental, but there's no sane way
    to cut this through. As a result of the refactor, a number of private
    Clutter functions are now exported for external backends to be possible.

 clutter/clutter/clutter-backend-private.h          |   1 +
 clutter/clutter/clutter-backend.c                  |   8 -
 clutter/clutter/clutter-device-manager-private.h   |  24 +
 clutter/clutter/clutter-device-manager.c           |   2 +-
 clutter/clutter/clutter-event-private.h            |   5 +
 .../clutter/clutter-input-pointer-a11y-private.h   |   5 +
 clutter/clutter/clutter-mutter.h                   |   7 +-
 clutter/clutter/clutter-private.h                  |   3 +
 clutter/clutter/clutter-stage-private.h            |   7 +
 clutter/clutter/clutter-stage-window.h             |   1 +
 clutter/clutter/meson.build                        |  19 -
 clutter/clutter/x11/clutter-backend-x11.c          | 146 -----
 clutter/clutter/x11/clutter-backend-x11.h          |  21 +-
 clutter/clutter/x11/clutter-device-manager-xi2.h   |  77 ---
 .../clutter/x11/clutter-input-device-tool-xi2.h    |  74 ---
 clutter/clutter/x11/clutter-keymap-x11.h           |  72 ---
 clutter/clutter/x11/clutter-stage-x11.h            | 101 ----
 .../clutter/x11/clutter-virtual-input-device-x11.c | 219 --------
 clutter/clutter/x11/clutter-x11.h                  |  18 -
 src/backends/x11/meta-backend-x11.c                |   6 +-
 src/backends/x11/meta-clutter-backend-x11.c        | 119 ++++-
 .../backends/x11/meta-device-manager-x11.c         | 590 ++++++++-------------
 src/backends/x11/meta-device-manager-x11.h         |  60 +++
 .../backends/x11/meta-event-x11.c                  |  86 +--
 src/backends/x11/meta-event-x11.h                  |  55 ++
 .../backends/x11/meta-input-device-tool-x11.c      |  20 +-
 src/backends/x11/meta-input-device-tool-x11.h      |  51 ++
 .../backends/x11/meta-input-device-x11.c           | 158 +++---
 src/backends/x11/meta-input-device-x11.h           |  73 +++
 .../backends/x11/meta-keymap-x11.c                 | 248 ++++-----
 src/backends/x11/meta-keymap-x11.h                 |  62 +++
 src/backends/x11/meta-stage-x11-nested.c           |  10 +-
 src/backends/x11/meta-stage-x11-nested.h           |   3 +-
 .../backends/x11/meta-stage-x11.c                  | 441 ++++++---------
 src/backends/x11/meta-stage-x11.h                  | 104 ++++
 src/backends/x11/meta-virtual-input-device-x11.c   | 214 ++++++++
 .../backends/x11/meta-virtual-input-device-x11.h   |  20 +-
 .../backends/x11/meta-xkb-a11y-x11.c               |  65 +--
 .../backends/x11/meta-xkb-a11y-x11.h               |  16 +-
 src/compositor/compositor.c                        |  10 +-
 src/compositor/meta-dnd.c                          |   3 +-
 src/core/display.c                                 |   3 +-
 src/meson.build                                    |  17 +
 43 files changed, 1473 insertions(+), 1771 deletions(-)
---
diff --git a/clutter/clutter/clutter-backend-private.h b/clutter/clutter/clutter-backend-private.h
index 26e5e0d51..e836272fe 100644
--- a/clutter/clutter/clutter-backend-private.h
+++ b/clutter/clutter/clutter-backend-private.h
@@ -134,6 +134,7 @@ void                    _clutter_backend_copy_event_data                (Clutter
                                                                          ClutterEvent           *dest);
 void                    _clutter_backend_free_event_data                (ClutterBackend         *backend,
                                                                          ClutterEvent           *event);
+CLUTTER_EXPORT
 gboolean                _clutter_backend_translate_event                (ClutterBackend         *backend,
                                                                          gpointer                native,
                                                                          ClutterEvent           *event);
diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c
index 088ece9e3..caecfd77c 100644
--- a/clutter/clutter/clutter-backend.c
+++ b/clutter/clutter/clutter-backend.c
@@ -529,14 +529,6 @@ clutter_backend_real_init_events (ClutterBackend *backend)
   if (input_backend != NULL)
     input_backend = g_intern_string (input_backend);
 
-#ifdef CLUTTER_INPUT_X11
-  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11) &&
-      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_X11)))
-    {
-      _clutter_backend_x11_events_init (backend);
-    }
-  else
-#endif
 #ifdef CLUTTER_INPUT_EVDEV
   /* Evdev can be used regardless of the windowing system */
   if ((input_backend != NULL && strcmp (input_backend, CLUTTER_INPUT_EVDEV) == 0)
diff --git a/clutter/clutter/clutter-device-manager-private.h 
b/clutter/clutter/clutter-device-manager-private.h
index 86355285a..40a1c7691 100644
--- a/clutter/clutter/clutter-device-manager-private.h
+++ b/clutter/clutter/clutter-device-manager-private.h
@@ -194,11 +194,14 @@ struct _ClutterInputDeviceClass
 };
 
 /* device manager */
+CLUTTER_EXPORT
 void            _clutter_device_manager_add_device              (ClutterDeviceManager *device_manager,
                                                                  ClutterInputDevice   *device);
+CLUTTER_EXPORT
 void            _clutter_device_manager_remove_device           (ClutterDeviceManager *device_manager,
                                                                  ClutterInputDevice   *device);
 void            _clutter_device_manager_update_devices          (ClutterDeviceManager *device_manager);
+CLUTTER_EXPORT
 void            _clutter_device_manager_select_stage_events     (ClutterDeviceManager *device_manager,
                                                                  ClutterStage         *stage);
 ClutterBackend *_clutter_device_manager_get_backend             (ClutterDeviceManager *device_manager);
@@ -208,23 +211,31 @@ void            _clutter_device_manager_compress_motion         (ClutterDeviceMa
                                                                  const ClutterEvent   *to_discard);
 
 /* input device */
+CLUTTER_EXPORT
 gboolean        _clutter_input_device_has_sequence              (ClutterInputDevice   *device,
                                                                  ClutterEventSequence *sequence);
+CLUTTER_EXPORT
 void            _clutter_input_device_add_event_sequence        (ClutterInputDevice   *device,
                                                                  ClutterEvent         *event);
+CLUTTER_EXPORT
 void            _clutter_input_device_remove_event_sequence     (ClutterInputDevice   *device,
                                                                  ClutterEvent         *event);
+CLUTTER_EXPORT
 void            _clutter_input_device_set_coords                (ClutterInputDevice   *device,
                                                                  ClutterEventSequence *sequence,
                                                                  gfloat                x,
                                                                  gfloat                y,
                                                                  ClutterStage         *stage);
+CLUTTER_EXPORT
 void            _clutter_input_device_set_state                 (ClutterInputDevice   *device,
                                                                  ClutterModifierType   state);
+CLUTTER_EXPORT
 void            _clutter_input_device_set_time                  (ClutterInputDevice   *device,
                                                                  guint32               time_);
+CLUTTER_EXPORT
 void            _clutter_input_device_set_stage                 (ClutterInputDevice   *device,
                                                                  ClutterStage         *stage);
+CLUTTER_EXPORT
 ClutterStage *  _clutter_input_device_get_stage                 (ClutterInputDevice   *device);
 void            _clutter_input_device_set_actor                 (ClutterInputDevice   *device,
                                                                  ClutterEventSequence *sequence,
@@ -233,44 +244,57 @@ void            _clutter_input_device_set_actor                 (ClutterInputDev
 ClutterActor *  _clutter_input_device_update                    (ClutterInputDevice   *device,
                                                                  ClutterEventSequence *sequence,
                                                                  gboolean              emit_crossing);
+CLUTTER_EXPORT
 void            _clutter_input_device_set_n_keys                (ClutterInputDevice   *device,
                                                                  guint                 n_keys);
+CLUTTER_EXPORT
 guint           _clutter_input_device_add_axis                  (ClutterInputDevice   *device,
                                                                  ClutterInputAxis      axis,
                                                                  gdouble               min_value,
                                                                  gdouble               max_value,
                                                                  gdouble               resolution);
+CLUTTER_EXPORT
 void            _clutter_input_device_reset_axes                (ClutterInputDevice   *device);
 
+CLUTTER_EXPORT
 void            _clutter_input_device_set_associated_device     (ClutterInputDevice   *device,
                                                                  ClutterInputDevice   *associated);
+CLUTTER_EXPORT
 void            _clutter_input_device_add_slave                 (ClutterInputDevice   *master,
                                                                  ClutterInputDevice   *slave);
+CLUTTER_EXPORT
 void            _clutter_input_device_remove_slave              (ClutterInputDevice   *master,
                                                                  ClutterInputDevice   *slave);
 
+CLUTTER_EXPORT
 gboolean        _clutter_input_device_translate_axis            (ClutterInputDevice   *device,
                                                                  guint                 index_,
                                                                  gdouble               value,
                                                                  gdouble              *axis_value);
 
+CLUTTER_EXPORT
 void            _clutter_input_device_add_scroll_info           (ClutterInputDevice   *device,
                                                                  guint                 index_,
                                                                  ClutterScrollDirection direction,
                                                                  gdouble               increment);
+CLUTTER_EXPORT
 void            _clutter_input_device_reset_scroll_info         (ClutterInputDevice   *device);
+CLUTTER_EXPORT
 gboolean        _clutter_input_device_get_scroll_delta          (ClutterInputDevice   *device,
                                                                  guint                 index_,
                                                                  gdouble               value,
                                                                  ClutterScrollDirection *direction_p,
                                                                  gdouble                *delta_p);
 
+CLUTTER_EXPORT
 ClutterInputDeviceTool * clutter_input_device_lookup_tool       (ClutterInputDevice         *device,
                                                                  guint64                     serial,
                                                                  ClutterInputDeviceToolType  type);
+CLUTTER_EXPORT
 void            clutter_input_device_add_tool                   (ClutterInputDevice     *device,
                                                                  ClutterInputDeviceTool *tool);
 
+CLUTTER_EXPORT
 void            clutter_input_device_update_from_tool           (ClutterInputDevice     *device,
                                                                  ClutterInputDeviceTool *tool);
 
diff --git a/clutter/clutter/clutter-device-manager.c b/clutter/clutter/clutter-device-manager.c
index 5c2b3c338..13edc0cba 100644
--- a/clutter/clutter/clutter-device-manager.c
+++ b/clutter/clutter/clutter-device-manager.c
@@ -322,7 +322,7 @@ clutter_device_manager_get_default (void)
 {
   ClutterBackend *backend = clutter_get_default_backend ();
 
-  return backend->device_manager;
+  return CLUTTER_BACKEND_GET_CLASS (backend)->get_device_manager (backend);
 }
 
 /**
diff --git a/clutter/clutter/clutter-event-private.h b/clutter/clutter/clutter-event-private.h
index 00d627d12..cd840e9a0 100644
--- a/clutter/clutter/clutter-event-private.h
+++ b/clutter/clutter/clutter-event-private.h
@@ -5,6 +5,7 @@
 
 G_BEGIN_DECLS
 
+CLUTTER_EXPORT
 void            _clutter_event_set_pointer_emulated     (ClutterEvent       *event,
                                                          gboolean            is_emulated);
 
@@ -17,10 +18,13 @@ gboolean        _clutter_event_process_filters          (ClutterEvent       *eve
 void            _clutter_clear_events_queue             (void);
 void            _clutter_clear_events_queue_for_stage   (ClutterStage       *stage);
 
+CLUTTER_EXPORT
 void            _clutter_event_set_platform_data        (ClutterEvent       *event,
                                                          gpointer            data);
+CLUTTER_EXPORT
 gpointer        _clutter_event_get_platform_data        (const ClutterEvent *event);
 
+CLUTTER_EXPORT
 void            _clutter_event_set_state_full           (ClutterEvent        *event,
                                                         ClutterModifierType  button_state,
                                                         ClutterModifierType  base_state,
@@ -28,6 +32,7 @@ void            _clutter_event_set_state_full           (ClutterEvent        *ev
                                                         ClutterModifierType  locked_state,
                                                         ClutterModifierType  effective_state);
 
+CLUTTER_EXPORT
 void            _clutter_event_push                     (const ClutterEvent *event,
                                                          gboolean            do_copy);
 
diff --git a/clutter/clutter/clutter-input-pointer-a11y-private.h 
b/clutter/clutter/clutter-input-pointer-a11y-private.h
index 6648909fc..fbbe04101 100644
--- a/clutter/clutter/clutter-input-pointer-a11y-private.h
+++ b/clutter/clutter/clutter-input-pointer-a11y-private.h
@@ -27,14 +27,19 @@
 
 G_BEGIN_DECLS
 
+CLUTTER_EXPORT
 void _clutter_input_pointer_a11y_add_device      (ClutterInputDevice   *device);
+CLUTTER_EXPORT
 void _clutter_input_pointer_a11y_remove_device   (ClutterInputDevice   *device);
+CLUTTER_EXPORT
 void _clutter_input_pointer_a11y_on_motion_event (ClutterInputDevice   *device,
                                                   float                 x,
                                                   float                 y);
+CLUTTER_EXPORT
 void _clutter_input_pointer_a11y_on_button_event (ClutterInputDevice   *device,
                                                   int                   button,
                                                   gboolean              pressed);
+CLUTTER_EXPORT
 gboolean _clutter_is_input_pointer_a11y_enabled  (ClutterInputDevice     *device);
 
 G_END_DECLS
diff --git a/clutter/clutter/clutter-mutter.h b/clutter/clutter/clutter-mutter.h
index a53080457..ca600da94 100644
--- a/clutter/clutter/clutter-mutter.h
+++ b/clutter/clutter/clutter-mutter.h
@@ -26,10 +26,15 @@
 #define __CLUTTER_H_INSIDE__
 
 #include "clutter-backend.h"
+#include "clutter-device-manager-private.h"
+#include "clutter-event-private.h"
+#include "clutter-input-pointer-a11y-private.h"
 #include "clutter-macros.h"
+#include "clutter-private.h"
+#include "clutter-stage-private.h"
 #include "clutter-stage-view.h"
 #include "cogl/clutter-stage-cogl.h"
-#include "x11/clutter-stage-x11.h"
+#include "clutter/x11/clutter-backend-x11.h"
 
 CLUTTER_EXPORT
 void clutter_set_custom_backend_func (ClutterBackend *(* func) (void));
diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h
index 4855f1d57..e5ef16d5b 100644
--- a/clutter/clutter/clutter-private.h
+++ b/clutter/clutter/clutter-private.h
@@ -189,7 +189,9 @@ typedef struct
 gboolean _clutter_threads_dispatch      (gpointer data);
 void     _clutter_threads_dispatch_free (gpointer data);
 
+CLUTTER_EXPORT
 void                    _clutter_threads_acquire_lock                   (void);
+CLUTTER_EXPORT
 void                    _clutter_threads_release_lock                   (void);
 
 ClutterMainContext *    _clutter_context_get_default                    (void);
@@ -302,6 +304,7 @@ gboolean        _clutter_util_matrix_decompose  (const ClutterMatrix *src,
                                                  ClutterVertex       *translate_p,
                                                  ClutterVertex4      *perspective_p);
 
+CLUTTER_EXPORT
 PangoDirection _clutter_pango_unichar_direction (gunichar ch);
 
 PangoDirection _clutter_pango_find_base_dir     (const gchar *text,
diff --git a/clutter/clutter/clutter-stage-private.h b/clutter/clutter/clutter-stage-private.h
index 4799c29e1..e09738068 100644
--- a/clutter/clutter/clutter-stage-private.h
+++ b/clutter/clutter/clutter-stage-private.h
@@ -40,8 +40,10 @@ void                _clutter_stage_paint_view            (ClutterStage
                                                           ClutterStageView            *view,
                                                           const cairo_rectangle_int_t *clip);
 
+CLUTTER_EXPORT
 void                _clutter_stage_set_window            (ClutterStage          *stage,
                                                           ClutterStageWindow    *stage_window);
+CLUTTER_EXPORT
 ClutterStageWindow *_clutter_stage_get_window            (ClutterStage          *stage);
 void                _clutter_stage_get_projection_matrix (ClutterStage          *stage,
                                                           CoglMatrix            *projection);
@@ -63,6 +65,7 @@ void                _clutter_stage_maybe_relayout        (ClutterActor
 gboolean            _clutter_stage_needs_update          (ClutterStage          *stage);
 gboolean            _clutter_stage_do_update             (ClutterStage          *stage);
 
+CLUTTER_EXPORT
 void     _clutter_stage_queue_event                       (ClutterStage *stage,
                                                            ClutterEvent *event,
                                                            gboolean      copy_event);
@@ -115,9 +118,13 @@ ClutterActor *  _clutter_stage_get_touch_drag_actor    (ClutterStage         *st
 void            _clutter_stage_remove_touch_drag_actor (ClutterStage         *stage,
                                                         ClutterEventSequence *sequence);
 
+CLUTTER_EXPORT
 ClutterStageState       _clutter_stage_get_state        (ClutterStage      *stage);
+CLUTTER_EXPORT
 gboolean                _clutter_stage_is_activated     (ClutterStage      *stage);
+CLUTTER_EXPORT
 gboolean                _clutter_stage_is_fullscreen    (ClutterStage      *stage);
+CLUTTER_EXPORT
 gboolean                _clutter_stage_update_state     (ClutterStage      *stage,
                                                          ClutterStageState  unset_state,
                                                          ClutterStageState  set_state);
diff --git a/clutter/clutter/clutter-stage-window.h b/clutter/clutter/clutter-stage-window.h
index 6c3601745..6d8adf0bc 100644
--- a/clutter/clutter/clutter-stage-window.h
+++ b/clutter/clutter/clutter-stage-window.h
@@ -100,6 +100,7 @@ void              _clutter_stage_window_hide                    (ClutterStageWin
 void              _clutter_stage_window_resize                  (ClutterStageWindow *window,
                                                                  gint                width,
                                                                  gint                height);
+CLUTTER_EXPORT
 void              _clutter_stage_window_get_geometry            (ClutterStageWindow *window,
                                                                  cairo_rectangle_int_t *geometry);
 void              _clutter_stage_window_schedule_update         (ClutterStageWindow *window,
diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build
index d3d3285c5..f06fec06d 100644
--- a/clutter/clutter/meson.build
+++ b/clutter/clutter/meson.build
@@ -271,21 +271,9 @@ clutter_backend_private_headers = [
 if have_x11
   clutter_x11_sources = [
     'x11/clutter-backend-x11.c',
-    'x11/clutter-device-manager-xi2.c',
-    'x11/clutter-event-x11.c',
-    'x11/clutter-input-device-tool-xi2.c',
-    'x11/clutter-input-device-xi2.c',
-    'x11/clutter-keymap-x11.c',
-    'x11/clutter-stage-x11.c',
-    'x11/clutter-virtual-input-device-x11.c',
   ]
   clutter_backend_sources += clutter_x11_sources
 
-  clutter_x11_nonintrospected_sources = [
-    'x11/clutter-xkb-a11y-x11.c',
-  ]
-  clutter_backend_nonintrospected_sources += clutter_x11_nonintrospected_sources
-
   clutter_x11_headers = [
     'x11/clutter-x11.h',
   ]
@@ -293,14 +281,7 @@ if have_x11
 
   clutter_x11_private_headers = [
     'x11/clutter-backend-x11.h',
-    'x11/clutter-device-manager-xi2.h',
-    'x11/clutter-input-device-tool-xi2.h',
-    'x11/clutter-input-device-xi2.h',
-    'x11/clutter-keymap-x11.h',
     'x11/clutter-settings-x11.h',
-    'x11/clutter-stage-x11.h',
-    'x11/clutter-virtual-input-device-x11.h',
-    'x11/clutter-xkb-a11y-x11.h',
   ]
   clutter_backend_private_headers += clutter_x11_private_headers
 
diff --git a/clutter/clutter/x11/clutter-backend-x11.c b/clutter/clutter/x11/clutter-backend-x11.c
index b9ea1285b..359e1c17c 100644
--- a/clutter/clutter/x11/clutter-backend-x11.c
+++ b/clutter/clutter/x11/clutter-backend-x11.c
@@ -34,9 +34,7 @@
 #include <errno.h>
 
 #include "clutter-backend-x11.h"
-#include "clutter-device-manager-xi2.h"
 #include "clutter-settings-x11.h"
-#include "clutter-stage-x11.h"
 #include "clutter-x11.h"
 
 #include "xsettings/xsettings-common.h"
@@ -54,7 +52,6 @@
 #include "clutter-main.h"
 #include "clutter-private.h"
 #include "clutter-settings-private.h"
-#include "clutter-xkb-a11y-x11.h"
 
 G_DEFINE_TYPE (ClutterBackendX11, clutter_backend_x11, CLUTTER_TYPE_BACKEND)
 
@@ -229,75 +226,6 @@ clutter_backend_x11_xsettings_notify (const char       *name,
   g_object_thaw_notify (G_OBJECT (settings));
 }
 
-static void
-clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11)
-{
-  ClutterBackend *backend;
-
-  if (clutter_enable_xinput)
-    {
-      int event_base, first_event, first_error;
-
-      if (XQueryExtension (backend_x11->xdpy, "XInputExtension",
-                           &event_base,
-                           &first_event,
-                           &first_error))
-        {
-          int major = 2;
-          int minor = 3;
-
-          if (XIQueryVersion (backend_x11->xdpy, &major, &minor) != BadRequest)
-            {
-              CLUTTER_NOTE (BACKEND, "Creating XI2 device manager");
-              backend_x11->device_manager =
-                g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_XI2,
-                              "backend", backend_x11,
-                              "opcode", event_base,
-                              NULL);
-            }
-        }
-    }
-
-  if (backend_x11->device_manager == NULL)
-    {
-      g_critical ("XI2 extension is missing.");
-    }
-
-  backend = CLUTTER_BACKEND (backend_x11);
-  backend->device_manager = backend_x11->device_manager;
-}
-
-static void
-on_keymap_state_change (ClutterKeymapX11 *keymap_x11,
-                        gpointer          data)
-{
-  ClutterDeviceManager *device_manager = CLUTTER_DEVICE_MANAGER (data);
-  ClutterKbdA11ySettings kbd_a11y_settings;
-
-  /* On keymaps state change, just reapply the current settings, it'll
-   * take care of enabling/disabling mousekeys based on NumLock state.
-   */
-  clutter_device_manager_get_kbd_a11y_settings (device_manager, &kbd_a11y_settings);
-  clutter_device_manager_x11_apply_kbd_a11y_settings (device_manager, &kbd_a11y_settings);
-}
-
-static void
-clutter_backend_x11_create_keymap (ClutterBackendX11 *backend_x11)
-{
-  if (backend_x11->keymap == NULL)
-    {
-      backend_x11->keymap =
-        g_object_new (CLUTTER_TYPE_KEYMAP_X11,
-                      "backend", backend_x11,
-                      NULL);
-
-      g_signal_connect (backend_x11->keymap,
-                        "state-changed",
-                        G_CALLBACK (on_keymap_state_change),
-                        backend_x11->device_manager);
-    }
-}
-
 static gboolean
 clutter_backend_x11_pre_parse (ClutterBackend  *backend,
                                GError         **error)
@@ -446,21 +374,6 @@ clutter_backend_x11_post_parse (ClutterBackend  *backend,
   return TRUE;
 }
 
-void
-_clutter_backend_x11_events_init (ClutterBackend *backend)
-{
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
-
-  CLUTTER_NOTE (EVENT, "initialising the event loop");
-
-  clutter_backend_x11_create_device_manager (backend_x11);
-
-  /* register keymap; unless we create a generic Keymap object, I'm
-   * afraid this will have to stay
-   */
-  clutter_backend_x11_create_keymap (backend_x11);
-}
-
 static const GOptionEntry entries[] =
 {
   {
@@ -582,7 +495,6 @@ clutter_backend_x11_translate_event (ClutterBackend *backend,
 {
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
   XEvent *xevent = native;
-  const GList *l;
 
   /* X11 filter functions have a higher priority */
   if (backend_x11->event_filters != NULL)
@@ -617,20 +529,6 @@ clutter_backend_x11_translate_event (ClutterBackend *backend,
    */
   update_last_event_time (backend_x11, xevent);
 
-  if (clutter_keymap_x11_handle_event (backend_x11->keymap,
-                                       native))
-    return TRUE;
-
-  for (l = clutter_backend_get_stage_windows (backend); l; l = l->next)
-    {
-      if (clutter_stage_x11_translate_event (l->data, native, event))
-        return TRUE;
-    }
-
-  if (clutter_device_manager_xi2_translate_event (CLUTTER_DEVICE_MANAGER_XI2 (backend_x11->device_manager),
-                                                  native, event))
-    return TRUE;
-
   return FALSE;
 }
 
@@ -751,45 +649,6 @@ clutter_backend_x11_get_display (ClutterBackend  *backend,
   return display;
 }
 
-static ClutterStageWindow *
-clutter_backend_x11_create_stage (ClutterBackend  *backend,
-                                 ClutterStage    *wrapper,
-                                 GError         **error)
-{
-  ClutterStageWindow *stage;
-
-  stage = g_object_new (CLUTTER_TYPE_STAGE_X11,
-                       "backend", backend,
-                       "wrapper", wrapper,
-                       NULL);
-
-  CLUTTER_NOTE (BACKEND, "X11 stage created (display:%p, screen:%d, root:%u)",
-                CLUTTER_BACKEND_X11 (backend)->xdpy,
-                CLUTTER_BACKEND_X11 (backend)->xscreen_num,
-                (unsigned int) CLUTTER_BACKEND_X11 (backend)->xwin_root);
-
-  return stage;
-}
-
-static PangoDirection
-clutter_backend_x11_get_keymap_direction (ClutterBackend *backend)
-{
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
-
-  if (G_UNLIKELY (backend_x11->keymap == NULL))
-    return PANGO_DIRECTION_NEUTRAL;
-
-  return _clutter_keymap_x11_get_direction (backend_x11->keymap);
-}
-
-static ClutterKeymap *
-clutter_backend_x11_get_keymap (ClutterBackend *backend)
-{
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
-
-  return CLUTTER_KEYMAP (backend_x11->keymap);
-}
-
 static void
 clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
 {
@@ -799,8 +658,6 @@ clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
   gobject_class->dispose = clutter_backend_x11_dispose;
   gobject_class->finalize = clutter_backend_x11_finalize;
 
-  backend_class->create_stage = clutter_backend_x11_create_stage;
-
   backend_class->pre_parse = clutter_backend_x11_pre_parse;
   backend_class->post_parse = clutter_backend_x11_post_parse;
   backend_class->add_options = clutter_backend_x11_add_options;
@@ -810,9 +667,6 @@ clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
 
   backend_class->get_renderer = clutter_backend_x11_get_renderer;
   backend_class->get_display = clutter_backend_x11_get_display;
-
-  backend_class->get_keymap_direction = clutter_backend_x11_get_keymap_direction;
-  backend_class->get_keymap = clutter_backend_x11_get_keymap;
 }
 
 static void
diff --git a/clutter/clutter/x11/clutter-backend-x11.h b/clutter/clutter/x11/clutter-backend-x11.h
index 7b6c22502..c5c69dced 100644
--- a/clutter/clutter/x11/clutter-backend-x11.h
+++ b/clutter/clutter/x11/clutter-backend-x11.h
@@ -30,7 +30,6 @@
 #include "clutter-x11.h"
 
 #include "clutter-backend-private.h"
-#include "clutter-keymap-x11.h"
 
 #include "xsettings/xsettings-client.h"
 
@@ -45,7 +44,6 @@ G_BEGIN_DECLS
 
 typedef struct _ClutterBackendX11       ClutterBackendX11;
 typedef struct _ClutterBackendX11Class  ClutterBackendX11Class;
-typedef struct _ClutterEventX11         ClutterEventX11;
 typedef struct _ClutterX11EventFilter   ClutterX11EventFilter;
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBackendX11, g_object_unref)
@@ -57,16 +55,6 @@ struct _ClutterX11EventFilter
 
 };
 
-struct _ClutterEventX11
-{
-  /* additional fields for Key events */
-  gint key_group;
-
-  guint key_is_modifier : 1;
-  guint num_lock_set    : 1;
-  guint caps_lock_set   : 1;
-};
-
 struct _ClutterBackendX11
 {
   ClutterBackend parent_instance;
@@ -105,8 +93,6 @@ struct _ClutterBackendX11
 
   XSettingsClient *xsettings;
   Window xsettings_xwin;
-
-  ClutterKeymapX11 *keymap;
 };
 
 struct _ClutterBackendX11Class
@@ -119,17 +105,12 @@ GType clutter_backend_x11_get_type (void) G_GNUC_CONST;
 
 ClutterBackend *clutter_backend_x11_new (void);
 
-void            _clutter_backend_x11_events_init        (ClutterBackend *backend);
-
 /* Private to glx/eglx backends */
+CLUTTER_EXPORT
 XVisualInfo *   _clutter_backend_x11_get_visual_info (ClutterBackendX11 *backend_x11);
 
 void            _clutter_x11_select_events (Window xwin);
 
-ClutterEventX11 *       _clutter_event_x11_new          (void);
-ClutterEventX11 *       _clutter_event_x11_copy         (ClutterEventX11 *event_x11);
-void                    _clutter_event_x11_free         (ClutterEventX11 *event_x11);
-
 gboolean        _clutter_x11_input_device_translate_screen_coord (ClutterInputDevice *device,
                                                                   gint                stage_root_x,
                                                                   gint                stage_root_y,
diff --git a/clutter/clutter/x11/clutter-x11.h b/clutter/clutter/x11/clutter-x11.h
index b59da81a2..a7de5044b 100644
--- a/clutter/clutter/x11/clutter-x11.h
+++ b/clutter/clutter/x11/clutter-x11.h
@@ -104,9 +104,6 @@ XVisualInfo *clutter_x11_get_visual_info (void);
 CLUTTER_EXPORT
 void     clutter_x11_set_display         (Display * xdpy);
 
-CLUTTER_EXPORT
-Window       clutter_x11_get_stage_window  (ClutterStage *stage);
-
 CLUTTER_EXPORT
 void         clutter_x11_add_filter    (ClutterX11FilterFunc func,
                                         gpointer             data);
@@ -114,12 +111,6 @@ CLUTTER_EXPORT
 void         clutter_x11_remove_filter (ClutterX11FilterFunc func,
                                         gpointer             data);
 
-CLUTTER_EXPORT
-ClutterX11FilterReturn clutter_x11_handle_event (XEvent *xevent);
-
-CLUTTER_EXPORT
-ClutterStage *clutter_x11_get_stage_from_window (Window win);
-
 CLUTTER_EXPORT
 gboolean clutter_x11_has_composite_extension (void);
 
@@ -133,15 +124,6 @@ void     clutter_x11_set_use_stereo_stage (gboolean use_stereo);
 CLUTTER_EXPORT
 gboolean clutter_x11_get_use_stereo_stage (void);
 
-CLUTTER_EXPORT
-Time clutter_x11_get_current_event_time (void);
-
-CLUTTER_EXPORT
-gint clutter_x11_event_get_key_group (const ClutterEvent *event);
-
-CLUTTER_EXPORT
-guint clutter_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence);
-
 G_END_DECLS
 
 #endif /* __CLUTTER_X11_H__ */
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 41fa643f7..99488f8ef 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -46,6 +46,8 @@
 #include "backends/meta-idle-monitor-private.h"
 #include "backends/meta-stage-private.h"
 #include "backends/x11/meta-clutter-backend-x11.h"
+#include "backends/x11/meta-event-x11.h"
+#include "backends/x11/meta-stage-x11.h"
 #include "backends/x11/meta-renderer-x11.h"
 #include "clutter/clutter.h"
 #include "clutter/x11/clutter-x11.h"
@@ -385,7 +387,7 @@ handle_host_xevent (MetaBackend *backend,
   if (!bypass_clutter)
     {
       handle_input_event (x11, event);
-      clutter_x11_handle_event (event);
+      meta_x11_handle_event (event);
     }
 
   XFreeEventData (priv->xdisplay, &event->xcookie);
@@ -804,7 +806,7 @@ Window
 meta_backend_x11_get_xwindow (MetaBackendX11 *x11)
 {
   ClutterActor *stage = meta_backend_get_stage (META_BACKEND (x11));
-  return clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
+  return meta_x11_get_stage_window (CLUTTER_STAGE (stage));
 }
 
 void
diff --git a/src/backends/x11/meta-clutter-backend-x11.c b/src/backends/x11/meta-clutter-backend-x11.c
index 7732276ad..0c6e082c9 100644
--- a/src/backends/x11/meta-clutter-backend-x11.c
+++ b/src/backends/x11/meta-clutter-backend-x11.c
@@ -29,7 +29,10 @@
 #include "backends/meta-backend-private.h"
 #include "backends/meta-renderer.h"
 #include "backends/x11/meta-clutter-backend-x11.h"
+#include "backends/x11/meta-device-manager-x11.h"
+#include "backends/x11/meta-keymap-x11.h"
 #include "backends/x11/meta-stage-x11-nested.h"
+#include "backends/x11/meta-xkb-a11y-x11.h"
 #include "clutter/clutter-mutter.h"
 #include "clutter/clutter.h"
 #include "core/bell.h"
@@ -38,6 +41,8 @@
 struct _MetaClutterBackendX11
 {
   ClutterBackendX11 parent;
+  MetaKeymapX11 *keymap;
+  MetaDeviceManagerX11 *device_manager;
 };
 
 G_DEFINE_TYPE (MetaClutterBackendX11, meta_clutter_backend_x11,
@@ -64,7 +69,7 @@ meta_clutter_backend_x11_create_stage (ClutterBackend  *backend,
   if (meta_is_wayland_compositor ())
     stage_type = META_TYPE_STAGE_X11_NESTED;
   else
-    stage_type  = CLUTTER_TYPE_STAGE_X11;
+    stage_type  = META_TYPE_STAGE_X11;
 
   stage = g_object_new (stage_type,
                        "backend", backend,
@@ -81,6 +86,113 @@ meta_clutter_backend_x11_bell_notify (ClutterBackend  *backend)
   meta_bell_notify (display, NULL);
 }
 
+static ClutterDeviceManager *
+meta_clutter_backend_x11_get_device_manager (ClutterBackend *backend)
+{
+  MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
+
+  return CLUTTER_DEVICE_MANAGER (backend_x11->device_manager);
+}
+
+static PangoDirection
+meta_clutter_backend_x11_get_keymap_direction (ClutterBackend *backend)
+{
+  ClutterKeymap *keymap = clutter_backend_get_keymap (backend);
+
+  if (G_UNLIKELY (keymap == NULL))
+    return PANGO_DIRECTION_NEUTRAL;
+
+  return meta_keymap_x11_get_direction (META_KEYMAP_X11 (keymap));
+}
+
+static ClutterKeymap *
+meta_clutter_backend_x11_get_keymap (ClutterBackend *backend)
+{
+  MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
+
+  return CLUTTER_KEYMAP (backend_x11->keymap);
+}
+
+static gboolean
+meta_clutter_backend_x11_translate_event (ClutterBackend *backend,
+                                          gpointer        native,
+                                          ClutterEvent   *event)
+{
+  MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
+  const GList *l;
+
+  if (CLUTTER_BACKEND_CLASS (meta_clutter_backend_x11_parent_class)->translate_event (backend, native, 
event))
+    return TRUE;
+
+  if (meta_keymap_x11_handle_event (backend_x11->keymap, native))
+    return TRUE;
+
+  for (l = clutter_backend_get_stage_windows (backend); l; l = l->next)
+    {
+      if (meta_stage_x11_translate_event (l->data, native, event))
+        return TRUE;
+    }
+
+  if (meta_device_manager_x11_translate_event (META_DEVICE_MANAGER_X11 (backend_x11->device_manager),
+                                               native, event))
+    return TRUE;
+
+  return FALSE;
+}
+
+static void
+on_keymap_state_change (MetaKeymapX11 *keymap_x11,
+                        gpointer          data)
+{
+  ClutterDeviceManager *device_manager = CLUTTER_DEVICE_MANAGER (data);
+  ClutterKbdA11ySettings kbd_a11y_settings;
+
+  /* On keymaps state change, just reapply the current settings, it'll
+   * take care of enabling/disabling mousekeys based on NumLock state.
+   */
+  clutter_device_manager_get_kbd_a11y_settings (device_manager, &kbd_a11y_settings);
+  meta_device_manager_x11_apply_kbd_a11y_settings (device_manager, &kbd_a11y_settings);
+}
+
+
+static void
+meta_clutter_backend_x11_init_events (ClutterBackend *backend)
+{
+  MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
+  int event_base, first_event, first_error;
+
+  if (XQueryExtension (clutter_x11_get_default_display (),
+                       "XInputExtension",
+                       &event_base,
+                       &first_event,
+                       &first_error))
+    {
+      int major = 2;
+      int minor = 3;
+
+      if (XIQueryVersion (clutter_x11_get_default_display (),
+                          &major, &minor) != BadRequest)
+        {
+          backend_x11->device_manager =
+            g_object_new (META_TYPE_DEVICE_MANAGER_X11,
+                          "backend", backend_x11,
+                          "opcode", event_base,
+                          NULL);
+        }
+    }
+
+  if (!backend_x11->device_manager)
+    g_error ("No XInput 2.3 support");
+
+  backend_x11->keymap = g_object_new (META_TYPE_KEYMAP_X11,
+                                      "backend", backend_x11,
+                                      NULL);
+  g_signal_connect (backend_x11->keymap,
+                    "state-changed",
+                    G_CALLBACK (on_keymap_state_change),
+                    backend_x11->device_manager);
+}
+
 static void
 meta_clutter_backend_x11_init (MetaClutterBackendX11 *clutter_backend_x11)
 {
@@ -94,4 +206,9 @@ meta_clutter_backend_x11_class_init (MetaClutterBackendX11Class *klass)
   clutter_backend_class->get_renderer = meta_clutter_backend_x11_get_renderer;
   clutter_backend_class->create_stage = meta_clutter_backend_x11_create_stage;
   clutter_backend_class->bell_notify = meta_clutter_backend_x11_bell_notify;
+  clutter_backend_class->get_device_manager = meta_clutter_backend_x11_get_device_manager;
+  clutter_backend_class->get_keymap_direction = meta_clutter_backend_x11_get_keymap_direction;
+  clutter_backend_class->get_keymap = meta_clutter_backend_x11_get_keymap;
+  clutter_backend_class->translate_event = meta_clutter_backend_x11_translate_event;
+  clutter_backend_class->init_events = meta_clutter_backend_x11_init_events;
 }
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c b/src/backends/x11/meta-device-manager-x11.c
similarity index 72%
rename from clutter/clutter/x11/clutter-device-manager-xi2.c
rename to src/backends/x11/meta-device-manager-x11.c
index 5128a16b2..a9f466f2d 100644
--- a/clutter/clutter/x11/clutter-device-manager-xi2.c
+++ b/src/backends/x11/meta-device-manager-x11.c
@@ -1,8 +1,4 @@
 /*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
  * Copyright © 2011  Intel Corp.
  *
  * This library is free software; you can redistribute it and/or
@@ -21,29 +17,25 @@
  * Author: Emmanuele Bassi <ebassi linux intel com>
  */
 
-#include "clutter-build-config.h"
+#include "config.h"
 
 #include <stdint.h>
-
-#include "clutter-device-manager-xi2.h"
-
-#include "clutter-backend-x11.h"
-#include "clutter-input-device-xi2.h"
-#include "clutter-input-device-tool-xi2.h"
-#include "clutter-input-pointer-a11y-private.h"
-#include "clutter-virtual-input-device-x11.h"
-#include "clutter-stage-x11.h"
-
-#include "clutter-backend.h"
-#include "clutter-debug.h"
-#include "clutter-device-manager-private.h"
-#include "clutter-event-private.h"
-#include "clutter-stage-private.h"
-#include "clutter-private.h"
-#include "clutter-xkb-a11y-x11.h"
-
+#include <clutter/clutter-mutter.h>
+#include <clutter/x11/clutter-x11.h>
 #include <X11/extensions/XInput2.h>
 
+#include "backends/x11/meta-backend-x11.h"
+#include "backends/x11/meta-device-manager-x11.h"
+#include "backends/x11/meta-event-x11.h"
+#include "backends/x11/meta-input-device-x11.h"
+#include "backends/x11/meta-input-device-tool-x11.h"
+#include "backends/x11/meta-keymap-x11.h"
+#include "backends/x11/meta-stage-x11.h"
+#include "backends/x11/meta-virtual-input-device-x11.h"
+#include "backends/x11/meta-xkb-a11y-x11.h"
+#include "core/display-private.h"
+#include "meta/meta-x11-errors.h"
+
 enum
 {
   PROP_0,
@@ -96,33 +88,31 @@ enum
 
 static Atom clutter_input_axis_atoms[N_AXIS_ATOMS] = { 0, };
 
-#define clutter_device_manager_xi2_get_type     _clutter_device_manager_xi2_get_type
-
-G_DEFINE_TYPE (ClutterDeviceManagerXI2,
-               clutter_device_manager_xi2,
+G_DEFINE_TYPE (MetaDeviceManagerX11,
+               meta_device_manager_x11,
                CLUTTER_TYPE_DEVICE_MANAGER)
 
 static void
-clutter_device_manager_xi2_copy_event_data (ClutterDeviceManager *device_manager,
-                                            const ClutterEvent   *src,
-                                            ClutterEvent         *dest)
+meta_device_manager_x11_copy_event_data (ClutterDeviceManager *device_manager,
+                                         const ClutterEvent   *src,
+                                         ClutterEvent         *dest)
 {
   gpointer event_x11;
 
   event_x11 = _clutter_event_get_platform_data (src);
   if (event_x11 != NULL)
-    _clutter_event_set_platform_data (dest, _clutter_event_x11_copy (event_x11));
+    _clutter_event_set_platform_data (dest, meta_event_x11_copy (event_x11));
 }
 
 static void
-clutter_device_manager_xi2_free_event_data (ClutterDeviceManager *device_manager,
-                                            ClutterEvent         *event)
+meta_device_manager_x11_free_event_data (ClutterDeviceManager *device_manager,
+                                         ClutterEvent         *event)
 {
   gpointer event_x11;
 
   event_x11 = _clutter_event_get_platform_data (event);
   if (event_x11 != NULL)
-    _clutter_event_x11_free (event_x11);
+    meta_event_x11_free (event_x11);
 }
 
 static void
@@ -158,14 +148,6 @@ translate_valuator_class (Display             *xdisplay,
                                   class->min,
                                   class->max,
                                   class->resolution);
-
-  CLUTTER_NOTE (BACKEND,
-                "Added axis '%s' (min:%.2f, max:%.2fd, res:%d) of device %d",
-                clutter_input_axis_atom_names[axis],
-                class->min,
-                class->max,
-                class->resolution,
-                device->id);
 }
 
 static void
@@ -214,13 +196,6 @@ translate_device_classes (Display             *xdisplay,
             else
               direction = CLUTTER_SCROLL_RIGHT;
 
-            CLUTTER_NOTE (BACKEND, "Scroll valuator %d: %s, increment: %f",
-                          scroll_info->number,
-                          scroll_info->scroll_type == XIScrollTypeVertical
-                            ? "vertical"
-                            : "horizontal",
-                          scroll_info->increment);
-
             _clutter_input_device_add_scroll_info (device,
                                                    scroll_info->number,
                                                    direction,
@@ -268,8 +243,7 @@ is_touch_device (XIAnyClassInfo         **classes,
 }
 
 static gboolean
-is_touchpad_device (ClutterBackendX11 *backend_x11,
-                    XIDeviceInfo      *info)
+is_touchpad_device (XIDeviceInfo *info)
 {
   gulong nitems, bytes_after;
   guint32 *data = NULL;
@@ -277,12 +251,12 @@ is_touchpad_device (ClutterBackendX11 *backend_x11,
   Atom type;
   Atom prop;
 
-  prop = XInternAtom (backend_x11->xdpy, "libinput Tapping Enabled", True);
+  prop = XInternAtom (clutter_x11_get_default_display (), "libinput Tapping Enabled", True);
   if (prop == None)
     return FALSE;
 
   clutter_x11_trap_x_errors ();
-  rc = XIGetProperty (backend_x11->xdpy,
+  rc = XIGetProperty (clutter_x11_get_default_display (),
                       info->deviceid,
                       prop,
                       0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
@@ -299,10 +273,9 @@ is_touchpad_device (ClutterBackendX11 *backend_x11,
 }
 
 static gboolean
-get_device_ids (ClutterBackendX11  *backend_x11,
-                XIDeviceInfo       *info,
-                gchar             **vendor_id,
-                gchar             **product_id)
+get_device_ids (XIDeviceInfo  *info,
+                gchar        **vendor_id,
+                gchar        **product_id)
 {
   gulong nitems, bytes_after;
   guint32 *data = NULL;
@@ -310,9 +283,9 @@ get_device_ids (ClutterBackendX11  *backend_x11,
   Atom type;
 
   clutter_x11_trap_x_errors ();
-  rc = XIGetProperty (backend_x11->xdpy,
+  rc = XIGetProperty (clutter_x11_get_default_display (),
                       info->deviceid,
-                      XInternAtom (backend_x11->xdpy, "Device Product ID", False),
+                      XInternAtom (clutter_x11_get_default_display (), "Device Product ID", False),
                       0, 2, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
                       (guchar **) &data);
   clutter_x11_untrap_x_errors ();
@@ -334,8 +307,7 @@ get_device_ids (ClutterBackendX11  *backend_x11,
 }
 
 static gchar *
-get_device_node_path (ClutterBackendX11  *backend_x11,
-                      XIDeviceInfo       *info)
+get_device_node_path (XIDeviceInfo *info)
 {
   gulong nitems, bytes_after;
   guchar *data;
@@ -343,13 +315,13 @@ get_device_node_path (ClutterBackendX11  *backend_x11,
   Atom prop, type;
   gchar *node_path;
 
-  prop = XInternAtom (backend_x11->xdpy, "Device Node", False);
+  prop = XInternAtom (clutter_x11_get_default_display (), "Device Node", False);
   if (prop == None)
     return NULL;
 
   clutter_x11_trap_x_errors ();
 
-  rc = XIGetProperty (backend_x11->xdpy,
+  rc = XIGetProperty (clutter_x11_get_default_display (),
                       info->deviceid, prop, 0, 1024, False,
                       XA_STRING, &type, &format, &nitems, &bytes_after,
                       (guchar **) &data);
@@ -402,8 +374,7 @@ get_pad_features (XIDeviceInfo *info,
 /* The Wacom driver exports the tool type as property. Use that over
    guessing based on the device name */
 static gboolean
-guess_source_from_wacom_type (ClutterBackendX11       *backend_x11,
-                              XIDeviceInfo            *info,
+guess_source_from_wacom_type (XIDeviceInfo            *info,
                               ClutterInputDeviceType  *source_out)
 {
   gulong nitems, bytes_after;
@@ -414,19 +385,18 @@ guess_source_from_wacom_type (ClutterBackendX11       *backend_x11,
   Atom device_type;
   Atom types[N_WACOM_TYPE_ATOMS];
 
-  prop = XInternAtom (backend_x11->xdpy, "Wacom Tool Type", True);
+  prop = XInternAtom (clutter_x11_get_default_display (), "Wacom Tool Type", True);
   if (prop == None)
     return FALSE;
 
   clutter_x11_trap_x_errors ();
-  rc = XIGetProperty (backend_x11->xdpy,
+  rc = XIGetProperty (clutter_x11_get_default_display (),
                       info->deviceid,
                       prop,
                       0, 1, False, XA_ATOM, &type, &format, &nitems, &bytes_after,
                       (guchar **) &data);
   clutter_x11_untrap_x_errors ();
 
-
   if (rc != Success || type != XA_ATOM || format != 32 || nitems != 1)
     {
       XFree (data);
@@ -439,7 +409,7 @@ guess_source_from_wacom_type (ClutterBackendX11       *backend_x11,
   if (device_type == 0)
       return FALSE;
 
-  rc = XInternAtoms (backend_x11->xdpy,
+  rc = XInternAtoms (clutter_x11_get_default_display (),
                      (char **)wacom_type_atoms,
                      N_WACOM_TYPE_ATOMS,
                      False,
@@ -480,9 +450,9 @@ guess_source_from_wacom_type (ClutterBackendX11       *backend_x11,
 }
 
 static ClutterInputDevice *
-create_device (ClutterDeviceManagerXI2 *manager_xi2,
-               ClutterBackendX11       *backend_x11,
-               XIDeviceInfo            *info)
+create_device (MetaDeviceManagerX11 *manager_xi2,
+               ClutterBackend       *backend,
+               XIDeviceInfo         *info)
 {
   ClutterInputDeviceType source, touch_source;
   ClutterInputDevice *retval;
@@ -495,7 +465,7 @@ create_device (ClutterDeviceManagerXI2 *manager_xi2,
     {
       source = CLUTTER_KEYBOARD_DEVICE;
     }
-  else if (is_touchpad_device (backend_x11, info))
+  else if (is_touchpad_device (info))
     {
       source = CLUTTER_TOUCHPAD_DEVICE;
     }
@@ -506,7 +476,7 @@ create_device (ClutterDeviceManagerXI2 *manager_xi2,
     {
       source = touch_source;
     }
-  else if (!guess_source_from_wacom_type (backend_x11, info, &source))
+  else if (!guess_source_from_wacom_type (info, &source))
     {
       gchar *name;
 
@@ -552,8 +522,8 @@ create_device (ClutterDeviceManagerXI2 *manager_xi2,
   if (info->use != XIMasterKeyboard &&
       info->use != XIMasterPointer)
     {
-      get_device_ids (backend_x11, info, &vendor_id, &product_id);
-      node_path = get_device_node_path (backend_x11, info);
+      get_device_ids (info, &vendor_id, &product_id);
+      node_path = get_device_node_path (info);
     }
 
   if (source == CLUTTER_PAD_DEVICE)
@@ -562,14 +532,14 @@ create_device (ClutterDeviceManagerXI2 *manager_xi2,
       get_pad_features (info, &num_rings, &num_strips);
     }
 
-  retval = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_XI2,
+  retval = g_object_new (META_TYPE_INPUT_DEVICE_X11,
                          "name", info->name,
                          "id", info->deviceid,
                          "has-cursor", (info->use == XIMasterPointer),
                          "device-manager", manager_xi2,
                          "device-type", source,
                          "device-mode", mode,
-                         "backend", backend_x11,
+                         "backend", backend,
                          "enabled", is_enabled,
                          "vendor-id", vendor_id,
                          "product-id", product_id,
@@ -579,24 +549,19 @@ create_device (ClutterDeviceManagerXI2 *manager_xi2,
                          "n-mode-groups", MAX (num_rings, num_strips),
                          NULL);
 
-  translate_device_classes (backend_x11->xdpy, retval,
+  translate_device_classes (clutter_x11_get_default_display (), retval,
                             info->classes,
                             info->num_classes);
 
 #ifdef HAVE_LIBWACOM
   if (source == CLUTTER_PAD_DEVICE)
-    clutter_input_device_xi2_ensure_wacom_info (retval, manager_xi2->wacom_db);
+    meta_input_device_x11_ensure_wacom_info (retval, manager_xi2->wacom_db);
 #endif
 
   g_free (vendor_id);
   g_free (product_id);
   g_free (node_path);
 
-  CLUTTER_NOTE (BACKEND, "Created device '%s' (id: %d, has-cursor: %s)",
-                info->name,
-                info->deviceid,
-                info->use == XIMasterPointer ? "yes" : "no");
-
   return retval;
 }
 
@@ -641,14 +606,14 @@ pad_passive_button_grab (ClutterInputDevice *device)
 }
 
 static ClutterInputDevice *
-add_device (ClutterDeviceManagerXI2 *manager_xi2,
-            ClutterBackendX11       *backend_x11,
-            XIDeviceInfo            *info,
-            gboolean                 in_construction)
+add_device (MetaDeviceManagerX11 *manager_xi2,
+            ClutterBackend       *backend,
+            XIDeviceInfo         *info,
+            gboolean              in_construction)
 {
   ClutterInputDevice *device;
 
-  device = create_device (manager_xi2, backend_x11, info);
+  device = create_device (manager_xi2, backend, info);
 
   /* we don't go through the DeviceManager::add_device() vfunc because
    * that emits the signal, and we only do it conditionally
@@ -703,8 +668,8 @@ add_device (ClutterDeviceManagerXI2 *manager_xi2,
 }
 
 static void
-remove_device (ClutterDeviceManagerXI2 *manager_xi2,
-               gint                     device_id)
+remove_device (MetaDeviceManagerX11 *manager_xi2,
+               gint                  device_id)
 {
   ClutterInputDevice *device;
 
@@ -732,9 +697,9 @@ remove_device (ClutterDeviceManagerXI2 *manager_xi2,
 }
 
 static void
-translate_hierarchy_event (ClutterBackendX11       *backend_x11,
-                           ClutterDeviceManagerXI2 *manager_xi2,
-                           XIHierarchyEvent        *ev)
+translate_hierarchy_event (ClutterBackend       *backend,
+                           MetaDeviceManagerX11 *manager_xi2,
+                           XIHierarchyEvent     *ev)
 {
   int i;
 
@@ -747,23 +712,19 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
           XIDeviceInfo *info;
           int n_devices;
 
-          CLUTTER_NOTE (EVENT, "Hierarchy event: device enabled");
-
           clutter_x11_trap_x_errors ();
-          info = XIQueryDevice (backend_x11->xdpy,
+          info = XIQueryDevice (clutter_x11_get_default_display (),
                                 ev->info[i].deviceid,
                                 &n_devices);
           clutter_x11_untrap_x_errors ();
           if (info != NULL)
             {
-              add_device (manager_xi2, backend_x11, &info[0], FALSE);
+              add_device (manager_xi2, backend, &info[0], FALSE);
               XIFreeDeviceInfo (info);
             }
         }
       else if (ev->info[i].flags & XIDeviceDisabled)
         {
-          CLUTTER_NOTE (EVENT, "Hierarchy event: device disabled");
-
           remove_device (manager_xi2, ev->info[i].deviceid);
         }
       else if ((ev->info[i].flags & XISlaveAttached) ||
@@ -774,11 +735,6 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
           int n_devices;
           gboolean send_changed = FALSE;
 
-          CLUTTER_NOTE (EVENT, "Hierarchy event: slave %s",
-                        (ev->info[i].flags & XISlaveAttached)
-                          ? "attached"
-                          : "detached");
-
           slave = g_hash_table_lookup (manager_xi2->devices_by_id,
                                        GINT_TO_POINTER (ev->info[i].deviceid));
           master = clutter_input_device_get_associated_device (slave);
@@ -796,7 +752,7 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
           if (ev->info[i].flags & XISlaveAttached)
             {
               clutter_x11_trap_x_errors ();
-              info = XIQueryDevice (backend_x11->xdpy,
+              info = XIQueryDevice (clutter_x11_get_default_display (),
                                     ev->info[i].deviceid,
                                     &n_devices);
               clutter_x11_untrap_x_errors ();
@@ -819,18 +775,20 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
             {
               ClutterStage *stage = _clutter_input_device_get_stage (master);
               if (stage != NULL)
-                _clutter_stage_x11_events_device_changed (CLUTTER_STAGE_X11 (_clutter_stage_get_window 
(stage)), 
-                                                          master,
-                                                          CLUTTER_DEVICE_MANAGER (manager_xi2));
+               {
+                 meta_stage_x11_events_device_changed (META_STAGE_X11 (_clutter_stage_get_window (stage)),
+                                                       master,
+                                                       CLUTTER_DEVICE_MANAGER (manager_xi2));
+               }
             }
         }
     }
 }
 
 static void
-clutter_device_manager_xi2_select_events (ClutterDeviceManager *manager,
-                                          Window                xwindow,
-                                          XIEventMask          *event_mask)
+meta_device_manager_x11_select_events (ClutterDeviceManager *manager,
+                                       Window                xwindow,
+                                       XIEventMask          *event_mask)
 {
   Display *xdisplay;
 
@@ -840,8 +798,8 @@ clutter_device_manager_xi2_select_events (ClutterDeviceManager *manager,
 }
 
 static ClutterStage *
-get_event_stage (ClutterDeviceManagerXI2 *manager_xi2,
-                 XIEvent                 *xi_event)
+get_event_stage (MetaDeviceManagerX11 *manager_xi2,
+                 XIEvent              *xi_event)
 {
   Window xwindow = None;
 
@@ -880,7 +838,7 @@ get_event_stage (ClutterDeviceManagerXI2 *manager_xi2,
   if (xwindow == None)
     return NULL;
 
-  return clutter_x11_get_stage_from_window (xwindow);
+  return meta_x11_get_stage_from_window (xwindow);
 }
 
 /*
@@ -1030,11 +988,11 @@ translate_pad_axis (ClutterInputDevice *device,
 }
 
 static void
-translate_coords (ClutterStageX11 *stage_x11,
-                  gdouble          event_x,
-                  gdouble          event_y,
-                  gfloat          *x_out,
-                  gfloat          *y_out)
+translate_coords (MetaStageX11 *stage_x11,
+                  gdouble       event_x,
+                  gdouble       event_y,
+                  gfloat       *x_out,
+                  gfloat       *y_out)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterActor *stage = CLUTTER_ACTOR (stage_cogl->wrapper);
@@ -1093,17 +1051,15 @@ scroll_valuators_changed (ClutterInputDevice *device,
 }
 
 static void
-clutter_device_manager_xi2_select_stage_events (ClutterDeviceManager *manager,
-                                                ClutterStage         *stage)
+meta_device_manager_x11_select_stage_events (ClutterDeviceManager *manager,
+                                             ClutterStage         *stage)
 {
-  ClutterBackendX11 *backend_x11;
-  ClutterStageX11 *stage_x11;
+  MetaStageX11 *stage_x11;
   XIEventMask xi_event_mask;
   unsigned char *mask;
   int len;
 
-  backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
-  stage_x11 = CLUTTER_STAGE_X11 (_clutter_stage_get_window (stage));
+  stage_x11 = META_STAGE_X11 (_clutter_stage_get_window (stage));
 
   len = XIMaskLen (XI_LASTEVENT);
   mask = g_new0 (unsigned char, len);
@@ -1124,14 +1080,14 @@ clutter_device_manager_xi2_select_stage_events (ClutterDeviceManager *manager,
   xi_event_mask.mask = mask;
   xi_event_mask.mask_len = len;
 
-  XISelectEvents (backend_x11->xdpy, stage_x11->xwin, &xi_event_mask, 1);
+  XISelectEvents (clutter_x11_get_default_display (),
+                  stage_x11->xwin, &xi_event_mask, 1);
 
   g_free (mask);
 }
 
 static guint
-device_get_tool_serial (ClutterBackendX11  *backend_x11,
-                        ClutterInputDevice *device)
+device_get_tool_serial (ClutterInputDevice *device)
 {
   gulong nitems, bytes_after;
   guint32 *data = NULL;
@@ -1140,12 +1096,12 @@ device_get_tool_serial (ClutterBackendX11  *backend_x11,
   Atom type;
   Atom prop;
 
-  prop = XInternAtom (backend_x11->xdpy, "Wacom Serial IDs", True);
+  prop = XInternAtom (clutter_x11_get_default_display (), "Wacom Serial IDs", True);
   if (prop == None)
     return 0;
 
   clutter_x11_trap_x_errors ();
-  rc = XIGetProperty (backend_x11->xdpy,
+  rc = XIGetProperty (clutter_x11_get_default_display (),
                       clutter_input_device_get_device_id (device),
                       prop, 0, 4, FALSE, XA_INTEGER, &type, &format, &nitems, &bytes_after,
                       (guchar **) &data);
@@ -1160,12 +1116,11 @@ device_get_tool_serial (ClutterBackendX11  *backend_x11,
 }
 
 static void
-handle_property_event (ClutterDeviceManagerXI2 *manager_xi2,
-                       XIEvent                 *event)
+handle_property_event (MetaDeviceManagerX11 *manager_xi2,
+                       XIEvent              *event)
 {
   XIPropertyEvent *xev = (XIPropertyEvent *) event;
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
-  Atom serial_ids_prop = XInternAtom (backend_x11->xdpy, "Wacom Serial IDs", True);
+  Atom serial_ids_prop = XInternAtom (clutter_x11_get_default_display (), "Wacom Serial IDs", True);
   ClutterInputDevice *device;
 
   device = g_hash_table_lookup (manager_xi2->devices_by_id,
@@ -1179,7 +1134,7 @@ handle_property_event (ClutterDeviceManagerXI2 *manager_xi2,
       ClutterInputDeviceToolType type;
       guint serial_id;
 
-      serial_id = device_get_tool_serial (backend_x11, device);
+      serial_id = device_get_tool_serial (device);
 
       if (serial_id != 0)
         {
@@ -1189,14 +1144,14 @@ handle_property_event (ClutterDeviceManagerXI2 *manager_xi2,
             {
               type = clutter_input_device_get_device_type (device) == CLUTTER_ERASER_DEVICE ?
                 CLUTTER_INPUT_DEVICE_TOOL_ERASER : CLUTTER_INPUT_DEVICE_TOOL_PEN;
-              tool = clutter_input_device_tool_xi2_new (serial_id, type);
+              tool = meta_input_device_tool_x11_new (serial_id, type);
               g_hash_table_insert (manager_xi2->tools_by_serial,
                                    GUINT_TO_POINTER (serial_id),
                                    tool);
             }
         }
 
-      clutter_input_device_xi2_update_tool (device, tool);
+      meta_input_device_x11_update_tool (device, tool);
       g_signal_emit_by_name (manager_xi2, "tool-changed", device, tool);
     }
 }
@@ -1222,7 +1177,7 @@ translate_pad_event (ClutterEvent       *event,
     value = -1;
 
 #ifdef HAVE_LIBWACOM
-  mode = clutter_input_device_xi2_get_pad_group_mode (device, number);
+  mode = meta_input_device_x11_get_pad_group_mode (device, number);
 #endif
 
   if (event->any.type == CLUTTER_PAD_RING)
@@ -1242,22 +1197,12 @@ translate_pad_event (ClutterEvent       *event,
   clutter_event_set_device (event, device);
   clutter_event_set_source_device (event, device);
 
-  CLUTTER_NOTE (EVENT,
-                "%s: win:0x%x, device:%d '%s', time:%d "
-                "(value:%f)",
-                event->any.type == CLUTTER_PAD_RING
-                ? "pad ring  "
-                : "pad strip",
-                (unsigned int) xev->event,
-                device->id,
-                device->device_name,
-                event->any.time, value);
   return TRUE;
 }
 
 static void
-handle_raw_event (ClutterDeviceManagerXI2 *manager_xi2,
-                  XEvent                  *xevent)
+handle_raw_event (MetaDeviceManagerX11 *manager_xi2,
+                  XEvent               *xevent)
 {
   ClutterInputDevice *device;
   XGenericEventCookie *cookie;
@@ -1280,28 +1225,16 @@ handle_raw_event (ClutterDeviceManagerXI2 *manager_xi2,
   switch (cookie->evtype)
     {
     case XI_RawMotion:
-      CLUTTER_NOTE (EVENT,
-                    "raw motion: device:%d '%s'",
-                    device->id,
-                    device->device_name);
       /* We don't get actual pointer location with raw events, and we cannot
        * rely on `clutter_input_device_get_coords()` either because of
        * unreparented toplevels (like all client-side decoration windows),
        * so we need to explicitely query the pointer here...
        */
-      if (clutter_input_device_xi2_get_pointer_location (device, &x, &y))
+      if (meta_input_device_x11_get_pointer_location (device, &x, &y))
         _clutter_input_pointer_a11y_on_motion_event (device, x, y);
       break;
     case XI_RawButtonPress:
     case XI_RawButtonRelease:
-      CLUTTER_NOTE (EVENT,
-                    "raw button %s: device:%d '%s' button %i",
-                    cookie->evtype == XI_RawButtonPress
-                      ? "press  "
-                      : "release",
-                    device->id,
-                    device->device_name,
-                    xev->detail);
       _clutter_input_pointer_a11y_on_button_event (device,
                                                   xev->detail,
                                                   (cookie->evtype == XI_RawButtonPress));
@@ -1310,20 +1243,18 @@ handle_raw_event (ClutterDeviceManagerXI2 *manager_xi2,
 }
 
 gboolean
-clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2,
-                                            XEvent                  *xevent,
-                                            ClutterEvent            *event)
+meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
+                                         XEvent               *xevent,
+                                         ClutterEvent         *event)
 {
   gboolean retval = FALSE;
-  ClutterBackendX11 *backend_x11;
-  ClutterStageX11 *stage_x11 = NULL;
+  ClutterBackend *backend = clutter_get_default_backend ();
+  MetaStageX11 *stage_x11 = NULL;
   ClutterStage *stage = NULL;
   ClutterInputDevice *device, *source_device;
   XGenericEventCookie *cookie;
   XIEvent *xi_event;
 
-  backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
-
   cookie = &xevent->xcookie;
 
   if (cookie->type != GenericEvent ||
@@ -1351,7 +1282,7 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
       if (stage == NULL || CLUTTER_ACTOR_IN_DESTRUCTION (stage))
         return FALSE;
       else
-        stage_x11 = CLUTTER_STAGE_X11 (_clutter_stage_get_window (stage));
+        stage_x11 = META_STAGE_X11 (_clutter_stage_get_window (stage));
     }
 
   event->any.stage = stage;
@@ -1362,7 +1293,7 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
       {
         XIHierarchyEvent *xev = (XIHierarchyEvent *) xi_event;
 
-        translate_hierarchy_event (backend_x11, manager_xi2, xev);
+        translate_hierarchy_event (backend, manager_xi2, xev);
       }
       retval = FALSE;
       break;
@@ -1378,7 +1309,7 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
         if (device)
           {
             _clutter_input_device_reset_axes (device);
-            translate_device_classes (backend_x11->xdpy,
+            translate_device_classes (clutter_x11_get_default_display (),
                                       device,
                                       xev->classes,
                                       xev->num_classes);
@@ -1394,7 +1325,8 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
     case XI_KeyRelease:
       {
         XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
-        ClutterEventX11 *event_x11;
+        MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (clutter_backend_get_keymap (backend));
+        MetaEventX11 *event_x11;
         char buffer[7] = { 0, };
         gunichar n;
 
@@ -1407,30 +1339,30 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
 
         event->key.time = xev->time;
         event->key.stage = stage;
-       _clutter_input_device_xi2_translate_state (event, &xev->mods, &xev->buttons, &xev->group);
+        meta_input_device_x11_translate_state (event, &xev->mods, &xev->buttons, &xev->group);
         event->key.hardware_keycode = xev->detail;
 
           /* keyval is the key ignoring all modifiers ('1' vs. '!') */
         event->key.keyval =
-          _clutter_keymap_x11_translate_key_state (backend_x11->keymap,
-                                                   event->key.hardware_keycode,
-                                                   &event->key.modifier_state,
-                                                   NULL);
+          meta_keymap_x11_translate_key_state (keymap_x11,
+                                               event->key.hardware_keycode,
+                                               &event->key.modifier_state,
+                                               NULL);
 
         /* KeyEvents have platform specific data associated to them */
-        event_x11 = _clutter_event_x11_new ();
+        event_x11 = meta_event_x11_new ();
         _clutter_event_set_platform_data (event, event_x11);
 
         event_x11->key_group =
-          _clutter_keymap_x11_get_key_group (backend_x11->keymap,
-                                             event->key.modifier_state);
+          meta_keymap_x11_get_key_group (keymap_x11,
+                                         event->key.modifier_state);
         event_x11->key_is_modifier =
-          _clutter_keymap_x11_get_is_modifier (backend_x11->keymap,
-                                               event->key.hardware_keycode);
+          meta_keymap_x11_get_is_modifier (keymap_x11,
+                                           event->key.hardware_keycode);
         event_x11->num_lock_set =
-          clutter_keymap_get_num_lock_state (CLUTTER_KEYMAP (backend_x11->keymap));
+          clutter_keymap_get_num_lock_state (CLUTTER_KEYMAP (keymap_x11));
         event_x11->caps_lock_set =
-          clutter_keymap_get_caps_lock_state (CLUTTER_KEYMAP (backend_x11->keymap));
+          clutter_keymap_get_caps_lock_state (CLUTTER_KEYMAP (keymap_x11));
 
         source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
                                              GINT_TO_POINTER (xev->sourceid));
@@ -1455,19 +1387,8 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
               event->key.unicode_value = (gunichar) '\0';
           }
 
-        CLUTTER_NOTE (EVENT,
-                      "%s: win:0x%x device:%d source:%d, key: %12s (%d)",
-                      event->any.type == CLUTTER_KEY_PRESS
-                        ? "key press  "
-                        : "key release",
-                      (unsigned int) stage_x11->xwin,
-                      xev->deviceid,
-                      xev->sourceid,
-                      event->key.keyval ? buffer : "(none)",
-                      event->key.keyval);
-
         if (xi_event->evtype == XI_KeyPress)
-          _clutter_stage_x11_set_user_time (stage_x11, event->key.time);
+          meta_stage_x11_set_user_time (stage_x11, event->key.time);
 
         retval = TRUE;
       }
@@ -1524,27 +1445,15 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
             /* Pad buttons are 0-indexed */
             event->pad_button.button = xev->detail - 1;
 #ifdef HAVE_LIBWACOM
-            clutter_input_device_xi2_update_pad_state (device,
-                                                       event->pad_button.button,
-                                                       (xi_event->evtype == XI_ButtonPress),
-                                                       &event->pad_button.group,
-                                                       &event->pad_button.mode);
+            meta_input_device_x11_update_pad_state (device,
+                                                    event->pad_button.button,
+                                                    (xi_event->evtype == XI_ButtonPress),
+                                                    &event->pad_button.group,
+                                                    &event->pad_button.mode);
 #endif
             clutter_event_set_device (event, device);
             clutter_event_set_source_device (event, source_device);
 
-            CLUTTER_NOTE (EVENT,
-                          "%s: win:0x%x, device:%d '%s', time:%d "
-                          "(button:%d)",
-                          event->any.type == CLUTTER_BUTTON_PRESS
-                            ? "pad button press  "
-                            : "pad button release",
-                          (unsigned int) stage_x11->xwin,
-                          device->id,
-                          device->device_name,
-                          event->any.time,
-                          event->pad_button.button);
-
             retval = TRUE;
             break;
           }
@@ -1574,10 +1483,10 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
 
             event->scroll.time = xev->time;
             translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y);
-           _clutter_input_device_xi2_translate_state (event,
-                                                      &xev->mods,
-                                                      &xev->buttons,
-                                                      &xev->group);
+            meta_input_device_x11_translate_state (event,
+                                                   &xev->mods,
+                                                   &xev->buttons,
+                                                   &xev->group);
 
             clutter_event_set_source_device (event, source_device);
             clutter_event_set_device (event, device);
@@ -1586,25 +1495,6 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
                                                  event->scroll.x,
                                                  event->scroll.y,
                                                  &xev->valuators);
-
-            CLUTTER_NOTE (EVENT,
-                          "scroll: win:0x%x, device:%d '%s', time:%d "
-                          "(direction:%s, "
-                          "x:%.2f, y:%.2f, "
-                          "emulated:%s)",
-                          (unsigned int) stage_x11->xwin,
-                          device->id,
-                          device->device_name,
-                          event->any.time,
-                          event->scroll.direction == CLUTTER_SCROLL_UP ? "up" :
-                          event->scroll.direction == CLUTTER_SCROLL_DOWN ? "down" :
-                          event->scroll.direction == CLUTTER_SCROLL_LEFT ? "left" :
-                          event->scroll.direction == CLUTTER_SCROLL_RIGHT ? "right" :
-                          "invalid",
-                          event->scroll.x,
-                          event->scroll.y,
-                          (xev->flags & XIPointerEmulated) ? "yes" : "no"
-                          );
             break;
 
           default:
@@ -1617,40 +1507,20 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
             event->button.time = xev->time;
             translate_coords (stage_x11, xev->event_x, xev->event_y, &event->button.x, &event->button.y);
             event->button.button = xev->detail;
-           _clutter_input_device_xi2_translate_state (event,
-                                                      &xev->mods,
-                                                      &xev->buttons,
-                                                      &xev->group);
+            meta_input_device_x11_translate_state (event,
+                                                   &xev->mods,
+                                                   &xev->buttons,
+                                                   &xev->group);
 
             clutter_event_set_source_device (event, source_device);
             clutter_event_set_device (event, device);
             clutter_event_set_device_tool (event,
-                                           clutter_input_device_xi2_get_current_tool (source_device));
+                                           meta_input_device_x11_get_current_tool (source_device));
 
             event->button.axes = translate_axes (event->button.device,
                                                  event->button.x,
                                                  event->button.y,
                                                  &xev->valuators);
-
-            CLUTTER_NOTE (EVENT,
-                          "%s: win:0x%x, device:%d '%s', time:%d "
-                          "(button:%d, "
-                          "x:%.2f, y:%.2f, "
-                          "axes:%s, "
-                          "emulated:%s)",
-                          event->any.type == CLUTTER_BUTTON_PRESS
-                            ? "button press  "
-                            : "button release",
-                          (unsigned int) stage_x11->xwin,
-                          device->id,
-                          device->device_name,
-                          event->any.time,
-                          event->button.button,
-                          event->button.x,
-                          event->button.y,
-                          event->button.axes != NULL ? "yes" : "no",
-                          (xev->flags & XIPointerEmulated) ? "yes" : "no"
-                          );
             break;
           }
 
@@ -1661,7 +1531,7 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
           _clutter_event_set_pointer_emulated (event, TRUE);
 
         if (xi_event->evtype == XI_ButtonPress)
-          _clutter_stage_x11_set_user_time (stage_x11, event->button.time);
+          meta_stage_x11_set_user_time (stage_x11, event->button.time);
 
         retval = TRUE;
       }
@@ -1702,24 +1572,15 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
             event->scroll.stage = stage;
             event->scroll.time = xev->time;
             translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y);
-           _clutter_input_device_xi2_translate_state (event,
-                                                      &xev->mods,
-                                                      &xev->buttons,
-                                                      &xev->group);
+            meta_input_device_x11_translate_state (event,
+                                                   &xev->mods,
+                                                   &xev->buttons,
+                                                   &xev->group);
 
             clutter_event_set_scroll_delta (event, delta_x, delta_y);
             clutter_event_set_source_device (event, source_device);
             clutter_event_set_device (event, device);
 
-            CLUTTER_NOTE (EVENT,
-                          "smooth scroll: win:0x%x device:%d '%s' (x:%.2f, y:%.2f, delta:%f, %f)",
-                          (unsigned int) stage_x11->xwin,
-                          event->scroll.device->id,
-                          event->scroll.device->device_name,
-                          event->scroll.x,
-                          event->scroll.y,
-                          delta_x, delta_y);
-
             retval = TRUE;
             break;
           }
@@ -1730,15 +1591,15 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
 
         event->motion.time = xev->time;
         translate_coords (stage_x11, xev->event_x, xev->event_y, &event->motion.x, &event->motion.y);
-       _clutter_input_device_xi2_translate_state (event,
-                                                  &xev->mods,
-                                                  &xev->buttons,
-                                                  &xev->group);
+        meta_input_device_x11_translate_state (event,
+                                               &xev->mods,
+                                               &xev->buttons,
+                                               &xev->group);
 
         clutter_event_set_source_device (event, source_device);
         clutter_event_set_device (event, device);
         clutter_event_set_device_tool (event,
-                                       clutter_input_device_xi2_get_current_tool (source_device));
+                                       meta_input_device_x11_get_current_tool (source_device));
 
         event->motion.axes = translate_axes (event->motion.device,
                                              event->motion.x,
@@ -1751,14 +1612,6 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
         if (xev->flags & XIPointerEmulated)
           _clutter_event_set_pointer_emulated (event, TRUE);
 
-        CLUTTER_NOTE (EVENT, "motion: win:0x%x device:%d '%s' (x:%.2f, y:%.2f, axes:%s)",
-                      (unsigned int) stage_x11->xwin,
-                      event->motion.device->id,
-                      event->motion.device->device_name,
-                      event->motion.x,
-                      event->motion.y,
-                      event->motion.axes != NULL ? "yes" : "no");
-
         retval = TRUE;
       }
       break;
@@ -1787,10 +1640,10 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
         event->touch.stage = stage;
         event->touch.time = xev->time;
         translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y);
-       _clutter_input_device_xi2_translate_state (event,
-                                                  &xev->mods,
-                                                  &xev->buttons,
-                                                  &xev->group);
+        meta_input_device_x11_translate_state (event,
+                                               &xev->mods,
+                                               &xev->buttons,
+                                               &xev->group);
 
         clutter_event_set_source_device (event, source_device);
 
@@ -1807,7 +1660,7 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
           {
             event->touch.modifier_state |= CLUTTER_BUTTON1_MASK;
 
-            _clutter_stage_x11_set_user_time (stage_x11, event->touch.time);
+            meta_stage_x11_set_user_time (stage_x11, event->touch.time);
           }
 
         event->touch.sequence = GUINT_TO_POINTER (xev->detail);
@@ -1815,16 +1668,6 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
         if (xev->flags & XITouchEmulatingPointer)
           _clutter_event_set_pointer_emulated (event, TRUE);
 
-        CLUTTER_NOTE (EVENT, "touch %s: win:0x%x device:%d '%s' (seq:%d, x:%.2f, y:%.2f, axes:%s)",
-                      event->type == CLUTTER_TOUCH_BEGIN ? "begin" : "end",
-                      (unsigned int) stage_x11->xwin,
-                      event->touch.device->id,
-                      event->touch.device->device_name,
-                      GPOINTER_TO_UINT (event->touch.sequence),
-                      event->touch.x,
-                      event->touch.y,
-                      event->touch.axes != NULL ? "yes" : "no");
-
         retval = TRUE;
       }
       break;
@@ -1853,24 +1696,15 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
                                             event->motion.y,
                                             &xev->valuators);
 
-       _clutter_input_device_xi2_translate_state (event,
-                                                  &xev->mods,
-                                                  &xev->buttons,
-                                                  &xev->group);
+        meta_input_device_x11_translate_state (event,
+                                               &xev->mods,
+                                               &xev->buttons,
+                                               &xev->group);
         event->touch.modifier_state |= CLUTTER_BUTTON1_MASK;
 
         if (xev->flags & XITouchEmulatingPointer)
           _clutter_event_set_pointer_emulated (event, TRUE);
 
-        CLUTTER_NOTE (EVENT, "touch update: win:0x%x device:%d '%s' (seq:%d, x:%.2f, y:%.2f, axes:%s)",
-                      (unsigned int) stage_x11->xwin,
-                      event->touch.device->id,
-                      event->touch.device->device_name,
-                      GPOINTER_TO_UINT (event->touch.sequence),
-                      event->touch.x,
-                      event->touch.y,
-                      event->touch.axes != NULL ? "yes" : "no");
-
         retval = TRUE;
       }
       break;
@@ -1903,10 +1737,6 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
           {
             if (device->stage == NULL)
               {
-                CLUTTER_NOTE (EVENT,
-                              "Discarding Leave for ButtonRelease "
-                              "event off-stage");
-
                 retval = FALSE;
                 break;
               }
@@ -1946,23 +1776,23 @@ clutter_device_manager_xi2_translate_event (ClutterDeviceManagerXI2 *manager_xi2
 }
 
 static void
-clutter_device_manager_xi2_add_device (ClutterDeviceManager *manager,
-                                       ClutterInputDevice   *device)
+meta_device_manager_x11_add_device (ClutterDeviceManager *manager,
+                                    ClutterInputDevice   *device)
 {
   /* XXX implement */
 }
 
 static void
-clutter_device_manager_xi2_remove_device (ClutterDeviceManager *manager,
-                                          ClutterInputDevice   *device)
+meta_device_manager_x11_remove_device (ClutterDeviceManager *manager,
+                                       ClutterInputDevice   *device)
 {
   /* XXX implement */
 }
 
 static const GSList *
-clutter_device_manager_xi2_get_devices (ClutterDeviceManager *manager)
+meta_device_manager_x11_get_devices (ClutterDeviceManager *manager)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager);
+  MetaDeviceManagerX11 *manager_xi2 = META_DEVICE_MANAGER_X11 (manager);
   GSList *all_devices = NULL;
   GList *l;
 
@@ -1981,20 +1811,20 @@ clutter_device_manager_xi2_get_devices (ClutterDeviceManager *manager)
 }
 
 static ClutterInputDevice *
-clutter_device_manager_xi2_get_device (ClutterDeviceManager *manager,
-                                       gint                  id)
+meta_device_manager_x11_get_device (ClutterDeviceManager *manager,
+                                    gint                  id)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager);
+  MetaDeviceManagerX11 *manager_xi2 = META_DEVICE_MANAGER_X11 (manager);
 
   return g_hash_table_lookup (manager_xi2->devices_by_id,
                               GINT_TO_POINTER (id));
 }
 
 static ClutterInputDevice *
-clutter_device_manager_xi2_get_core_device (ClutterDeviceManager   *manager,
-                                            ClutterInputDeviceType  device_type)
+meta_device_manager_x11_get_core_device (ClutterDeviceManager   *manager,
+                                         ClutterInputDeviceType  device_type)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager);
+  MetaDeviceManagerX11 *manager_xi2 = META_DEVICE_MANAGER_X11 (manager);
   ClutterInputDevice *pointer = NULL;
   GList *l;
 
@@ -2031,7 +1861,7 @@ relate_masters (gpointer key,
                 gpointer value,
                 gpointer data)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = data;
+  MetaDeviceManagerX11 *manager_xi2 = data;
   ClutterInputDevice *device, *relative;
 
   device = g_hash_table_lookup (manager_xi2->devices_by_id, key);
@@ -2046,7 +1876,7 @@ relate_slaves (gpointer key,
                gpointer value,
                gpointer data)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = data;
+  MetaDeviceManagerX11 *manager_xi2 = data;
   ClutterInputDevice *master, *slave;
 
   slave = g_hash_table_lookup (manager_xi2->devices_by_id, key);
@@ -2057,24 +1887,22 @@ relate_slaves (gpointer key,
 }
 
 static void
-clutter_device_manager_xi2_constructed (GObject *gobject)
+meta_device_manager_x11_constructed (GObject *gobject)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (gobject);
+  MetaDeviceManagerX11 *manager_xi2 = META_DEVICE_MANAGER_X11 (gobject);
   ClutterDeviceManager *manager = CLUTTER_DEVICE_MANAGER (gobject);
-  ClutterBackendX11 *backend_x11;
+  ClutterBackend *backend = clutter_get_default_backend ();
   GHashTable *masters, *slaves;
   XIDeviceInfo *info;
   XIEventMask event_mask;
   unsigned char mask[(XI_LASTEVENT + 7) / 8] = { 0, };
   int n_devices, i;
 
-  backend_x11 =
-    CLUTTER_BACKEND_X11 (_clutter_device_manager_get_backend (manager));
-
   masters = g_hash_table_new (NULL, NULL);
   slaves = g_hash_table_new (NULL, NULL);
 
-  info = XIQueryDevice (backend_x11->xdpy, XIAllDevices, &n_devices);
+  info = XIQueryDevice (clutter_x11_get_default_display (),
+                        XIAllDevices, &n_devices);
 
   for (i = 0; i < n_devices; i++)
     {
@@ -2083,7 +1911,7 @@ clutter_device_manager_xi2_constructed (GObject *gobject)
       if (!xi_device->enabled)
         continue;
 
-      add_device (manager_xi2, backend_x11, xi_device, TRUE);
+      add_device (manager_xi2, backend, xi_device, TRUE);
 
       if (xi_device->use == XIMasterPointer ||
           xi_device->use == XIMasterKeyboard)
@@ -2117,9 +1945,9 @@ clutter_device_manager_xi2_constructed (GObject *gobject)
   event_mask.mask_len = sizeof (mask);
   event_mask.mask = mask;
 
-  clutter_device_manager_xi2_select_events (manager,
-                                            clutter_x11_get_root_window (),
-                                            &event_mask);
+  meta_device_manager_x11_select_events (manager,
+                                         clutter_x11_get_root_window (),
+                                         &event_mask);
 
   memset(mask, 0, sizeof (mask));
   XISetMask (mask, XI_RawMotion);
@@ -2130,25 +1958,25 @@ clutter_device_manager_xi2_constructed (GObject *gobject)
   event_mask.mask_len = sizeof (mask);
   event_mask.mask = mask;
 
-  clutter_device_manager_xi2_select_events (manager,
-                                            clutter_x11_get_root_window (),
-                                            &event_mask);
+  meta_device_manager_x11_select_events (manager,
+                                        clutter_x11_get_root_window (),
+                                        &event_mask);
 
-  XSync (backend_x11->xdpy, False);
+  XSync (clutter_x11_get_default_display (), False);
 
-  clutter_device_manager_x11_a11y_init (manager);
+  meta_device_manager_x11_a11y_init (manager);
 
-  if (G_OBJECT_CLASS (clutter_device_manager_xi2_parent_class)->constructed)
-    G_OBJECT_CLASS (clutter_device_manager_xi2_parent_class)->constructed (gobject);
+  if (G_OBJECT_CLASS (meta_device_manager_x11_parent_class)->constructed)
+    G_OBJECT_CLASS (meta_device_manager_x11_parent_class)->constructed (gobject);
 }
 
 static void
-clutter_device_manager_xi2_set_property (GObject      *gobject,
-                                         guint         prop_id,
-                                         const GValue *value,
-                                         GParamSpec   *pspec)
+meta_device_manager_x11_set_property (GObject      *gobject,
+                                      guint         prop_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec)
 {
-  ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (gobject);
+  MetaDeviceManagerX11 *manager_xi2 = META_DEVICE_MANAGER_X11 (gobject);
 
   switch (prop_id)
     {
@@ -2163,24 +1991,24 @@ clutter_device_manager_xi2_set_property (GObject      *gobject,
 }
 
 static ClutterVirtualInputDevice *
-clutter_device_manager_xi2_create_virtual_device (ClutterDeviceManager   *manager,
-                                                  ClutterInputDeviceType  device_type)
+meta_device_manager_x11_create_virtual_device (ClutterDeviceManager   *manager,
+                                               ClutterInputDeviceType  device_type)
 {
-  return g_object_new (CLUTTER_TYPE_VIRTUAL_INPUT_DEVICE_X11,
+  return g_object_new (META_TYPE_VIRTUAL_INPUT_DEVICE_X11,
                        "device-manager", manager,
                        "device-type", device_type,
                        NULL);
 }
 
 static ClutterVirtualDeviceType
-clutter_device_manager_xi2_get_supported_virtual_device_types (ClutterDeviceManager *device_manager)
+meta_device_manager_x11_get_supported_virtual_device_types (ClutterDeviceManager *device_manager)
 {
   return (CLUTTER_VIRTUAL_DEVICE_TYPE_KEYBOARD |
           CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER);
 }
 
 static void
-clutter_device_manager_xi2_class_init (ClutterDeviceManagerXI2Class *klass)
+meta_device_manager_x11_class_init (MetaDeviceManagerX11Class *klass)
 {
   ClutterDeviceManagerClass *manager_class;
   GObjectClass *gobject_class;
@@ -2191,30 +2019,30 @@ clutter_device_manager_xi2_class_init (ClutterDeviceManagerXI2Class *klass)
                       "The XI2 opcode",
                       -1, G_MAXINT,
                       -1,
-                      CLUTTER_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+                      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
 
   gobject_class = G_OBJECT_CLASS (klass);
-  gobject_class->constructed = clutter_device_manager_xi2_constructed;
-  gobject_class->set_property = clutter_device_manager_xi2_set_property;
+  gobject_class->constructed = meta_device_manager_x11_constructed;
+  gobject_class->set_property = meta_device_manager_x11_set_property;
 
   g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
   
   manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass);
-  manager_class->add_device = clutter_device_manager_xi2_add_device;
-  manager_class->remove_device = clutter_device_manager_xi2_remove_device;
-  manager_class->get_devices = clutter_device_manager_xi2_get_devices;
-  manager_class->get_core_device = clutter_device_manager_xi2_get_core_device;
-  manager_class->get_device = clutter_device_manager_xi2_get_device;
-  manager_class->select_stage_events = clutter_device_manager_xi2_select_stage_events;
-  manager_class->create_virtual_device = clutter_device_manager_xi2_create_virtual_device;
-  manager_class->get_supported_virtual_device_types = 
clutter_device_manager_xi2_get_supported_virtual_device_types;
-  manager_class->apply_kbd_a11y_settings = clutter_device_manager_x11_apply_kbd_a11y_settings;
-  manager_class->copy_event_data = clutter_device_manager_xi2_copy_event_data;
-  manager_class->free_event_data = clutter_device_manager_xi2_free_event_data;
+  manager_class->add_device = meta_device_manager_x11_add_device;
+  manager_class->remove_device = meta_device_manager_x11_remove_device;
+  manager_class->get_devices = meta_device_manager_x11_get_devices;
+  manager_class->get_core_device = meta_device_manager_x11_get_core_device;
+  manager_class->get_device = meta_device_manager_x11_get_device;
+  manager_class->select_stage_events = meta_device_manager_x11_select_stage_events;
+  manager_class->create_virtual_device = meta_device_manager_x11_create_virtual_device;
+  manager_class->get_supported_virtual_device_types = 
meta_device_manager_x11_get_supported_virtual_device_types;
+  manager_class->apply_kbd_a11y_settings = meta_device_manager_x11_apply_kbd_a11y_settings;
+  manager_class->copy_event_data = meta_device_manager_x11_copy_event_data;
+  manager_class->free_event_data = meta_device_manager_x11_free_event_data;
 }
 
 static void
-clutter_device_manager_xi2_init (ClutterDeviceManagerXI2 *self)
+meta_device_manager_x11_init (MetaDeviceManagerX11 *self)
 {
   self->devices_by_id = g_hash_table_new_full (NULL, NULL,
                                                NULL,
diff --git a/src/backends/x11/meta-device-manager-x11.h b/src/backends/x11/meta-device-manager-x11.h
new file mode 100644
index 000000000..4bf762cdd
--- /dev/null
+++ b/src/backends/x11/meta-device-manager-x11.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2011  Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#ifndef META_DEVICE_MANAGER_X11_H
+#define META_DEVICE_MANAGER_X11_H
+
+#include <clutter/clutter.h>
+
+#ifdef HAVE_LIBWACOM
+#include <libwacom/libwacom.h>
+#endif
+
+G_BEGIN_DECLS
+
+#define META_TYPE_DEVICE_MANAGER_X11 (meta_device_manager_x11_get_type ())
+G_DECLARE_FINAL_TYPE (MetaDeviceManagerX11, meta_device_manager_x11,
+                      META, DEVICE_MANAGER_X11, ClutterDeviceManager)
+
+struct _MetaDeviceManagerX11
+{
+  ClutterDeviceManager parent_instance;
+
+  GHashTable *devices_by_id;
+  GHashTable *tools_by_serial;
+
+  GSList *all_devices;
+
+  GList *master_devices;
+  GList *slave_devices;
+
+  int opcode;
+
+#ifdef HAVE_LIBWACOM
+  WacomDeviceDatabase *wacom_db;
+#endif
+};
+
+gboolean meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
+                                                  XEvent               *xevent,
+                                                  ClutterEvent         *event);
+
+G_END_DECLS
+
+#endif /* META_DEVICE_MANAGER_X11_H */
diff --git a/clutter/clutter/x11/clutter-event-x11.c b/src/backends/x11/meta-event-x11.c
similarity index 71%
rename from clutter/clutter/x11/clutter-event-x11.c
rename to src/backends/x11/meta-event-x11.c
index 9396ecee4..800ef6d88 100644
--- a/clutter/clutter/x11/clutter-event-x11.c
+++ b/src/backends/x11/meta-event-x11.c
@@ -1,7 +1,4 @@
-/* Clutter.
- * An OpenGL based 'interactive canvas' library.
- *
- * Copyright (C) 2006, 2007, 2008  OpenedHand Ltd
+/* Copyright (C) 2006, 2007, 2008  OpenedHand Ltd
  * Copyright (C) 2009, 2010  Intel Corp.
  *
  * This library is free software; you can redistribute it and/or
@@ -24,21 +21,14 @@
  *      Emmanuele Bassi <ebassi linux intel com>
  */
 
-#include "clutter-build-config.h"
-
-#include "clutter-backend-x11.h"
-#include "clutter-x11.h"
-
-#include "clutter-backend-private.h"
-#include "clutter-debug.h"
-#include "clutter-event-private.h"
-#include "clutter-main.h"
-#include "clutter-private.h"
-#include "clutter-stage-private.h"
+#include "config.h"
 
+#include <clutter/clutter-mutter.h>
+#include <clutter/x11/clutter-x11.h>
+#include <glib.h>
 #include <string.h>
 
-#include <glib.h>
+#include "backends/x11/meta-event-x11.h"
 
 #if 0
 /* XEMBED protocol support for toolkit embedding */
@@ -63,30 +53,30 @@
 static Window ParentEmbedderWin = None;
 #endif
 
-ClutterEventX11 *
-_clutter_event_x11_new (void)
+MetaEventX11 *
+meta_event_x11_new (void)
 {
-  return g_slice_new0 (ClutterEventX11);
+  return g_slice_new0 (MetaEventX11);
 }
 
-ClutterEventX11 *
-_clutter_event_x11_copy (ClutterEventX11 *event_x11)
+MetaEventX11 *
+meta_event_x11_copy (MetaEventX11 *event_x11)
 {
   if (event_x11 != NULL)
-    return g_slice_dup (ClutterEventX11, event_x11);
+    return g_slice_dup (MetaEventX11, event_x11);
 
   return NULL;
 }
 
 void
-_clutter_event_x11_free (ClutterEventX11 *event_x11)
+meta_event_x11_free (MetaEventX11 *event_x11)
 {
   if (event_x11 != NULL)
-    g_slice_free (ClutterEventX11, event_x11);
+    g_slice_free (MetaEventX11, event_x11);
 }
 
 /**
- * clutter_x11_handle_event:
+ * meta_x11_handle_event:
  * @xevent: pointer to XEvent structure
  *
  * This function processes a single X event; it can be used to hook
@@ -104,7 +94,7 @@ _clutter_event_x11_free (ClutterEventX11 *event_x11)
  * Since: 0.8
  */
 ClutterX11FilterReturn
-clutter_x11_handle_event (XEvent *xevent)
+meta_x11_handle_event (XEvent *xevent)
 {
   ClutterX11FilterReturn result;
   ClutterBackend *backend;
@@ -115,12 +105,12 @@ clutter_x11_handle_event (XEvent *xevent)
   gboolean allocated_event;
 
   /* The return values here are someone approximate; we return
-   * CLUTTER_X11_FILTER_REMOVE if a clutter event is
+   * META_X11_FILTER_REMOVE if a clutter event is
    * generated for the event. This mostly, but not entirely,
    * corresponds to whether other event processing should be
    * excluded. As long as the stage window is not shared with another
    * toolkit it should be safe, and never return
-   * %CLUTTER_X11_FILTER_REMOVE when more processing is needed.
+   * %META_X11_FILTER_REMOVE when more processing is needed.
    */
 
   result = CLUTTER_X11_FILTER_CONTINUE;
@@ -173,40 +163,18 @@ out:
   return result;
 }
 
-/**
- * clutter_x11_get_current_event_time: (skip)
- *
- * Retrieves the timestamp of the last X11 event processed by
- * Clutter. This might be different from the timestamp returned
- * by clutter_get_current_event_time(), as Clutter may synthesize
- * or throttle events.
- *
- * Return value: a timestamp, in milliseconds
- *
- * Since: 1.0
- */
 Time
-clutter_x11_get_current_event_time (void)
+meta_x11_get_current_event_time (void)
 {
   ClutterBackend *backend = clutter_get_default_backend ();
 
   return CLUTTER_BACKEND_X11 (backend)->last_event_time;
 }
 
-/**
- * clutter_x11_event_get_key_group:
- * @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS or %CLUTTER_KEY_RELEASE
- *
- * Retrieves the group for the modifiers set in @event
- *
- * Return value: the group id
- *
- * Since: 1.4
- */
 gint
-clutter_x11_event_get_key_group (const ClutterEvent *event)
+meta_x11_event_get_key_group (const ClutterEvent *event)
 {
-  ClutterEventX11 *event_x11;
+  MetaEventX11 *event_x11;
 
   g_return_val_if_fail (event != NULL, 0);
   g_return_val_if_fail (event->type == CLUTTER_KEY_PRESS ||
@@ -219,18 +187,8 @@ clutter_x11_event_get_key_group (const ClutterEvent *event)
   return event_x11->key_group;
 }
 
-/**
- * clutter_x11_event_sequence_get_touch_detail:
- * @sequence: a #ClutterEventSequence
- *
- * Retrieves the touch detail froma #ClutterEventSequence.
- *
- * Return value: the touch detail
- *
- * Since: 1.12
- */
 guint
-clutter_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence)
+meta_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence)
 {
   g_return_val_if_fail (sequence != NULL, 0);
 
diff --git a/src/backends/x11/meta-event-x11.h b/src/backends/x11/meta-event-x11.h
new file mode 100644
index 000000000..81a0fa2b5
--- /dev/null
+++ b/src/backends/x11/meta-event-x11.h
@@ -0,0 +1,55 @@
+/* Copyright (C) 2006, 2007, 2008  OpenedHand Ltd
+ * Copyright (C) 2009, 2010  Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ *
+ * Authored by:
+ *      Matthew Allum <mallum openedhand com>
+ *      Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#ifndef META_EVENT_X11_H
+#define META_EVENT_X11_H
+
+#include <clutter/x11/clutter-backend-x11.h>
+#include <clutter/x11/clutter-x11.h>
+#include <X11/Xlib.h>
+
+typedef struct _MetaEventX11         MetaEventX11;
+
+struct _MetaEventX11
+{
+  /* additional fields for Key events */
+  gint key_group;
+
+  guint key_is_modifier : 1;
+  guint num_lock_set    : 1;
+  guint caps_lock_set   : 1;
+};
+
+MetaEventX11 *       meta_event_x11_new          (void);
+MetaEventX11 *       meta_event_x11_copy         (MetaEventX11 *event_x11);
+void                 meta_event_x11_free         (MetaEventX11 *event_x11);
+
+Time  meta_x11_get_current_event_time (void);
+
+gint  meta_x11_event_get_key_group (const ClutterEvent *event);
+
+guint meta_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence);
+
+ClutterX11FilterReturn meta_x11_handle_event (XEvent *xevent);
+
+#endif /* META_EVENT_X11_H */
diff --git a/clutter/clutter/x11/clutter-input-device-tool-xi2.c 
b/src/backends/x11/meta-input-device-tool-x11.c
similarity index 63%
rename from clutter/clutter/x11/clutter-input-device-tool-xi2.c
rename to src/backends/x11/meta-input-device-tool-x11.c
index 9f038b4d0..0632fea5a 100644
--- a/clutter/clutter/x11/clutter-input-device-tool-xi2.c
+++ b/src/backends/x11/meta-input-device-tool-x11.c
@@ -1,8 +1,4 @@
 /*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
  * Copyright © 2016 Red Hat
  *
  * This library is free software; you can redistribute it and/or
@@ -21,28 +17,28 @@
  * Author: Carlos Garnacho <carlosg gnome org>
  */
 
-#include "clutter-build-config.h"
+#include "config.h"
 
-#include "clutter-input-device-tool-xi2.h"
+#include "meta-input-device-tool-x11.h"
 
-G_DEFINE_TYPE (ClutterInputDeviceToolXI2, clutter_input_device_tool_xi2,
+G_DEFINE_TYPE (MetaInputDeviceToolX11, meta_input_device_tool_x11,
                CLUTTER_TYPE_INPUT_DEVICE_TOOL)
 
 static void
-clutter_input_device_tool_xi2_class_init (ClutterInputDeviceToolXI2Class *klass)
+meta_input_device_tool_x11_class_init (MetaInputDeviceToolX11Class *klass)
 {
 }
 
 static void
-clutter_input_device_tool_xi2_init (ClutterInputDeviceToolXI2 *tool)
+meta_input_device_tool_x11_init (MetaInputDeviceToolX11 *tool)
 {
 }
 
 ClutterInputDeviceTool *
-clutter_input_device_tool_xi2_new (guint                        serial,
-                                   ClutterInputDeviceToolType   type)
+meta_input_device_tool_x11_new (guint                      serial,
+                                ClutterInputDeviceToolType type)
 {
-  return g_object_new (CLUTTER_TYPE_INPUT_DEVICE_TOOL_XI2,
+  return g_object_new (META_TYPE_INPUT_DEVICE_TOOL_X11,
                        "type", type,
                        "serial", serial,
                        NULL);
diff --git a/src/backends/x11/meta-input-device-tool-x11.h b/src/backends/x11/meta-input-device-tool-x11.h
new file mode 100644
index 000000000..ee0e711f2
--- /dev/null
+++ b/src/backends/x11/meta-input-device-tool-x11.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2016 Red Hat
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef META_INPUT_DEVICE_TOOL_X11_H
+#define META_INPUT_DEVICE_TOOL_X11_H
+
+#include <clutter/clutter.h>
+
+#define META_TYPE_INPUT_DEVICE_TOOL_X11 (meta_input_device_tool_x11_get_type ())
+
+#define META_INPUT_DEVICE_TOOL_X11(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_INPUT_DEVICE_TOOL_X11, 
MetaInputDeviceToolX11))
+#define META_IS_INPUT_DEVICE_TOOL_X11(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), META_TYPE_INPUT_DEVICE_TOOL_X11))
+#define META_INPUT_DEVICE_TOOL_X11_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_INPUT_DEVICE_TOOL_X11, 
MetaInputDeviceToolX11Class))
+#define META_IS_INPUT_DEVICE_TOOL_X11_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), 
META_TYPE_INPUT_DEVICE_TOOL_X1))
+#define META_INPUT_DEVICE_TOOL_X11_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), 
META_TYPE_INPUT_DEVICE_TOOL_X11, MetaInputDeviceToolX11Class))
+
+typedef struct _MetaInputDeviceToolX11 MetaInputDeviceToolX11;
+typedef struct _MetaInputDeviceToolX11Class MetaInputDeviceToolX11Class;
+
+struct _MetaInputDeviceToolX11
+{
+  ClutterInputDeviceTool parent_instance;
+};
+
+struct _MetaInputDeviceToolX11Class
+{
+  ClutterInputDeviceToolClass parent_class;
+};
+
+GType meta_input_device_tool_x11_get_type (void) G_GNUC_CONST;
+
+ClutterInputDeviceTool * meta_input_device_tool_x11_new (guint                        serial,
+                                                         ClutterInputDeviceToolType   type);
+
+#endif /* META_INPUT_DEVICE_TOOL_X11_H */
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.c b/src/backends/x11/meta-input-device-x11.c
similarity index 61%
rename from clutter/clutter/x11/clutter-input-device-xi2.c
rename to src/backends/x11/meta-input-device-x11.c
index 0033166c5..3060553f5 100644
--- a/clutter/clutter/x11/clutter-input-device-xi2.c
+++ b/src/backends/x11/meta-input-device-x11.c
@@ -1,8 +1,4 @@
 /*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
  * Copyright © 2011  Intel Corp.
  *
  * This library is free software; you can redistribute it and/or
@@ -21,25 +17,15 @@
  * Author: Emmanuele Bassi <ebassi linux intel com>
  */
 
-#include "clutter-build-config.h"
-
-#include "clutter-input-device-xi2.h"
-
-#include "clutter-debug.h"
-#include "clutter-device-manager-private.h"
-#include "clutter-event-private.h"
-#include "clutter-private.h"
-#include "clutter-stage-private.h"
-
-#include "clutter-backend-x11.h"
-#include "clutter-stage-x11.h"
+#include "config.h"
 
+#include <clutter/x11/clutter-x11.h>
 #include <X11/extensions/XInput2.h>
 
-typedef struct _ClutterInputDeviceClass         ClutterInputDeviceXI2Class;
+#include "clutter/clutter-mutter.h"
+#include "backends/x11/meta-input-device-x11.h"
 
-/* a specific XI2 input device */
-struct _ClutterInputDeviceXI2
+struct _MetaInputDeviceX11
 {
   ClutterInputDevice device;
 
@@ -57,23 +43,26 @@ struct _ClutterInputDeviceXI2
 #endif
 };
 
-#define N_BUTTONS       5
+struct _MetaInputDeviceX11Class
+{
+  ClutterInputDeviceClass device_class;
+};
 
-#define clutter_input_device_xi2_get_type       _clutter_input_device_xi2_get_type
+#define N_BUTTONS       5
 
-G_DEFINE_TYPE (ClutterInputDeviceXI2,
-               clutter_input_device_xi2,
-               CLUTTER_TYPE_INPUT_DEVICE);
+G_DEFINE_TYPE (MetaInputDeviceX11,
+               meta_input_device_x11,
+               CLUTTER_TYPE_INPUT_DEVICE)
 
 static void
-clutter_input_device_xi2_constructed (GObject *gobject)
+meta_input_device_x11_constructed (GObject *gobject)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (gobject);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (gobject);
 
   g_object_get (gobject, "id", &device_xi2->device_id, NULL);
 
-  if (G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed)
-    G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed (gobject);
+  if (G_OBJECT_CLASS (meta_input_device_x11_parent_class)->constructed)
+    G_OBJECT_CLASS (meta_input_device_x11_parent_class)->constructed (gobject);
 
 #ifdef HAVE_LIBWACOM
   if (clutter_input_device_get_device_type (CLUTTER_INPUT_DEVICE (gobject)) == CLUTTER_PAD_DEVICE)
@@ -86,9 +75,9 @@ clutter_input_device_xi2_constructed (GObject *gobject)
 }
 
 static gboolean
-clutter_input_device_xi2_keycode_to_evdev (ClutterInputDevice *device,
-                                           guint hardware_keycode,
-                                           guint *evdev_keycode)
+meta_input_device_x11_keycode_to_evdev (ClutterInputDevice *device,
+                                        guint               hardware_keycode,
+                                        guint              *evdev_keycode)
 {
   /* When using evdev under X11 the hardware keycodes are the evdev
      keycodes plus 8. I haven't been able to find any documentation to
@@ -100,17 +89,17 @@ clutter_input_device_xi2_keycode_to_evdev (ClutterInputDevice *device,
 }
 
 static gboolean
-clutter_input_device_xi2_is_grouped (ClutterInputDevice *device,
-                                     ClutterInputDevice *other_device)
+meta_input_device_x11_is_grouped (ClutterInputDevice *device,
+                                  ClutterInputDevice *other_device)
 {
   return FALSE;
 }
 
 static void
-clutter_input_device_xi2_finalize (GObject *object)
+meta_input_device_x11_finalize (GObject *object)
 {
 #ifdef HAVE_LIBWACOM
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (object);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (object);
 
   if (device_xi2->wacom_device)
     libwacom_destroy (device_xi2->wacom_device);
@@ -122,15 +111,15 @@ clutter_input_device_xi2_finalize (GObject *object)
   if (device_xi2->inhibit_pointer_query_timer)
     g_source_remove (device_xi2->inhibit_pointer_query_timer);
 
-  G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->finalize (object);
+  G_OBJECT_CLASS (meta_input_device_x11_parent_class)->finalize (object);
 }
 
 static gint
-clutter_input_device_xi2_get_group_n_modes (ClutterInputDevice *device,
-                                            gint                group)
+meta_input_device_x11_get_group_n_modes (ClutterInputDevice *device,
+                                         gint                group)
 {
 #ifdef HAVE_LIBWACOM
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
 
   if (device_xi2->wacom_device)
     {
@@ -156,10 +145,10 @@ clutter_input_device_xi2_get_group_n_modes (ClutterInputDevice *device,
 
 #ifdef HAVE_LIBWACOM
 static int
-clutter_input_device_xi2_get_button_group (ClutterInputDevice *device,
-                                           guint               button)
+meta_input_device_x11_get_button_group (ClutterInputDevice *device,
+                                        guint               button)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
 
   if (device_xi2->wacom_device)
     {
@@ -175,36 +164,36 @@ clutter_input_device_xi2_get_button_group (ClutterInputDevice *device,
 #endif
 
 static gboolean
-clutter_input_device_xi2_is_mode_switch_button (ClutterInputDevice *device,
-                                                guint               group,
-                                                guint               button)
+meta_input_device_x11_is_mode_switch_button (ClutterInputDevice *device,
+                                             guint               group,
+                                             guint               button)
 {
   int button_group = -1;
 
 #ifdef HAVE_LIBWACOM
-  button_group = clutter_input_device_xi2_get_button_group (device, button);
+  button_group = meta_input_device_x11_get_button_group (device, button);
 #endif
 
   return button_group == (int) group;
 }
 
 static void
-clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass)
+meta_input_device_x11_class_init (MetaInputDeviceX11Class *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   ClutterInputDeviceClass *device_class = CLUTTER_INPUT_DEVICE_CLASS (klass);
 
-  gobject_class->constructed = clutter_input_device_xi2_constructed;
-  gobject_class->finalize = clutter_input_device_xi2_finalize;
+  gobject_class->constructed = meta_input_device_x11_constructed;
+  gobject_class->finalize = meta_input_device_x11_finalize;
 
-  device_class->keycode_to_evdev = clutter_input_device_xi2_keycode_to_evdev;
-  device_class->is_grouped = clutter_input_device_xi2_is_grouped;
-  device_class->get_group_n_modes = clutter_input_device_xi2_get_group_n_modes;
-  device_class->is_mode_switch_button = clutter_input_device_xi2_is_mode_switch_button;
+  device_class->keycode_to_evdev = meta_input_device_x11_keycode_to_evdev;
+  device_class->is_grouped = meta_input_device_x11_is_grouped;
+  device_class->get_group_n_modes = meta_input_device_x11_get_group_n_modes;
+  device_class->is_mode_switch_button = meta_input_device_x11_is_mode_switch_button;
 }
 
 static void
-clutter_input_device_xi2_init (ClutterInputDeviceXI2 *self)
+meta_input_device_x11_init (MetaInputDeviceX11 *self)
 {
 }
 
@@ -229,10 +218,10 @@ get_modifier_for_button (int i)
 }
 
 void
-_clutter_input_device_xi2_translate_state (ClutterEvent    *event,
-                                          XIModifierState *modifiers_state,
-                                           XIButtonState   *buttons_state,
-                                           XIGroupState    *group_state)
+meta_input_device_x11_translate_state (ClutterEvent    *event,
+                                       XIModifierState *modifiers_state,
+                                       XIButtonState   *buttons_state,
+                                       XIGroupState    *group_state)
 {
   guint button = 0;
   guint base = 0;
@@ -287,22 +276,22 @@ _clutter_input_device_xi2_translate_state (ClutterEvent    *event,
 }
 
 void
-clutter_input_device_xi2_update_tool (ClutterInputDevice     *device,
-                                      ClutterInputDeviceTool *tool)
+meta_input_device_x11_update_tool (ClutterInputDevice     *device,
+                                   ClutterInputDeviceTool *tool)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
   g_set_object (&device_xi2->current_tool, tool);
 }
 
 ClutterInputDeviceTool *
-clutter_input_device_xi2_get_current_tool (ClutterInputDevice *device)
+meta_input_device_x11_get_current_tool (ClutterInputDevice *device)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
   return device_xi2->current_tool;
 }
 
 static gboolean
-clutter_input_device_xi2_query_pointer_location (ClutterInputDeviceXI2 *device_xi2)
+meta_input_device_x11_query_pointer_location (MetaInputDeviceX11 *device_xi2)
 {
   Window xroot_window, xchild_window;
   double xroot_x, xroot_y, xwin_x, xwin_y;
@@ -336,7 +325,7 @@ clutter_input_device_xi2_query_pointer_location (ClutterInputDeviceXI2 *device_x
 static gboolean
 clear_inhibit_pointer_query_cb (gpointer data)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (data);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (data);
 
   device_xi2->inhibit_pointer_query_timer = 0;
 
@@ -344,22 +333,21 @@ clear_inhibit_pointer_query_cb (gpointer data)
 }
 
 gboolean
-clutter_input_device_xi2_get_pointer_location (ClutterInputDevice *device,
-                                               float              *x,
-                                               float              *y)
+meta_input_device_x11_get_pointer_location (ClutterInputDevice *device,
+                                            float              *x,
+                                            float              *y)
 
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
 
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_XI2 (device_xi2), FALSE);
+  g_return_val_if_fail (META_IS_INPUT_DEVICE_X11 (device), FALSE);
   g_return_val_if_fail (device->device_type == CLUTTER_POINTER_DEVICE, FALSE);
 
   /* Throttle XServer queries and roundtrips using an idle timeout */
   if (device_xi2->inhibit_pointer_query_timer == 0)
     {
       device_xi2->query_status =
-        clutter_input_device_xi2_query_pointer_location (device_xi2);
+        meta_input_device_x11_query_pointer_location (device_xi2);
       device_xi2->inhibit_pointer_query_timer =
         clutter_threads_add_idle (clear_inhibit_pointer_query_cb, device_xi2);
     }
@@ -372,10 +360,10 @@ clutter_input_device_xi2_get_pointer_location (ClutterInputDevice *device,
 
 #ifdef HAVE_LIBWACOM
 void
-clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
-                                            WacomDeviceDatabase *wacom_db)
+meta_input_device_x11_ensure_wacom_info (ClutterInputDevice  *device,
+                                         WacomDeviceDatabase *wacom_db)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
   const gchar *node_path;
 
   node_path = clutter_input_device_get_device_node (device);
@@ -384,10 +372,10 @@ clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
 }
 
 guint
-clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
-                                             guint               group)
+meta_input_device_x11_get_pad_group_mode (ClutterInputDevice *device,
+                                          guint               group)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
 
   if (group >= device_xi2->group_modes->len)
     return 0;
@@ -396,17 +384,17 @@ clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
 }
 
 void
-clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
-                                           guint               button,
-                                           guint               state,
-                                           guint              *group,
-                                           guint              *mode)
+meta_input_device_x11_update_pad_state (ClutterInputDevice *device,
+                                        guint               button,
+                                        guint               state,
+                                        guint              *group,
+                                        guint              *mode)
 {
-  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
   guint button_group, *group_mode;
   gboolean is_mode_switch = FALSE;
 
-  button_group = clutter_input_device_xi2_get_button_group (device, button);
+  button_group = meta_input_device_x11_get_button_group (device, button);
   is_mode_switch = button_group >= 0;
 
   /* Assign all non-mode-switch buttons to group 0 so far */
diff --git a/src/backends/x11/meta-input-device-x11.h b/src/backends/x11/meta-input-device-x11.h
new file mode 100644
index 000000000..12ee7cf8f
--- /dev/null
+++ b/src/backends/x11/meta-input-device-x11.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2011  Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#ifndef META_INPUT_DEVICE_X11_H
+#define META_INPUT_DEVICE_X11_H
+
+#include <clutter/clutter.h>
+#include <X11/extensions/XInput2.h>
+
+#ifdef HAVE_LIBWACOM
+#include <libwacom/libwacom.h>
+#endif
+
+G_BEGIN_DECLS
+
+#define META_TYPE_INPUT_DEVICE_X11 (meta_input_device_x11_get_type ())
+#define META_INPUT_DEVICE_X11(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_INPUT_DEVICE_X11, 
MetaInputDeviceX11))
+#define META_IS_INPUT_DEVICE_X11(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), META_TYPE_INPUT_DEVICE_X11))
+#define META_INPUT_DEVICE_X11_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_INPUT_DEVICE_X11, 
MetaInputDeviceX11Class))
+#define META_IS_INPUT_DEVICE_X11_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), META_TYPE_INPUT_DEVICE_X11))
+#define META_INPUT_DEVICE_X11_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), META_TYPE_INPUT_DEVICE_X11, 
MetaInputDeviceX11Class))
+
+typedef struct _MetaInputDeviceX11 MetaInputDeviceX11;
+typedef struct _MetaInputDeviceX11Class MetaInputDeviceX11Class;
+
+GType meta_input_device_x11_get_type (void) G_GNUC_CONST;
+
+void  meta_input_device_x11_translate_state (ClutterEvent    *event,
+                                             XIModifierState *modifiers_state,
+                                             XIButtonState   *buttons_state,
+                                             XIGroupState    *group_state);
+void  meta_input_device_x11_update_tool     (ClutterInputDevice     *device,
+                                             ClutterInputDeviceTool *tool);
+ClutterInputDeviceTool * meta_input_device_x11_get_current_tool (ClutterInputDevice *device);
+
+#ifdef HAVE_LIBWACOM
+void meta_input_device_x11_ensure_wacom_info (ClutterInputDevice  *device,
+                                              WacomDeviceDatabase *wacom_db);
+
+guint meta_input_device_x11_get_pad_group_mode (ClutterInputDevice *device,
+                                                guint               group);
+
+void meta_input_device_x11_update_pad_state (ClutterInputDevice *device,
+                                             guint               button,
+                                             guint               state,
+                                             guint              *group,
+                                             guint              *mode);
+
+#endif
+
+gboolean meta_input_device_x11_get_pointer_location (ClutterInputDevice *device,
+                                                     float              *x,
+                                                     float              *y);
+
+G_END_DECLS
+
+#endif /* META_INPUT_DEVICE_X11_H */
diff --git a/clutter/clutter/x11/clutter-keymap-x11.c b/src/backends/x11/meta-keymap-x11.c
similarity index 72%
rename from clutter/clutter/x11/clutter-keymap-x11.c
rename to src/backends/x11/meta-keymap-x11.c
index 0dbb91650..2e71c148d 100644
--- a/clutter/clutter/x11/clutter-keymap-x11.c
+++ b/src/backends/x11/meta-keymap-x11.c
@@ -21,18 +21,16 @@
  * Author: Emmanuele Bassi <ebassi linux intel com>
  */
 
-#include "clutter-build-config.h"
-
-#include "clutter-keymap-x11.h"
-#include "clutter-backend-x11.h"
-
-#include "clutter-debug.h"
-#include "clutter-private.h"
+#include "config.h"
 
+#include <clutter/clutter.h>
+#include <clutter/x11/clutter-x11.h>
 #include <X11/Xatom.h>
 #include <X11/XKBlib.h>
 
-typedef struct _ClutterKeymapX11Class   ClutterKeymapX11Class;
+#include "backends/x11/meta-keymap-x11.h"
+#include "clutter/clutter-mutter.h"
+
 typedef struct _DirectionCacheEntry     DirectionCacheEntry;
 typedef struct _ClutterKeymapKey        ClutterKeymapKey;
 
@@ -50,7 +48,7 @@ struct _DirectionCacheEntry
   PangoDirection direction;
 };
 
-struct _ClutterKeymapX11
+struct _MetaKeymapX11
 {
   ClutterKeymap parent_instance;
 
@@ -88,11 +86,6 @@ struct _ClutterKeymapX11
   guint have_xkb_autorepeat : 1;
 };
 
-struct _ClutterKeymapX11Class
-{
-  ClutterKeymapClass parent_class;
-};
-
 enum
 {
   PROP_0,
@@ -104,14 +97,12 @@ enum
 
 static GParamSpec *obj_props[PROP_LAST] = { NULL, };
 
-#define clutter_keymap_x11_get_type     _clutter_keymap_x11_get_type
-
-G_DEFINE_TYPE (ClutterKeymapX11, clutter_keymap_x11, CLUTTER_TYPE_KEYMAP)
+G_DEFINE_TYPE (MetaKeymapX11, meta_keymap_x11, CLUTTER_TYPE_KEYMAP)
 
 /* code adapted from gdk/x11/gdkkeys-x11.c - update_modmap */
 static void
-update_modmap (Display          *display,
-               ClutterKeymapX11 *keymap_x11)
+update_modmap (Display       *display,
+               MetaKeymapX11 *keymap_x11)
 {
   static struct {
     const gchar *name;
@@ -150,12 +141,12 @@ update_modmap (Display          *display,
 }
 
 static XkbDescPtr
-get_xkb (ClutterKeymapX11 *keymap_x11)
+get_xkb (MetaKeymapX11 *keymap_x11)
 {
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
 
   if (keymap_x11->max_keycode == 0)
-    XDisplayKeycodes (backend_x11->xdpy,
+    XDisplayKeycodes (xdisplay,
                       &keymap_x11->min_keycode,
                       &keymap_x11->max_keycode);
 
@@ -166,7 +157,7 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
                 | XkbModifierMapMask
                 | XkbVirtualModsMask;
 
-      keymap_x11->xkb_desc = XkbGetMap (backend_x11->xdpy, flags, XkbUseCoreKbd);
+      keymap_x11->xkb_desc = XkbGetMap (xdisplay, flags, XkbUseCoreKbd);
       if (G_UNLIKELY (keymap_x11->xkb_desc == NULL))
         {
           g_error ("Failed to get the keymap from XKB");
@@ -174,9 +165,9 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
         }
 
       flags = XkbGroupNamesMask | XkbVirtualModNamesMask;
-      XkbGetNames (backend_x11->xdpy, flags, keymap_x11->xkb_desc);
+      XkbGetNames (xdisplay, flags, keymap_x11->xkb_desc);
 
-      update_modmap (backend_x11->xdpy, keymap_x11);
+      update_modmap (xdisplay, keymap_x11);
     }
   else if (keymap_x11->xkb_map_serial != keymap_x11->keymap_serial)
     {
@@ -185,35 +176,32 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
                 | XkbModifierMapMask
                 | XkbVirtualModsMask;
 
-      CLUTTER_NOTE (BACKEND, "Updating XKB keymap");
-
-      XkbGetUpdatedMap (backend_x11->xdpy, flags, keymap_x11->xkb_desc);
+      XkbGetUpdatedMap (xdisplay, flags, keymap_x11->xkb_desc);
 
       flags = XkbGroupNamesMask | XkbVirtualModNamesMask;
-      XkbGetNames (backend_x11->xdpy, flags, keymap_x11->xkb_desc);
+      XkbGetNames (xdisplay, flags, keymap_x11->xkb_desc);
 
-      update_modmap (backend_x11->xdpy, keymap_x11);
+      update_modmap (xdisplay, keymap_x11);
 
       keymap_x11->xkb_map_serial = keymap_x11->keymap_serial;
     }
 
   if (keymap_x11->num_lock_mask == 0)
-    keymap_x11->num_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy,
-                                                      XK_Num_Lock);
+    keymap_x11->num_lock_mask = XkbKeysymToModifiers (xdisplay, XK_Num_Lock);
 
   if (keymap_x11->scroll_lock_mask == 0)
-    keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy,
+    keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (xdisplay,
                                                          XK_Scroll_Lock);
   if (keymap_x11->level3_shift_mask == 0)
-    keymap_x11->level3_shift_mask = XkbKeysymToModifiers (backend_x11->xdpy,
+    keymap_x11->level3_shift_mask = XkbKeysymToModifiers (xdisplay,
                                                           XK_ISO_Level3_Shift);
 
   return keymap_x11->xkb_desc;
 }
 
 static void
-update_locked_mods (ClutterKeymapX11 *keymap_x11,
-                    gint              locked_mods)
+update_locked_mods (MetaKeymapX11 *keymap_x11,
+                    gint           locked_mods)
 {
   gboolean old_caps_lock_state, old_num_lock_state;
 
@@ -223,10 +211,6 @@ update_locked_mods (ClutterKeymapX11 *keymap_x11,
   keymap_x11->caps_lock_state = (locked_mods & CLUTTER_LOCK_MASK) != 0;
   keymap_x11->num_lock_state  = (locked_mods & keymap_x11->num_lock_mask) != 0;
 
-  CLUTTER_NOTE (BACKEND, "Locks state changed - Num: %s, Caps: %s",
-                keymap_x11->num_lock_state ? "set" : "unset",
-                keymap_x11->caps_lock_state ? "set" : "unset");
-
   if ((keymap_x11->caps_lock_state != old_caps_lock_state) ||
       (keymap_x11->num_lock_state != old_num_lock_state))
     g_signal_emit_by_name (keymap_x11, "state-changed");
@@ -274,9 +258,9 @@ get_direction (XkbDescPtr xkb,
 }
 
 static PangoDirection
-get_direction_from_cache (ClutterKeymapX11 *keymap_x11,
-                          XkbDescPtr        xkb,
-                          int               group)
+get_direction_from_cache (MetaKeymapX11 *keymap_x11,
+                          XkbDescPtr     xkb,
+                          int            group)
 {
   Atom group_atom = xkb->names->groups[group];
   gboolean cache_hit = FALSE;
@@ -335,8 +319,8 @@ get_direction_from_cache (ClutterKeymapX11 *keymap_x11,
 }
 
 static void
-update_direction (ClutterKeymapX11 *keymap_x11,
-                  int               group)
+update_direction (MetaKeymapX11 *keymap_x11,
+                  int            group)
 {
   XkbDescPtr xkb = get_xkb (keymap_x11);
   Atom group_atom;
@@ -352,22 +336,21 @@ update_direction (ClutterKeymapX11 *keymap_x11,
 }
 
 static void
-clutter_keymap_x11_constructed (GObject *gobject)
+meta_keymap_x11_constructed (GObject *gobject)
 {
-  ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (gobject);
-  ClutterBackendX11 *backend_x11;
+  MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (gobject);
+  Display *xdisplay = clutter_x11_get_default_display ();
   gint xkb_major = XkbMajorVersion;
   gint xkb_minor = XkbMinorVersion;
 
   g_assert (keymap_x11->backend != NULL);
-  backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend);
 
   if (XkbLibraryVersion (&xkb_major, &xkb_minor))
     {
       xkb_major = XkbMajorVersion;
       xkb_minor = XkbMinorVersion;
 
-      if (XkbQueryExtension (backend_x11->xdpy,
+      if (XkbQueryExtension (xdisplay,
                              NULL,
                              &keymap_x11->xkb_event_base,
                              NULL,
@@ -377,18 +360,18 @@ clutter_keymap_x11_constructed (GObject *gobject)
 
           keymap_x11->use_xkb = TRUE;
 
-          XkbSelectEvents (backend_x11->xdpy,
+          XkbSelectEvents (xdisplay,
                            XkbUseCoreKbd,
                            XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
                            XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
 
-          XkbSelectEventDetails (backend_x11->xdpy,
+          XkbSelectEventDetails (xdisplay,
                                  XkbUseCoreKbd, XkbStateNotify,
                                  XkbAllStateComponentsMask,
                                  XkbGroupLockMask | XkbModifierLockMask);
 
           /* enable XKB autorepeat */
-          XkbSetDetectableAutoRepeat (backend_x11->xdpy,
+          XkbSetDetectableAutoRepeat (xdisplay,
                                       True,
                                       &detectable_autorepeat_supported);
 
@@ -398,12 +381,12 @@ clutter_keymap_x11_constructed (GObject *gobject)
 }
 
 static void
-clutter_keymap_x11_set_property (GObject      *gobject,
-                                 guint         prop_id,
-                                 const GValue *value,
-                                 GParamSpec   *pspec)
+meta_keymap_x11_set_property (GObject      *gobject,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
 {
-  ClutterKeymapX11 *keymap = CLUTTER_KEYMAP_X11 (gobject);
+  MetaKeymapX11 *keymap = META_KEYMAP_X11 (gobject);
 
   switch (prop_id)
     {
@@ -418,7 +401,7 @@ clutter_keymap_x11_set_property (GObject      *gobject,
 }
 
 static void
-clutter_keymap_x11_refresh_reserved_keycodes (ClutterKeymapX11 *keymap_x11)
+meta_keymap_x11_refresh_reserved_keycodes (MetaKeymapX11 *keymap_x11)
 {
   Display *dpy = clutter_x11_get_default_display ();
   GHashTableIter iter;
@@ -444,9 +427,9 @@ clutter_keymap_x11_refresh_reserved_keycodes (ClutterKeymapX11 *keymap_x11)
 }
 
 static gboolean
-clutter_keymap_x11_replace_keycode (ClutterKeymapX11 *keymap_x11,
-                                    KeyCode           keycode,
-                                    KeySym            keysym)
+meta_keymap_x11_replace_keycode (MetaKeymapX11 *keymap_x11,
+                                 KeyCode        keycode,
+                                 KeySym         keysym)
 {
   if (keymap_x11->use_xkb)
     {
@@ -487,20 +470,20 @@ clutter_keymap_x11_replace_keycode (ClutterKeymapX11 *keymap_x11,
 }
 
 static void
-clutter_keymap_x11_finalize (GObject *gobject)
+meta_keymap_x11_finalize (GObject *gobject)
 {
-  ClutterKeymapX11 *keymap;
+  MetaKeymapX11 *keymap;
   GHashTableIter iter;
   gpointer key, value;
 
-  keymap = CLUTTER_KEYMAP_X11 (gobject);
+  keymap = META_KEYMAP_X11 (gobject);
 
-  clutter_keymap_x11_refresh_reserved_keycodes (keymap);
+  meta_keymap_x11_refresh_reserved_keycodes (keymap);
   g_hash_table_iter_init (&iter, keymap->reserved_keycodes);
   while (g_hash_table_iter_next (&iter, &key, &value))
     {
       guint keycode = GPOINTER_TO_UINT (key);
-      clutter_keymap_x11_replace_keycode (keymap, keycode, NoSymbol);
+      meta_keymap_x11_replace_keycode (keymap, keycode, NoSymbol);
     }
 
   g_hash_table_destroy (keymap->reserved_keycodes);
@@ -509,50 +492,50 @@ clutter_keymap_x11_finalize (GObject *gobject)
   if (keymap->xkb_desc != NULL)
     XkbFreeKeyboard (keymap->xkb_desc, XkbAllComponentsMask, True);
 
-  G_OBJECT_CLASS (clutter_keymap_x11_parent_class)->finalize (gobject);
+  G_OBJECT_CLASS (meta_keymap_x11_parent_class)->finalize (gobject);
 }
 
 static gboolean
-clutter_keymap_x11_get_num_lock_state (ClutterKeymap *keymap)
+meta_keymap_x11_get_num_lock_state (ClutterKeymap *keymap)
 {
-  ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (keymap);
+  MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (keymap);
 
   return keymap_x11->num_lock_state;
 }
 
 static gboolean
-clutter_keymap_x11_get_caps_lock_state (ClutterKeymap *keymap)
+meta_keymap_x11_get_caps_lock_state (ClutterKeymap *keymap)
 {
-  ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (keymap);
+  MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (keymap);
 
   return keymap_x11->caps_lock_state;
 }
 
 static void
-clutter_keymap_x11_class_init (ClutterKeymapX11Class *klass)
+meta_keymap_x11_class_init (MetaKeymapX11Class *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   ClutterKeymapClass *keymap_class = CLUTTER_KEYMAP_CLASS (klass);
 
   obj_props[PROP_BACKEND] =
     g_param_spec_object ("backend",
-                         P_("Backend"),
-                         P_("The Clutter backend"),
+                         "Backend",
+                         "The Clutter backend",
                          CLUTTER_TYPE_BACKEND,
-                         CLUTTER_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
 
-  gobject_class->constructed = clutter_keymap_x11_constructed;
-  gobject_class->set_property = clutter_keymap_x11_set_property;
-  gobject_class->finalize = clutter_keymap_x11_finalize;
+  gobject_class->constructed = meta_keymap_x11_constructed;
+  gobject_class->set_property = meta_keymap_x11_set_property;
+  gobject_class->finalize = meta_keymap_x11_finalize;
 
-  keymap_class->get_num_lock_state = clutter_keymap_x11_get_num_lock_state;
-  keymap_class->get_caps_lock_state = clutter_keymap_x11_get_caps_lock_state;
+  keymap_class->get_num_lock_state = meta_keymap_x11_get_num_lock_state;
+  keymap_class->get_caps_lock_state = meta_keymap_x11_get_caps_lock_state;
 
   g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
 }
 
 static void
-clutter_keymap_x11_init (ClutterKeymapX11 *keymap)
+meta_keymap_x11_init (MetaKeymapX11 *keymap)
 {
   keymap->current_direction = PANGO_DIRECTION_NEUTRAL;
   keymap->current_group = -1;
@@ -561,8 +544,8 @@ clutter_keymap_x11_init (ClutterKeymapX11 *keymap)
 }
 
 gboolean
-clutter_keymap_x11_handle_event (ClutterKeymapX11 *keymap_x11,
-                                 XEvent           *xevent)
+meta_keymap_x11_handle_event (MetaKeymapX11 *keymap_x11,
+                              XEvent        *xevent)
 {
   gboolean retval;
 
@@ -578,7 +561,6 @@ clutter_keymap_x11_handle_event (ClutterKeymapX11 *keymap_x11,
       switch (xkb_event->any.xkb_type)
         {
         case XkbStateNotify:
-          CLUTTER_NOTE (EVENT, "Updating keyboard state");
           keymap_x11->current_group = XkbStateGroup (&xkb_event->state);
           update_direction (keymap_x11, keymap_x11->current_group);
           update_locked_mods (keymap_x11, xkb_event->state.locked_mods);
@@ -587,7 +569,6 @@ clutter_keymap_x11_handle_event (ClutterKeymapX11 *keymap_x11,
 
         case XkbNewKeyboardNotify:
         case XkbMapNotify:
-          CLUTTER_NOTE (EVENT, "Updating keyboard mapping");
           XkbRefreshKeyboardMapping (&xkb_event->map);
           keymap_x11->keymap_serial += 1;
           retval = TRUE;
@@ -608,8 +589,8 @@ clutter_keymap_x11_handle_event (ClutterKeymapX11 *keymap_x11,
 }
 
 gint
-_clutter_keymap_x11_get_key_group (ClutterKeymapX11    *keymap,
-                                   ClutterModifierType  state)
+meta_keymap_x11_get_key_group (MetaKeymapX11       *keymap,
+                               ClutterModifierType  state)
 {
   return XkbGroupForCoreState (state);
 }
@@ -622,32 +603,29 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  * a fallback path.
  */
 static int
-translate_keysym (ClutterKeymapX11 *keymap,
-                  guint             hardware_keycode)
+translate_keysym (MetaKeymapX11 *keymap,
+                  guint          hardware_keycode)
 {
-  ClutterBackendX11 *backend_x11;
   gint retval;
 
-  backend_x11 = CLUTTER_BACKEND_X11 (keymap->backend);
-
-  retval = XKeycodeToKeysym (backend_x11->xdpy, hardware_keycode, 0);
-
+  retval = XKeycodeToKeysym (clutter_x11_get_default_display (),
+                             hardware_keycode, 0);
   return retval;
 }
 
 G_GNUC_END_IGNORE_DEPRECATIONS
 
 gint
-_clutter_keymap_x11_translate_key_state (ClutterKeymapX11    *keymap,
-                                         guint                hardware_keycode,
-                                         ClutterModifierType *modifier_state_p,
-                                         ClutterModifierType *mods_p)
+meta_keymap_x11_translate_key_state (MetaKeymapX11       *keymap,
+                                     guint                hardware_keycode,
+                                     ClutterModifierType *modifier_state_p,
+                                     ClutterModifierType *mods_p)
 {
   ClutterModifierType unconsumed_modifiers = 0;
   ClutterModifierType modifier_state = *modifier_state_p;
   gint retval;
 
-  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), 0);
+  g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), 0);
 
   if (keymap->use_xkb)
     {
@@ -677,10 +655,10 @@ _clutter_keymap_x11_translate_key_state (ClutterKeymapX11    *keymap,
 }
 
 gboolean
-_clutter_keymap_x11_get_is_modifier (ClutterKeymapX11 *keymap,
-                                     gint              keycode)
+meta_keymap_x11_get_is_modifier (MetaKeymapX11 *keymap,
+                                 gint           keycode)
 {
-  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), FALSE);
+  g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), FALSE);
 
   if (keycode < keymap->min_keycode || keycode > keymap->max_keycode)
     return FALSE;
@@ -697,18 +675,18 @@ _clutter_keymap_x11_get_is_modifier (ClutterKeymapX11 *keymap,
 }
 
 PangoDirection
-_clutter_keymap_x11_get_direction (ClutterKeymapX11 *keymap)
+meta_keymap_x11_get_direction (MetaKeymapX11 *keymap)
 {
-  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL);
+  g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL);
 
   if (keymap->use_xkb)
     {
       if (!keymap->has_direction)
         {
-          Display *xdisplay = CLUTTER_BACKEND_X11 (keymap->backend)->xdpy;
           XkbStateRec state_rec;
 
-          XkbGetState (xdisplay, XkbUseCoreKbd, &state_rec);
+          XkbGetState (clutter_x11_get_default_display (),
+                       XkbUseCoreKbd, &state_rec);
           update_direction (keymap, XkbStateGroup (&state_rec));
         }
 
@@ -719,10 +697,10 @@ _clutter_keymap_x11_get_direction (ClutterKeymapX11 *keymap)
 }
 
 static gboolean
-clutter_keymap_x11_get_entries_for_keyval (ClutterKeymapX11  *keymap_x11,
-                                           guint              keyval,
-                                           ClutterKeymapKey **keys,
-                                           gint              *n_keys)
+meta_keymap_x11_get_entries_for_keyval (MetaKeymapX11     *keymap_x11,
+                                        guint              keyval,
+                                        ClutterKeymapKey **keys,
+                                        gint              *n_keys)
 {
   if (keymap_x11->use_xkb)
     {
@@ -802,11 +780,11 @@ clutter_keymap_x11_get_entries_for_keyval (ClutterKeymapX11  *keymap_x11,
 }
 
 static guint
-clutter_keymap_x11_get_available_keycode (ClutterKeymapX11 *keymap_x11)
+meta_keymap_x11_get_available_keycode (MetaKeymapX11 *keymap_x11)
 {
   if (keymap_x11->use_xkb)
     {
-      clutter_keymap_x11_refresh_reserved_keycodes (keymap_x11);
+      meta_keymap_x11_refresh_reserved_keycodes (keymap_x11);
 
       if (g_hash_table_size (keymap_x11->reserved_keycodes) < 5)
         {
@@ -827,15 +805,16 @@ clutter_keymap_x11_get_available_keycode (ClutterKeymapX11 *keymap_x11)
   return 0;
 }
 
-gboolean clutter_keymap_x11_reserve_keycode (ClutterKeymapX11 *keymap_x11,
-                                             guint             keyval,
-                                             guint            *keycode_out)
+gboolean
+meta_keymap_x11_reserve_keycode (MetaKeymapX11 *keymap_x11,
+                                 guint          keyval,
+                                 guint         *keycode_out)
 {
-  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap_x11), FALSE);
+  g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap_x11), FALSE);
   g_return_val_if_fail (keyval != 0, FALSE);
   g_return_val_if_fail (keycode_out != NULL, FALSE);
 
-  *keycode_out = clutter_keymap_x11_get_available_keycode (keymap_x11);
+  *keycode_out = meta_keymap_x11_get_available_keycode (keymap_x11);
 
   if (*keycode_out == NoSymbol)
     {
@@ -843,7 +822,7 @@ gboolean clutter_keymap_x11_reserve_keycode (ClutterKeymapX11 *keymap_x11,
       return FALSE;
     }
 
-  if (!clutter_keymap_x11_replace_keycode (keymap_x11, *keycode_out, keyval))
+  if (!meta_keymap_x11_replace_keycode (keymap_x11, *keycode_out, keyval))
     {
       g_warning ("Failed to remap keycode %d to keyval %d", *keycode_out, keyval);
       return FALSE;
@@ -855,10 +834,11 @@ gboolean clutter_keymap_x11_reserve_keycode (ClutterKeymapX11 *keymap_x11,
   return TRUE;
 }
 
-void clutter_keymap_x11_release_keycode_if_needed (ClutterKeymapX11 *keymap_x11,
-                                                   guint             keycode)
+void
+meta_keymap_x11_release_keycode_if_needed (MetaKeymapX11 *keymap_x11,
+                                           guint          keycode)
 {
-  g_return_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap_x11));
+  g_return_if_fail (META_IS_KEYMAP_X11 (keymap_x11));
 
   if (!g_hash_table_contains (keymap_x11->reserved_keycodes, GUINT_TO_POINTER (keycode)) ||
       g_queue_index (keymap_x11->available_keycodes, GUINT_TO_POINTER (keycode)) != -1)
@@ -868,9 +848,9 @@ void clutter_keymap_x11_release_keycode_if_needed (ClutterKeymapX11 *keymap_x11,
 }
 
 void
-clutter_keymap_x11_latch_modifiers (ClutterKeymapX11 *keymap_x11,
-                                    uint32_t          level,
-                                    gboolean          enable)
+meta_keymap_x11_latch_modifiers (MetaKeymapX11 *keymap_x11,
+                                 uint32_t       level,
+                                 gboolean       enable)
 {
   uint32_t modifiers[] = {
     0,
@@ -896,23 +876,23 @@ clutter_keymap_x11_latch_modifiers (ClutterKeymapX11 *keymap_x11,
 }
 
 static uint32_t
-clutter_keymap_x11_get_current_group (ClutterKeymapX11 *keymap_x11)
+meta_keymap_x11_get_current_group (MetaKeymapX11 *keymap_x11)
 {
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend);
   XkbStateRec state_rec;
 
   if (keymap_x11->current_group >= 0)
     return keymap_x11->current_group;
 
-  XkbGetState (backend_x11->xdpy, XkbUseCoreKbd, &state_rec);
+  XkbGetState (clutter_x11_get_default_display (),
+               XkbUseCoreKbd, &state_rec);
   return XkbStateGroup (&state_rec);
 }
 
 gboolean
-clutter_keymap_x11_keycode_for_keyval (ClutterKeymapX11 *keymap_x11,
-                                       guint             keyval,
-                                       guint            *keycode_out,
-                                       guint            *level_out)
+meta_keymap_x11_keycode_for_keyval (MetaKeymapX11 *keymap_x11,
+                                    guint          keyval,
+                                    guint         *keycode_out,
+                                    guint         *level_out)
 {
   ClutterKeymapKey *keys;
   gint i, n_keys, group;
@@ -921,9 +901,9 @@ clutter_keymap_x11_keycode_for_keyval (ClutterKeymapX11 *keymap_x11,
   g_return_val_if_fail (keycode_out != NULL, FALSE);
   g_return_val_if_fail (level_out != NULL, FALSE);
 
-  group = clutter_keymap_x11_get_current_group (keymap_x11);
+  group = meta_keymap_x11_get_current_group (keymap_x11);
 
-  if (!clutter_keymap_x11_get_entries_for_keyval (keymap_x11, keyval, &keys, &n_keys))
+  if (!meta_keymap_x11_get_entries_for_keyval (keymap_x11, keyval, &keys, &n_keys))
     return FALSE;
 
   for (i = 0; i < n_keys && !found; i++)
diff --git a/src/backends/x11/meta-keymap-x11.h b/src/backends/x11/meta-keymap-x11.h
new file mode 100644
index 000000000..e2bb52634
--- /dev/null
+++ b/src/backends/x11/meta-keymap-x11.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2009  Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#ifndef META_KEYMAP_X11_H
+#define META_KEYMAP_X11_H
+
+#include <glib-object.h>
+#include <pango/pango.h>
+#include <clutter/clutter.h>
+
+G_BEGIN_DECLS
+
+#define META_TYPE_KEYMAP_X11 (meta_keymap_x11_get_type ())
+G_DECLARE_FINAL_TYPE (MetaKeymapX11, meta_keymap_x11,
+                      META, KEYMAP_X11, ClutterKeymap)
+
+gint     meta_keymap_x11_get_key_group       (MetaKeymapX11       *keymap,
+                                              ClutterModifierType  state);
+gint     meta_keymap_x11_translate_key_state (MetaKeymapX11       *keymap,
+                                              guint                hardware_keycode,
+                                              ClutterModifierType *modifier_state_p,
+                                              ClutterModifierType *mods_p);
+gboolean meta_keymap_x11_get_is_modifier     (MetaKeymapX11       *keymap,
+                                              gint                 keycode);
+
+PangoDirection meta_keymap_x11_get_direction (MetaKeymapX11       *keymap);
+
+gboolean meta_keymap_x11_keycode_for_keyval       (MetaKeymapX11    *keymap_x11,
+                                                   guint             keyval,
+                                                   guint            *keycode_out,
+                                                   guint            *level_out);
+void     meta_keymap_x11_latch_modifiers          (MetaKeymapX11 *keymap_x11,
+                                                   uint32_t          level,
+                                                   gboolean          enable);
+gboolean meta_keymap_x11_reserve_keycode           (MetaKeymapX11 *keymap_x11,
+                                                    guint             keyval,
+                                                    guint            *keycode_out);
+void     meta_keymap_x11_release_keycode_if_needed (MetaKeymapX11 *keymap_x11,
+                                                    guint             keycode);
+
+gboolean meta_keymap_x11_handle_event        (MetaKeymapX11 *keymap_x11,
+                                              XEvent        *xevent);
+
+G_END_DECLS
+
+#endif /* META_KEYMAP_X11_H */
diff --git a/src/backends/x11/meta-stage-x11-nested.c b/src/backends/x11/meta-stage-x11-nested.c
index 02fef1e55..f6dc5dbcb 100644
--- a/src/backends/x11/meta-stage-x11-nested.c
+++ b/src/backends/x11/meta-stage-x11-nested.c
@@ -39,7 +39,7 @@ static ClutterStageWindowInterface *clutter_stage_window_parent_iface = NULL;
 
 struct _MetaStageX11Nested
 {
-  ClutterStageX11 parent;
+  MetaStageX11 parent;
 
   CoglPipeline *pipeline;
 };
@@ -48,11 +48,11 @@ static void
 clutter_stage_window_iface_init (ClutterStageWindowInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (MetaStageX11Nested, meta_stage_x11_nested,
-                         CLUTTER_TYPE_STAGE_X11,
+                         META_TYPE_STAGE_X11,
                          G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
                                                 clutter_stage_window_iface_init))
 
-typedef struct _ClutterStageX11View
+typedef struct _MetaStageX11View
 {
   CoglTexture *texture;
   ClutterStageViewCogl *view;
@@ -108,7 +108,7 @@ draw_crtc (MetaMonitor         *monitor,
            GError             **error)
 {
   DrawCrtcData *data = user_data;
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (data->stage_nested);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (data->stage_nested);
   CoglFramebuffer *onscreen = COGL_FRAMEBUFFER (stage_x11->onscreen);
   CoglTexture *texture = data->texture;
   MetaLogicalMonitor *logical_monitor = data->logical_monitor;
@@ -247,7 +247,7 @@ static void
 meta_stage_x11_nested_finish_frame (ClutterStageWindow *stage_window)
 {
   MetaStageX11Nested *stage_nested = META_STAGE_X11_NESTED (stage_window);
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   MetaBackend *backend = meta_get_backend ();
   MetaRenderer *renderer = meta_backend_get_renderer (backend);
   ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
diff --git a/src/backends/x11/meta-stage-x11-nested.h b/src/backends/x11/meta-stage-x11-nested.h
index 412aea027..b605e07e2 100644
--- a/src/backends/x11/meta-stage-x11-nested.h
+++ b/src/backends/x11/meta-stage-x11-nested.h
@@ -26,9 +26,10 @@
 #define META_STAGE_X11_NESTED_H
 
 #include "clutter/clutter-mutter.h"
+#include "meta-stage-x11.h"
 
 #define META_TYPE_STAGE_X11_NESTED (meta_stage_x11_nested_get_type ())
 G_DECLARE_FINAL_TYPE (MetaStageX11Nested, meta_stage_x11_nested,
-                      META, STAGE_X11_NESTED, ClutterStageX11)
+                      META, STAGE_X11_NESTED, MetaStageX11)
 
 #endif /* META_STAGE_X11_NESTED_H */
diff --git a/clutter/clutter/x11/clutter-stage-x11.c b/src/backends/x11/meta-stage-x11.c
similarity index 69%
rename from clutter/clutter/x11/clutter-stage-x11.c
rename to src/backends/x11/meta-stage-x11.c
index acc1f3d12..ce0f7866d 100644
--- a/clutter/clutter/x11/clutter-stage-x11.c
+++ b/src/backends/x11/meta-stage-x11.c
@@ -1,5 +1,4 @@
-/* Clutter.
- * An OpenGL based 'interactive canvas' library.
+/*
  * Authored By Matthew Allum  <mallum openedhand com>
  * Copyright (C) 2006-2007 OpenedHand
  *
@@ -16,10 +15,9 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
- *
  */
 
-#include "clutter-build-config.h"
+#include "config.h"
 
 #include <math.h>
 #include <stdlib.h>
@@ -29,38 +27,28 @@
 #endif
 
 #include <cogl/cogl.h>
+#include <clutter/clutter-mutter.h>
+#include <clutter/x11/clutter-x11.h>
+#include <clutter/x11/clutter-backend-x11.h>
 
-#include "clutter-backend-x11.h"
-#include "clutter-stage-x11.h"
-#include "clutter-x11.h"
-
-#include "clutter-actor-private.h"
-#include "clutter-debug.h"
-#include "clutter-device-manager-private.h"
-#include "clutter-enum-types.h"
-#include "clutter-event-private.h"
-#include "clutter-feature.h"
-#include "clutter-main.h"
-#include "clutter-mutter.h"
-#include "clutter-paint-volume-private.h"
-#include "clutter-private.h"
-#include "clutter-stage-private.h"
+#include "core/display-private.h"
+#include "meta/meta-x11-errors.h"
+#include "meta-backend-x11.h"
+#include "meta-stage-x11.h"
 
-#define STAGE_X11_IS_MAPPED(s)  ((((ClutterStageX11 *) (s))->wm_state & STAGE_X11_WITHDRAWN) == 0)
+#define STAGE_X11_IS_MAPPED(s)  ((((MetaStageX11 *) (s))->wm_state & STAGE_X11_WITHDRAWN) == 0)
 
 static ClutterStageWindowInterface *clutter_stage_window_parent_iface = NULL;
 
 static void
 clutter_stage_window_iface_init (ClutterStageWindowInterface *iface);
 
-static ClutterStageCogl *clutter_x11_get_stage_window_from_window (Window win);
+static ClutterStageCogl *meta_x11_get_stage_window_from_window (Window win);
 
 static GHashTable *clutter_stages_by_xid = NULL;
 
-#define clutter_stage_x11_get_type      _clutter_stage_x11_get_type
-
-G_DEFINE_TYPE_WITH_CODE (ClutterStageX11,
-                         clutter_stage_x11,
+G_DEFINE_TYPE_WITH_CODE (MetaStageX11,
+                         meta_stage_x11,
                          CLUTTER_TYPE_STAGE_COGL,
                          G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
                                                 clutter_stage_window_iface_init));
@@ -69,7 +57,7 @@ G_DEFINE_TYPE_WITH_CODE (ClutterStageX11,
 #define _NET_WM_STATE_ADD           1    /* add/set property */
 #define _NET_WM_STATE_TOGGLE        2    /* toggle property  */
 
-#define CLUTTER_STAGE_X11_EVENT_MASK \
+#define META_STAGE_X11_EVENT_MASK \
   StructureNotifyMask | \
   FocusChangeMask | \
   ExposureMask | \
@@ -88,10 +76,9 @@ send_wmspec_change_state (ClutterBackendX11 *backend_x11,
                           Atom               state,
                           gboolean           add)
 {
+  Display *xdisplay = clutter_x11_get_default_display ();
   XClientMessageEvent xclient;
 
-  CLUTTER_NOTE (BACKEND, "%s NET_WM state", add ? "adding" : "removing");
-
   memset (&xclient, 0, sizeof (xclient));
 
   xclient.type         = ClientMessage;
@@ -105,23 +92,25 @@ send_wmspec_change_state (ClutterBackendX11 *backend_x11,
   xclient.data.l[3] = 0;
   xclient.data.l[4] = 0;
 
-  XSendEvent (backend_x11->xdpy, 
-              DefaultRootWindow (backend_x11->xdpy),
+  XSendEvent (xdisplay,
+              DefaultRootWindow (xdisplay),
               False,
               SubstructureRedirectMask | SubstructureNotifyMask,
               (XEvent *)&xclient);
 }
 
 static void
-update_state (ClutterStageX11   *stage_x11,
+update_state (MetaStageX11      *stage_x11,
               ClutterBackendX11 *backend_x11,
               Atom              *state,
               gboolean           add)
 {
+  Display *xdisplay = clutter_x11_get_default_display ();
+
   if (add)
     {
       /* FIXME: This wont work if we support more states */
-      XChangeProperty (backend_x11->xdpy,
+      XChangeProperty (xdisplay,
                        stage_x11->xwin,
                        backend_x11->atom_NET_WM_STATE, XA_ATOM, 32,
                        PropModeReplace,
@@ -129,23 +118,23 @@ update_state (ClutterStageX11   *stage_x11,
     }
   else
     {
-       /* FIXME: This wont work if we support more states */
-       XDeleteProperty (backend_x11->xdpy,
-                        stage_x11->xwin,
-                        backend_x11->atom_NET_WM_STATE);
+      /* FIXME: This wont work if we support more states */
+      XDeleteProperty (xdisplay,
+                       stage_x11->xwin,
+                       backend_x11->atom_NET_WM_STATE);
     }
 }
 
 static void
-clutter_stage_x11_fix_window_size (ClutterStageX11 *stage_x11,
-                                   gint             new_width,
-                                   gint             new_height)
+meta_stage_x11_fix_window_size (MetaStageX11 *stage_x11,
+                                gint          new_width,
+                                gint          new_height)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
 
   if (stage_x11->xwin != None)
     {
+      Display *xdisplay = clutter_x11_get_default_display ();
       guint min_width, min_height;
       XSizeHints *size_hints;
       gboolean resize;
@@ -186,33 +175,35 @@ clutter_stage_x11_fix_window_size (ClutterStageX11 *stage_x11,
             }
         }
 
-      XSetWMNormalHints (backend_x11->xdpy, stage_x11->xwin, size_hints);
+      XSetWMNormalHints (xdisplay, stage_x11->xwin, size_hints);
 
       XFree(size_hints);
     }
 }
 
 static void
-clutter_stage_x11_set_wm_protocols (ClutterStageX11 *stage_x11)
+meta_stage_x11_set_wm_protocols (MetaStageX11 *stage_x11)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
   Atom protocols[2];
   int n = 0;
   
   protocols[n++] = backend_x11->atom_WM_DELETE_WINDOW;
   protocols[n++] = backend_x11->atom_NET_WM_PING;
 
-  XSetWMProtocols (backend_x11->xdpy, stage_x11->xwin, protocols, n);
+  XSetWMProtocols (xdisplay, stage_x11->xwin, protocols, n);
 }
 
 static void
-clutter_stage_x11_get_geometry (ClutterStageWindow    *stage_window,
-                                cairo_rectangle_int_t *geometry)
+meta_stage_x11_get_geometry (ClutterStageWindow    *stage_window,
+                             cairo_rectangle_int_t *geometry)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
 
   geometry->x = geometry->y = 0;
 
@@ -227,8 +218,8 @@ clutter_stage_x11_get_geometry (ClutterStageWindow    *stage_window,
   if (_clutter_stage_is_fullscreen (stage_cogl->wrapper) &&
       stage_x11->fullscreening)
     {
-      geometry->width = DisplayWidth (backend_x11->xdpy, backend_x11->xscreen_num);
-      geometry->height = DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num);
+      geometry->width = DisplayWidth (xdisplay, backend_x11->xscreen_num);
+      geometry->height = DisplayHeight (xdisplay, backend_x11->xscreen_num);
 
       return;
     }
@@ -238,13 +229,11 @@ clutter_stage_x11_get_geometry (ClutterStageWindow    *stage_window,
 }
 
 static void
-clutter_stage_x11_resize (ClutterStageWindow *stage_window,
-                          gint                width,
-                          gint                height)
+meta_stage_x11_resize (ClutterStageWindow *stage_window,
+                       gint                width,
+                       gint                height)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
-  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   /* If we're going fullscreen, don't mess with the size */
   if (stage_x11->fullscreening)
@@ -260,26 +249,20 @@ clutter_stage_x11_resize (ClutterStageWindow *stage_window,
       height = 1;
     }
 
-  CLUTTER_NOTE (BACKEND, "New size received: (%d, %d)", width, height);
-
   if (stage_x11->xwin != None)
     {
-      clutter_stage_x11_fix_window_size (stage_x11, width, height);
+      meta_stage_x11_fix_window_size (stage_x11, width, height);
 
       if (width != stage_x11->xwin_width ||
           height != stage_x11->xwin_height)
         {
-          CLUTTER_NOTE (BACKEND, "%s: XResizeWindow[%x] (%d, %d)",
-                        G_STRLOC,
-                        (unsigned int) stage_x11->xwin,
-                        width,
-                        height);
+          Display *xdisplay = clutter_x11_get_default_display ();
 
           /* XXX: in this case we can rely on a subsequent
            * ConfigureNotify that will result in the stage
            * being reallocated so we don't actively do anything
            * to affect the stage allocation here. */
-          XResizeWindow (backend_x11->xdpy,
+          XResizeWindow (xdisplay,
                          stage_x11->xwin,
                          width,
                          height);
@@ -296,24 +279,25 @@ clutter_stage_x11_resize (ClutterStageWindow *stage_window,
 }
 
 static inline void
-set_wm_pid (ClutterStageX11 *stage_x11)
+set_wm_pid (MetaStageX11 *stage_x11)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
   long pid;
 
   if (stage_x11->xwin == None)
     return;
 
   /* this will take care of WM_CLIENT_MACHINE and WM_LOCALE_NAME */
-  XSetWMProperties (backend_x11->xdpy, stage_x11->xwin,
+  XSetWMProperties (xdisplay, stage_x11->xwin,
                     NULL,
                     NULL,
                     NULL, 0,
                     NULL, NULL, NULL);
 
   pid = getpid ();
-  XChangeProperty (backend_x11->xdpy,
+  XChangeProperty (xdisplay,
                    stage_x11->xwin,
                    backend_x11->atom_NET_WM_PID, XA_CARDINAL, 32,
                    PropModeReplace,
@@ -321,23 +305,24 @@ set_wm_pid (ClutterStageX11 *stage_x11)
 }
 
 static inline void
-set_wm_title (ClutterStageX11 *stage_x11)
+set_wm_title (MetaStageX11 *stage_x11)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
 
   if (stage_x11->xwin == None)
     return;
 
   if (stage_x11->title == NULL)
     {
-      XDeleteProperty (backend_x11->xdpy,
+      XDeleteProperty (xdisplay,
                        stage_x11->xwin, 
                        backend_x11->atom_NET_WM_NAME);
     }
   else
     {
-      XChangeProperty (backend_x11->xdpy,
+      XChangeProperty (xdisplay,
                        stage_x11->xwin, 
                        backend_x11->atom_NET_WM_NAME,
                        backend_x11->atom_UTF8_STRING,
@@ -349,21 +334,16 @@ set_wm_title (ClutterStageX11 *stage_x11)
 }
 
 static inline void
-set_cursor_visible (ClutterStageX11 *stage_x11)
+set_cursor_visible (MetaStageX11 *stage_x11)
 {
-  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
 
   if (stage_x11->xwin == None)
     return;
 
-  CLUTTER_NOTE (BACKEND, "setting cursor state ('%s') over stage window (%u)",
-                stage_x11->is_cursor_visible ? "visible" : "invisible",
-                (unsigned int) stage_x11->xwin);
-
   if (stage_x11->is_cursor_visible)
     {
-      XUndefineCursor (backend_x11->xdpy, stage_x11->xwin);
+      XUndefineCursor (xdisplay, stage_x11->xwin);
     }
   else
     {
@@ -371,29 +351,25 @@ set_cursor_visible (ClutterStageX11 *stage_x11)
       Pixmap pix;
       Cursor curs;
 
-      pix = XCreatePixmap (backend_x11->xdpy, stage_x11->xwin, 1, 1, 1);
+      pix = XCreatePixmap (xdisplay, stage_x11->xwin, 1, 1, 1);
       memset (&col, 0, sizeof (col));
-      curs = XCreatePixmapCursor (backend_x11->xdpy,
+      curs = XCreatePixmapCursor (xdisplay,
                                   pix, pix,
                                   &col, &col,
                                   1, 1);
-      XFreePixmap (backend_x11->xdpy, pix);
-      XDefineCursor (backend_x11->xdpy, stage_x11->xwin, curs);
+      XFreePixmap (xdisplay, pix);
+      XDefineCursor (xdisplay, stage_x11->xwin, curs);
     }
 }
 
 static void
-clutter_stage_x11_unrealize (ClutterStageWindow *stage_window)
+meta_stage_x11_unrealize (ClutterStageWindow *stage_window)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window);
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   if (clutter_stages_by_xid != NULL)
     {
-      CLUTTER_NOTE (BACKEND, "Removing X11 stage 0x%x [%p]",
-                    (unsigned int) stage_x11->xwin,
-                    stage_x11);
-
       g_hash_table_remove (clutter_stages_by_xid,
                            GINT_TO_POINTER (stage_x11->xwin));
     }
@@ -426,10 +402,10 @@ clutter_stage_x11_unrealize (ClutterStageWindow *stage_window)
 }
 
 static void
-clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
-                                  gboolean            is_fullscreen)
+meta_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
+                               gboolean            is_fullscreen)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
   ClutterStage *stage = stage_cogl->wrapper;
@@ -444,8 +420,6 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
   if (was_fullscreen == is_fullscreen)
     return;
 
-  CLUTTER_NOTE (BACKEND, "%ssetting fullscreen", is_fullscreen ? "" : "un");
-
   if (is_fullscreen)
     {
 #if 0
@@ -456,8 +430,8 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
          but Metacity (at least) will fullscreen to only one of the
          displays. This will cause the actor to report the wrong size
          until the ConfigureNotify for the correct size is received */
-      width  = DisplayWidth (backend_x11->xdpy, backend_x11->xscreen_num);
-      height = DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num);
+      width  = DisplayWidth (xdisplay, backend_x11->xscreen_num);
+      height = DisplayHeight (xdisplay, backend_x11->xscreen_num);
 #endif
 
       /* Set the fullscreen hint so we can retain the old size of the window. */
@@ -472,21 +446,17 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
            */
           if (!STAGE_X11_IS_MAPPED (stage_x11))
             {
-              CLUTTER_NOTE (BACKEND, "Fullscreening unmapped stage");
-
               update_state (stage_x11, backend_x11,
                             &backend_x11->atom_NET_WM_STATE_FULLSCREEN,
                             TRUE);
             }
           else
             {
-              CLUTTER_NOTE (BACKEND, "Fullscreening mapped stage");
-
               /* We need to fix the window size so that it will remove
                  the maximum and minimum window hints. Otherwise
                  metacity will honour the restrictions and not
                  fullscreen correctly. */
-              clutter_stage_x11_fix_window_size (stage_x11, -1, -1);
+              meta_stage_x11_fix_window_size (stage_x11, -1, -1);
 
               send_wmspec_change_state (backend_x11, stage_x11->xwin,
                                         backend_x11->atom_NET_WM_STATE_FULLSCREEN,
@@ -504,16 +474,12 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
         {
           if (!STAGE_X11_IS_MAPPED (stage_x11))
             {
-              CLUTTER_NOTE (BACKEND, "Un-fullscreening unmapped stage");
-
               update_state (stage_x11, backend_x11,
                             &backend_x11->atom_NET_WM_STATE_FULLSCREEN,
                             FALSE);
             }
           else
             {
-              CLUTTER_NOTE (BACKEND, "Un-fullscreening mapped stage");
-
               send_wmspec_change_state (backend_x11,
                                         stage_x11->xwin,
                                         backend_x11->atom_NET_WM_STATE_FULLSCREEN,
@@ -521,9 +487,9 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
 
               /* Fix the window size to restore the minimum/maximum
                  restriction */
-              clutter_stage_x11_fix_window_size (stage_x11,
-                                                 stage_x11->xwin_width,
-                                                 stage_x11->xwin_height);
+              meta_stage_x11_fix_window_size (stage_x11,
+                                              stage_x11->xwin_width,
+                                              stage_x11->xwin_height);
             }
         }
       else
@@ -537,9 +503,9 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
 }
 
 void
-_clutter_stage_x11_events_device_changed (ClutterStageX11 *stage_x11,
-                                          ClutterInputDevice *device,
-                                          ClutterDeviceManager *device_manager)
+meta_stage_x11_events_device_changed (MetaStageX11         *stage_x11,
+                                      ClutterInputDevice   *device,
+                                      ClutterDeviceManager *device_manager)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
 
@@ -579,23 +545,18 @@ frame_cb (CoglOnscreen  *onscreen,
 }
 
 static gboolean
-clutter_stage_x11_realize (ClutterStageWindow *stage_window)
+meta_stage_x11_realize (ClutterStageWindow *stage_window)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window);
   ClutterBackend *backend = CLUTTER_BACKEND (stage_cogl->backend);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
   ClutterDeviceManager *device_manager;
   gfloat width, height;
   GError *error = NULL;
 
   clutter_actor_get_size (CLUTTER_ACTOR (stage_cogl->wrapper), &width, &height);
 
-  CLUTTER_NOTE (BACKEND, "Wrapper size: %.2f x %.2f", width, height);
-
-  CLUTTER_NOTE (BACKEND, "Creating a new Cogl onscreen surface: %.2f x %.2f",
-                width, height);
-
   stage_x11->onscreen = cogl_onscreen_new (backend->cogl_context, width, height);
 
   stage_x11->frame_closure =
@@ -614,7 +575,7 @@ clutter_stage_x11_realize (ClutterStageWindow *stage_window)
   stage_x11->xwin_width = width;
   stage_x11->xwin_height = height;
 
-  if (!cogl_framebuffer_allocate (stage_x11->onscreen, &error))
+  if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (stage_x11->onscreen), &error))
     {
       g_warning ("Failed to allocate stage: %s", error->message);
       g_error_free (error);
@@ -655,7 +616,7 @@ clutter_stage_x11_realize (ClutterStageWindow *stage_window)
    * for an example of things that break if we do conditional event
    * selection.
    */
-  XSelectInput (backend_x11->xdpy, stage_x11->xwin, CLUTTER_STAGE_X11_EVENT_MASK);
+  XSelectInput (xdisplay, stage_x11->xwin, META_STAGE_X11_EVENT_MASK);
 
   /* input events also depent on the actual device, so we need to
    * use the device manager to let every device select them, using
@@ -672,38 +633,36 @@ clutter_stage_x11_realize (ClutterStageWindow *stage_window)
                         stage_window);
     }
 
-  clutter_stage_x11_fix_window_size (stage_x11,
-                                     stage_x11->xwin_width,
-                                     stage_x11->xwin_height);
-  clutter_stage_x11_set_wm_protocols (stage_x11);
+  meta_stage_x11_fix_window_size (stage_x11,
+                                  stage_x11->xwin_width,
+                                  stage_x11->xwin_height);
+  meta_stage_x11_set_wm_protocols (stage_x11);
 
   if (stage_x11->fullscreen_on_realize)
     {
       stage_x11->fullscreen_on_realize = FALSE;
 
-      clutter_stage_x11_set_fullscreen (stage_window, TRUE);
+      meta_stage_x11_set_fullscreen (stage_window, TRUE);
     }
 
-  CLUTTER_NOTE (BACKEND, "Successfully realized stage");
-
   return TRUE;
 }
 
 static void
-clutter_stage_x11_set_cursor_visible (ClutterStageWindow *stage_window,
-                                      gboolean            cursor_visible)
+meta_stage_x11_set_cursor_visible (ClutterStageWindow *stage_window,
+                                   gboolean            cursor_visible)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   stage_x11->is_cursor_visible = !!cursor_visible;
   set_cursor_visible (stage_x11);
 }
 
 static void
-clutter_stage_x11_set_title (ClutterStageWindow *stage_window,
-                             const gchar        *title)
+meta_stage_x11_set_title (ClutterStageWindow *stage_window,
+                          const gchar        *title)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   g_free (stage_x11->title);
   stage_x11->title = g_strdup (title);
@@ -711,21 +670,20 @@ clutter_stage_x11_set_title (ClutterStageWindow *stage_window,
 }
 
 static void
-clutter_stage_x11_set_user_resizable (ClutterStageWindow *stage_window,
-                                      gboolean            is_resizable)
+meta_stage_x11_set_user_resizable (ClutterStageWindow *stage_window,
+                                   gboolean            is_resizable)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
-  clutter_stage_x11_fix_window_size (stage_x11,
-                                     stage_x11->xwin_width,
-                                     stage_x11->xwin_height);
+  meta_stage_x11_fix_window_size (stage_x11,
+                                  stage_x11->xwin_width,
+                                  stage_x11->xwin_height);
 }
 
 static inline void
-update_wm_hints (ClutterStageX11 *stage_x11)
+update_wm_hints (MetaStageX11 *stage_x11)
 {
-  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
+  Display *xdisplay = clutter_x11_get_default_display ();
   XWMHints wm_hints;
 
   if (stage_x11->wm_state & STAGE_X11_WITHDRAWN)
@@ -735,25 +693,25 @@ update_wm_hints (ClutterStageX11 *stage_x11)
   wm_hints.initial_state = NormalState;
   wm_hints.input = stage_x11->accept_focus ? True : False;
 
-  XSetWMHints (backend_x11->xdpy, stage_x11->xwin, &wm_hints);
+  XSetWMHints (xdisplay, stage_x11->xwin, &wm_hints);
 }
 
 static void
-clutter_stage_x11_set_accept_focus (ClutterStageWindow *stage_window,
-                                    gboolean            accept_focus)
+meta_stage_x11_set_accept_focus (ClutterStageWindow *stage_window,
+                                 gboolean            accept_focus)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   stage_x11->accept_focus = !!accept_focus;
   update_wm_hints (stage_x11);
 }
 
 static void
-set_stage_x11_state (ClutterStageX11      *stage_x11,
-                     ClutterStageX11State  unset_flags,
-                     ClutterStageX11State  set_flags)
+set_stage_x11_state (MetaStageX11      *stage_x11,
+                     MetaStageX11State  unset_flags,
+                     MetaStageX11State  set_flags)
 {
-  ClutterStageX11State new_stage_state, old_stage_state;
+  MetaStageX11State new_stage_state, old_stage_state;
 
   old_stage_state = stage_x11->wm_state;
 
@@ -768,54 +726,51 @@ set_stage_x11_state (ClutterStageX11      *stage_x11,
 }
 
 static void
-clutter_stage_x11_show (ClutterStageWindow *stage_window,
-                        gboolean            do_raise)
+meta_stage_x11_show (ClutterStageWindow *stage_window,
+                     gboolean            do_raise)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
 
   if (stage_x11->xwin != None)
     {
+      Display *xdisplay = clutter_x11_get_default_display ();
+
       if (do_raise)
         {
-          CLUTTER_NOTE (BACKEND, "Raising stage[%lu]",
-                        (unsigned long) stage_x11->xwin);
-          XRaiseWindow (backend_x11->xdpy, stage_x11->xwin);
+          XRaiseWindow (xdisplay, stage_x11->xwin);
         }
 
       if (!STAGE_X11_IS_MAPPED (stage_x11))
         {
-          CLUTTER_NOTE (BACKEND, "Mapping stage[%lu]",
-                        (unsigned long) stage_x11->xwin);
-
           set_stage_x11_state (stage_x11, STAGE_X11_WITHDRAWN, 0);
 
           update_wm_hints (stage_x11);
 
           if (stage_x11->fullscreening)
-            clutter_stage_x11_set_fullscreen (stage_window, TRUE);
+            meta_stage_x11_set_fullscreen (stage_window, TRUE);
           else
-            clutter_stage_x11_set_fullscreen (stage_window, FALSE);
+            meta_stage_x11_set_fullscreen (stage_window, FALSE);
         }
 
       g_assert (STAGE_X11_IS_MAPPED (stage_x11));
 
       clutter_actor_map (CLUTTER_ACTOR (stage_cogl->wrapper));
 
-      XMapWindow (backend_x11->xdpy, stage_x11->xwin);
+      XMapWindow (xdisplay, stage_x11->xwin);
     }
 }
 
 static void
-clutter_stage_x11_hide (ClutterStageWindow *stage_window)
+meta_stage_x11_hide (ClutterStageWindow *stage_window)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
 
   if (stage_x11->xwin != None)
     {
+      Display *xdisplay = clutter_x11_get_default_display ();
+
       if (STAGE_X11_IS_MAPPED (stage_x11))
         set_stage_x11_state (stage_x11, 0, STAGE_X11_WITHDRAWN);
 
@@ -823,14 +778,14 @@ clutter_stage_x11_hide (ClutterStageWindow *stage_window)
 
       clutter_actor_unmap (CLUTTER_ACTOR (stage_cogl->wrapper));
 
-      XWithdrawWindow (backend_x11->xdpy, stage_x11->xwin, 0);
+      XWithdrawWindow (xdisplay, stage_x11->xwin, 0);
     }
 }
 
 static gboolean
-clutter_stage_x11_can_clip_redraws (ClutterStageWindow *stage_window)
+meta_stage_x11_can_clip_redraws (ClutterStageWindow *stage_window)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   /* while resizing a window, clipped redraws are disabled in order to
    * avoid artefacts.
@@ -841,7 +796,7 @@ clutter_stage_x11_can_clip_redraws (ClutterStageWindow *stage_window)
 static void
 ensure_legacy_view (ClutterStageWindow *stage_window)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   cairo_rectangle_int_t view_layout;
   CoglFramebuffer *framebuffer;
 
@@ -859,9 +814,9 @@ ensure_legacy_view (ClutterStageWindow *stage_window)
 }
 
 static GList *
-clutter_stage_x11_get_views (ClutterStageWindow *stage_window)
+meta_stage_x11_get_views (ClutterStageWindow *stage_window)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   ensure_legacy_view (stage_window);
 
@@ -869,33 +824,33 @@ clutter_stage_x11_get_views (ClutterStageWindow *stage_window)
 }
 
 static int64_t
-clutter_stage_x11_get_frame_counter (ClutterStageWindow *stage_window)
+meta_stage_x11_get_frame_counter (ClutterStageWindow *stage_window)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
 
   return cogl_onscreen_get_frame_counter (stage_x11->onscreen);
 }
 
 static void
-clutter_stage_x11_finalize (GObject *gobject)
+meta_stage_x11_finalize (GObject *gobject)
 {
-  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (gobject);
+  MetaStageX11 *stage_x11 = META_STAGE_X11 (gobject);
 
   g_free (stage_x11->title);
 
-  G_OBJECT_CLASS (clutter_stage_x11_parent_class)->finalize (gobject);
+  G_OBJECT_CLASS (meta_stage_x11_parent_class)->finalize (gobject);
 }
 
 static void
-clutter_stage_x11_class_init (ClutterStageX11Class *klass)
+meta_stage_x11_class_init (MetaStageX11Class *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
-  gobject_class->finalize = clutter_stage_x11_finalize;
+  gobject_class->finalize = meta_stage_x11_finalize;
 }
 
 static void
-clutter_stage_x11_init (ClutterStageX11 *stage)
+meta_stage_x11_init (MetaStageX11 *stage)
 {
   stage->xwin = None;
   stage->xwin_width = 640;
@@ -915,30 +870,32 @@ clutter_stage_window_iface_init (ClutterStageWindowInterface *iface)
 {
   clutter_stage_window_parent_iface = g_type_interface_peek_parent (iface);
 
-  iface->set_title = clutter_stage_x11_set_title;
-  iface->set_fullscreen = clutter_stage_x11_set_fullscreen;
-  iface->set_cursor_visible = clutter_stage_x11_set_cursor_visible;
-  iface->set_user_resizable = clutter_stage_x11_set_user_resizable;
-  iface->set_accept_focus = clutter_stage_x11_set_accept_focus;
-  iface->show = clutter_stage_x11_show;
-  iface->hide = clutter_stage_x11_hide;
-  iface->resize = clutter_stage_x11_resize;
-  iface->get_geometry = clutter_stage_x11_get_geometry;
-  iface->realize = clutter_stage_x11_realize;
-  iface->unrealize = clutter_stage_x11_unrealize;
-  iface->can_clip_redraws = clutter_stage_x11_can_clip_redraws;
-  iface->get_views = clutter_stage_x11_get_views;
-  iface->get_frame_counter = clutter_stage_x11_get_frame_counter;
+  iface->set_title = meta_stage_x11_set_title;
+  iface->set_fullscreen = meta_stage_x11_set_fullscreen;
+  iface->set_cursor_visible = meta_stage_x11_set_cursor_visible;
+  iface->set_user_resizable = meta_stage_x11_set_user_resizable;
+  iface->set_accept_focus = meta_stage_x11_set_accept_focus;
+  iface->show = meta_stage_x11_show;
+  iface->hide = meta_stage_x11_hide;
+  iface->resize = meta_stage_x11_resize;
+  iface->get_geometry = meta_stage_x11_get_geometry;
+  iface->realize = meta_stage_x11_realize;
+  iface->unrealize = meta_stage_x11_unrealize;
+  iface->can_clip_redraws = meta_stage_x11_can_clip_redraws;
+  iface->get_views = meta_stage_x11_get_views;
+  iface->get_frame_counter = meta_stage_x11_get_frame_counter;
 }
 
 static inline void
 set_user_time (ClutterBackendX11 *backend_x11,
-               ClutterStageX11   *stage_x11,
+               MetaStageX11      *stage_x11,
                long               timestamp)
 {
   if (timestamp != CLUTTER_CURRENT_TIME)
     {
-      XChangeProperty (backend_x11->xdpy,
+      Display *xdisplay = clutter_x11_get_default_display ();
+
+      XChangeProperty (xdisplay,
                        stage_x11->xwin,
                        backend_x11->atom_NET_WM_USER_TIME,
                        XA_CARDINAL, 32,
@@ -949,7 +906,7 @@ set_user_time (ClutterBackendX11 *backend_x11,
 
 static gboolean
 handle_wm_protocols_event (ClutterBackendX11 *backend_x11,
-                           ClutterStageX11   *stage_x11,
+                           MetaStageX11      *stage_x11,
                            XEvent            *xevent)
 {
   Atom atom = (Atom) xevent->xclient.data.l[0];
@@ -957,20 +914,6 @@ handle_wm_protocols_event (ClutterBackendX11 *backend_x11,
   if (atom == backend_x11->atom_WM_DELETE_WINDOW &&
       xevent->xany.window == stage_x11->xwin)
     {
-#ifdef CLUTTER_ENABLE_DEBUG
-      ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
-
-      /* the WM_DELETE_WINDOW is a request: we do not destroy
-       * the window right away, as it might contain vital data;
-       * we relay the event to the application and we let it
-       * handle the request
-       */
-      CLUTTER_NOTE (EVENT, "Delete stage %s[%p], win:0x%x",
-                    _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage_cogl->wrapper)),
-                    stage_cogl->wrapper,
-                    (unsigned int) stage_x11->xwin);
-#endif /* CLUTTER_ENABLE_DEBUG */
-
       set_user_time (backend_x11, stage_x11, xevent->xclient.data.l[1]);
 
       return TRUE;
@@ -979,9 +922,10 @@ handle_wm_protocols_event (ClutterBackendX11 *backend_x11,
            xevent->xany.window == stage_x11->xwin)
     {
       XClientMessageEvent xclient = xevent->xclient;
+      Display *xdisplay = clutter_x11_get_default_display ();
 
       xclient.window = backend_x11->xwin_root;
-      XSendEvent (backend_x11->xdpy, xclient.window,
+      XSendEvent (xdisplay, xclient.window,
                   False,
                   SubstructureRedirectMask | SubstructureNotifyMask,
                   (XEvent *) &xclient);
@@ -995,7 +939,7 @@ handle_wm_protocols_event (ClutterBackendX11 *backend_x11,
 static gboolean
 clipped_redraws_cool_off_cb (void *data)
 {
-  ClutterStageX11 *stage_x11 = data;
+  MetaStageX11 *stage_x11 = data;
 
   stage_x11->clipped_redraws_cool_off = 0;
 
@@ -1003,9 +947,9 @@ clipped_redraws_cool_off_cb (void *data)
 }
 
 gboolean
-clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
-                                   XEvent          *xevent,
-                                   ClutterEvent    *event)
+meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
+                                XEvent       *xevent,
+                                ClutterEvent *event)
 {
   ClutterStageCogl *stage_cogl;
   gboolean res = FALSE;
@@ -1013,7 +957,7 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
   Window stage_xwindow;
   ClutterStage *stage;
 
-  stage_cogl = clutter_x11_get_stage_window_from_window (xevent->xany.window);
+  stage_cogl = meta_x11_get_stage_window_from_window (xevent->xany.window);
   if (stage_cogl == NULL)
     return FALSE;
 
@@ -1029,11 +973,6 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
           int stage_width;
           int stage_height;
 
-          CLUTTER_NOTE (BACKEND, "ConfigureNotify[%x] (%d, %d)",
-                        (unsigned int) stage_x11->xwin,
-                        xevent->xconfigure.width,
-                        xevent->xconfigure.height);
-
           /* When fullscreen, we'll keep the xwin_width/height
              variables to track the old size of the window and we'll
              assume all ConfigureNotifies constitute a size change */
@@ -1134,6 +1073,7 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
       if (xevent->xproperty.atom == backend_x11->atom_NET_WM_STATE &&
           xevent->xproperty.window == stage_xwindow)
         {
+          Display *xdisplay = clutter_x11_get_default_display ();
           Atom     type;
           gint     format;
           gulong   n_items, bytes_after;
@@ -1141,7 +1081,7 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
           gboolean fullscreen_set = FALSE;
 
           clutter_x11_trap_x_errors ();
-          XGetWindowProperty (backend_x11->xdpy, stage_xwindow,
+          XGetWindowProperty (xdisplay, stage_xwindow,
                               backend_x11->atom_NET_WM_STATE,
                               0, G_MAXLONG,
                               False, XA_ATOM,
@@ -1203,17 +1143,6 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
         XExposeEvent *expose = (XExposeEvent *) xevent;
         cairo_rectangle_int_t clip;
 
-        CLUTTER_NOTE (EVENT,
-                      "expose for stage: %s[%p], win:0x%x - "
-                      "redrawing area (x: %d, y: %d, width: %d, height: %d)",
-                      _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage)),
-                      stage,
-                      (unsigned int) stage_xwindow,
-                      expose->x,
-                      expose->y,
-                      expose->width,
-                      expose->height);
-
         clip.x = expose->x;
         clip.y = expose->y;
         clip.width = expose->width;
@@ -1223,21 +1152,12 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
       break;
 
     case DestroyNotify:
-      CLUTTER_NOTE (EVENT,
-                    "Destroy notification received for stage %s[%p], win:0x%x",
-                    _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage)),
-                    stage,
-                    (unsigned int) stage_xwindow);
       event->any.type = CLUTTER_DESTROY_NOTIFY;
       event->any.stage = stage;
       res = TRUE;
       break;
 
     case ClientMessage:
-      CLUTTER_NOTE (EVENT, "Client message for stage %s[%p], win:0x%x",
-                    _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage)),
-                    stage,
-                    (unsigned int) stage_xwindow);
       if (handle_wm_protocols_event (backend_x11, stage_x11, xevent))
         {
           event->any.type = CLUTTER_DELETE;
@@ -1254,31 +1174,21 @@ clutter_stage_x11_translate_event (ClutterStageX11 *stage_x11,
   return res;
 }
 
-/**
- * clutter_x11_get_stage_window: (skip)
- * @stage: a #ClutterStage
- *
- * Gets the stages X Window.
- *
- * Return value: An XID for the stage window.
- *
- * Since: 0.4
- */
 Window
-clutter_x11_get_stage_window (ClutterStage *stage)
+meta_x11_get_stage_window (ClutterStage *stage)
 {
   ClutterStageWindow *impl;
 
   g_return_val_if_fail (CLUTTER_IS_STAGE (stage), None);
 
   impl = _clutter_stage_get_window (stage);
-  g_assert (CLUTTER_IS_STAGE_X11 (impl));
+  g_assert (META_IS_STAGE_X11 (impl));
 
-  return CLUTTER_STAGE_X11 (impl)->xwin;
+  return META_STAGE_X11 (impl)->xwin;
 }
 
 static ClutterStageCogl *
-clutter_x11_get_stage_window_from_window (Window win)
+meta_x11_get_stage_window_from_window (Window win)
 {
   if (clutter_stages_by_xid == NULL)
     return NULL;
@@ -1287,23 +1197,12 @@ clutter_x11_get_stage_window_from_window (Window win)
                               GINT_TO_POINTER (win));
 }
 
-/**
- * clutter_x11_get_stage_from_window:
- * @win: an X Window ID
- *
- * Gets the stage for a particular X window.
- *
- * Return value: (transfer none): A #ClutterStage, or% NULL if a stage
- *   does not exist for the window
- *
- * Since: 0.8
- */
 ClutterStage *
-clutter_x11_get_stage_from_window (Window win)
+meta_x11_get_stage_from_window (Window win)
 {
   ClutterStageCogl *stage_cogl;
 
-  stage_cogl = clutter_x11_get_stage_window_from_window (win);
+  stage_cogl = meta_x11_get_stage_window_from_window (win);
 
   if (stage_cogl != NULL)
     return stage_cogl->wrapper;
@@ -1312,8 +1211,8 @@ clutter_x11_get_stage_from_window (Window win)
 }
 
 void
-_clutter_stage_x11_set_user_time (ClutterStageX11 *stage_x11,
-                                  guint32          user_time)
+meta_stage_x11_set_user_time (MetaStageX11 *stage_x11,
+                              guint32       user_time)
 {
   ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
   ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
diff --git a/src/backends/x11/meta-stage-x11.h b/src/backends/x11/meta-stage-x11.h
new file mode 100644
index 000000000..f4b190403
--- /dev/null
+++ b/src/backends/x11/meta-stage-x11.h
@@ -0,0 +1,104 @@
+/* Clutter.
+ * An OpenGL based 'interactive canvas' library.
+ * Authored By Matthew Allum  <mallum openedhand com>
+ * Copyright (C) 2006-2007 OpenedHand
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ */
+
+#ifndef META_STAGE_X11_H
+#define META_STAGE_X11_H
+
+#include <clutter/clutter-mutter.h>
+#include <clutter/x11/clutter-x11.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+G_BEGIN_DECLS
+
+#define META_TYPE_STAGE_X11                  (meta_stage_x11_get_type ())
+#define META_STAGE_X11(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_STAGE_X11, 
MetaStageX11))
+#define META_IS_STAGE_X11(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_STAGE_X11))
+#define META_STAGE_X11_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_STAGE_X11, 
MetaStageX11Class))
+#define META_IS_STAGE_X11_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_STAGE_X11))
+#define META_STAGE_X11_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_STAGE_X11, 
MetaStageX11Class))
+
+typedef struct _MetaStageX11         MetaStageX11;
+typedef struct _MetaStageX11Class    MetaStageX11Class;
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaStageX11, g_object_unref)
+
+typedef enum
+{
+  STAGE_X11_WITHDRAWN = 1 << 1
+} MetaStageX11State;
+
+struct _MetaStageX11
+{
+  ClutterStageCogl parent_instance;
+
+  CoglOnscreen *onscreen;
+  Window xwin;
+  gint xwin_width;
+  gint xwin_height; /* FIXME target_width / height */
+
+  ClutterStageView *legacy_view;
+  GList *legacy_views;
+
+  CoglFrameClosure *frame_closure;
+
+  gchar *title;
+
+  guint clipped_redraws_cool_off;
+
+  MetaStageX11State wm_state;
+
+  guint is_foreign_xwin       : 1;
+  guint fullscreening         : 1;
+  guint is_cursor_visible     : 1;
+  guint viewport_initialized  : 1;
+  guint accept_focus          : 1;
+  guint fullscreen_on_realize : 1;
+};
+
+struct _MetaStageX11Class
+{
+  ClutterStageCoglClass parent_class;
+};
+
+CLUTTER_EXPORT
+GType meta_stage_x11_get_type (void) G_GNUC_CONST;
+
+void  meta_stage_x11_events_device_changed (MetaStageX11         *stage_x11,
+                                           ClutterInputDevice   *device,
+                                           ClutterDeviceManager *device_manager);
+
+/* Private to subclasses */
+void            meta_stage_x11_set_user_time                (MetaStageX11 *stage_x11,
+                                                            guint32       user_time);
+
+gboolean meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
+                                        XEvent       *xevent,
+                                        ClutterEvent *event);
+
+ClutterStage *meta_x11_get_stage_from_window (Window win);
+
+Window       meta_x11_get_stage_window  (ClutterStage *stage);
+
+
+G_END_DECLS
+
+#endif /* META_STAGE_H */
diff --git a/src/backends/x11/meta-virtual-input-device-x11.c 
b/src/backends/x11/meta-virtual-input-device-x11.c
new file mode 100644
index 000000000..65133ed15
--- /dev/null
+++ b/src/backends/x11/meta-virtual-input-device-x11.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2016  Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Jonas Ådahl <jadahl gmail com>
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+
+#include <clutter/clutter.h>
+#include <clutter/x11/clutter-x11.h>
+#include <X11/extensions/XTest.h>
+
+#include "meta-keymap-x11.h"
+#include "meta-virtual-input-device-x11.h"
+
+struct _MetaVirtualInputDeviceX11
+{
+  ClutterVirtualInputDevice parent;
+};
+
+G_DEFINE_TYPE (MetaVirtualInputDeviceX11,
+               meta_virtual_input_device_x11,
+               CLUTTER_TYPE_VIRTUAL_INPUT_DEVICE)
+
+static void
+meta_virtual_input_device_x11_notify_relative_motion (ClutterVirtualInputDevice *virtual_device,
+                                                      uint64_t                   time_us,
+                                                      double                     dx,
+                                                      double                     dy)
+{
+  XTestFakeRelativeMotionEvent (clutter_x11_get_default_display (),
+                                (int) dx,
+                                (int) dy,
+                                0);
+}
+
+static void
+meta_virtual_input_device_x11_notify_absolute_motion (ClutterVirtualInputDevice *virtual_device,
+                                                      uint64_t                   time_us,
+                                                      double                     x,
+                                                      double                     y)
+{
+  XTestFakeMotionEvent (clutter_x11_get_default_display (),
+                        clutter_x11_get_default_screen (),
+                        (int) x,
+                        (int) y,
+                        0);
+}
+
+static void
+meta_virtual_input_device_x11_notify_button (ClutterVirtualInputDevice *virtual_device,
+                                             uint64_t                   time_us,
+                                             uint32_t                   button,
+                                             ClutterButtonState         button_state)
+{
+  XTestFakeButtonEvent (clutter_x11_get_default_display (),
+                        button, button_state == CLUTTER_BUTTON_STATE_PRESSED, 0);
+}
+
+static void
+meta_virtual_input_device_x11_notify_discrete_scroll (ClutterVirtualInputDevice *virtual_device,
+                                                      uint64_t                   time_us,
+                                                      ClutterScrollDirection     direction,
+                                                      ClutterScrollSource        scroll_source)
+{
+  Display *xdisplay = clutter_x11_get_default_display ();
+  int button;
+
+  switch (direction)
+    {
+    case CLUTTER_SCROLL_UP:
+      button = 4;
+      break;
+    case CLUTTER_SCROLL_DOWN:
+      button = 5;
+      break;
+    case CLUTTER_SCROLL_LEFT:
+      button = 6;
+      break;
+    case CLUTTER_SCROLL_RIGHT:
+      button = 7;
+      break;
+    default:
+      g_warn_if_reached ();
+      return;
+    }
+
+  XTestFakeButtonEvent (xdisplay, button, True, 0);
+  XTestFakeButtonEvent (xdisplay, button, False, 0);
+}
+
+static void
+meta_virtual_input_device_x11_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
+                                                        uint64_t                   time_us,
+                                                        double                     dx,
+                                                        double                     dy,
+                                                        ClutterScrollSource        scroll_source,
+                                                        ClutterScrollFinishFlags   finish_flags)
+{
+}
+
+static void
+meta_virtual_input_device_x11_notify_key (ClutterVirtualInputDevice *virtual_device,
+                                          uint64_t                   time_us,
+                                          uint32_t                   key,
+                                          ClutterKeyState            key_state)
+{
+  XTestFakeKeyEvent (clutter_x11_get_default_display (),
+                     key, key_state == CLUTTER_KEY_STATE_PRESSED, 0);
+}
+
+static void
+meta_virtual_input_device_x11_notify_keyval (ClutterVirtualInputDevice *virtual_device,
+                                             uint64_t                   time_us,
+                                             uint32_t                   keyval,
+                                             ClutterKeyState            key_state)
+{
+  ClutterBackend *backend = clutter_get_default_backend ();
+  MetaKeymapX11 *keymap = META_KEYMAP_X11 (clutter_backend_get_keymap (backend));
+  uint32_t keycode, level;
+
+  if (!meta_keymap_x11_keycode_for_keyval (keymap, keyval, &keycode, &level))
+    {
+      level = 0;
+
+      if (!meta_keymap_x11_reserve_keycode (keymap, keyval, &keycode))
+        {
+          g_warning ("No keycode found for keyval %x in current group", keyval);
+          return;
+        }
+    }
+
+  if (!meta_keymap_x11_get_is_modifier (keymap, keycode) &&
+      key_state == CLUTTER_KEY_STATE_PRESSED)
+    meta_keymap_x11_latch_modifiers (keymap, level, TRUE);
+
+  XTestFakeKeyEvent (clutter_x11_get_default_display (),
+                     (KeyCode) keycode,
+                     key_state == CLUTTER_KEY_STATE_PRESSED, 0);
+
+
+  if (key_state == CLUTTER_KEY_STATE_RELEASED)
+    {
+      if (!meta_keymap_x11_get_is_modifier (keymap, keycode))
+        meta_keymap_x11_latch_modifiers (keymap, level, FALSE);
+      meta_keymap_x11_release_keycode_if_needed (keymap, keycode);
+    }
+}
+
+static void
+meta_virtual_input_device_x11_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
+                                                 uint64_t                   time_us,
+                                                 int                        device_slot,
+                                                 double                     x,
+                                                 double                     y)
+{
+  g_warning ("Virtual touch motion not implemented under X11");
+}
+
+static void
+meta_virtual_input_device_x11_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
+                                                   uint64_t                   time_us,
+                                                   int                        device_slot,
+                                                   double                     x,
+                                                   double                     y)
+{
+  g_warning ("Virtual touch motion not implemented under X11");
+}
+
+static void
+meta_virtual_input_device_x11_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
+                                               uint64_t                   time_us,
+                                               int                        device_slot)
+{
+  g_warning ("Virtual touch motion not implemented under X11");
+}
+
+static void
+meta_virtual_input_device_x11_init (MetaVirtualInputDeviceX11 *virtual_device_x11)
+{
+}
+
+static void
+meta_virtual_input_device_x11_class_init (MetaVirtualInputDeviceX11Class *klass)
+{
+  ClutterVirtualInputDeviceClass *virtual_input_device_class =
+    CLUTTER_VIRTUAL_INPUT_DEVICE_CLASS (klass);
+
+  virtual_input_device_class->notify_relative_motion = meta_virtual_input_device_x11_notify_relative_motion;
+  virtual_input_device_class->notify_absolute_motion = meta_virtual_input_device_x11_notify_absolute_motion;
+  virtual_input_device_class->notify_button = meta_virtual_input_device_x11_notify_button;
+  virtual_input_device_class->notify_discrete_scroll = meta_virtual_input_device_x11_notify_discrete_scroll;
+  virtual_input_device_class->notify_scroll_continuous = 
meta_virtual_input_device_x11_notify_scroll_continuous;
+  virtual_input_device_class->notify_key = meta_virtual_input_device_x11_notify_key;
+  virtual_input_device_class->notify_keyval = meta_virtual_input_device_x11_notify_keyval;
+  virtual_input_device_class->notify_touch_down = meta_virtual_input_device_x11_notify_touch_down;
+  virtual_input_device_class->notify_touch_motion = meta_virtual_input_device_x11_notify_touch_motion;
+  virtual_input_device_class->notify_touch_up = meta_virtual_input_device_x11_notify_touch_up;
+}
diff --git a/clutter/clutter/x11/clutter-virtual-input-device-x11.h 
b/src/backends/x11/meta-virtual-input-device-x11.h
similarity index 61%
rename from clutter/clutter/x11/clutter-virtual-input-device-x11.h
rename to src/backends/x11/meta-virtual-input-device-x11.h
index b1bb101bf..0db9cab64 100644
--- a/clutter/clutter/x11/clutter-virtual-input-device-x11.h
+++ b/src/backends/x11/meta-virtual-input-device-x11.h
@@ -1,8 +1,4 @@
 /*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
  * Copyright (C) 2016  Red Hat Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -21,15 +17,15 @@
  * Author: Jonas Ådahl <jadahl gmail com>
  */
 
-#ifndef __CLUTTER_VIRTUAL_INPUT_DEVICE_X11_H__
-#define __CLUTTER_VIRTUAL_INPUT_DEVICE_X11_H__
+#ifndef META_VIRTUAL_INPUT_DEVICE_X11_H
+#define META_VIRTUAL_INPUT_DEVICE_X11_H
 
-#include "clutter-virtual-input-device.h"
+#include <clutter/clutter.h>
 
-#define CLUTTER_TYPE_VIRTUAL_INPUT_DEVICE_X11 (clutter_virtual_input_device_x11_get_type ())
-G_DECLARE_FINAL_TYPE (ClutterVirtualInputDeviceX11,
-                      clutter_virtual_input_device_x11,
-                      CLUTTER, VIRTUAL_INPUT_DEVICE_X11,
+#define META_TYPE_VIRTUAL_INPUT_DEVICE_X11 (meta_virtual_input_device_x11_get_type ())
+G_DECLARE_FINAL_TYPE (MetaVirtualInputDeviceX11,
+                      meta_virtual_input_device_x11,
+                      META, VIRTUAL_INPUT_DEVICE_X11,
                       ClutterVirtualInputDevice)
 
-#endif /* __CLUTTER_VIRTUAL_INPUT_DEVICE_X11_H__ */
+#endif /* META_VIRTUAL_INPUT_DEVICE_X11_H */
diff --git a/clutter/clutter/x11/clutter-xkb-a11y-x11.c b/src/backends/x11/meta-xkb-a11y-x11.c
similarity index 86%
rename from clutter/clutter/x11/clutter-xkb-a11y-x11.c
rename to src/backends/x11/meta-xkb-a11y-x11.c
index 6b782c7a5..b0e7c9af4 100644
--- a/clutter/clutter/x11/clutter-xkb-a11y-x11.c
+++ b/src/backends/x11/meta-xkb-a11y-x11.c
@@ -1,5 +1,4 @@
 /*
- *
  * Copyright © 2001 Ximian, Inc.
  * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
  * Copyright (C) 2017 Red Hat
@@ -21,11 +20,15 @@
  *
  */
 
-#include "clutter-device-manager-private.h"
-#include "clutter-xkb-a11y-x11.h"
+#include "config.h"
 
 #include <X11/XKBlib.h>
 #include <X11/extensions/XKBstr.h>
+#include <clutter/x11/clutter-x11.h>
+
+#include "backends/x11/meta-xkb-a11y-x11.h"
+#include "core/display-private.h"
+#include "meta/meta-x11-errors.h"
 
 #define DEFAULT_XKB_SET_CONTROLS_MASK XkbSlowKeysMask         | \
                                       XkbBounceKeysMask       | \
@@ -40,17 +43,17 @@
 static int _xkb_event_base;
 
 static XkbDescRec *
-get_xkb_desc_rec (ClutterBackendX11 *backend_x11)
+get_xkb_desc_rec (Display *xdisplay)
 {
   XkbDescRec *desc;
   Status      status = Success;
 
   clutter_x11_trap_x_errors ();
-  desc = XkbGetMap (backend_x11->xdpy, XkbAllMapComponentsMask, XkbUseCoreKbd);
+  desc = XkbGetMap (xdisplay, XkbAllMapComponentsMask, XkbUseCoreKbd);
   if (desc != NULL)
     {
       desc->ctrls = NULL;
-      status = XkbGetControls (backend_x11->xdpy, XkbAllControlsMask, desc);
+      status = XkbGetControls (xdisplay, XkbAllControlsMask, desc);
     }
   clutter_x11_untrap_x_errors ();
 
@@ -62,25 +65,24 @@ get_xkb_desc_rec (ClutterBackendX11 *backend_x11)
 }
 
 static void
-set_xkb_desc_rec (ClutterBackendX11 *backend_x11,
-                  XkbDescRec        *desc)
+set_xkb_desc_rec (Display    *xdisplay,
+                  XkbDescRec *desc)
 {
   clutter_x11_trap_x_errors ();
-  XkbSetControls (backend_x11->xdpy, DEFAULT_XKB_SET_CONTROLS_MASK, desc);
-  XSync (backend_x11->xdpy, FALSE);
+  XkbSetControls (xdisplay, DEFAULT_XKB_SET_CONTROLS_MASK, desc);
+  XSync (xdisplay, FALSE);
   clutter_x11_untrap_x_errors ();
 }
 
 static void
 check_settings_changed (ClutterDeviceManager *device_manager)
 {
-  ClutterBackendX11 *backend_x11;
+  Display *xdisplay = clutter_x11_get_default_display ();
   ClutterKbdA11ySettings kbd_a11y_settings;
   ClutterKeyboardA11yFlags what_changed = 0;
   XkbDescRec *desc;
 
-  backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
-  desc = get_xkb_desc_rec (backend_x11);
+  desc = get_xkb_desc_rec (xdisplay);
   if (!desc)
     return;
 
@@ -145,14 +147,14 @@ xkb_a11y_event_filter (XEvent       *xevent,
 }
 
 static gboolean
-is_xkb_available (ClutterBackendX11 *backend_x11)
+is_xkb_available (Display *xdisplay)
 {
   gint opcode, error_base, event_base, major, minor;
 
   if (_xkb_event_base)
     return TRUE;
 
-  if (!XkbQueryExtension (backend_x11->xdpy,
+  if (!XkbQueryExtension (xdisplay,
                           &opcode,
                           &event_base,
                           &error_base,
@@ -160,7 +162,7 @@ is_xkb_available (ClutterBackendX11 *backend_x11)
                           &minor))
     return FALSE;
 
-  if (!XkbUseExtension (backend_x11->xdpy, &major, &minor))
+  if (!XkbUseExtension (xdisplay, &major, &minor))
     return FALSE;
 
   _xkb_event_base = event_base;
@@ -192,18 +194,20 @@ set_xkb_ctrl (XkbDescRec               *desc,
 }
 
 void
-clutter_device_manager_x11_apply_kbd_a11y_settings (ClutterDeviceManager   *device_manager,
-                                                    ClutterKbdA11ySettings *kbd_a11y_settings)
+meta_device_manager_x11_apply_kbd_a11y_settings (ClutterDeviceManager   *device_manager,
+                                                 ClutterKbdA11ySettings *kbd_a11y_settings)
 {
-  ClutterBackendX11 *backend_x11;
-  XkbDescRec      *desc;
-  gboolean         enable_accessX;
+  ClutterBackend *backend;
+  Display *xdisplay = clutter_x11_get_default_display ();
+  XkbDescRec *desc;
+  gboolean enable_accessX;
 
-  backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
-  desc = get_xkb_desc_rec (backend_x11);
+  desc = get_xkb_desc_rec (xdisplay);
   if (!desc)
     return;
 
+  backend = clutter_get_default_backend ();
+
   /* general */
   enable_accessX = kbd_a11y_settings->controls & CLUTTER_A11Y_KEYBOARD_ENABLED;
 
@@ -241,7 +245,7 @@ clutter_device_manager_x11_apply_kbd_a11y_settings (ClutterDeviceManager   *devi
     }
 
   /* mouse keys */
-  if (clutter_keymap_get_num_lock_state (CLUTTER_KEYMAP (backend_x11->keymap)))
+  if (clutter_keymap_get_num_lock_state (clutter_backend_get_keymap (backend)))
     {
       /* Disable mousekeys when NumLock is ON */
       desc->ctrls->enabled_ctrls &= ~(XkbMouseKeysMask | XkbMouseKeysAccelMask);
@@ -307,25 +311,22 @@ clutter_device_manager_x11_apply_kbd_a11y_settings (ClutterDeviceManager   *devi
     set_value_mask (kbd_a11y_settings->controls & CLUTTER_A11Y_TOGGLE_KEYS_ENABLED,
                     desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_IndicatorFBMask);
 
-  set_xkb_desc_rec (backend_x11, desc);
+  set_xkb_desc_rec (xdisplay, desc);
   XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE);
 }
 
 gboolean
-clutter_device_manager_x11_a11y_init (ClutterDeviceManager *device_manager)
+meta_device_manager_x11_a11y_init (ClutterDeviceManager *device_manager)
 {
-  ClutterBackendX11 *backend_x11;
+  Display *xdisplay = clutter_x11_get_default_display ();
   guint event_mask;
 
-  backend_x11 =
-    CLUTTER_BACKEND_X11 (_clutter_device_manager_get_backend (device_manager));
-
-  if (!is_xkb_available (backend_x11))
+  if (!is_xkb_available (xdisplay))
     return FALSE;
 
   event_mask = XkbControlsNotifyMask | XkbAccessXNotifyMask;
 
-  XkbSelectEvents (backend_x11->xdpy, XkbUseCoreKbd, event_mask, event_mask);
+  XkbSelectEvents (xdisplay, XkbUseCoreKbd, event_mask, event_mask);
 
   clutter_x11_add_filter (xkb_a11y_event_filter, device_manager);
 
diff --git a/clutter/clutter/x11/clutter-xkb-a11y-x11.h b/src/backends/x11/meta-xkb-a11y-x11.h
similarity index 66%
rename from clutter/clutter/x11/clutter-xkb-a11y-x11.h
rename to src/backends/x11/meta-xkb-a11y-x11.h
index 8446bc8ca..2e78b27b2 100644
--- a/clutter/clutter/x11/clutter-xkb-a11y-x11.h
+++ b/src/backends/x11/meta-xkb-a11y-x11.h
@@ -21,19 +21,17 @@
  *
  */
 
-#ifndef CLUTTER_XKB_A11Y_X11_H
-#define CLUTTER_XKB_A11Y_X11_H
-
-#include "clutter-device-manager-private.h"
-#include "clutter-backend-x11.h"
+#ifndef META_XKB_A11Y_X11_H
+#define META_XKB_A11Y_X11_H
 
+#include <clutter/clutter.h>
 #include <X11/Xlib.h>
 
 void
-clutter_device_manager_x11_apply_kbd_a11y_settings (ClutterDeviceManager   *device_manager,
-                                                    ClutterKbdA11ySettings *kbd_a11y_settings);
+meta_device_manager_x11_apply_kbd_a11y_settings (ClutterDeviceManager   *device_manager,
+                                                 ClutterKbdA11ySettings *kbd_a11y_settings);
 
 gboolean
-clutter_device_manager_x11_a11y_init               (ClutterDeviceManager *device_manager);
+meta_device_manager_x11_a11y_init               (ClutterDeviceManager *device_manager);
 
-#endif /* CLUTTER_XKB_A11Y_X11_H */
+#endif /* META_XKB_A11Y_X11_H */
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index e4ffd1e84..52024d357 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -59,6 +59,8 @@
 
 #include "backends/meta-dnd-private.h"
 #include "backends/x11/meta-backend-x11.h"
+#include "backends/x11/meta-event-x11.h"
+#include "backends/x11/meta-stage-x11.h"
 #include "clutter/clutter-mutter.h"
 #include "clutter/x11/clutter-x11.h"
 #include "compositor/meta-sync-ring.h"
@@ -260,7 +262,7 @@ meta_set_stage_input_region (MetaDisplay  *display,
     {
       MetaCompositor *compositor = display->compositor;
       Display *xdpy = meta_x11_display_get_xdisplay (display->x11_display);
-      Window xstage = clutter_x11_get_stage_window (CLUTTER_STAGE (compositor->stage));
+      Window xstage = meta_x11_get_stage_window (CLUTTER_STAGE (compositor->stage));
 
       XFixesSetWindowShapeRegion (xdpy, xstage, ShapeInput, 0, 0, region);
 
@@ -300,7 +302,7 @@ meta_focus_stage_window (MetaDisplay *display,
   if (!stage)
     return;
 
-  window = clutter_x11_get_stage_window (stage);
+  window = meta_x11_get_stage_window (stage);
 
   if (window == None)
     return;
@@ -323,7 +325,7 @@ meta_stage_is_focused (MetaDisplay *display)
   if (!stage)
     return FALSE;
 
-  window = clutter_x11_get_stage_window (stage);
+  window = meta_x11_get_stage_window (stage);
 
   if (window == None)
     return FALSE;
@@ -826,7 +828,7 @@ meta_compositor_process_event (MetaCompositor *compositor,
   /* Clutter needs to know about MapNotify events otherwise it will
      think the stage is invisible */
   if (!meta_is_wayland_compositor () && event->type == MapNotify)
-    clutter_x11_handle_event (event);
+    meta_x11_handle_event (event);
 
   /* The above handling is basically just "observing" the events, so we return
    * FALSE to indicate that the event should not be filtered out; if we have
diff --git a/src/compositor/meta-dnd.c b/src/compositor/meta-dnd.c
index 467aec347..3fe1e5e78 100644
--- a/src/compositor/meta-dnd.c
+++ b/src/compositor/meta-dnd.c
@@ -26,6 +26,7 @@
 #include "compositor/compositor-private.h"
 #include "core/display-private.h"
 #include "backends/meta-dnd-private.h"
+#include "backends/x11/meta-stage-x11.h"
 #include "meta/meta-dnd.h"
 #include "x11/meta-x11-display-private.h"
 
@@ -150,7 +151,7 @@ meta_dnd_handle_xdnd_event (MetaBackend    *backend,
     return FALSE;
 
   if (xev->xany.window != output_window &&
-      xev->xany.window != clutter_x11_get_stage_window (CLUTTER_STAGE (compositor->stage)))
+      xev->xany.window != meta_x11_get_stage_window (CLUTTER_STAGE (compositor->stage)))
     return FALSE;
 
   if (xev->xclient.message_type == XInternAtom (xdisplay, "XdndPosition", TRUE))
diff --git a/src/core/display.c b/src/core/display.c
index 704ec1662..d6ada2953 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -49,6 +49,7 @@
 #include "backends/meta-logical-monitor.h"
 #include "backends/meta-stage-private.h"
 #include "backends/x11/meta-backend-x11.h"
+#include "backends/x11/meta-event-x11.h"
 #include "backends/x11/cm/meta-backend-x11-cm.h"
 #include "clutter/x11/clutter-x11.h"
 #include "core/bell.h"
@@ -619,7 +620,7 @@ gesture_tracker_state_changed (MetaGestureTracker   *tracker,
 
       XIAllowTouchEvents (meta_backend_x11_get_xdisplay (backend),
                           META_VIRTUAL_CORE_POINTER_ID,
-                          clutter_x11_event_sequence_get_touch_detail (sequence),
+                          meta_x11_event_sequence_get_touch_detail (sequence),
                           DefaultRootWindow (display->x11_display->xdisplay), event_mode);
     }
 }
diff --git a/src/meson.build b/src/meson.build
index 53db81e85..6d08bf612 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -101,6 +101,7 @@ if have_x11
     x11_xcb_dep,
     xcb_randr_dep,
     xcb_res_dep,
+    xtst_dep,
   ]
 
   if have_sm
@@ -240,18 +241,34 @@ mutter_sources = [
   'backends/x11/meta-crtc-xrandr.h',
   'backends/x11/meta-cursor-renderer-x11.c',
   'backends/x11/meta-cursor-renderer-x11.h',
+  'backends/x11/meta-device-manager-x11.c',
+  'backends/x11/meta-device-manager-x11.h',
+  'backends/x11/meta-event-x11.c',
+  'backends/x11/meta-event-x11.h',
   'backends/x11/meta-gpu-xrandr.c',
   'backends/x11/meta-gpu-xrandr.h',
+  'backends/x11/meta-input-device-x11.c',
+  'backends/x11/meta-input-device-x11.h',
+  'backends/x11/meta-input-device-tool-x11.c',
+  'backends/x11/meta-input-device-tool-x11.h',
   'backends/x11/meta-input-settings-x11.c',
   'backends/x11/meta-input-settings-x11.h',
+  'backends/x11/meta-keymap-x11.c',
+  'backends/x11/meta-keymap-x11.h',
   'backends/x11/meta-monitor-manager-xrandr.c',
   'backends/x11/meta-monitor-manager-xrandr.h',
   'backends/x11/meta-output-xrandr.c',
   'backends/x11/meta-output-xrandr.h',
   'backends/x11/meta-renderer-x11.c',
   'backends/x11/meta-renderer-x11.h',
+  'backends/x11/meta-stage-x11.c',
+  'backends/x11/meta-stage-x11.h',
   'backends/x11/meta-stage-x11-nested.c',
   'backends/x11/meta-stage-x11-nested.h',
+  'backends/x11/meta-virtual-input-device-x11.c',
+  'backends/x11/meta-virtual-input-device-x11.h',
+  'backends/x11/meta-xkb-a11y-x11.c',
+  'backends/x11/meta-xkb-a11y-x11.h',
   'backends/x11/nested/meta-backend-x11-nested.c',
   'backends/x11/nested/meta-backend-x11-nested.h',
   'backends/x11/nested/meta-cursor-renderer-x11-nested.c',


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