clutter: Rename CallyUtil to ClutterAccessibility

As nothing is supposed to use it oustide of Clutter, make
it private and final

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3917>
This commit is contained in:
Bilal Elmoussaoui 2024-08-02 17:03:51 +02:00 committed by Marge Bot
parent e2e93353d9
commit 7c5223dfc7
5 changed files with 79 additions and 114 deletions

View File

@ -1,4 +1,4 @@
/* CALLY - The Clutter Accessibility Implementation Library /* Clutter.
* *
* Copyright (C) 2008 Igalia, S.L. * Copyright (C) 2008 Igalia, S.L.
* *
@ -20,10 +20,6 @@
#pragma once #pragma once
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#include <atk/atk.h> #include <atk/atk.h>
#include "clutter/clutter-macros.h" #include "clutter/clutter-macros.h"
@ -31,27 +27,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLY_TYPE_UTIL (cally_util_get_type ()) void _clutter_accessibility_override_atk_util (void);
typedef struct _CallyUtil CallyUtil; gboolean clutter_accessibility_snoop_key_event (ClutterStage *stage,
typedef struct _CallyUtilClass CallyUtilClass; ClutterKeyEvent *key);
CLUTTER_EXPORT
G_DECLARE_DERIVABLE_TYPE (CallyUtil,
cally_util,
CALLY,
UTIL,
AtkUtil)
struct _CallyUtilClass
{
/*< private >*/
AtkUtilClass parent_class;
};
void _cally_util_override_atk_util (void);
gboolean cally_snoop_key_event (ClutterStage *stage,
ClutterKeyEvent *key);
G_END_DECLS G_END_DECLS

View File

