1 /*
2    (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
3    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
4 
5    All rights reserved.
6 
7    Written by Denis Oliver Kropp <dok@directfb.org>,
8               Andreas Hundt <andi@fischlustig.de>,
9               Sven Neumann <neo@directfb.org>,
10               Ville Syrjälä <syrjala@sci.fi> and
11               Claudio Ciccani <klan@users.sf.net>.
12 
13    This library is free software; you can redistribute it and/or
14    modify it under the terms of the GNU Lesser General Public
15    License as published by the Free Software Foundation; either
16    version 2 of the License, or (at your option) any later version.
17 
18    This library is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    Lesser General Public License for more details.
22 
23    You should have received a copy of the GNU Lesser General Public
24    License along with this library; if not, write to the
25    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26    Boston, MA 02111-1307, USA.
27 */
28 
29 #ifndef __INPUT_H__
30 #define __INPUT_H__
31 
32 #include <pthread.h>
33 #include <directfb.h>
34 
35 #include <direct/modules.h>
36 
37 #include <fusion/reactor.h>
38 
39 #include <core/coretypes.h>
40 
41 
42 
43 DECLARE_MODULE_DIRECTORY( dfb_input_modules );
44 
45 
46 /*
47  * Increase this number when changes result in binary incompatibility!
48  */
49 #define DFB_INPUT_DRIVER_ABI_VERSION         7
50 
51 #define DFB_INPUT_DRIVER_INFO_NAME_LENGTH   48
52 #define DFB_INPUT_DRIVER_INFO_VENDOR_LENGTH 64
53 
54 
55 typedef struct {
56      int          major;              /* major version */
57      int          minor;              /* minor version */
58 } InputDriverVersion;                 /* major.minor, e.g. 0.1 */
59 
60 typedef struct {
61      InputDriverVersion version;
62 
63      char               name[DFB_INPUT_DRIVER_INFO_NAME_LENGTH];
64                                       /* Name of driver,
65                                          e.g. 'Serial Mouse Driver' */
66 
67      char               vendor[DFB_INPUT_DRIVER_INFO_VENDOR_LENGTH];
68                                       /* Vendor (or author) of the driver,
69                                          e.g. 'directfb.org' or 'Sven Neumann' */
70 } InputDriverInfo;
71 
72 typedef struct {
73      unsigned int       prefered_id;  /* Prefered predefined input device id,
74                                          e.g. DIDID_MOUSE */
75 
76      DFBInputDeviceDescription desc;  /* Capabilities, type, etc. */
77 } InputDeviceInfo;
78 
79 /*
80  *  Input provider capability flags.
81  */
82 typedef enum {
83      IDC_NONE      = 0x00,            /* None */
84      IDC_HOTPLUG   = 0x01,            /* Input devices support hot-plug */
85 
86      IDC_ALL       = 0x01             /* All flags supported */
87 } InputDriverCapability;
88 
89 typedef struct {
90      CoreDFB          *core;
91      void             *driver;
92 } HotplugThreadData;
93 
94 typedef struct {
95      int       (*GetAvailable)   (void);
96      void      (*GetDriverInfo)  (InputDriverInfo              *driver_info);
97      DFBResult (*OpenDevice)     (CoreInputDevice              *device,
98                                   unsigned int                  number,
99                                   InputDeviceInfo              *device_info,
100                                   void                        **driver_data);
101      DFBResult (*GetKeymapEntry) (CoreInputDevice              *device,
102                                   void                         *driver_data,
103                                   DFBInputDeviceKeymapEntry    *entry);
104      void      (*CloseDevice)    (void                         *driver_data);
105      DFBResult (*Suspend)        (void);
106      DFBResult (*Resume)         (void);
107      DFBResult (*IsCreated)      (int                        index,
108                                   void                      *data);
109      InputDriverCapability
110                (*GetCapability)  (void);
111      DFBResult (*LaunchHotplug)  (CoreDFB                  *core,
112                                   void                     *input_driver);
113      DFBResult (*StopHotplug)    (void);
114 
115      DFBResult (*GetAxisInfo)    (CoreInputDevice              *device,
116                                   void                         *driver_data,
117                                   DFBInputDeviceAxisIdentifier  axis,
118                                   DFBInputDeviceAxisInfo       *ret_info);
119 } InputDriverFuncs;
120 
121 
122 typedef DFBEnumerationResult (*InputDeviceCallback) (CoreInputDevice *device,
123                                                      void            *ctx);
124 
125 void dfb_input_enumerate_devices( InputDeviceCallback         callback,
126                                   void                       *ctx,
127                                   DFBInputDeviceCapabilities  caps );
128 
129 
130 DirectResult dfb_input_attach       ( CoreInputDevice *device,
131                                       ReactionFunc     func,
132                                       void            *ctx,
133                                       Reaction        *reaction );
134 
135 DirectResult dfb_input_detach       ( CoreInputDevice *device,
136                                       Reaction        *reaction );
137 
138 DirectResult dfb_input_attach_global( CoreInputDevice *device,
139                                       int              index,
140                                       void            *ctx,
141                                       GlobalReaction  *reaction );
142 
143 DirectResult dfb_input_detach_global( CoreInputDevice *device,
144                                       GlobalReaction  *reaction );
145 
146 
147 DFBResult    dfb_input_add_global   ( ReactionFunc     func,
148                                       int             *ret_index );
149 
150 DFBResult    dfb_input_set_global   ( ReactionFunc     func,
151                                       int              index );
152 
153 
154 void         dfb_input_dispatch     ( CoreInputDevice *device,
155                                       DFBInputEvent   *event );
156 
157 
158 
159 void              dfb_input_device_description( const CoreInputDevice     *device,
160                                                 DFBInputDeviceDescription *desc );
161 
162 DFBInputDeviceID  dfb_input_device_id         ( const CoreInputDevice     *device );
163 
164 CoreInputDevice  *dfb_input_device_at         ( DFBInputDeviceID           id );
165 
166 
167 
168 DFBInputDeviceCapabilities dfb_input_device_caps( const CoreInputDevice *device );
169 
170 
171 
172 DFBResult         dfb_input_device_get_keymap_entry( CoreInputDevice           *device,
173                                                      int                        keycode,
174                                                      DFBInputDeviceKeymapEntry *entry );
175 
176 DFBResult         dfb_input_device_set_keymap_entry( CoreInputDevice                 *device,
177                                                      int                              keycode,
178                                                      const DFBInputDeviceKeymapEntry *entry );
179 
180 DFBResult         dfb_input_device_load_keymap   ( CoreInputDevice           *device,
181                                                    char                      *filename );
182 
183 DFBResult         dfb_input_device_reload_keymap   ( CoreInputDevice           *device );
184 
185 
186 typedef struct {
187      DFBInputDeviceModifierMask   modifiers_l;
188      DFBInputDeviceModifierMask   modifiers_r;
189      DFBInputDeviceLockState      locks;
190      DFBInputDeviceButtonMask     buttons;
191 } CoreInputDeviceState;
192 
193 DFBResult         dfb_input_device_get_state( CoreInputDevice      *device,
194                                               CoreInputDeviceState *ret_state );
195 
196 
197 
198 void              containers_attach_device( CoreInputDevice *device );
199 
200 void              containers_detach_device( CoreInputDevice *device );
201 
202 void              stack_containers_attach_device( CoreInputDevice *device );
203 
204 void              stack_containers_detach_device( CoreInputDevice *device );
205 
206 DFBResult         dfb_input_create_device( int      device_index,
207                                            CoreDFB *core_in,
208                                            void    *driver_in );
209 
210 DFBResult         dfb_input_remove_device( int   device_index,
211                                            void *driver_in );
212 
213 /* global reactions */
214 
215 typedef enum {
216      DFB_WINDOWSTACK_INPUTDEVICE_LISTENER
217 } DFB_INPUT_GLOBALS;
218 
219 
220 DirectResult CoreInputDevice_Call( CoreInputDevice     *device,
221                                    FusionCallExecFlags  flags,
222                                    int                  call_arg,
223                                    void                *ptr,
224                                    unsigned int         length,
225                                    void                *ret_ptr,
226                                    unsigned int         ret_size,
227                                    unsigned int        *ret_length );
228 
229 #endif
230