diff --git a/clutter/clutter-backend.h b/clutter/clutter-backend.h index 4e5d83e22..637dc1e1f 100644 --- a/clutter/clutter-backend.h +++ b/clutter/clutter-backend.h @@ -48,6 +48,73 @@ 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: * diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 6ee8986e9..888d215c3 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -1326,32 +1326,32 @@ clutter_context_get_default_unlocked (void) backend = g_getenv ("CLUTTER_BACKEND"); #ifdef CLUTTER_WINDOWING_OSX - if (backend == NULL || strcmp (backend, "osx") == 0) + if (backend == NULL || strcmp (backend, CLUTTER_OSX_BACKEND) == 0) ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_OSX, NULL); else #endif #ifdef CLUTTER_WINDOWING_WIN32 - if (backend == NULL || strcmp (backend, "win32") == 0) + if (backend == NULL || strcmp (backend, CLUTTER_WIN32_BACKEND) == 0) ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_WIN32, NULL); else #endif #ifdef CLUTTER_WINDOWING_WAYLAND - if (backend == NULL || strcmp (backend, "wayland") == 0) + if (backend == NULL || strcmp (backend, CLUTTER_WAYLAND_BACKEND) == 0) ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_WAYLAND, NULL); else #endif #ifdef CLUTTER_WINDOWING_EGL - if (backend == NULL || strcmp (backend, "eglnative") == 0) + if (backend == NULL || strcmp (backend, CLUTTER_EGL_NATIVE_BACKEND) == 0) ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_EGLNATIVE, NULL); else #endif #ifdef CLUTTER_WINDOWING_X11 - if (backend == NULL || strcmp (backend, "x11") == 0) + if (backend == NULL || strcmp (backend, CLUTTER_X11_BACKEND) == 0) ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_X11, NULL); else #endif #ifdef CLUTTER_WINDOWING_GDK - if (backend == NULL || strcmp (backend, "gdk") == 0) + if (backend == NULL || strcmp (backend, CLUTTER_GDK_BACKEND) == 0) ctx->backend = g_object_new (CLUTTER_TYPE_BACKEND_GDK, NULL); else #endif @@ -3610,3 +3610,61 @@ _clutter_context_get_motion_events_enabled (void) return context->motion_events_per_actor; } + +/** + * clutter_check_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. + * + * Return value: %TRUE if the current Clutter backend is the one checked, + * and %FALSE otherwise + * + * Since: 1.10 + */ +gboolean +clutter_check_backend (const char *backend_type) +{ + ClutterMainContext *context = _clutter_context_get_default (); + + g_return_val_if_fail (backend_type != NULL, FALSE); + +#ifdef CLUTTER_WINDOWING_OSX + if (strcmp (backend_type, CLUTTER_OSX_BACKEND) == 0 && + CLUTTER_IS_BACKEND_OSX (context->backend)) + return TRUE; + else +#endif +#ifdef CLUTTER_WINDOWING_WIN32 + if (strcmp (backend_type, CLUTTER_WIN32_BACKEND) == 0 && + CLUTTER_IS_BACKEND_WIN32 (context->backend)) + return TRUE; + else +#endif +#ifdef CLUTTER_WINDOWING_WAYLAND + if (strcmp (backend_type, CLUTTER_WAYLAND_BACKEND) == 0 && + CLUTTER_IS_BACKEND_WAYLAND (context->backend)) + return TRUE; + else +#endif +#ifdef CLUTTER_WINDOWING_EGL + if (strcmp (backend_type, CLUTTER_EGL_BACKEND) == 0 && + 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)) + return TRUE; + else +#endif +#ifdef CLUTTER_WINDOWING_GDK + if (strcmp (backend_type, CLUTTER_GDK_BACKEND) == 0 && + CLUTTER_IS_BACKEND_GDK (context->backend)) + return TRUE; + else +#endif + return FALSE; +} diff --git a/clutter/clutter-version.h.in b/clutter/clutter-version.h.in index 835e29f76..5b38ee04f 100644 --- a/clutter/clutter-version.h.in +++ b/clutter/clutter-version.h.in @@ -195,6 +195,8 @@ gboolean clutter_check_version (guint major, guint minor, guint micro); +gboolean clutter_check_backend (const char *backend_type); + G_END_DECLS #endif /* __CLUTTER_VERSION_H__ */