File: cally-examples-util.c

package info (click to toggle)
clutter-1.0 1.26.2%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 33,916 kB
  • sloc: ansic: 128,518; sh: 5,542; makefile: 1,595; xml: 1,248; ruby: 149; perl: 142; sed: 16
file content (146 lines) | stat: -rw-r--r-- 4,081 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* CALLY - The Clutter Accessibility Implementation Library
 *
 * Copyright (C) 2009 Igalia, S.L.
 *
 * Author: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#include <gmodule.h>
#include <stdlib.h>

#include <clutter/clutter.h>

#include "cally-examples-util.h"

/* Checking the at-spi sources, the module directory is
 *   $(libdir)/gtk-2.0/modules
 *
 * It is supposed cally would be installed on the same libdir.
 *
 * You could use the option atk-bridge-dir to use other directory.
 */
#define ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY PREFIXDIR"/gtk-2.0/modules"

static gchar *
_search_for_bridge_module (const gchar *module_name)
{
  /* We simplify the search for the atk bridge, see see the definition
   * of the macro for more information*/
  return g_strdup (ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY);
}

static gchar*
_a11y_check_custom_bridge (int    *argc,
                           char ***argv)
{
  GError *error = NULL;
  GOptionContext *context;
  static gchar *bridge_dir = NULL;
  static GOptionEntry entries [] =
    {
      {"atk-bridge-dir", 'd', 0, G_OPTION_ARG_STRING, &bridge_dir, "atk-bridge module directory", NULL}
    };

  context = g_option_context_new ("- cally examples");
  g_option_context_add_main_entries (context, entries, NULL);
  if (!g_option_context_parse (context, argc, argv, &error))
    {
      g_print ("%s\n", error->message);
      g_print ("Use --help for more information.\n");
      exit (0);
    }

  return bridge_dir;
}


static gboolean
_a11y_invoke_module (const gchar  *module_path,
                     gboolean      init)
{
  GModule    *handle;
  void      (*invoke_fn) (void);
  const char *method;

  if (init)
    method = "gnome_accessibility_module_init";
  else
    method = "gnome_accessibility_module_shutdown";

  if (!module_path)
    return FALSE;

  if (!(handle = g_module_open (module_path, G_MODULE_BIND_LAZY)))
    {
      g_warning ("Accessibility: failed to load module '%s': '%s'",
                 module_path, g_module_error ());

      return FALSE;
    }

  if (!g_module_symbol (handle, method, (gpointer *)&invoke_fn))
    {
      g_warning ("Accessibility: error library '%s' does not include "
                 "method '%s' required for accessibility support",
                 module_path, method);
      g_module_close (handle);

      return FALSE;
    }

  g_debug ("Module %s loaded successfully", module_path);
  invoke_fn ();

  return TRUE;
}

/**
 * This method will initialize the accessibility support provided by cally.
 *
 * Basically it will load the cally module using gmodule functions.
 *
 * Returns if it was able to init the a11y support or not.
 */
gboolean
cally_util_a11y_init (int *argc, char ***argv)
{
  gchar *bridge_dir = NULL;
  gchar *bridge_path = NULL;
  gboolean result = FALSE;

  if (clutter_get_accessibility_enabled () == FALSE)
    {
      g_warning ("Accessibility: clutter has no accessibility enabled"
                 " skipping the atk-bridge load");
      return FALSE;
    }

  bridge_dir = _a11y_check_custom_bridge (argc, argv);
  if (bridge_dir == NULL)
    bridge_dir = _search_for_bridge_module ("atk-bridge");

  bridge_path = g_module_build_path (bridge_dir, "libatk-bridge");

  result = _a11y_invoke_module (bridge_path, TRUE);

  g_free (bridge_dir);
  g_free (bridge_path);

  return result;
}