Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_x / xcb / ecore_xcb_private.h
1 #ifndef __ECORE_XCB_PRIVATE_H__
2 # define __ECORE_XCB_PRIVATE_H__
3
4 //# define LOGFNS 1
5
6 # ifdef HAVE_CONFIG_H
7 #  include "config.h"
8 # endif
9
10 # include <unistd.h> // included for close & gethostname functions
11
12 /* generic xcb includes */
13 # include <xcb/xcb.h>
14 # include <xcb/bigreq.h>
15 # include <xcb/shm.h>
16 # include <xcb/xcb_image.h>
17
18 /* EFL includes */
19 # include "Ecore.h"
20 # include "Ecore_Input.h"
21 # include "Ecore_X.h"
22
23 /* logging */
24 extern int _ecore_xcb_log_dom;
25
26 # ifdef ECORE_XCB_DEFAULT_LOG_COLOR
27 #  undef ECORE_XCB_DEFAULT_LOG_COLOR
28 # endif
29 # define ECORE_XCB_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
30
31 # ifdef ERR
32 #  undef ERR
33 # endif
34 # define ERR(...) EINA_LOG_DOM_ERR(_ecore_xcb_log_dom, __VA_ARGS__)
35
36 # ifdef DBG
37 #  undef DBG
38 # endif
39 # define DBG(...) EINA_LOG_DOM_DBG(_ecore_xcb_log_dom, __VA_ARGS__)
40
41 # ifdef INF
42 #  undef INF
43 # endif
44 # define INF(...) EINA_LOG_DOM_INFO(_ecore_xcb_log_dom, __VA_ARGS__)
45
46 # ifdef WRN
47 #  undef WRN
48 # endif
49 # define WRN(...) EINA_LOG_DOM_WARN(_ecore_xcb_log_dom, __VA_ARGS__)
50
51 # ifdef CRIT
52 #  undef CRIT
53 # endif
54 # define CRIT(...)          EINA_LOG_DOM_CRIT(_ecore_xcb_log_dom, __VA_ARGS__)
55
56 # ifdef LOGFNS
57 #  include <stdio.h>
58 #  define LOGFN(fl, ln, fn) printf("-ECORE-XCB: %25s: %5i - %s\n", fl, ln, fn);
59 # else
60 #  define LOGFN(fl, ln, fn)
61 # endif
62
63 # ifndef MAXHOSTNAMELEN
64 #  define MAXHOSTNAMELEN 256
65 # endif
66
67 # ifndef MIN
68 #  define MIN(x, y) (((x) > (y)) ? (y) : (x))
69 # endif
70
71 # ifndef MAX
72 #  define MAX(a, b) ((a < b) ? b : a)
73 # endif
74
75 #define CHECK_XCB_CONN                              \
76   {                                                 \
77      if (xcb_connection_has_error(_ecore_xcb_conn)) \
78        {                                            \
79           DBG("XCB Connection Has Error !!");       \
80           _ecore_xcb_io_error_handle(NULL);         \
81        }                                            \
82   }
83
84 /* enums */
85 typedef enum _Ecore_Xcb_Encoding_Style Ecore_Xcb_Encoding_Style;
86
87 enum _Ecore_Xcb_Encoding_Style
88 {
89    XcbStringStyle,
90    XcbCompoundTextStyle,
91    XcbTextStyle,
92    XcbStdICCTextStyle,
93    XcbUTF8StringStyle
94 };
95
96 /* structures */
97 typedef struct _Ecore_X_DND_Source          Ecore_X_DND_Source;
98 typedef struct _Ecore_X_DND_Target          Ecore_X_DND_Target;
99 typedef struct _Ecore_X_Selection_Intern    Ecore_X_Selection_Intern;
100 typedef struct _Ecore_X_Selection_Converter Ecore_X_Selection_Converter;
101 typedef struct _Ecore_X_Selection_Parser    Ecore_X_Selection_Parser;
102 typedef struct _Ecore_Xcb_Textproperty      Ecore_Xcb_Textproperty;
103
104 struct _Ecore_X_DND_Source
105 {
106    int            version;
107    Ecore_X_Window win, dest;
108
109    enum
110    {
111       ECORE_X_DND_SOURCE_IDLE,
112       ECORE_X_DND_SOURCE_DRAGGING,
113       ECORE_X_DND_SOURCE_DROPPED,
114       ECORE_X_DND_SOURCE_CONVERTING
115    } state;
116
117    struct
118    {
119       short          x, y;
120       unsigned short width, height;
121    } rectangle;
122
123    struct
124    {
125       Ecore_X_Window window;
126       int            x, y;
127    } prev;
128
129    Ecore_X_Time time;
130
131    Ecore_X_Atom action, accepted_action;
132
133    int          will_accept, suppress;
134    int          await_status;
135 };
136
137 struct _Ecore_X_DND_Target
138 {
139    int            version;
140    Ecore_X_Window win, source;
141
142    enum
143    {
144       ECORE_X_DND_TARGET_IDLE,
145       ECORE_X_DND_TARGET_ENTERED
146    } state;
147
148    struct
149    {
150       int x, y;
151    } pos;
152
153    Ecore_X_Time time;
154
155    Ecore_X_Atom action, accepted_action;
156    int          will_accept;
157 };
158
159 struct _Ecore_X_Selection_Intern
160 {
161    Ecore_X_Window win;
162    Ecore_X_Atom   selection;
163    unsigned char *data;
164    int            length;
165    Ecore_X_Time   time;
166 };
167
168 struct _Ecore_X_Selection_Converter
169 {
170    Ecore_X_Atom                 target;
171    Eina_Bool                    (*convert)(char *target,
172                                            void *data,
173                                            int size,
174                                            void **data_ret,
175                                            int *size_ret,
176                                            Ecore_X_Atom *type,
177                                            int *size_type);
178    Ecore_X_Selection_Converter *next;
179 };
180
181 struct _Ecore_X_Selection_Parser
182 {
183    char                     *target;
184    void                     *(*parse)(const char *target, void *data, int size, int format);
185    Ecore_X_Selection_Parser *next;
186 };
187
188 struct _Ecore_Xcb_Textproperty
189 {
190    char        *value;
191    Ecore_X_Atom encoding;
192    unsigned int format, nitems;
193 };
194
195 /* external variables */
196 extern Ecore_X_Connection *_ecore_xcb_conn;
197 extern Ecore_X_Screen *_ecore_xcb_screen;
198 extern double _ecore_xcb_double_click_time;
199 extern int16_t _ecore_xcb_event_last_root_x;
200 extern int16_t _ecore_xcb_event_last_root_y;
201
202 /* external variables for extension events */
203 extern int _ecore_xcb_event_damage;
204 extern int _ecore_xcb_event_randr;
205 extern int _ecore_xcb_event_screensaver;
206 extern int _ecore_xcb_event_shape;
207 extern int _ecore_xcb_event_sync;
208 extern int _ecore_xcb_event_xfixes;
209 extern int _ecore_xcb_event_input;
210 extern int _ecore_xcb_event_gesture;
211
212 extern Ecore_X_Atom _ecore_xcb_atoms_wm_protocol[ECORE_X_WM_PROTOCOL_NUM];
213
214 extern int _ecore_xcb_button_grabs_num;
215 extern int _ecore_xcb_key_grabs_num;
216 extern Ecore_X_Window *_ecore_xcb_button_grabs;
217 extern Ecore_X_Window *_ecore_xcb_key_grabs;
218 extern Eina_Bool (*_ecore_xcb_window_grab_replay_func)(void *data,
219                                                        int type,
220                                                        void *event);
221 extern void *_ecore_xcb_window_grab_replay_data;
222
223 /* private function prototypes */
224 void _ecore_xcb_error_handler_init(void);
225 void _ecore_xcb_error_handler_shutdown(void);
226
227 void _ecore_xcb_atoms_init(void);
228 void _ecore_xcb_atoms_finalize(void);
229
230 void _ecore_xcb_extensions_init(void);
231 void _ecore_xcb_extensions_finalize(void);
232
233 void _ecore_xcb_shape_init(void);
234 void _ecore_xcb_shape_finalize(void);
235
236 void _ecore_xcb_screensaver_init(void);
237 void _ecore_xcb_screensaver_finalize(void);
238
239 void _ecore_xcb_sync_init(void);
240 void _ecore_xcb_sync_finalize(void);
241 void _ecore_xcb_sync_magic_send(int val,
242                                 Ecore_X_Window win);
243
244 void                _ecore_xcb_render_init(void);
245 void                _ecore_xcb_render_finalize(void);
246 Eina_Bool           _ecore_xcb_render_argb_get(void);
247 Eina_Bool           _ecore_xcb_render_anim_get(void);
248 Eina_Bool           _ecore_xcb_render_avail_get(void);
249
250 Eina_Bool           _ecore_xcb_render_visual_supports_alpha(Ecore_X_Visual visual);
251 uint32_t            _ecore_xcb_render_find_visual_id(int type,
252                                                      Eina_Bool check_alpha);
253 Ecore_X_Visual     *_ecore_xcb_render_visual_get(int visual_id);
254
255 void                _ecore_xcb_randr_init(void);
256 void                _ecore_xcb_randr_finalize(void);
257
258 void _ecore_xcb_gesture_init(void);
259 void _ecore_xcb_gesture_finalize(void);
260 void _ecore_xcb_gesture_shutdown(void);
261
262 void                _ecore_xcb_xfixes_init(void);
263 void                _ecore_xcb_xfixes_finalize(void);
264 Eina_Bool           _ecore_xcb_xfixes_avail_get(void);
265
266 void                _ecore_xcb_damage_init(void);
267 void                _ecore_xcb_damage_finalize(void);
268
269 void                _ecore_xcb_composite_init(void);
270 void                _ecore_xcb_composite_finalize(void);
271
272 void                _ecore_xcb_dpms_init(void);
273 void                _ecore_xcb_dpms_finalize(void);
274
275 void                _ecore_xcb_cursor_init(void);
276 void                _ecore_xcb_cursor_finalize(void);
277
278 void                _ecore_xcb_xinerama_init(void);
279 void                _ecore_xcb_xinerama_finalize(void);
280
281 void                _ecore_xcb_dnd_init(void);
282 void                _ecore_xcb_dnd_shutdown(void);
283 Ecore_X_DND_Source *_ecore_xcb_dnd_source_get(void);
284 Ecore_X_DND_Target *_ecore_xcb_dnd_target_get(void);
285 void                _ecore_xcb_dnd_drag(Ecore_X_Window root,
286                                         int x,
287                                         int y);
288
289 void  _ecore_xcb_selection_init(void);
290 void  _ecore_xcb_selection_shutdown(void);
291 void *_ecore_xcb_selection_parse(const char *target,
292                                  void *data,
293                                  int size,
294                                  int format);
295 char                     *_ecore_xcb_selection_target_get(Ecore_X_Atom target);
296 Ecore_X_Selection_Intern *_ecore_xcb_selection_get(Ecore_X_Atom selection);
297
298 # ifdef HAVE_ICONV
299 Eina_Bool _ecore_xcb_utf8_textlist_to_textproperty(char **list,
300                                                    int count,
301                                                    Ecore_Xcb_Encoding_Style style,
302                                                    Ecore_Xcb_Textproperty *ret);
303 # endif
304 Eina_Bool _ecore_xcb_mb_textlist_to_textproperty(char **list,
305                                                  int count,
306                                                  Ecore_Xcb_Encoding_Style style,
307                                                  Ecore_Xcb_Textproperty *ret);
308 Eina_Bool _ecore_xcb_textlist_to_textproperty(const char *type,
309                                               char **list,
310                                               int count,
311                                               Ecore_Xcb_Encoding_Style style,
312                                               Ecore_Xcb_Textproperty *ret);
313
314 # ifdef HAVE_ICONV
315 Eina_Bool _ecore_xcb_utf8_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop,
316                                                    char ***list_ret,
317                                                    int *count_ret);
318 # endif
319 Eina_Bool _ecore_xcb_mb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop,
320                                                  char ***list_ret,
321                                                  int *count_ret);
322 Eina_Bool _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop,
323                                               const char *type,
324                                               char ***list_ret,
325                                               int *count_ret);
326
327 void         _ecore_xcb_events_init(void);
328 void         _ecore_xcb_events_shutdown(void);
329 void         _ecore_xcb_events_handle(xcb_generic_event_t *ev);
330 Ecore_X_Time _ecore_xcb_events_last_time_get(void);
331 unsigned int _ecore_xcb_events_modifiers_get(unsigned int state);
332 void         _ecore_xcb_event_mouse_move(uint16_t timestamp,
333                                          uint16_t modifiers,
334                                          int16_t x,
335                                          int16_t y,
336                                          int16_t root_x,
337                                          int16_t root_y,
338                                          xcb_window_t event_win,
339                                          xcb_window_t win,
340                                          xcb_window_t root_win,
341                                          uint8_t same_screen,
342                                          int dev,
343                                          double radx,
344                                          double rady,
345                                          double pressure,
346                                          double angle,
347                                          int16_t mx,
348                                          int16_t my,
349                                          int16_t mrx,
350                                          int16_t mry);
351 Ecore_Event_Mouse_Button *_ecore_xcb_event_mouse_button(int event,
352                                                         uint16_t timestamp,
353                                                         uint16_t modifiers,
354                                                         xcb_button_t buttons,
355                                                         int16_t x,
356                                                         int16_t y,
357                                                         int16_t root_x,
358                                                         int16_t root_y,
359                                                         xcb_window_t event_win,
360                                                         xcb_window_t win,
361                                                         xcb_window_t root_win,
362                                                         uint8_t same_screen,
363                                                         int dev,
364                                                         double radx,
365                                                         double rady,
366                                                         double pressure,
367                                                         double angle,
368                                                         int16_t mx,
369                                                         int16_t my,
370                                                         int16_t mrx,
371                                                         int16_t mry);
372
373 void           _ecore_xcb_keymap_init(void);
374 void           _ecore_xcb_keymap_finalize(void);
375 void           _ecore_xcb_keymap_shutdown(void);
376 void           _ecore_xcb_keymap_refresh(xcb_mapping_notify_event_t *event);
377 xcb_keysym_t   _ecore_xcb_keymap_keycode_to_keysym(xcb_keycode_t keycode,
378                                                    int col);
379 xcb_keycode_t *_ecore_xcb_keymap_keysym_to_keycode(xcb_keysym_t keysym);
380 char          *_ecore_xcb_keymap_keysym_to_string(xcb_keysym_t keysym);
381 xcb_keycode_t  _ecore_xcb_keymap_string_to_keycode(const char *key);
382 int            _ecore_xcb_keymap_lookup_string(xcb_keycode_t keycode,
383                                                int state,
384                                                char *buffer,
385                                                int bytes,
386                                                xcb_keysym_t *sym);
387
388 void _ecore_xcb_input_init(void);
389 void _ecore_xcb_input_finalize(void);
390 void _ecore_xcb_input_shutdown(void);
391 # ifdef ECORE_XCB_XINPUT
392 void _ecore_xcb_input_handle_event(xcb_generic_event_t *event);
393 # else
394 void _ecore_xcb_input_handle_event(xcb_generic_event_t *event __UNUSED__);
395 # endif
396
397 void           _ecore_xcb_dri_init(void);
398 void           _ecore_xcb_dri_finalize(void);
399
400 void           _ecore_xcb_xtest_init(void);
401 void           _ecore_xcb_xtest_finalize(void);
402
403 Ecore_X_Window _ecore_xcb_window_root_of_screen_get(int screen);
404 void           _ecore_xcb_window_prop_string_utf8_set(Ecore_X_Window win,
405                                                       Ecore_X_Atom atom,
406                                                       const char *str);
407 Ecore_X_Visual _ecore_xcb_window_visual_get(Ecore_X_Window win);
408 void           _ecore_xcb_window_button_grab_remove(Ecore_X_Window win);
409 void           _ecore_xcb_window_key_grab_remove(Ecore_X_Window win);
410 void           _ecore_xcb_window_grab_allow_events(Ecore_X_Window event_win,
411                                                    Ecore_X_Window child_win,
412                                                    int type,
413                                                    void *event,
414                                                    Ecore_X_Time timestamp);
415
416 int                  _ecore_xcb_netwm_startup_info_begin(Ecore_X_Window win __UNUSED__,
417                                                          uint8_t data __UNUSED__);
418 int                  _ecore_xcb_netwm_startup_info(Ecore_X_Window win __UNUSED__,
419                                                    uint8_t data __UNUSED__);
420 Ecore_X_Window_State _ecore_xcb_netwm_window_state_get(Ecore_X_Atom atom);
421
422 int                  _ecore_xcb_error_handle(xcb_generic_error_t *err);
423 int                  _ecore_xcb_io_error_handle(xcb_generic_error_t *err);
424
425 xcb_image_t         *_ecore_xcb_image_create_native(int w,
426                                                     int h,
427                                                     xcb_image_format_t format,
428                                                     uint8_t depth,
429                                                     void *base,
430                                                     uint32_t bytes,
431                                                     uint8_t *data);
432
433 void  _ecore_xcb_xdefaults_init(void);
434 void  _ecore_xcb_xdefaults_shutdown(void);
435 char *_ecore_xcb_xdefaults_string_get(const char *prog,
436                                       const char *param);
437 int   _ecore_xcb_xdefaults_int_get(const char *prog,
438                                    const char *param);
439
440 void _ecore_xcb_modifiers_get(void);
441
442 #endif