From 9c7eafc8c378aa641d8017d4bb517f5759c8f5d8 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 7 Aug 2024 12:50:45 +0200 Subject: [PATCH] clutter/context: Track if accessibility enabled Currently, we would only disable a11y if a certain flag is passed but the function is always called with NONE flag. Instead drop the flag, use a new environment variable for that That value is then used by actors to short-circuit get_accessible implementation and return NULL if the accessibility is not enabled Also clean the other accessibility functions Part-of: --- clutter/clutter/clutter-actor.c | 4 +++ clutter/clutter/clutter-context.c | 26 +++++++++++++---- clutter/clutter/clutter-context.h | 8 +----- clutter/clutter/clutter-main.c | 47 ++----------------------------- clutter/clutter/clutter-main.h | 3 -- clutter/clutter/clutter-mutter.h | 3 +- src/backends/meta-backend.c | 3 +- 7 files changed, 30 insertions(+), 64 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index c82409cea..237c3aeed 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -5462,8 +5462,12 @@ static AtkObject * clutter_actor_real_get_accessible (ClutterActor *actor) { ClutterActorPrivate *priv = actor->priv; + if (priv->accessible == NULL) { + if (!clutter_get_accessibility_enabled ()) + return NULL; + priv->accessible = g_object_new (CLUTTER_ACTOR_GET_CLASS (actor)->get_accessible_type (), NULL); diff --git a/clutter/clutter/clutter-context.c b/clutter/clutter/clutter-context.c index efb3c6623..e0b517246 100644 --- a/clutter/clutter/clutter-context.c +++ b/clutter/clutter/clutter-context.c @@ -33,6 +33,7 @@ static gboolean clutter_disable_mipmap_text = FALSE; static gboolean clutter_show_fps = FALSE; +static gboolean clutter_enable_accessibility = TRUE; #ifdef CLUTTER_ENABLE_DEBUG static const GDebugKey clutter_debug_keys[] = { @@ -167,7 +168,6 @@ clutter_get_text_direction (void) static gboolean clutter_context_init_real (ClutterContext *context, - ClutterContextFlags flags, GError **error) { ClutterContextPrivate *priv = clutter_context_get_instance_private (context); @@ -197,7 +197,7 @@ clutter_context_init_real (ClutterContext *context, context->is_initialized = TRUE; /* Initialize a11y */ - if (!(flags & CLUTTER_CONTEXT_FLAG_NO_A11Y)) + if (clutter_enable_accessibility) { _clutter_accessibility_override_atk_util (); CLUTTER_NOTE (MISC, "Clutter Accessibility initialized"); @@ -250,14 +250,17 @@ init_clutter_debug (ClutterContext *context) if (env_string) clutter_show_fps = TRUE; + env_string = g_getenv ("CLUTTER_DISABLE_ACCESSIBILITY"); + if (env_string) + clutter_enable_accessibility = FALSE; + env_string = g_getenv ("CLUTTER_DISABLE_MIPMAPPED_TEXT"); if (env_string) clutter_disable_mipmap_text = TRUE; } ClutterContext * -clutter_context_new (ClutterContextFlags flags, - ClutterBackendConstructor backend_constructor, +clutter_context_new (ClutterBackendConstructor backend_constructor, gpointer user_data, GError **error) { @@ -285,7 +288,7 @@ clutter_context_new (ClutterContextFlags flags, NULL); priv->pipeline_cache = g_object_new (CLUTTER_TYPE_PIPELINE_CACHE, NULL); - if (!clutter_context_init_real (context, flags, error)) + if (!clutter_context_init_real (context, error)) return NULL; return context; @@ -357,3 +360,16 @@ clutter_context_get_color_manager (ClutterContext *context) return priv->color_manager; } + +/** + * clutter_get_accessibility_enabled: + * + * Returns whether Clutter has accessibility support enabled. + * + * Return value: %TRUE if Clutter has accessibility support enabled + */ +gboolean +clutter_get_accessibility_enabled (void) +{ + return clutter_enable_accessibility; +} diff --git a/clutter/clutter/clutter-context.h b/clutter/clutter/clutter-context.h index 3b4d152c6..7aaf71a61 100644 --- a/clutter/clutter/clutter-context.h +++ b/clutter/clutter/clutter-context.h @@ -24,11 +24,6 @@ #include "clutter-settings.h" #include "cogl-pango/cogl-pango.h" -typedef enum _ClutterContextFlags -{ - CLUTTER_CONTEXT_FLAG_NONE = 0, - CLUTTER_CONTEXT_FLAG_NO_A11Y = 1 << 0, -} ClutterContextFlags; typedef ClutterBackend * (* ClutterBackendConstructor) (gpointer user_data); @@ -40,8 +35,7 @@ G_DECLARE_FINAL_TYPE (ClutterContext, clutter_context, /** * clutter_context_new: (skip) */ -ClutterContext * clutter_context_new (ClutterContextFlags flags, - ClutterBackendConstructor backend_constructor, +ClutterContext * clutter_context_new (ClutterBackendConstructor backend_constructor, gpointer user_data, GError **error); diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index 1f008d708..c48ce3bb7 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -58,10 +58,6 @@ G_DEFINE_QUARK (clutter_pipeline_capability, clutter_pipeline_capability) /* main context */ static ClutterContext *ClutterCntx = NULL; -/* command line options */ -static gboolean clutter_is_initialized = FALSE; -static gboolean clutter_enable_accessibility = TRUE; - /* debug flags */ guint clutter_debug_flags = 0; guint clutter_paint_debug_flags = 0; @@ -80,42 +76,6 @@ _clutter_context_get_show_fps (void) return context->show_fps; } -/** - * clutter_get_accessibility_enabled: - * - * Returns whether Clutter has accessibility support enabled. As - * least, a value of TRUE means that there are a proper AtkUtil - * implementation available - * - * Return value: %TRUE if Clutter has accessibility support enabled - */ -gboolean -clutter_get_accessibility_enabled (void) -{ - return !g_strcmp0 (atk_get_toolkit_name (), "clutter"); -} - -/** - * clutter_disable_accessibility: - * - * Disable loading the accessibility support. It has the same effect - * as setting the environment variable - * CLUTTER_DISABLE_ACCESSIBILITY. For the same reason, this method - * should be called before clutter_init(). - */ -void -clutter_disable_accessibility (void) -{ - if (clutter_is_initialized) - { - g_warning ("clutter_disable_accessibility() can only be called before " - "initializing Clutter."); - return; - } - - clutter_enable_accessibility = FALSE; -} - static gboolean _clutter_threads_dispatch (gpointer data) { @@ -358,8 +318,7 @@ _clutter_context_get_default (void) } ClutterContext * -clutter_create_context (ClutterContextFlags flags, - ClutterBackendConstructor backend_constructor, +clutter_create_context (ClutterBackendConstructor backend_constructor, gpointer user_data, GError **error) { @@ -370,13 +329,11 @@ clutter_create_context (ClutterContextFlags flags, return NULL; } - ClutterCntx = clutter_context_new (flags, - backend_constructor, user_data, + ClutterCntx = clutter_context_new (backend_constructor, user_data, error); if (!ClutterCntx) return NULL; - clutter_is_initialized = TRUE; g_object_add_weak_pointer (G_OBJECT (ClutterCntx), (gpointer *) &ClutterCntx); return ClutterCntx; } diff --git a/clutter/clutter/clutter-main.h b/clutter/clutter/clutter-main.h index 6f7a11302..b5884f35b 100644 --- a/clutter/clutter/clutter-main.h +++ b/clutter/clutter/clutter-main.h @@ -107,9 +107,6 @@ void clutter_stage_handle_event (ClutterStage *s CLUTTER_EXPORT gboolean clutter_get_accessibility_enabled (void); -CLUTTER_EXPORT -void clutter_disable_accessibility (void); - /* Threading functions */ CLUTTER_EXPORT guint clutter_threads_add_idle (GSourceFunc func, diff --git a/clutter/clutter/clutter-mutter.h b/clutter/clutter/clutter-mutter.h index cf46aaafa..76d5a2441 100644 --- a/clutter/clutter/clutter-mutter.h +++ b/clutter/clutter/clutter-mutter.h @@ -48,8 +48,7 @@ * clutter_create_context: (skip) */ CLUTTER_EXPORT -ClutterContext * clutter_create_context (ClutterContextFlags flags, - ClutterBackendConstructor backend_constructor, +ClutterContext * clutter_create_context (ClutterBackendConstructor backend_constructor, gpointer user_data, GError **error); diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index da667867b..29f2712b3 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -1223,8 +1223,7 @@ init_clutter (MetaBackend *backend, MetaBackendSource *backend_source; GSource *source; - priv->clutter_context = clutter_create_context (CLUTTER_CONTEXT_FLAG_NONE, - meta_clutter_backend_constructor, + priv->clutter_context = clutter_create_context (meta_clutter_backend_constructor, backend, error); if (!priv->clutter_context)