Clean up the windowing system defines

Instead of defining new symbols for the windowing systems enabled at
configure time, we can reuse the same symbols for both the compile time
and run time checks, e.g.:

  #ifdef CLUTTER_WINDOWING_X11
    if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
      /* use the clutter_x11_* API */
    else
  #endif
  #ifdef CLUTTER_WINDOWING_WIN32
    if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32))
      /* use the clutter_win32_* API */
  #endif

This scheme allows us to ensure that the input system namespace is free
for us to use and select at run time in later versions of Clutter.
This commit is contained in:
Emmanuele Bassi 2011-10-17 16:03:19 +01:00
parent 98c177def5
commit 8249e48802
5 changed files with 71 additions and 114 deletions

View File

@ -23,6 +23,9 @@
#define __CLUTTER_BACKEND_PRIVATE_H__
#include <clutter/clutter-backend.h>
#include <clutter/clutter-device-manager.h>
#include <clutter/clutter-stage-window.h>
#include "clutter-event-translator.h"
#define CLUTTER_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BACKEND, ClutterBackendClass))

View File

@ -29,18 +29,14 @@
#define __CLUTTER_BACKEND_H__
#include <cairo.h>
#include <glib-object.h>
#include <pango/pango.h>
#ifdef COGL_ENABLE_EXPERIMENTAL_2_0_API
#include <cogl/cogl.h>
#endif
#include <clutter/clutter-actor.h>
#include <clutter/clutter-device-manager.h>
#include <clutter/clutter-event.h>
#include <clutter/clutter-feature.h>
#include <clutter/clutter-stage.h>
#include <clutter/clutter-stage-window.h>
#include <clutter/clutter-config.h>
#include <clutter/clutter-types.h>
G_BEGIN_DECLS
@ -48,73 +44,6 @@ G_BEGIN_DECLS
#define CLUTTER_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BACKEND, ClutterBackend))
#define CLUTTER_IS_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BACKEND))
/**
* CLUTTER_OSX_BACKEND:
*
* Evaluates to the symbolic name of the Quartz Clutter backend.
*
* This macro should be used with clutter_check_backend().
*
* Since: 1.10
*/
#define CLUTTER_OSX_BACKEND "osx"
/**
* CLUTTER_X11_BACKEND:
*
* Evaluates to the symbolic name of the X11 Clutter backend.
*
* This macro should be used with clutter_check_backend().
*
* Since: 1.10
*/
#define CLUTTER_X11_BACKEND "x11"
/**
* CLUTTER_WIN32_BACKEND:
*
* Evaluates to the symbolic name of the Windows Clutter backend.
*
* This macro should be used with clutter_check_backend().
*
* Since: 1.10
*/
#define CLUTTER_WIN32_BACKEND "win32"
/**
* CLUTTER_EGL_NATIVE_BACKEND:
*
* Evaluates to the symbolic name of the EGL framebuffer Clutter backend.
*
* This macro should be used with clutter_check_backend().
*
* Since: 1.10
*/
#define CLUTTER_EGL_NATIVE_BACKEND "eglnative"
/**
* CLUTTER_WAYLAND_BACKEND:
*
* Evaluates to the symbolic name of the Wayland client Clutter backend.
*
* This macro should be used with clutter_check_backend().
*
* Since: 1.10
*/
#define CLUTTER_WAYLAND_BACKEND "wayland"
/**
* CLUTTER_GDK_BACKEND:
*
* Evaluates to the symbolic name of the GDK Clutter backend.
*
* This macro should be used with clutter_check_backend().
*
* Since: 1.10
*/
#define CLUTTER_GDK_BACKEND "gdk"
/**
* ClutterBackend:
*

View File

@ -1319,44 +1319,43 @@ clutter_create_backend (void)
const char *backend = g_getenv ("CLUTTER_BACKEND");
ClutterBackend *retval = NULL;
if (backend != NULL)
backend = g_intern_string (backend);
#ifdef CLUTTER_WINDOWING_OSX
if (backend == NULL || strcmp (backend, CLUTTER_OSX_BACKEND) == 0)
if (backend == NULL || backend == I_(CLUTTER_WINDOWING_OSX))
retval = g_object_new (CLUTTER_TYPE_BACKEND_OSX, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_WIN32
if (backend == NULL || strcmp (backend, CLUTTER_WIN32_BACKEND) == 0)
if (backend == NULL || backend == I_(CLUTTER_WINDOWING_WIN32))
retval = g_object_new (CLUTTER_TYPE_BACKEND_WIN32, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_WAYLAND
if (backend == NULL || strcmp (backend, CLUTTER_WAYLAND_BACKEND) == 0)
if (backend == NULL || backend == I_(CLUTTER_WINDOWING_WAYLAND))
retval = g_object_new (CLUTTER_TYPE_BACKEND_WAYLAND, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_EGL
if (backend == NULL || strcmp (backend, CLUTTER_EGL_NATIVE_BACKEND) == 0)
if (backend == NULL || backend == I_(CLUTTER_WINDOWING_EGL))
retval = g_object_new (CLUTTER_TYPE_BACKEND_EGL_NATIVE, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_X11
if (backend == NULL || strcmp (backend, CLUTTER_X11_BACKEND) == 0)
if (backend == NULL || backend == I_(CLUTTER_WINDOWING_X11))
retval = g_object_new (CLUTTER_TYPE_BACKEND_X11, NULL);
else
#endif
#ifdef CLUTTER_WINDOWING_GDK
if (backend == NULL || strcmp (backend, CLUTTER_GDK_BACKEND) == 0)
if (backend == NULL || backend == I_(CLUTTER_WINDOWING_GDK))
retval = g_object_new (CLUTTER_TYPE_BACKEND_GDK, NULL);
else
#endif
if (backend != NULL)
g_error ("Unsupported Clutter backend: '%s'", backend);
else
if (backend == NULL)
g_error ("No default Clutter backend found.");
CLUTTER_NOTE (BACKEND, "Backend type: '%s' (requested: '%s')",
G_OBJECT_TYPE_NAME (retval),
backend != NULL ? backend : "<default>");
else
g_error ("Unsupported Clutter backend: '%s'", backend);
return retval;
}
@ -3621,57 +3620,83 @@ _clutter_context_get_motion_events_enabled (void)
}
/**
* clutter_check_backend:
* clutter_check_windowing_backend:
* @backend_type: the name of the backend to check
*
* Checks the run-time name of the Clutter backend, using the symbolic
* macros like %CLUTTER_OSX_BACKEND or %CLUTTER_X11_BACKEND.
* Checks the run-time name of the Clutter windowing system backend, using
* the symbolic macros like %CLUTTER_WINDOWING_WIN32 or
* %CLUTTER_WINDOWING_X11.
*
* Return value: %TRUE if the current Clutter backend is the one checked,
* and %FALSE otherwise
* This function should be used in conjuction with the compile-time macros
* inside applications and libraries that are using the platform-specific
* windowing system API, to ensure that they are running on the correct
* windowing system; for instance:
*
* |[
* &num;ifdef CLUTTER_WINDOWING_X11
* if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
* {
* /&ast; it is safe to use the clutter_x11_* API &ast;/
* }
* else
* &num;endif
* &num;ifdef CLUTTER_WINDOWING_WIN32
* if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32))
* {
* /&ast; it is safe to use the clutter_win32_* API &ast;/
* }
* else
* &num;endif
* g_error ("Unknown Clutter backend.");
* ]|
*
* Return value: %TRUE if the current Clutter windowing system backend is
* the one checked, and %FALSE otherwise
*
* Since: 1.10
*/
gboolean
clutter_check_backend (const char *backend_type)
clutter_check_windowing_backend (const char *backend_type)
{
ClutterMainContext *context = _clutter_context_get_default ();
g_return_val_if_fail (backend_type != NULL, FALSE);
backend_type = g_intern_string (backend_type);
#ifdef CLUTTER_WINDOWING_OSX
if (strcmp (backend_type, CLUTTER_OSX_BACKEND) == 0 &&
if (backend_type == I_(CLUTTER_WINDOWING_OSX) &&
CLUTTER_IS_BACKEND_OSX (context->backend))
return TRUE;
else
#endif
#ifdef CLUTTER_WINDOWING_WIN32
if (strcmp (backend_type, CLUTTER_WIN32_BACKEND) == 0 &&
if (backend_type == I_(CLUTTER_WINDOWING_WIN32) &&
CLUTTER_IS_BACKEND_WIN32 (context->backend))
return TRUE;
else
#endif
#ifdef CLUTTER_WINDOWING_WAYLAND
if (strcmp (backend_type, CLUTTER_WAYLAND_BACKEND) == 0 &&
if (backend_type == I_(CLUTTER_WINDOWING_WAYLAND) &&
CLUTTER_IS_BACKEND_WAYLAND (context->backend))
return TRUE;
else
#endif
#ifdef CLUTTER_WINDOWING_EGL
if (strcmp (backend_type, CLUTTER_EGL_NATIVE_BACKEND) == 0 &&
if (backend_type == I_(CLUTTER_WINDOWING_EGL) &&
CLUTTER_IS_BACKEND_EGL_NATIVE (context->backend))
return TRUE;
else
#endif
#ifdef CLUTTER_WINDOWING_X11
if (strcmp (backend_type, CLUTTER_X11_BACKEND) == 0 &&
CLUTTER_IS_BACKEND_X11 (context->backend))
#ifdef CLUTTER_WINDOWING_GDK
if (backend_type == I_(CLUTTER_WINDOWING_GDK) &&
CLUTTER_IS_BACKEND_GDK (context->backend))
return TRUE;
else
#endif
#ifdef CLUTTER_WINDOWING_GDK
if (strcmp (backend_type, CLUTTER_GDK_BACKEND) == 0 &&
CLUTTER_IS_BACKEND_GDK (context->backend))
#ifdef CLUTTER_WINDOWING_X11
if (backend_type == I_(CLUTTER_WINDOWING_X11) &&
CLUTTER_IS_BACKEND_X11 (context->backend))
return TRUE;
else
#endif

View File

@ -195,7 +195,7 @@ gboolean clutter_check_version (guint major,
guint minor,
guint micro);
gboolean clutter_check_backend (const char *backend_type);
gboolean clutter_check_windowing_backend (const char *backend_type);
G_END_DECLS

View File

@ -460,34 +460,34 @@ CLUTTER_CONFIG_DEFINES=
# windowing systems
AS_IF([test "x$SUPPORT_X11" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_X11 1"])
#define CLUTTER_WINDOWING_X11 \"x11\""])
AS_IF([test "x$SUPPORT_GDK" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_GDK 1"])
#define CLUTTER_WINDOWING_GDK \"gdk\""])
AS_IF([test "x$SUPPORT_GLX" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_GLX 1"])
#define CLUTTER_WINDOWING_GLX \"glx\""])
AS_IF([test "x$SUPPORT_EGL" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_EGL 1"])
#define CLUTTER_WINDOWING_EGL \"eglnative\""])
AS_IF([test "x$SUPPORT_WAYLAND" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_WAYLAND 1"])
#define CLUTTER_WINDOWING_WAYLAND \"wayland\""])
AS_IF([test "x$SUPPORT_OSX" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_OSX 1"])
#define CLUTTER_WINDOWING_OSX \"osx\""])
AS_IF([test "x$SUPPORT_WIN32" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_WIN32 1"])
#define CLUTTER_WINDOWING_WIN32 \"win32\""])
AS_IF([test "x$SUPPORT_EGL_PLATFORM_GDL" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_CEX100 1"])
#define CLUTTER_WINDOWING_CEX100 \"cex100\""])
AS_IF([test "x$SUPPORT_EVDEV" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_EVDEV 1"])
#define CLUTTER_INPUT_EVDEV \"evdev\""])
AS_IF([test "x$SUPPORT_TSLIB" = "x1"],
[CLUTTER_CONFIG_DEFINES="$CLUTTER_CONFIG_DEFINES
#define CLUTTER_WINDOWING_TSLIB 1"])
#define CLUTTER_INPUT_TSLIB \"tslib\""])
AC_SUBST([CLUTTER_CONFIG_DEFINES])