0c6eee43cb7c4985a7a38f8facb5f56a1e777883
[platform/upstream/at-spi2-core.git] / registryd / deviceeventcontroller.h
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifndef SPI_DEVICE_EVENT_CONTROLLER_H_
25 #define SPI_DEVICE_EVENT_CONTROLLER_H_
26
27 #ifdef HAVE_X11
28 #include <X11/Xlib.h>
29 #endif
30 #include <dbus/dbus.h>
31
32 typedef struct _SpiDEController SpiDEController;
33
34 #include "registry.h"
35 #include "de-types.h"
36
37 G_BEGIN_DECLS
38
39 #define SPI_DEVICE_EVENT_CONTROLLER_TYPE        (spi_device_event_controller_get_type ())
40 #define SPI_DEVICE_EVENT_CONTROLLER(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), SPI_DEVICE_EVENT_CONTROLLER_TYPE, SpiDEController))
41 #define SPI_DEVICE_EVENT_CONTROLLER_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), SPI_DEVICE_EVENT_CONTROLLER_TYPE, SpiDEControllerClass))
42 #define SPI_IS_DEVICE_EVENT_CONTROLLER(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), SPI_DEVICE_EVENT_CONTROLLER_TYPE))
43 #define SPI_IS_DEVICE_EVENT_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SPI_DEVICE_EVENT_CONTROLLER_TYPE))
44 #define SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SPI_DEVICE_EVENT_CONTROLLER_TYPE, SpiDEControllerClass))
45
46 struct _SpiDEController {
47         GObject parent;
48         DBusConnection *bus;
49         SpiRegistry    *registry;
50         GList          *key_listeners;
51         GList          *mouse_listeners;
52         GList          *keygrabs_list;
53         GQueue *message_queue;
54         guint message_queue_idle;
55   gpointer priv;
56 };
57
58 typedef enum {
59   SPI_DEVICE_TYPE_KBD,
60   SPI_DEVICE_TYPE_MOUSE,
61   SPI_DEVICE_TYPE_LAST_DEFINED
62 } SpiDeviceTypeCategory;
63
64 typedef struct {
65   char *bus_name;
66   char *path;
67   SpiDeviceTypeCategory type;
68   gulong types;
69 } DEControllerListener;
70
71 typedef struct {
72   DEControllerListener listener;
73
74  GSList *keys;
75   Accessibility_ControllerEventMask mask;
76   Accessibility_EventListenerMode  *mode;       
77 } DEControllerKeyListener;
78
79 typedef struct
80 {
81   gint (*get_keycode) (SpiDEController *controller,
82                        gint keysym,
83                        gchar *key_str,
84                        gboolean fix,
85                        guint *modmask);
86
87   guint (*mouse_check) (SpiDEController *controller, 
88                         gint *x,
89                         gint *y,
90                         gboolean *moved);
91
92   gboolean (*register_global_keygrabs) (SpiDEController         *controller,
93                                         DEControllerKeyListener *key_listener);
94
95   void (*deregister_global_keygrabs) (SpiDEController         *controller,
96                                       DEControllerKeyListener *key_listener);
97
98   gboolean (*synth_keycode_press) (SpiDEController *controller,
99                                    guint keycode);
100
101   gboolean (*synth_keycode_release) (SpiDEController *controller,
102                                    guint keycode);
103
104   gboolean (*lock_modifiers) (SpiDEController *controller,
105                               unsigned modifiers);
106
107   gboolean (*unlock_modifiers) (SpiDEController *controller,
108                                 unsigned modifiers);
109
110   gboolean (*synth_keystring) (SpiDEController *controller,
111                                guint synth_type,
112                                gint keycode,
113                                const char *keystring);
114
115   gboolean (*grab_key) (SpiDEController *controller,
116                         guint key_val,
117                         Accessibility_ControllerEventMask mod_mask);
118
119   void (*ungrab_key) (SpiDEController *controller,
120                       guint key_val,
121                       Accessibility_ControllerEventMask mod_mask);
122
123   void (*emit_modifier_event) (SpiDEController *controller,
124                                guint prev_mask,
125                                guint current_mask);
126
127   void (*generate_mouse_event) (SpiDEController *controller,
128                                 gint x,
129                                 gint y,
130                                 const char *eventName);
131
132   void (*init) (SpiDEController *controller);
133   void (*finalize) (SpiDEController *controller);
134 } SpiDEControllerPlat;
135
136 typedef struct {
137   GObjectClass parent_class;
138   SpiDEControllerPlat plat;
139 } SpiDEControllerClass;
140
141 GType            spi_device_event_controller_get_type (void);
142 SpiDEController *spi_device_event_controller_new      (SpiRegistry    *registry,
143                                                        DBusConnection *bus);
144
145 gboolean spi_clear_error_state (void);
146
147 void spi_device_event_controller_start_poll_mouse (SpiRegistry *registry);
148 void spi_device_event_controller_stop_poll_mouse (void);
149
150 void spi_remove_device_listeners (SpiDEController *controller, const char *bus_name);
151
152 SpiDEController *spi_registry_dec_new (SpiRegistry *reg, DBusConnection *bus);
153
154 gboolean
155 spi_controller_notify_mouselisteners (SpiDEController                 *controller,
156                                       const Accessibility_DeviceEvent *event);
157
158 gboolean
159 spi_controller_notify_keylisteners (SpiDEController                 *controller,
160                                     Accessibility_DeviceEvent       *key_event,
161                                     dbus_bool_t                    is_system_global);
162
163 gboolean spi_controller_update_key_grabs               (SpiDEController           *controller,
164                                                                Accessibility_DeviceEvent *recv);
165
166 gboolean spi_dec_synth_keysym (SpiDEController *controller, long keysym);
167
168 void spi_dec_dbus_emit(SpiDEController *controller, const char *interface, const char *name, const char *minor, int a1, int a2);
169
170 #ifdef HAVE_X11
171 void spi_dec_setup_x11 (SpiDEControllerClass *klass);
172 #endif
173
174 long ucs2keysym (long ucs);
175 long keysym2ucs(long keysym);
176
177 G_END_DECLS
178
179 #endif /* DEVICEEVENTCONTROLLER_H_ */