@ -1,4 +1,4 @@
/* CALLY - The Clutter Accessibility Implementation Library /* Clutter.
* *
* Copyright (C) 2008 Igalia, S.L. * Copyright (C) 2008 Igalia, S.L.
* *
@ -22,14 +22,11 @@
*/ */
/** /**
* CallyUtil: * ClutterAccessibility:
* *
* #AtkUtil implementation
* *
* #CallyUtil implements #AtkUtil abstract methods. Although it * A #AtkUtil implementation.
* includes the name "Util" it is in fact one of the most important *
* interfaces to be implemented in any ATK toolkit implementation.
* For instance, it defines [func@Atk.get_root], the method that returns * For instance, it defines [func@Atk.get_root], the method that returns
* the root object in the hierarchy. Without it, you don't have * the root object in the hierarchy. Without it, you don't have
* available any accessible object. * available any accessible object.
@ -40,78 +37,45 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "clutter/cally-util.h" #include "clutter/clutter-accessibility-private.h"
#include "clutter/cally-root.h" #include "clutter/cally-root.h"
#include "clutter/cally-stage.h" #include "clutter/cally-stage.h"
#include "clutter/clutter.h" #include "clutter/clutter.h"
#define DEFAULT_PASSWORD_CHAR '*' #define DEFAULT_PASSWORD_CHAR '*'
/* atkutil.h */
static guint cally_util_add_key_event_listener (AtkKeySnoopFunc listener,
gpointer data);
static void cally_util_remove_key_event_listener (guint remove_listener);
static AtkObject* cally_util_get_root (void);
static const gchar * cally_util_get_toolkit_name (void);
static const gchar * cally_util_get_toolkit_version (void);
/* private */
static gboolean notify_hf (gpointer key,
gpointer value,
gpointer data);
static void insert_hf (gpointer key,
gpointer value,
gpointer data);
/* This is just a copy of the Gail one, a shared library or place to /* This is just a copy of the Gail one, a shared library or place to
define it could be a good idea. */ define it could be a good idea. */
typedef struct _CallyKeyEventInfo CallyKeyEventInfo; typedef struct _KeyEventInfo
struct _CallyKeyEventInfo
{ {
AtkKeySnoopFunc listener; AtkKeySnoopFunc listener;
gpointer func_data; gpointer func_data;
}; } KeyEventInfo;
static AtkObject* root = NULL; static AtkObject*root = NULL;
static GHashTable *key_listener_list = NULL; static GHashTable *key_listener_list = NULL;
G_DECLARE_FINAL_TYPE (ClutterAccessibility,
clutter_accessibility,
CLUTTER,
ACCESSIBILITY,
AtkUtil)
G_DEFINE_TYPE (CallyUtil, cally_util, ATK_TYPE_UTIL); struct _ClutterAccessibility {
AtkUtil parent;
};
G_DEFINE_FINAL_TYPE (ClutterAccessibility, clutter_accessibility, ATK_TYPE_UTIL);
static void static void
cally_util_class_init (CallyUtilClass *klass) clutter_accessibility_init (ClutterAccessibility *accessibility)
{ {
AtkUtilClass *atk_class;
gpointer data;
data = g_type_class_peek (ATK_TYPE_UTIL);
atk_class = ATK_UTIL_CLASS (data);
atk_class->add_key_event_listener = cally_util_add_key_event_listener;
atk_class->remove_key_event_listener = cally_util_remove_key_event_listener;
atk_class->get_root = cally_util_get_root;
atk_class->get_toolkit_name = cally_util_get_toolkit_name;
atk_class->get_toolkit_version = cally_util_get_toolkit_version;
/* FIXME: Instead of create this on the class, I think that would
worth to implement CallyUtil as a singleton instance, so the
class methods will access this instance. This will be a good
future enhancement, meanwhile, just using the same *working*
implementation used on GailUtil */
}
static void
cally_util_init (CallyUtil *cally_util)
{
/* instance init: usually not required */
} }
/* ------------------------------ ATK UTIL METHODS -------------------------- */ /* ------------------------------ ATK UTIL METHODS -------------------------- */
static AtkObject* static AtkObject*
cally_util_get_root (void) clutter_accessibility_get_root (void)
{ {
if (!root) if (!root)
root = cally_root_new (); root = cally_root_new ();
@ -120,28 +84,28 @@ cally_util_get_root (void)
} }
static const gchar * static const gchar *
cally_util_get_toolkit_name (void) clutter_accessibility_get_toolkit_name (void)
{ {
return "clutter"; return "clutter";
} }
static const gchar * static const gchar *
cally_util_get_toolkit_version (void) clutter_accessibility_get_toolkit_version (void)
{ {
return VERSION; return VERSION;
} }
static guint static guint
cally_util_add_key_event_listener (AtkKeySnoopFunc listener, clutter_accessibility_add_key_event_listener (AtkKeySnoopFunc listener,
gpointer data) gpointer data)
{ {
static guint key = 1; static guint key = 1;
CallyKeyEventInfo *event_info = NULL; KeyEventInfo *event_info = NULL;
if (!key_listener_list) if (!key_listener_list)
key_listener_list = g_hash_table_new_full (NULL, NULL, NULL, g_free); key_listener_list = g_hash_table_new_full (NULL, NULL, NULL, g_free);
event_info = g_new (CallyKeyEventInfo, 1); event_info = g_new (KeyEventInfo, 1);
event_info->listener = listener; event_info->listener = listener;
event_info->func_data = data; event_info->func_data = data;
@ -151,11 +115,11 @@ cally_util_add_key_event_listener (AtkKeySnoopFunc listener,
} }
static void static void
cally_util_remove_key_event_listener (guint remove_listener) clutter_accessibility_remove_key_event_listener (guint remove_listener)
{ {
if (!g_hash_table_remove (key_listener_list, GUINT_TO_POINTER (remove_listener))) { if (!g_hash_table_remove (key_listener_list, GUINT_TO_POINTER (remove_listener))) {
g_warning ("Not able to remove listener with id %i", remove_listener); g_warning ("Not able to remove listener with id %i", remove_listener);
} }
if (g_hash_table_size (key_listener_list) == 0) if (g_hash_table_size (key_listener_list) == 0)
{ {
@ -240,13 +204,13 @@ atk_key_event_from_clutter_event_key (ClutterKeyEvent *clutter_event,
atk_event->timestamp = clutter_event_get_time ((ClutterEvent *) clutter_event); atk_event->timestamp = clutter_event_get_time ((ClutterEvent *) clutter_event);
#ifdef CALLY_DEBUG #ifdef CLUTTER_ENABLE_DEBUG
g_debug ("CallyKeyEvent:\tsym 0x%x\n\t\tmods %x\n\t\tcode %u\n\t\ttime %lx \n\t\tstring %s\n", g_debug ("KeyEvent:\tsym 0x%x\n\t\tmods %x\n\t\tcode %u\n\t\ttime %lx \n\t\tstring %s\n",
(unsigned int) atk_event->keyval, (unsigned int) atk_event->keyval,
(unsigned int) atk_event->state, (unsigned int) atk_event->state,
(unsigned int) atk_event->keycode, (unsigned int) atk_event->keycode,
(unsigned long int) atk_event->timestamp, (unsigned long int) atk_event->timestamp,
atk_event->string); atk_event->string);
#endif #endif
@ -255,16 +219,20 @@ atk_key_event_from_clutter_event_key (ClutterKeyEvent *clutter_event,
static gboolean static gboolean
notify_hf (gpointer key, gpointer value, gpointer data) notify_hf (gpointer key,
gpointer value,
gpointer data)
{ {
CallyKeyEventInfo *info = (CallyKeyEventInfo *) value; KeyEventInfo *info = (KeyEventInfo *) value;
AtkKeyEventStruct *key_event = (AtkKeyEventStruct *)data; AtkKeyEventStruct *key_event = (AtkKeyEventStruct *)data;
return (*(AtkKeySnoopFunc) info->listener) (key_event, info->func_data) ? TRUE : FALSE; return (*(AtkKeySnoopFunc) info->listener) (key_event, info->func_data) ? TRUE : FALSE;
} }
static void static void
insert_hf (gpointer key, gpointer value, gpointer data) insert_hf (gpointer key,
gpointer value,
gpointer data)
{ {
GHashTable *new_table = (GHashTable *) data; GHashTable *new_table = (GHashTable *) data;
g_hash_table_insert (new_table, key, value); g_hash_table_insert (new_table, key, value);
@ -305,8 +273,8 @@ check_key_visibility (ClutterStage *stage)
} }
gboolean gboolean
cally_snoop_key_event (ClutterStage *stage, clutter_accessibility_snoop_key_event (ClutterStage *stage,
ClutterKeyEvent *key) ClutterKeyEvent *key)
{ {
ClutterEvent *event = (ClutterEvent *) key; ClutterEvent *event = (ClutterEvent *) key;
AtkKeyEventStruct *key_event = NULL; AtkKeyEventStruct *key_event = NULL;
@ -338,14 +306,33 @@ cally_snoop_key_event (ClutterStage *stage,
return consumed; return consumed;
} }
static void
clutter_accessibility_class_init (ClutterAccessibilityClass *klass)
{
gpointer data = g_type_class_peek (ATK_TYPE_UTIL);
AtkUtilClass *atk_class = ATK_UTIL_CLASS (data);
atk_class->add_key_event_listener = clutter_accessibility_add_key_event_listener;
atk_class->remove_key_event_listener = clutter_accessibility_remove_key_event_listener;
atk_class->get_root = clutter_accessibility_get_root;
atk_class->get_toolkit_name = clutter_accessibility_get_toolkit_name;
atk_class->get_toolkit_version = clutter_accessibility_get_toolkit_version;
/* FIXME: Instead of create this on the class, I think that would
worth to implement ClutterAccessibility as a singleton instance, so the
class methods will access this instance. This will be a good
future enhancement, meanwhile, just using the same *working*
implementation used on GailUtil */
}
void void
_cally_util_override_atk_util (void) _clutter_accessibility_override_atk_util (void)
{ {
AtkUtilClass *atk_class = ATK_UTIL_CLASS (g_type_class_ref (ATK_TYPE_UTIL)); AtkUtilClass *atk_class = ATK_UTIL_CLASS (g_type_class_ref (ATK_TYPE_UTIL));
atk_class->add_key_event_listener = cally_util_add_key_event_listener; atk_class->add_key_event_listener = clutter_accessibility_add_key_event_listener;
atk_class->remove_key_event_listener = cally_util_remove_key_event_listener; atk_class->remove_key_event_listener = clutter_accessibility_remove_key_event_listener;
atk_class->get_root = cally_util_get_root; atk_class->get_root = clutter_accessibility_get_root;
atk_class->get_toolkit_name = cally_util_get_toolkit_name; atk_class->get_toolkit_name = clutter_accessibility_get_toolkit_name;
atk_class->get_toolkit_version = cally_util_get_toolkit_version; atk_class->get_toolkit_version = clutter_accessibility_get_toolkit_version;
} }

View File

@ -22,7 +22,7 @@
#include <hb-glib.h> #include <hb-glib.h>
#include "clutter/cally-util.h" #include "clutter/clutter-accessibility-private.h"
#include "clutter/clutter-backend-private.h" #include "clutter/clutter-backend-private.h"
#include "clutter/clutter-color-manager.h" #include "clutter/clutter-color-manager.h"
#include "clutter/clutter-debug.h" #include "clutter/clutter-debug.h"
@ -199,7 +199,7 @@ clutter_context_init_real (ClutterContext *context,
/* Initialize a11y */ /* Initialize a11y */
if (!(flags & CLUTTER_CONTEXT_FLAG_NO_A11Y)) if (!(flags & CLUTTER_CONTEXT_FLAG_NO_A11Y))
{ {
_cally_util_override_atk_util (); _clutter_accessibility_override_atk_util ();
CLUTTER_NOTE (MISC, "Clutter Accessibility initialized"); CLUTTER_NOTE (MISC, "Clutter Accessibility initialized");
} }

View File

@ -25,7 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include "clutter/cally-util.h" #include "clutter/clutter-accessibility-private.h"
#include "clutter/clutter-actor-private.h" #include "clutter/clutter-actor-private.h"
#include "clutter/clutter-backend-private.h" #include "clutter/clutter-backend-private.h"
#include "clutter/clutter-context-private.h" #include "clutter/clutter-context-private.h"
@ -426,7 +426,7 @@ emit_event (ClutterStage *stage,
if (event_type == CLUTTER_KEY_PRESS || if (event_type == CLUTTER_KEY_PRESS ||
event_type == CLUTTER_KEY_RELEASE) event_type == CLUTTER_KEY_RELEASE)
cally_snoop_key_event (stage, (ClutterKeyEvent *) event); clutter_accessibility_snoop_key_event (stage, (ClutterKeyEvent *) event);
clutter_stage_emit_event (stage, event); clutter_stage_emit_event (stage, event);
} }

View File

@ -86,6 +86,7 @@ clutter_headers = [
] ]
clutter_sources = [ clutter_sources = [
'clutter-accessibility.c',
'clutter-action.c', 'clutter-action.c',
'clutter-actor-box.c', 'clutter-actor-box.c',
'clutter-actor-accessible.c', 'clutter-actor-accessible.c',
@ -176,6 +177,7 @@ clutter_sources = [
] ]
clutter_private_headers = [ clutter_private_headers = [
'clutter-accessibility-private.h',
'clutter-actor-meta-private.h', 'clutter-actor-meta-private.h',
'clutter-actor-private.h', 'clutter-actor-private.h',
'clutter-backend-private.h', 'clutter-backend-private.h',
@ -220,7 +222,6 @@ clutter_headers += [
'cally-root.h', 'cally-root.h',
'cally-stage.h', 'cally-stage.h',
'cally-text.h', 'cally-text.h',
'cally-util.h',
] ]
clutter_sources += [ clutter_sources += [
@ -228,7 +229,6 @@ clutter_sources += [
'cally-root.c', 'cally-root.c',
'cally-stage.c', 'cally-stage.c',
'cally-text.c', 'cally-text.c',
'cally-util.c',
] ]
clutter_built_sources = [] clutter_built_sources = []