Back to index

unity  6.0.0
Classes | Functions | Variables
unity-util-accessible.cpp File Reference
#include <gdk/gdk.h>
#include <stdlib.h>
#include <string.h>
#include "unity-util-accessible.h"
#include "unity-root-accessible.h"
#include "nux-base-window-accessible.h"

Go to the source code of this file.

Classes

struct  UnityUtilListenerInfo
struct  UnityKeyEventListener

Functions

static void unity_util_accessible_class_init (UnityUtilAccessibleClass *klass)
static void unity_util_accessible_init (UnityUtilAccessible *unity_util_accessible)
static guint unity_util_accessible_add_global_event_listener (GSignalEmissionHook listener, const gchar *event_type)
static void unity_util_accessible_remove_global_event_listener (guint remove_listener)
static AtkObject * unity_util_accessible_get_root (void)
static const gchar * unity_util_accessible_get_toolkit_name (void)
static const gchar * unity_util_accessible_get_toolkit_version (void)
static guint unity_util_accessible_add_key_event_listener (AtkKeySnoopFunc listener, gpointer data)
static void unity_util_accessible_remove_key_event_listener (guint remove_listener)
 G_DEFINE_TYPE (UnityUtilAccessible, unity_util_accessible, ATK_TYPE_UTIL)
static guint add_listener (GSignalEmissionHook listener, const gchar *object_type, const gchar *signal_name, const gchar *hook_data)
static void do_window_event_initialization (void)
static guint translate_nux_modifiers_to_gdk_state (unsigned long nux_modifier)
static AtkKeyEventStruct * atk_key_event_from_nux_event_key (nux::Event *event)
static int unity_util_event_inspector (nux::Area *area, nux::Event *event, void *data)
void unity_util_accessible_set_window_thread (nux::WindowThread *wt)

Variables

static GHashTable * listener_list = NULL
static AtkObject * root = NULL
static GSList * key_listener_list = NULL
static guint event_inspector_id = 0
static nux::WindowThread * unity_window_thread = NULL

Class Documentation

struct UnityUtilListenerInfo

Definition at line 44 of file unity-util-accessible.cpp.

Class Members
gulong hook_id
guint idx
guint signal_id
struct UnityKeyEventListener

Definition at line 51 of file unity-util-accessible.cpp.

Class Members
gpointer data
AtkKeySnoopFunc func
guint key

Function Documentation

static guint add_listener ( GSignalEmissionHook  listener,
const gchar *  object_type,
const gchar *  signal_name,
const gchar *  hook_data 
) [static]

Definition at line 117 of file unity-util-accessible.cpp.

{
  GType type;
  guint signal_id;
  guint rc = 0;
  static guint listener_idx = 1;

  if (!listener_list)
    listener_list =  g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);

  type = g_type_from_name(object_type);
  if (type)
  {
    signal_id = g_signal_lookup(signal_name, type);
    if (signal_id > 0)
    {
      UnityUtilListenerInfo* listener_info;

      rc = listener_idx;
      listener_info = g_new0(UnityUtilListenerInfo, 1);
      listener_info->idx = listener_idx;
      listener_info->hook_id = g_signal_add_emission_hook(signal_id, 0, listener,
                                                          g_strdup(hook_data),
                                                          (GDestroyNotify) g_free);
      listener_info->signal_id = signal_id;

      g_hash_table_insert(listener_list, &(listener_info->idx), listener_info);

      listener_idx++;
    }
    else
    {
      /* Mainly becase some "window::xxx" methods not implemented
         on NuxBaseWindowAccessible */
      g_debug("Signal type %s not supported\n", signal_name);
    }
  }
  else
    g_warning("Invalid object type %s\n", object_type);

  return rc;
}

Here is the caller graph for this function:

static AtkKeyEventStruct* atk_key_event_from_nux_event_key ( nux::Event *  event) [static]

Definition at line 267 of file unity-util-accessible.cpp.

{
  AtkKeyEventStruct* atk_event = g_new0(AtkKeyEventStruct, 1);
  gunichar key_unichar;
  static GdkDisplay* display = gdk_display_get_default();
  static GdkKeymap* keymap = gdk_keymap_get_for_display(display);
  GdkKeymapKey* keys = NULL;
  gint n_keys = 0;
  gboolean success = FALSE;

  switch (event->type)
  {
    case nux::NUX_KEYDOWN:
      atk_event->type = ATK_KEY_EVENT_PRESS;
      break;
    case nux::NUX_KEYUP:
      atk_event->type = ATK_KEY_EVENT_RELEASE;
      break;
    default:
      /* we don't call atk_key_event_from_nux_event_key if the event
         is different to keydown or keyup */
      g_assert_not_reached();
      return NULL;
  }

  atk_event->state = translate_nux_modifiers_to_gdk_state(event->key_modifiers);

  atk_event->keyval = event->x11_keysym;
  atk_event->keycode = event->x11_keycode;

  /* GDK applies the modifiers to the keyval, and ATK expects that, so
   * we need to do this also here, as it is not done on the release  */

  success = gdk_keymap_get_entries_for_keyval(keymap, atk_event->keyval,
                                              &keys, &n_keys);
  success &= n_keys > 0;

  if (success)
  {
    gint group;
    guint new_keyval;
    gint effective_group;
    gint level;
    GdkModifierType consumed;

    group = keys [0].group;

    success = gdk_keymap_translate_keyboard_state(keymap,
                                                  atk_event->keycode,
                                                  (GdkModifierType) atk_event->state,
                                                  group,
                                                  &new_keyval,
                                                  &effective_group,
                                                  &level,
                                                  &consumed);
    if (success)
      atk_event->keyval = new_keyval;
  }

  atk_event->string = NULL;
  if (event->text && event->text[0])
  {
    key_unichar = g_utf8_get_char(event->text);

    if (g_unichar_validate(key_unichar) && g_unichar_isgraph(key_unichar))
    {
      GString* new_string = NULL;

      new_string = g_string_new("");
      new_string = g_string_insert_unichar(new_string, 0, key_unichar);
      atk_event->string = new_string->str;
      g_string_free(new_string, FALSE);
    }
  }

  /* If ->string is still NULL we compute it from the keyval*/
  if (atk_event->string == NULL)
    atk_event->string = g_strdup(gdk_keyval_name(atk_event->keyval));

  /* e_x11_timestamp is zero, see bug LB#735645*/
  atk_event->timestamp = g_get_real_time() / 1000;

#ifdef DEBUG_ANY_KEY_EVENT
  g_debug("[a11y] AtkKeyEvent:\n\t\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->state,
          (unsigned int) atk_event->keycode,
          (unsigned long int) atk_event->timestamp,
          atk_event->string);
#endif

  return atk_event;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_window_event_initialization ( void  ) [static]

Definition at line 164 of file unity-util-accessible.cpp.

{
  /*
   * Ensure that NuxBaseWindowClass exists
   */
  g_type_class_unref(g_type_class_ref(NUX_TYPE_BASE_WINDOW_ACCESSIBLE));
}

Here is the caller graph for this function:

G_DEFINE_TYPE ( UnityUtilAccessible  ,
unity_util_accessible  ,
ATK_TYPE_UTIL   
)
static guint translate_nux_modifiers_to_gdk_state ( unsigned long  nux_modifier) [static]

Definition at line 236 of file unity-util-accessible.cpp.

{
  guint result = 0;

  if (nux_modifier & nux::NUX_STATE_SHIFT)
    result |= GDK_SHIFT_MASK;

  if (nux_modifier & nux::NUX_STATE_CAPS_LOCK)
    result |= GDK_LOCK_MASK;

  if (nux_modifier & nux::NUX_STATE_CTRL)
    result |= GDK_CONTROL_MASK;

  /* From gdk documentation

     GDK_MOD1_MASK : the fourth modifier key (it depends on the
     modifier mapping of the X server which key is interpreted as this
     modifier, but normally it is the Alt key).
   */

  if (nux_modifier & nux::NUX_STATE_ALT)
    result |= GDK_MOD1_MASK;

  /* FIXME: not sure how to translate this ones */
  // if (nux_modifier & NUX_STATE_SCROLLLOCK)
  // if (nux_modifier & NUX_STATE_NUMLOCK)

  return result;
}

Here is the caller graph for this function:

static guint unity_util_accessible_add_global_event_listener ( GSignalEmissionHook  listener,
const gchar *  event_type 
) [static]

Definition at line 173 of file unity-util-accessible.cpp.

{
  gchar** split_string;
  guint rc = 0;

  split_string = g_strsplit(event_type, ":", 3);
  if (split_string)
  {
    if (g_str_equal("window", split_string[0]))
    {
      /* Using NuxBaseWindow as the toplevelwindow */
      static gboolean initialized = FALSE;

      if (initialized == FALSE)
      {
        do_window_event_initialization();
        initialized = TRUE;
      }

      rc = add_listener(listener, "NuxBaseWindowAccessible", split_string [1], event_type);
    }
    else
    {
      rc = add_listener(listener, split_string[1], split_string[2], event_type);
    }

    g_strfreev(split_string);
  }

  return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static guint unity_util_accessible_add_key_event_listener ( AtkKeySnoopFunc  listener,
gpointer  data 
) [static]

Definition at line 389 of file unity-util-accessible.cpp.

{
  static guint key = 0;
  UnityKeyEventListener* listener;

  if (event_inspector_id == 0)
  {
    if (unity_window_thread == NULL)
      return 0;

    event_inspector_id = unity_window_thread->InstallEventInspector(unity_util_event_inspector, NULL);
  }

  key++;

  listener = g_slice_new0(UnityKeyEventListener);
  listener->func = listener_func;
  listener->data = data;
  listener->key = key;

  key_listener_list = g_slist_append(key_listener_list, listener);

  return key;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void unity_util_accessible_class_init ( UnityUtilAccessibleClass *  klass) [static]

Definition at line 68 of file unity-util-accessible.cpp.

{
  AtkUtilClass* atk_class;
  gpointer data;

  data = g_type_class_peek(ATK_TYPE_UTIL);
  atk_class = ATK_UTIL_CLASS(data);

  atk_class->add_global_event_listener    = unity_util_accessible_add_global_event_listener;
  atk_class->remove_global_event_listener = unity_util_accessible_remove_global_event_listener;
  atk_class->add_key_event_listener       = unity_util_accessible_add_key_event_listener;
  atk_class->remove_key_event_listener    = unity_util_accessible_remove_key_event_listener;
  atk_class->get_root                     = unity_util_accessible_get_root;
  atk_class->get_toolkit_name             = unity_util_accessible_get_toolkit_name;
  atk_class->get_toolkit_version          = unity_util_accessible_get_toolkit_version;
}

Here is the call graph for this function:

static AtkObject * unity_util_accessible_get_root ( void  ) [static]

Definition at line 91 of file unity-util-accessible.cpp.

{
  if (!root)
    root = unity_root_accessible_new();

  return root;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const gchar * unity_util_accessible_get_toolkit_name ( void  ) [static]

Definition at line 100 of file unity-util-accessible.cpp.

{
  return "UNITY";
}

Here is the caller graph for this function:

static const gchar * unity_util_accessible_get_toolkit_version ( void  ) [static]

Definition at line 106 of file unity-util-accessible.cpp.

{
  /*
   * FIXME:
   * Version is passed in as a -D flag when this file is
   * compiled.
   */
  return "0.1";
}

Here is the caller graph for this function:

static void unity_util_accessible_init ( UnityUtilAccessible *  unity_util_accessible) [static]

Definition at line 86 of file unity-util-accessible.cpp.

{
}
static void unity_util_accessible_remove_global_event_listener ( guint  remove_listener) [static]

Definition at line 207 of file unity-util-accessible.cpp.

{
  if (remove_listener > 0)
  {
    UnityUtilListenerInfo* listener_info;

    listener_info = (UnityUtilListenerInfo*) g_hash_table_lookup(listener_list, &remove_listener);
    if (listener_info != NULL)
    {
      if (listener_info->hook_id != 0 && listener_info->signal_id != 0)
      {
        g_signal_remove_emission_hook(listener_info->signal_id,
                                      listener_info->hook_id);
        g_hash_table_remove(listener_list, &remove_listener);
      }
      else
      {
        g_warning("Invalid listener hook_id %ld or signal_id %d",
                  listener_info->hook_id, listener_info->signal_id);
      }
    }
    else
      g_warning("No listener with the specified ID: %d", remove_listener);
  }
  else
    g_warning("Invalid listener_id: %d", remove_listener);
}

Here is the caller graph for this function:

static void unity_util_accessible_remove_key_event_listener ( guint  remove_listener) [static]

Definition at line 416 of file unity-util-accessible.cpp.

{
  GSList* l;

  for (l = key_listener_list; l; l = l->next)
  {
    UnityKeyEventListener* listener = (UnityKeyEventListener*) l->data;

    if (listener->key == remove_listener)
    {
      g_slice_free(UnityKeyEventListener, listener);
      key_listener_list = g_slist_delete_link(key_listener_list, l);

      break;
    }
  }

  if (key_listener_list == NULL)
  {
    if (unity_window_thread == NULL)
      return;

    unity_window_thread->RemoveEventInspector(event_inspector_id);
    event_inspector_id = 0;
  }
}

Here is the caller graph for this function:

void unity_util_accessible_set_window_thread ( nux::WindowThread *  wt)

Definition at line 445 of file unity-util-accessible.cpp.

Here is the caller graph for this function:

static int unity_util_event_inspector ( nux::Area *  area,
nux::Event *  event,
void *  data 
) [static]

Definition at line 362 of file unity-util-accessible.cpp.

{
  GSList* list = NULL;
  AtkKeyEventStruct* atk_key_event = NULL;
  gint result = 0;

  if ((event->type != nux::NUX_KEYDOWN) && (event->type != nux::NUX_KEYUP))
    return 0;

  atk_key_event = atk_key_event_from_nux_event_key(event);

  for (list = key_listener_list; list; list = list->next)
  {
    UnityKeyEventListener* listener = (UnityKeyEventListener*) list->data;

    result |= listener->func(atk_key_event, listener->data);
  }

  g_free(atk_key_event->string);
  g_free(atk_key_event);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

guint event_inspector_id = 0 [static]

Definition at line 62 of file unity-util-accessible.cpp.

GSList* key_listener_list = NULL [static]

Definition at line 61 of file unity-util-accessible.cpp.

GHashTable* listener_list = NULL [static]

Definition at line 59 of file unity-util-accessible.cpp.

AtkObject* root = NULL [static]

Definition at line 60 of file unity-util-accessible.cpp.

nux::WindowThread* unity_window_thread = NULL [static]

Definition at line 63 of file unity-util-accessible.cpp.