3 #endif /* ifdef HAVE_CONFIG_H */
13 #endif /* ifdef LOGRT */
16 #include "ecore_private.h"
17 #include "ecore_x_private.h"
19 #include "Ecore_X_Atoms.h"
20 #include "Ecore_Input.h"
22 static Eina_Bool _ecore_x_fd_handler(void *data,
23 Ecore_Fd_Handler *fd_handler);
24 static Eina_Bool _ecore_x_fd_handler_buf(void *data,
25 Ecore_Fd_Handler *fd_handler);
26 static int _ecore_x_key_mask_get(KeySym sym);
27 static int _ecore_x_event_modifier(unsigned int state);
29 static Ecore_Fd_Handler *_ecore_x_fd_handler_handle = NULL;
31 static const int AnyXEvent = 0; /* 0 can be used as there are no event types
32 * with index 0 and 1 as they are used for
36 static int _ecore_x_event_shape_id = 0;
37 static int _ecore_x_event_screensaver_id = 0;
38 static int _ecore_x_event_sync_id = 0;
39 int _ecore_xlib_log_dom = -1;
42 static int _ecore_x_event_randr_id = 0;
43 #endif /* ifdef ECORE_XRANDR */
45 static int _ecore_x_event_fixes_selection_id = 0;
46 #endif /* ifdef ECORE_XFIXES */
48 static int _ecore_x_event_damage_id = 0;
49 #endif /* ifdef ECORE_XDAMAGE */
51 static int _ecore_x_event_gesture_id = 0;
52 #endif /* ifdef ECORE_XGESTURE */
54 static int _ecore_x_event_xkb_id = 0;
55 #endif /* ifdef ECORE_XKB */
56 static int _ecore_x_event_handlers_num = 0;
57 static void (**_ecore_x_event_handlers) (XEvent * event) = NULL;
59 static int _ecore_x_init_count = 0;
60 static int _ecore_x_grab_count = 0;
62 Display *_ecore_x_disp = NULL;
63 double _ecore_x_double_click_time = 0.25;
64 Time _ecore_x_event_last_time = 0;
65 Window _ecore_x_event_last_win = 0;
66 int _ecore_x_event_last_root_x = 0;
67 int _ecore_x_event_last_root_y = 0;
68 Eina_Bool _ecore_x_xcursor = EINA_FALSE;
70 Ecore_X_Window _ecore_x_private_win = 0;
72 Ecore_X_Atom _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_NUM];
74 EAPI int ECORE_X_EVENT_ANY = 0;
75 EAPI int ECORE_X_EVENT_MOUSE_IN = 0;
76 EAPI int ECORE_X_EVENT_MOUSE_OUT = 0;
77 EAPI int ECORE_X_EVENT_WINDOW_FOCUS_IN = 0;
78 EAPI int ECORE_X_EVENT_WINDOW_FOCUS_OUT = 0;
79 EAPI int ECORE_X_EVENT_WINDOW_KEYMAP = 0;
80 EAPI int ECORE_X_EVENT_WINDOW_DAMAGE = 0;
81 EAPI int ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE = 0;
82 EAPI int ECORE_X_EVENT_WINDOW_CREATE = 0;
83 EAPI int ECORE_X_EVENT_WINDOW_DESTROY = 0;
84 EAPI int ECORE_X_EVENT_WINDOW_HIDE = 0;
85 EAPI int ECORE_X_EVENT_WINDOW_SHOW = 0;
86 EAPI int ECORE_X_EVENT_WINDOW_SHOW_REQUEST = 0;
87 EAPI int ECORE_X_EVENT_WINDOW_REPARENT = 0;
88 EAPI int ECORE_X_EVENT_WINDOW_CONFIGURE = 0;
89 EAPI int ECORE_X_EVENT_WINDOW_CONFIGURE_REQUEST = 0;
90 EAPI int ECORE_X_EVENT_WINDOW_GRAVITY = 0;
91 EAPI int ECORE_X_EVENT_WINDOW_RESIZE_REQUEST = 0;
92 EAPI int ECORE_X_EVENT_WINDOW_STACK = 0;
93 EAPI int ECORE_X_EVENT_WINDOW_STACK_REQUEST = 0;
94 EAPI int ECORE_X_EVENT_WINDOW_PROPERTY = 0;
95 EAPI int ECORE_X_EVENT_WINDOW_COLORMAP = 0;
96 EAPI int ECORE_X_EVENT_WINDOW_MAPPING = 0;
97 EAPI int ECORE_X_EVENT_MAPPING_CHANGE = 0;
98 EAPI int ECORE_X_EVENT_SELECTION_CLEAR = 0;
99 EAPI int ECORE_X_EVENT_SELECTION_REQUEST = 0;
100 EAPI int ECORE_X_EVENT_SELECTION_NOTIFY = 0;
101 EAPI int ECORE_X_EVENT_FIXES_SELECTION_NOTIFY = 0;
102 EAPI int ECORE_X_EVENT_CLIENT_MESSAGE = 0;
103 EAPI int ECORE_X_EVENT_WINDOW_SHAPE = 0;
104 EAPI int ECORE_X_EVENT_SCREENSAVER_NOTIFY = 0;
105 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_FLICK;
106 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_PAN;
107 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_PINCHROTATION;
108 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_TAP;
109 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_TAPNHOLD;
110 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_HOLD;
111 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_GROUP;
112 EAPI int ECORE_X_EVENT_SYNC_COUNTER = 0;
113 EAPI int ECORE_X_EVENT_SYNC_ALARM = 0;
114 EAPI int ECORE_X_EVENT_SCREEN_CHANGE = 0;
115 EAPI int ECORE_X_EVENT_DAMAGE_NOTIFY = 0;
116 EAPI int ECORE_X_EVENT_RANDR_CRTC_CHANGE = 0;
117 EAPI int ECORE_X_EVENT_RANDR_OUTPUT_CHANGE = 0;
118 EAPI int ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY = 0;
119 EAPI int ECORE_X_EVENT_WINDOW_DELETE_REQUEST = 0;
120 EAPI int ECORE_X_EVENT_WINDOW_MOVE_RESIZE_REQUEST = 0;
121 EAPI int ECORE_X_EVENT_WINDOW_STATE_REQUEST = 0;
122 EAPI int ECORE_X_EVENT_FRAME_EXTENTS_REQUEST = 0;
123 EAPI int ECORE_X_EVENT_PING = 0;
124 EAPI int ECORE_X_EVENT_DESKTOP_CHANGE = 0;
126 EAPI int ECORE_X_EVENT_STARTUP_SEQUENCE_NEW = 0;
127 EAPI int ECORE_X_EVENT_STARTUP_SEQUENCE_CHANGE = 0;
128 EAPI int ECORE_X_EVENT_STARTUP_SEQUENCE_REMOVE = 0;
130 EAPI int ECORE_X_EVENT_XKB_STATE_NOTIFY = 0;
131 EAPI int ECORE_X_EVENT_XKB_NEWKBD_NOTIFY = 0;
134 EAPI int ECORE_X_EVENT_GENERIC = 0;
136 EAPI int ECORE_X_MODIFIER_SHIFT = 0;
137 EAPI int ECORE_X_MODIFIER_CTRL = 0;
138 EAPI int ECORE_X_MODIFIER_ALT = 0;
139 EAPI int ECORE_X_MODIFIER_WIN = 0;
140 EAPI int ECORE_X_MODIFIER_ALTGR = 0;
142 EAPI int ECORE_X_LOCK_SCROLL = 0;
143 EAPI int ECORE_X_LOCK_NUM = 0;
144 EAPI int ECORE_X_LOCK_CAPS = 0;
145 EAPI int ECORE_X_LOCK_SHIFT = 0;
147 EAPI int ECORE_X_RAW_BUTTON_PRESS = 0;
148 EAPI int ECORE_X_RAW_BUTTON_RELEASE = 0;
149 EAPI int ECORE_X_RAW_MOTION = 0;
152 static double t0 = 0.0;
153 static Status (*_logrt_real_reply)(Display *disp,
156 Bool discard) = NULL;
162 lib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
164 lib = dlopen("libX11.so.6", RTLD_GLOBAL | RTLD_LAZY);
167 lib = dlopen("libX11.so.6.3", RTLD_GLOBAL | RTLD_LAZY);
170 lib = dlopen("libX11.so.6.3.0", RTLD_GLOBAL | RTLD_LAZY);
172 _logrt_real_reply = dlsym(lib, "_XReply");
173 t0 = ecore_time_get();
177 _XReply(Display *disp,
186 n = backtrace(bt, 128);
189 sym = backtrace_symbols(bt, n);
190 printf("ROUNDTRIP: %4.4f :", ecore_time_get() - t0);
193 for (i = n - 1; i > 0; i--)
195 char *fname = strchr(sym[i], '(');
198 char *tsym = alloca(strlen(fname) + 1);
200 strcpy(tsym, fname + 1);
201 end = strchr(tsym, '+');
221 return _logrt_real_reply(disp, rep, extra, discard);
224 #endif /* ifdef LOGRT */
226 /* wrapper to use XkbKeycodeToKeysym when possible */
228 _ecore_x_XKeycodeToKeysym(Display *display, KeyCode keycode, int idx)
231 return XkbKeycodeToKeysym(display, keycode, 0, idx);
233 return XKeycodeToKeysym(display, keycode, idx);
238 _ecore_x_modifiers_get(void)
240 /* everything has these... unless its like a pda... :) */
241 ECORE_X_MODIFIER_SHIFT = _ecore_x_key_mask_get(XK_Shift_L);
242 ECORE_X_MODIFIER_CTRL = _ecore_x_key_mask_get(XK_Control_L);
244 /* apple's xdarwin has no alt!!!! */
245 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Alt_L);
246 if (!ECORE_X_MODIFIER_ALT)
247 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Meta_L);
249 if (!ECORE_X_MODIFIER_ALT)
250 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Super_L);
252 /* the windows key... a valid modifier :) */
253 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Super_L);
254 if (!ECORE_X_MODIFIER_WIN)
255 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Meta_L);
257 ECORE_X_MODIFIER_ALTGR = _ecore_x_key_mask_get(XK_Mode_switch);
259 if (ECORE_X_MODIFIER_WIN == ECORE_X_MODIFIER_ALT)
260 ECORE_X_MODIFIER_WIN = 0;
262 if (ECORE_X_MODIFIER_ALT == ECORE_X_MODIFIER_CTRL)
263 ECORE_X_MODIFIER_ALT = 0;
265 ECORE_X_LOCK_SCROLL = _ecore_x_key_mask_get(XK_Scroll_Lock);
266 ECORE_X_LOCK_NUM = _ecore_x_key_mask_get(XK_Num_Lock);
267 ECORE_X_LOCK_CAPS = _ecore_x_key_mask_get(XK_Caps_Lock);
268 ECORE_X_LOCK_SHIFT = _ecore_x_key_mask_get(XK_Shift_Lock);
272 * @defgroup Ecore_X_Init_Group X Library Init and Shutdown Functions
274 * Functions that start and shut down the Ecore X Library.
278 * Initialize the X display connection to the given display.
280 * @param name Display target name. If @c NULL, the default display is
282 * @return The number of times the library has been initialized without
283 * being shut down. 0 is returned if an error occurs.
284 * @ingroup Ecore_X_Init_Group
287 ecore_x_init(const char *name)
290 int shape_err_base = 0;
292 int screensaver_base = 0;
293 int screensaver_err_base = 0;
294 #endif /* ifdef ECORE_XSS */
296 int sync_err_base = 0;
299 int randr_err_base = 0;
300 #endif /* ifdef ECORE_XRANDR */
303 int fixes_err_base = 0;
304 #endif /* ifdef ECORE_XFIXES */
307 int damage_err_base = 0;
308 #endif /* ifdef ECORE_XDAMAGE */
309 #ifdef ECORE_XGESTURE
310 int gesture_base = 0;
311 int gesture_err_base = 0;
312 #endif /* ifdef ECORE_XGESTURE */
315 #endif /* ifdef ECORE_XKB */
316 if (++_ecore_x_init_count != 1)
317 return _ecore_x_init_count;
319 LOGFN(__FILE__, __LINE__, __FUNCTION__);
322 #endif /* ifdef LOGRT */
325 _ecore_xlib_log_dom = eina_log_domain_register
326 ("ecore_x", ECORE_XLIB_DEFAULT_LOG_COLOR);
327 if (_ecore_xlib_log_dom < 0)
330 "Impossible to create a log domain for the Ecore Xlib module.");
331 return --_ecore_x_init_count;
336 if (!ecore_event_init())
339 #ifdef EVAS_FRAME_QUEUING
341 #endif /* ifdef EVAS_FRAME_QUEUING */
342 _ecore_x_disp = XOpenDisplay((char *)name);
344 goto shutdown_ecore_event;
346 _ecore_x_error_handler_init();
347 _ecore_x_event_handlers_num = LASTEvent;
349 #define ECORE_X_EVENT_HANDLERS_GROW(ext_base, ext_num_events) \
351 if (_ecore_x_event_handlers_num < (ext_base + ext_num_events)) { \
352 _ecore_x_event_handlers_num = (ext_base + ext_num_events); } \
355 if (XShapeQueryExtension(_ecore_x_disp, &shape_base, &shape_err_base))
356 _ecore_x_event_shape_id = shape_base;
358 ECORE_X_EVENT_HANDLERS_GROW(shape_base, ShapeNumberEvents);
361 if (XScreenSaverQueryExtension(_ecore_x_disp, &screensaver_base,
362 &screensaver_err_base))
363 _ecore_x_event_screensaver_id = screensaver_base;
365 ECORE_X_EVENT_HANDLERS_GROW(screensaver_base, ScreenSaverNumberEvents);
366 #endif /* ifdef ECORE_XSS */
368 if (XSyncQueryExtension(_ecore_x_disp, &sync_base, &sync_err_base))
372 _ecore_x_event_sync_id = sync_base;
373 if (!XSyncInitialize(_ecore_x_disp, &major, &minor))
374 _ecore_x_event_sync_id = 0;
377 ECORE_X_EVENT_HANDLERS_GROW(sync_base, XSyncNumberEvents);
380 if (XRRQueryExtension(_ecore_x_disp, &randr_base, &randr_err_base))
381 _ecore_x_event_randr_id = randr_base;
383 ECORE_X_EVENT_HANDLERS_GROW(randr_base, RRNumberEvents);
384 #endif /* ifdef ECORE_XRANDR */
387 if (XFixesQueryExtension(_ecore_x_disp, &fixes_base, &fixes_err_base))
388 _ecore_x_event_fixes_selection_id = fixes_base;
390 ECORE_X_EVENT_HANDLERS_GROW(fixes_base, XFixesNumberEvents);
391 #endif /* ifdef ECORE_XFIXES */
394 if (XDamageQueryExtension(_ecore_x_disp, &damage_base, &damage_err_base))
395 _ecore_x_event_damage_id = damage_base;
397 ECORE_X_EVENT_HANDLERS_GROW(damage_base, XDamageNumberEvents);
398 #endif /* ifdef ECORE_XDAMAGE */
400 #ifdef ECORE_XGESTURE
401 if (XGestureQueryExtension(_ecore_x_disp, &gesture_base, &gesture_err_base))
402 _ecore_x_event_gesture_id = gesture_base;
404 ECORE_X_EVENT_HANDLERS_GROW(gesture_base, GestureNumberEvents);
405 #endif /* ifdef ECORE_XGESTURE */
410 if (XkbQueryExtension(_ecore_x_disp, &dummy, &xkb_base,
411 &dummy, &dummy, &dummy))
412 _ecore_x_event_xkb_id = xkb_base;
413 XkbSelectEventDetails(_ecore_x_disp, XkbUseCoreKbd, XkbStateNotify,
414 XkbAllStateComponentsMask, XkbGroupStateMask);
416 ECORE_X_EVENT_HANDLERS_GROW(xkb_base, XkbNumberEvents);
419 _ecore_x_event_handlers = calloc(_ecore_x_event_handlers_num, sizeof(void *));
420 if (!_ecore_x_event_handlers)
424 _ecore_x_xcursor = XcursorSupportsARGB(_ecore_x_disp) ? EINA_TRUE : EINA_FALSE;
425 #endif /* ifdef ECORE_XCURSOR */
426 _ecore_x_event_handlers[AnyXEvent] = _ecore_x_event_handle_any_event;
427 _ecore_x_event_handlers[KeyPress] = _ecore_x_event_handle_key_press;
428 _ecore_x_event_handlers[KeyRelease] = _ecore_x_event_handle_key_release;
429 _ecore_x_event_handlers[ButtonPress] = _ecore_x_event_handle_button_press;
430 _ecore_x_event_handlers[ButtonRelease] =
431 _ecore_x_event_handle_button_release;
432 _ecore_x_event_handlers[MotionNotify] = _ecore_x_event_handle_motion_notify;
433 _ecore_x_event_handlers[EnterNotify] = _ecore_x_event_handle_enter_notify;
434 _ecore_x_event_handlers[LeaveNotify] = _ecore_x_event_handle_leave_notify;
435 _ecore_x_event_handlers[FocusIn] = _ecore_x_event_handle_focus_in;
436 _ecore_x_event_handlers[FocusOut] = _ecore_x_event_handle_focus_out;
437 _ecore_x_event_handlers[KeymapNotify] = _ecore_x_event_handle_keymap_notify;
438 _ecore_x_event_handlers[Expose] = _ecore_x_event_handle_expose;
439 _ecore_x_event_handlers[GraphicsExpose] =
440 _ecore_x_event_handle_graphics_expose;
441 _ecore_x_event_handlers[VisibilityNotify] =
442 _ecore_x_event_handle_visibility_notify;
443 _ecore_x_event_handlers[CreateNotify] = _ecore_x_event_handle_create_notify;
444 _ecore_x_event_handlers[DestroyNotify] =
445 _ecore_x_event_handle_destroy_notify;
446 _ecore_x_event_handlers[UnmapNotify] = _ecore_x_event_handle_unmap_notify;
447 _ecore_x_event_handlers[MapNotify] = _ecore_x_event_handle_map_notify;
448 _ecore_x_event_handlers[MapRequest] = _ecore_x_event_handle_map_request;
449 _ecore_x_event_handlers[ReparentNotify] =
450 _ecore_x_event_handle_reparent_notify;
451 _ecore_x_event_handlers[ConfigureNotify] =
452 _ecore_x_event_handle_configure_notify;
453 _ecore_x_event_handlers[ConfigureRequest] =
454 _ecore_x_event_handle_configure_request;
455 _ecore_x_event_handlers[GravityNotify] =
456 _ecore_x_event_handle_gravity_notify;
457 _ecore_x_event_handlers[ResizeRequest] =
458 _ecore_x_event_handle_resize_request;
459 _ecore_x_event_handlers[CirculateNotify] =
460 _ecore_x_event_handle_circulate_notify;
461 _ecore_x_event_handlers[CirculateRequest] =
462 _ecore_x_event_handle_circulate_request;
463 _ecore_x_event_handlers[PropertyNotify] =
464 _ecore_x_event_handle_property_notify;
465 _ecore_x_event_handlers[SelectionClear] =
466 _ecore_x_event_handle_selection_clear;
467 _ecore_x_event_handlers[SelectionRequest] =
468 _ecore_x_event_handle_selection_request;
469 _ecore_x_event_handlers[SelectionNotify] =
470 _ecore_x_event_handle_selection_notify;
471 _ecore_x_event_handlers[ColormapNotify] =
472 _ecore_x_event_handle_colormap_notify;
473 _ecore_x_event_handlers[ClientMessage] =
474 _ecore_x_event_handle_client_message;
475 _ecore_x_event_handlers[MappingNotify] =
476 _ecore_x_event_handle_mapping_notify;
478 _ecore_x_event_handlers[GenericEvent] = _ecore_x_event_handle_generic_event;
479 #endif /* ifdef GenericEvent */
481 if (_ecore_x_event_shape_id)
482 _ecore_x_event_handlers[_ecore_x_event_shape_id] =
483 _ecore_x_event_handle_shape_change;
485 if (_ecore_x_event_screensaver_id)
486 _ecore_x_event_handlers[_ecore_x_event_screensaver_id] =
487 _ecore_x_event_handle_screensaver_notify;
489 if (_ecore_x_event_sync_id)
491 _ecore_x_event_handlers[_ecore_x_event_sync_id + XSyncCounterNotify] =
492 _ecore_x_event_handle_sync_counter;
493 _ecore_x_event_handlers[_ecore_x_event_sync_id + XSyncAlarmNotify] =
494 _ecore_x_event_handle_sync_alarm;
498 if (_ecore_x_event_randr_id)
500 _ecore_x_event_handlers[_ecore_x_event_randr_id +
501 RRScreenChangeNotify] =
502 _ecore_x_event_handle_randr_change;
503 _ecore_x_event_handlers[_ecore_x_event_randr_id +
504 RRNotify] = _ecore_x_event_handle_randr_notify;
507 #endif /* ifdef ECORE_XRANDR */
509 if (_ecore_x_event_fixes_selection_id)
510 _ecore_x_event_handlers[_ecore_x_event_fixes_selection_id] =
511 _ecore_x_event_handle_fixes_selection_notify;
513 #endif /* ifdef ECORE_XFIXES */
515 if (_ecore_x_event_damage_id)
516 _ecore_x_event_handlers[_ecore_x_event_damage_id] =
517 _ecore_x_event_handle_damage_notify;
519 #endif /* ifdef ECORE_XDAMAGE */
521 // set x autorepeat detection to on. that means instead of
522 // press-release-press-release-press-release
524 // press-press-press-press-press-release
528 XkbSetDetectableAutoRepeat(_ecore_x_disp, 1, &works);
531 if (_ecore_x_event_xkb_id)
532 _ecore_x_event_handlers[_ecore_x_event_xkb_id] = _ecore_x_event_handle_xkb;
533 #endif /* ifdef ECORE_XKB */
535 #ifdef ECORE_XGESTURE
536 if (_ecore_x_event_gesture_id)
538 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyFlick] =
539 _ecore_x_event_handle_gesture_notify_flick;
540 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyPan] =
541 _ecore_x_event_handle_gesture_notify_pan;
542 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyPinchRotation] =
543 _ecore_x_event_handle_gesture_notify_pinchrotation;
544 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyTap] =
545 _ecore_x_event_handle_gesture_notify_tap;
546 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyTapNHold] =
547 _ecore_x_event_handle_gesture_notify_tapnhold;
548 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyHold] =
549 _ecore_x_event_handle_gesture_notify_hold;
550 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyGroup] =
551 _ecore_x_event_handle_gesture_notify_group;
554 #endif /* ifdef ECORE_XGESTURE */
556 if (!ECORE_X_EVENT_ANY)
558 ECORE_X_EVENT_ANY = ecore_event_type_new();
559 ECORE_X_EVENT_MOUSE_IN = ecore_event_type_new();
560 ECORE_X_EVENT_MOUSE_OUT = ecore_event_type_new();
561 ECORE_X_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
562 ECORE_X_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
563 ECORE_X_EVENT_WINDOW_KEYMAP = ecore_event_type_new();
564 ECORE_X_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
565 ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE = ecore_event_type_new();
566 ECORE_X_EVENT_WINDOW_CREATE = ecore_event_type_new();
567 ECORE_X_EVENT_WINDOW_DESTROY = ecore_event_type_new();
568 ECORE_X_EVENT_WINDOW_HIDE = ecore_event_type_new();
569 ECORE_X_EVENT_WINDOW_SHOW = ecore_event_type_new();
570 ECORE_X_EVENT_WINDOW_SHOW_REQUEST = ecore_event_type_new();
571 ECORE_X_EVENT_WINDOW_REPARENT = ecore_event_type_new();
572 ECORE_X_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
573 ECORE_X_EVENT_WINDOW_CONFIGURE_REQUEST = ecore_event_type_new();
574 ECORE_X_EVENT_WINDOW_GRAVITY = ecore_event_type_new();
575 ECORE_X_EVENT_WINDOW_RESIZE_REQUEST = ecore_event_type_new();
576 ECORE_X_EVENT_WINDOW_STACK = ecore_event_type_new();
577 ECORE_X_EVENT_WINDOW_STACK_REQUEST = ecore_event_type_new();
578 ECORE_X_EVENT_WINDOW_PROPERTY = ecore_event_type_new();
579 ECORE_X_EVENT_WINDOW_COLORMAP = ecore_event_type_new();
580 ECORE_X_EVENT_WINDOW_MAPPING = ecore_event_type_new();
581 ECORE_X_EVENT_MAPPING_CHANGE = ecore_event_type_new();
582 ECORE_X_EVENT_SELECTION_CLEAR = ecore_event_type_new();
583 ECORE_X_EVENT_SELECTION_REQUEST = ecore_event_type_new();
584 ECORE_X_EVENT_SELECTION_NOTIFY = ecore_event_type_new();
585 ECORE_X_EVENT_CLIENT_MESSAGE = ecore_event_type_new();
586 ECORE_X_EVENT_WINDOW_SHAPE = ecore_event_type_new();
587 ECORE_X_EVENT_SCREENSAVER_NOTIFY = ecore_event_type_new();
588 ECORE_X_EVENT_GESTURE_NOTIFY_FLICK = ecore_event_type_new();
589 ECORE_X_EVENT_GESTURE_NOTIFY_PAN = ecore_event_type_new();
590 ECORE_X_EVENT_GESTURE_NOTIFY_PINCHROTATION = ecore_event_type_new();
591 ECORE_X_EVENT_GESTURE_NOTIFY_TAP = ecore_event_type_new();
592 ECORE_X_EVENT_GESTURE_NOTIFY_TAPNHOLD = ecore_event_type_new();
593 ECORE_X_EVENT_GESTURE_NOTIFY_HOLD = ecore_event_type_new();
594 ECORE_X_EVENT_GESTURE_NOTIFY_GROUP = ecore_event_type_new();
595 ECORE_X_EVENT_SYNC_COUNTER = ecore_event_type_new();
596 ECORE_X_EVENT_SYNC_ALARM = ecore_event_type_new();
597 ECORE_X_EVENT_SCREEN_CHANGE = ecore_event_type_new();
598 ECORE_X_EVENT_RANDR_CRTC_CHANGE = ecore_event_type_new();
599 ECORE_X_EVENT_RANDR_OUTPUT_CHANGE = ecore_event_type_new();
600 ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY = ecore_event_type_new();
601 ECORE_X_EVENT_DAMAGE_NOTIFY = ecore_event_type_new();
603 ECORE_X_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
605 ECORE_X_EVENT_DESKTOP_CHANGE = ecore_event_type_new();
606 ECORE_X_EVENT_WINDOW_MOVE_RESIZE_REQUEST = ecore_event_type_new();
607 ECORE_X_EVENT_WINDOW_STATE_REQUEST = ecore_event_type_new();
608 ECORE_X_EVENT_FRAME_EXTENTS_REQUEST = ecore_event_type_new();
609 ECORE_X_EVENT_PING = ecore_event_type_new();
611 ECORE_X_EVENT_STARTUP_SEQUENCE_NEW = ecore_event_type_new();
612 ECORE_X_EVENT_STARTUP_SEQUENCE_CHANGE = ecore_event_type_new();
613 ECORE_X_EVENT_STARTUP_SEQUENCE_REMOVE = ecore_event_type_new();
615 ECORE_X_EVENT_XKB_STATE_NOTIFY = ecore_event_type_new();
616 ECORE_X_EVENT_XKB_NEWKBD_NOTIFY = ecore_event_type_new();
618 ECORE_X_EVENT_GENERIC = ecore_event_type_new();
620 ECORE_X_RAW_BUTTON_PRESS = ecore_event_type_new();
621 ECORE_X_RAW_BUTTON_RELEASE = ecore_event_type_new();
622 ECORE_X_RAW_MOTION = ecore_event_type_new();
625 _ecore_x_modifiers_get();
627 _ecore_x_fd_handler_handle =
628 ecore_main_fd_handler_add(ConnectionNumber(_ecore_x_disp),
630 _ecore_x_fd_handler, _ecore_x_disp,
631 _ecore_x_fd_handler_buf, _ecore_x_disp);
632 if (!_ecore_x_fd_handler_handle)
633 goto free_event_handlers;
635 _ecore_x_atoms_init();
637 /* Set up the ICCCM hints */
638 ecore_x_icccm_init();
640 /* Set up the _NET_... hints */
641 ecore_x_netwm_init();
643 /* old e hints init */
646 /* This is just to be anal about naming conventions */
648 _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_DELETE_REQUEST] =
649 ECORE_X_ATOM_WM_DELETE_WINDOW;
650 _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_TAKE_FOCUS] =
651 ECORE_X_ATOM_WM_TAKE_FOCUS;
652 _ecore_x_atoms_wm_protocols[ECORE_X_NET_WM_PROTOCOL_PING] =
653 ECORE_X_ATOM_NET_WM_PING;
654 _ecore_x_atoms_wm_protocols[ECORE_X_NET_WM_PROTOCOL_SYNC_REQUEST] =
655 ECORE_X_ATOM_NET_WM_SYNC_REQUEST;
657 _ecore_x_selection_data_init();
659 _ecore_x_fixes_init();
660 _ecore_x_damage_init();
661 _ecore_x_composite_init();
662 _ecore_x_dpms_init();
663 _ecore_x_randr_init();
664 _ecore_x_gesture_init();
665 _ecore_x_input_init();
666 _ecore_x_events_init();
668 _ecore_x_private_win = ecore_x_window_override_new(0, -77, -777, 123, 456);
670 return _ecore_x_init_count;
673 free(_ecore_x_event_handlers);
674 _ecore_x_event_handlers = NULL;
676 XCloseDisplay(_ecore_x_disp);
677 _ecore_x_fd_handler_handle = NULL;
678 _ecore_x_disp = NULL;
679 shutdown_ecore_event:
680 ecore_event_shutdown();
684 eina_log_domain_unregister(_ecore_xlib_log_dom);
685 _ecore_xlib_log_dom = -1;
688 return --_ecore_x_init_count;
692 _ecore_x_shutdown(int close_display)
694 if (--_ecore_x_init_count != 0)
695 return _ecore_x_init_count;
698 return _ecore_x_init_count;
700 LOGFN(__FILE__, __LINE__, __FUNCTION__);
702 ecore_main_fd_handler_del(_ecore_x_fd_handler_handle);
704 XCloseDisplay(_ecore_x_disp);
707 close(ConnectionNumber(_ecore_x_disp));
708 // FIXME: may have to clean up x display internal here
709 // getting segv here? hmmm. odd. disable
710 // XFree(_ecore_x_disp);
713 free(_ecore_x_event_handlers);
714 _ecore_x_fd_handler_handle = NULL;
715 _ecore_x_disp = NULL;
716 _ecore_x_event_handlers = NULL;
717 _ecore_x_events_shutdown();
718 _ecore_x_input_shutdown();
719 _ecore_x_selection_shutdown();
720 _ecore_x_dnd_shutdown();
721 ecore_x_netwm_shutdown();
723 ecore_event_shutdown();
726 eina_log_domain_unregister(_ecore_xlib_log_dom);
727 _ecore_xlib_log_dom = -1;
730 return _ecore_x_init_count;
734 * Shuts down the Ecore X library.
736 * In shutting down the library, the X display connection is terminated
737 * and any event handlers for it are removed.
739 * @return The number of times the library has been initialized without
740 * being shut down. 0 is returned if an error occurs.
741 * @ingroup Ecore_X_Init_Group
744 ecore_x_shutdown(void)
746 return _ecore_x_shutdown(1);
750 * Shuts down the Ecore X library.
752 * As ecore_x_shutdown, except do not close Display, only connection.
754 * @ingroup Ecore_X_Init_Group
757 ecore_x_disconnect(void)
759 return _ecore_x_shutdown(0);
763 * @defgroup Ecore_X_Display_Attr_Group X Display Attributes
765 * Functions that set and retrieve X display attributes.
769 * Retrieves the Ecore_X_Display handle used for the current X connection.
770 * @return The current X display.
771 * @ingroup Ecore_X_Display_Attr_Group
773 EAPI Ecore_X_Display *
774 ecore_x_display_get(void)
776 return (Ecore_X_Display *)_ecore_x_disp;
780 * Retrieves the X display file descriptor.
781 * @return The current X display file descriptor.
782 * @ingroup Ecore_X_Display_Attr_Group
787 LOGFN(__FILE__, __LINE__, __FUNCTION__);
788 return ConnectionNumber(_ecore_x_disp);
792 * Retrieves the Ecore_X_Screen handle used for the current X connection.
793 * @return The current default screen.
794 * @ingroup Ecore_X_Display_Attr_Group
796 EAPI Ecore_X_Screen *
797 ecore_x_default_screen_get(void)
799 LOGFN(__FILE__, __LINE__, __FUNCTION__);
800 return (Ecore_X_Screen *)DefaultScreenOfDisplay(_ecore_x_disp);
804 * Retrieves the size of an Ecore_X_Screen.
805 * @param screen the handle to the screen to query.
806 * @param w where to return the width. May be NULL. Returns 0 on errors.
807 * @param h where to return the height. May be NULL. Returns 0 on errors.
808 * @ingroup Ecore_X_Display_Attr_Group
809 * @see ecore_x_default_screen_get()
814 ecore_x_screen_size_get(const Ecore_X_Screen *screen,
818 Screen *s = (Screen *)screen;
819 LOGFN(__FILE__, __LINE__, __FUNCTION__);
823 if (w) *w = s->width;
824 if (h) *h = s->height;
828 * Retrieves the number of screens.
830 * @return The count of the number of screens.
831 * @ingroup Ecore_X_Display_Attr_Group
836 ecore_x_screen_count_get(void)
838 LOGFN(__FILE__, __LINE__, __FUNCTION__);
840 return ScreenCount(_ecore_x_disp);
844 * Retrieves the index number of the given screen.
846 * @param screen The screen for which the index will be retrieved.
847 * @return The index number of the screen.
848 * @ingroup Ecore_X_Display_Attr_Group
853 ecore_x_screen_index_get(const Ecore_X_Screen *screen)
855 return XScreenNumberOfScreen((Screen *)screen);
859 * Retrieves the screen based on index number.
861 * @param idx The index that will be used to retrieve the screen.
862 * @return The Ecore_X_Screen at this index.
863 * @ingroup Ecore_X_Display_Attr_Group
867 EAPI Ecore_X_Screen *
868 ecore_x_screen_get(int idx)
870 return XScreenOfDisplay(_ecore_x_disp, idx);
874 * Sets the timeout for a double and triple clicks to be flagged.
876 * This sets the time between clicks before the double_click flag is
877 * set in a button down event. If 3 clicks occur within double this
878 * time, the triple_click flag is also set.
880 * @param t The time in seconds
881 * @ingroup Ecore_X_Display_Attr_Group
884 ecore_x_double_click_time_set(double t)
889 _ecore_x_double_click_time = t;
893 * Retrieves the double and triple click flag timeout.
895 * See @ref ecore_x_double_click_time_set for more information.
897 * @return The timeout for double clicks in seconds.
898 * @ingroup Ecore_X_Display_Attr_Group
901 ecore_x_double_click_time_get(void)
903 return _ecore_x_double_click_time;
907 * @defgroup Ecore_X_Flush_Group X Synchronization Functions
909 * Functions that ensure that all commands that have been issued by the
910 * Ecore X library have been sent to the server.
914 * Sends all X commands in the X Display buffer.
915 * @ingroup Ecore_X_Flush_Group
920 LOGFN(__FILE__, __LINE__, __FUNCTION__);
921 XFlush(_ecore_x_disp);
925 * Flushes the command buffer and waits until all requests have been
926 * processed by the server.
927 * @ingroup Ecore_X_Flush_Group
932 LOGFN(__FILE__, __LINE__, __FUNCTION__);
933 XSync(_ecore_x_disp, False);
937 * Kill all clients with subwindows under a given window.
939 * You can kill all clients connected to the X server by using
940 * @ref ecore_x_window_root_list to get a list of root windows, and
941 * then passing each root window to this function.
943 * @param root The window whose children will be killed.
946 ecore_x_killall(Ecore_X_Window root)
951 Window *children_r = NULL;
952 unsigned int num_children = 0;
954 LOGFN(__FILE__, __LINE__, __FUNCTION__);
955 XGrabServer(_ecore_x_disp);
956 /* Tranverse window tree starting from root, and drag each
957 * before the firing squad */
958 while (XQueryTree(_ecore_x_disp, root, &root_r, &parent_r,
959 &children_r, &num_children) && (num_children > 0))
961 for (j = 0; j < num_children; ++j)
963 XKillClient(_ecore_x_disp, children_r[j]);
968 XUngrabServer(_ecore_x_disp);
969 XSync(_ecore_x_disp, False);
973 * Kill a specific client
975 * You can kill a specific client owning window @p win
977 * @param win Window of the client to be killed
980 ecore_x_kill(Ecore_X_Window win)
982 LOGFN(__FILE__, __LINE__, __FUNCTION__);
983 XKillClient(_ecore_x_disp, win);
987 * Return the last event time
990 ecore_x_current_time_get(void)
992 return _ecore_x_event_last_time;
996 * Return the screen DPI
998 * This is a simplistic call to get DPI. It does not account for differing
999 * DPI in the x amd y axes nor does it account for multihead or xinerama and
1000 * xrander where different parts of the screen may have different DPI etc.
1002 * @return the general screen DPI (dots/pixels per inch).
1005 ecore_x_dpi_get(void)
1009 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1010 s = DefaultScreenOfDisplay(_ecore_x_disp);
1014 return (((s->width * 254) / s->mwidth) + 5) / 10;
1018 * Invoke the standard system beep to alert users
1020 * @param percent The volume at which the bell rings. Must be in the range
1021 * [-100,+100]. If percent >= 0, the final volume will be:
1022 * base - [(base * percent) / 100] + percent
1023 * Otherwise, it's calculated as:
1024 * base + [(base * percent) / 100]
1025 * where @c base is the bell's base volume as set by XChangeKeyboardControl(3).
1027 * @returns @c EINA_TRUE on success, @c EINA_FALSE otherwise.
1030 ecore_x_bell(int percent)
1034 ret = XBell(_ecore_x_disp, percent);
1035 if (ret == BadValue)
1042 _ecore_x_fd_handler(void *data,
1043 Ecore_Fd_Handler *fd_handler __UNUSED__)
1054 /* Filter event for XIM */
1055 if (XFilterEvent(&ev, ev.xkey.window))
1058 #endif /* ifdef ENABLE_XIM */
1059 if ((ev.type >= 0) && (ev.type < _ecore_x_event_handlers_num))
1061 if (_ecore_x_event_handlers[AnyXEvent])
1062 _ecore_x_event_handlers[AnyXEvent] (&ev);
1064 if (_ecore_x_event_handlers[ev.type])
1065 _ecore_x_event_handlers[ev.type] (&ev);
1068 return ECORE_CALLBACK_RENEW;
1072 _ecore_x_fd_handler_buf(void *data,
1073 Ecore_Fd_Handler *fd_handler __UNUSED__)
1079 return ECORE_CALLBACK_RENEW;
1081 return ECORE_CALLBACK_CANCEL;
1085 _ecore_x_key_mask_get(KeySym sym)
1087 XModifierKeymap *mod;
1090 const int masks[8] =
1092 ShiftMask, LockMask, ControlMask,
1093 Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
1096 mod = XGetModifierMapping(_ecore_x_disp);
1097 if ((mod) && (mod->max_keypermod > 0))
1098 for (i = 0; i < (8 * mod->max_keypermod); i++)
1100 for (j = 0; j < 8; j++)
1102 sym2 = _ecore_x_XKeycodeToKeysym(_ecore_x_disp,
1103 mod->modifiermap[i], j);
1111 mask = masks[i / mod->max_keypermod];
1112 if (mod->modifiermap)
1113 XFree(mod->modifiermap);
1122 if (mod->modifiermap)
1123 XFree(mod->modifiermap);
1131 /*****************************************************************************/
1132 /*****************************************************************************/
1133 /*****************************************************************************/
1134 /* FIXME: these funcs need categorising */
1135 /*****************************************************************************/
1138 * Get a list of all the root windows on the server.
1140 * @note The returned array will need to be freed after use.
1141 * @param num_ret Pointer to integer to put number of windows returned in.
1142 * @return An array of all the root windows. @c NULL is returned if memory
1143 * could not be allocated for the list, or if @p num_ret is @c NULL.
1145 EAPI Ecore_X_Window *
1146 ecore_x_window_root_list(int *num_ret)
1149 Ecore_X_Window *roots;
1151 int xp_base, xp_err_base;
1152 #endif /* ifdef ECORE_XPRINT */
1159 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1161 num = ScreenCount(_ecore_x_disp);
1162 if (XpQueryExtension(_ecore_x_disp, &xp_base, &xp_err_base))
1167 ps = XpQueryScreens(_ecore_x_disp, &psnum);
1173 for (i = 0; i < num; i++)
1175 for (j = 0; j < psnum; j++)
1177 if (ScreenOfDisplay(_ecore_x_disp, i) == ps[j])
1181 roots = malloc(MAX((num - overlap) * sizeof(Window), 1));
1187 for (i = 0; i < num; i++)
1192 for (j = 0; j < psnum; j++)
1194 if (ScreenOfDisplay(_ecore_x_disp, i) == ps[j])
1202 roots[k] = RootWindow(_ecore_x_disp, i);
1213 roots = malloc(num * sizeof(Window));
1218 for (i = 0; i < num; i++)
1219 roots[i] = RootWindow(_ecore_x_disp, i);
1224 roots = malloc(num * sizeof(Window));
1229 for (i = 0; i < num; i++)
1230 roots[i] = RootWindow(_ecore_x_disp, i);
1233 #else /* ifdef ECORE_XPRINT */
1234 num = ScreenCount(_ecore_x_disp);
1235 roots = malloc(num * sizeof(Window));
1240 for (i = 0; i < num; i++)
1241 roots[i] = RootWindow(_ecore_x_disp, i);
1242 #endif /* ifdef ECORE_XPRINT */
1247 ecore_x_window_root_first_get(void)
1249 return RootWindow(_ecore_x_disp, 0);
1252 Ecore_X_Window root, *roots = NULL;
1254 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1255 roots = ecore_x_window_root_list(&num);
1256 if (!(roots)) return 0;
1268 static void _ecore_x_window_manage_error(void *data);
1270 static int _ecore_x_window_manage_failed = 0;
1272 _ecore_x_window_manage_error(void *data __UNUSED__)
1274 if ((ecore_x_error_request_get() == X_ChangeWindowAttributes) &&
1275 (ecore_x_error_code_get() == BadAccess))
1276 _ecore_x_window_manage_failed = 1;
1280 ecore_x_window_manage(Ecore_X_Window win)
1282 XWindowAttributes att;
1284 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1285 if (XGetWindowAttributes(_ecore_x_disp, win, &att) != True)
1289 _ecore_x_window_manage_failed = 0;
1290 ecore_x_error_handler_set(_ecore_x_window_manage_error, NULL);
1291 XSelectInput(_ecore_x_disp, win,
1294 PropertyChangeMask |
1295 ResizeRedirectMask |
1296 SubstructureRedirectMask |
1297 SubstructureNotifyMask |
1298 StructureNotifyMask |
1301 att.your_event_mask);
1303 ecore_x_error_handler_set(NULL, NULL);
1304 if (_ecore_x_window_manage_failed)
1306 _ecore_x_window_manage_failed = 0;
1314 ecore_x_window_container_manage(Ecore_X_Window win)
1316 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1317 XSelectInput(_ecore_x_disp, win,
1318 SubstructureRedirectMask |
1319 SubstructureNotifyMask);
1323 ecore_x_window_client_manage(Ecore_X_Window win)
1325 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1326 XSelectInput(_ecore_x_disp, win,
1327 PropertyChangeMask |
1328 // ResizeRedirectMask |
1330 ColormapChangeMask |
1331 VisibilityChangeMask |
1332 StructureNotifyMask |
1333 SubstructureNotifyMask
1335 XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
1339 ecore_x_window_sniff(Ecore_X_Window win)
1341 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1342 XSelectInput(_ecore_x_disp, win,
1343 PropertyChangeMask |
1344 SubstructureNotifyMask);
1348 ecore_x_window_client_sniff(Ecore_X_Window win)
1350 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1351 XSelectInput(_ecore_x_disp, win,
1352 PropertyChangeMask |
1354 ColormapChangeMask |
1355 VisibilityChangeMask |
1356 StructureNotifyMask |
1357 SubstructureNotifyMask);
1358 XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
1362 ecore_x_window_attributes_get(Ecore_X_Window win,
1363 Ecore_X_Window_Attributes *att_ret)
1365 XWindowAttributes att;
1367 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1368 if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
1371 memset(att_ret, 0, sizeof(Ecore_X_Window_Attributes));
1372 att_ret->root = att.root;
1375 att_ret->w = att.width;
1376 att_ret->h = att.height;
1377 att_ret->border = att.border_width;
1378 att_ret->depth = att.depth;
1379 if (att.map_state != IsUnmapped)
1380 att_ret->visible = 1;
1382 if (att.map_state == IsViewable)
1383 att_ret->viewable = 1;
1385 if (att.override_redirect)
1386 att_ret->override = 1;
1388 if (att.class == InputOnly)
1389 att_ret->input_only = 1;
1392 att_ret->save_under = 1;
1394 att_ret->event_mask.mine = att.your_event_mask;
1395 att_ret->event_mask.all = att.all_event_masks;
1396 att_ret->event_mask.no_propagate = att.do_not_propagate_mask;
1397 att_ret->window_gravity = att.win_gravity;
1398 att_ret->pixel_gravity = att.bit_gravity;
1399 att_ret->colormap = att.colormap;
1400 att_ret->visual = att.visual;
1405 ecore_x_window_save_set_add(Ecore_X_Window win)
1407 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1408 XAddToSaveSet(_ecore_x_disp, win);
1412 ecore_x_window_save_set_del(Ecore_X_Window win)
1414 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1415 XRemoveFromSaveSet(_ecore_x_disp, win);
1418 EAPI Ecore_X_Window *
1419 ecore_x_window_children_get(Ecore_X_Window win,
1422 Ecore_X_Window *windows = NULL;
1423 Window root_ret = 0, parent_ret = 0, *children_ret = NULL;
1424 unsigned int children_ret_num = 0;
1426 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1427 if (!XQueryTree(_ecore_x_disp, win, &root_ret, &parent_ret, &children_ret,
1433 windows = malloc(children_ret_num * sizeof(Ecore_X_Window));
1438 for (i = 0; i < children_ret_num; i++)
1439 windows[i] = children_ret[i];
1440 *num = children_ret_num;
1443 XFree(children_ret);
1450 ecore_x_pointer_control_set(int accel_num,
1454 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1455 return XChangePointerControl(_ecore_x_disp, 1, 1,
1456 accel_num, accel_denom, threshold) ? EINA_TRUE : EINA_FALSE;
1460 ecore_x_pointer_control_get(int *accel_num,
1464 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1465 return XGetPointerControl(_ecore_x_disp,
1466 accel_num, accel_denom, threshold) ? EINA_TRUE : EINA_FALSE;
1470 ecore_x_pointer_mapping_set(unsigned char *map,
1473 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1474 return (XSetPointerMapping(_ecore_x_disp, map, nmap) == MappingSuccess) ? EINA_TRUE : EINA_FALSE;
1478 ecore_x_pointer_mapping_get(unsigned char *map,
1481 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1482 return XGetPointerMapping(_ecore_x_disp, map, nmap) ? EINA_TRUE : EINA_FALSE;
1486 ecore_x_pointer_grab(Ecore_X_Window win)
1488 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1489 if (XGrabPointer(_ecore_x_disp, win, False,
1490 ButtonPressMask | ButtonReleaseMask |
1491 EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1492 GrabModeAsync, GrabModeAsync,
1493 None, None, CurrentTime) == GrabSuccess)
1500 ecore_x_pointer_confine_grab(Ecore_X_Window win)
1502 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1503 if (XGrabPointer(_ecore_x_disp, win, False,
1504 ButtonPressMask | ButtonReleaseMask |
1505 EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1506 GrabModeAsync, GrabModeAsync,
1507 win, None, CurrentTime) == GrabSuccess)
1514 ecore_x_pointer_ungrab(void)
1516 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1517 XUngrabPointer(_ecore_x_disp, CurrentTime);
1521 ecore_x_pointer_warp(Ecore_X_Window win,
1525 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1526 return XWarpPointer(_ecore_x_disp, None, win, 0, 0, 0, 0, x, y) ? EINA_TRUE : EINA_FALSE;
1530 ecore_x_keyboard_grab(Ecore_X_Window win)
1532 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1533 if (XGrabKeyboard(_ecore_x_disp, win, False,
1534 GrabModeAsync, GrabModeAsync,
1535 CurrentTime) == GrabSuccess)
1542 ecore_x_keyboard_ungrab(void)
1544 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1545 XUngrabKeyboard(_ecore_x_disp, CurrentTime);
1551 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1552 _ecore_x_grab_count++;
1553 if (_ecore_x_grab_count == 1)
1554 XGrabServer(_ecore_x_disp);
1558 ecore_x_ungrab(void)
1560 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1561 _ecore_x_grab_count--;
1562 if (_ecore_x_grab_count < 0)
1563 _ecore_x_grab_count = 0;
1565 if (_ecore_x_grab_count == 0)
1566 XUngrabServer(_ecore_x_disp);
1569 int _ecore_window_grabs_num = 0;
1570 Window *_ecore_window_grabs = NULL;
1571 Eina_Bool (*_ecore_window_grab_replay_func)(void *data,
1574 void *_ecore_window_grab_replay_data;
1577 ecore_x_passive_grab_replay_func_set(Eina_Bool (*func)(void *data,
1582 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1583 _ecore_window_grab_replay_func = func;
1584 _ecore_window_grab_replay_data = data;
1588 ecore_x_window_button_grab(Ecore_X_Window win,
1590 Ecore_X_Event_Mask event_mask,
1596 unsigned int locks[8];
1600 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1605 m = _ecore_x_event_modifier(mod);
1610 locks[1] = ECORE_X_LOCK_CAPS;
1611 locks[2] = ECORE_X_LOCK_NUM;
1612 locks[3] = ECORE_X_LOCK_SCROLL;
1613 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1614 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1615 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1616 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1618 for (i = 0; i < 8; i++)
1619 XGrabButton(_ecore_x_disp, b, m | locks[i],
1620 win, False, ev, GrabModeSync, GrabModeAsync, None, None);
1621 _ecore_window_grabs_num++;
1622 t = realloc(_ecore_window_grabs,
1623 _ecore_window_grabs_num * sizeof(Window));
1625 _ecore_window_grabs = t;
1626 _ecore_window_grabs[_ecore_window_grabs_num - 1] = win;
1630 _ecore_x_sync_magic_send(int val,
1631 Ecore_X_Window swin)
1635 xev.xclient.type = ClientMessage;
1636 xev.xclient.serial = 0;
1637 xev.xclient.send_event = True;
1638 xev.xclient.display = _ecore_x_disp;
1639 xev.xclient.window = _ecore_x_private_win;
1640 xev.xclient.format = 32;
1641 xev.xclient.message_type = 27777;
1642 xev.xclient.data.l[0] = 0x7162534;
1643 xev.xclient.data.l[1] = 0x10000000 + val;
1644 xev.xclient.data.l[2] = swin;
1645 XSendEvent(_ecore_x_disp, _ecore_x_private_win, False, NoEventMask, &xev);
1649 _ecore_x_window_grab_remove(Ecore_X_Window win)
1654 if (_ecore_window_grabs_num > 0)
1656 for (i = 0; i < _ecore_window_grabs_num; i++)
1659 _ecore_window_grabs[i - 1] = _ecore_window_grabs[i];
1661 if ((!shuffle) && (_ecore_window_grabs[i] == win))
1666 _ecore_window_grabs_num--;
1667 if (_ecore_window_grabs_num <= 0)
1669 free(_ecore_window_grabs);
1670 _ecore_window_grabs = NULL;
1673 t = realloc(_ecore_window_grabs,
1674 _ecore_window_grabs_num *
1677 _ecore_window_grabs = t;
1683 ecore_x_window_button_ungrab(Ecore_X_Window win,
1690 unsigned int locks[8];
1693 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1698 m = _ecore_x_event_modifier(mod);
1703 locks[1] = ECORE_X_LOCK_CAPS;
1704 locks[2] = ECORE_X_LOCK_NUM;
1705 locks[3] = ECORE_X_LOCK_SCROLL;
1706 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1707 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1708 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1709 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1710 for (i = 0; i < 8; i++)
1711 XUngrabButton(_ecore_x_disp, b, m | locks[i], win);
1712 _ecore_x_sync_magic_send(1, win);
1715 int _ecore_key_grabs_num = 0;
1716 Window *_ecore_key_grabs = NULL;
1719 ecore_x_window_key_grab(Ecore_X_Window win,
1724 KeyCode keycode = 0;
1727 unsigned int locks[8];
1731 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1732 if (!strncmp(key, "Keycode-", 8))
1733 keycode = atoi(key + 8);
1736 keysym = XStringToKeysym(key);
1737 if (keysym == NoSymbol)
1740 keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key));
1746 m = _ecore_x_event_modifier(mod);
1751 locks[1] = ECORE_X_LOCK_CAPS;
1752 locks[2] = ECORE_X_LOCK_NUM;
1753 locks[3] = ECORE_X_LOCK_SCROLL;
1754 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1755 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1756 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1757 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1758 for (i = 0; i < 8; i++)
1759 XGrabKey(_ecore_x_disp, keycode, m | locks[i],
1760 win, False, GrabModeSync, GrabModeAsync);
1761 _ecore_key_grabs_num++;
1762 t = realloc(_ecore_key_grabs,
1763 _ecore_key_grabs_num * sizeof(Window));
1765 _ecore_key_grabs = t;
1766 _ecore_key_grabs[_ecore_key_grabs_num - 1] = win;
1770 _ecore_x_key_grab_remove(Ecore_X_Window win)
1775 if (_ecore_key_grabs_num > 0)
1777 for (i = 0; i < _ecore_key_grabs_num; i++)
1780 _ecore_key_grabs[i - 1] = _ecore_key_grabs[i];
1782 if ((!shuffle) && (_ecore_key_grabs[i] == win))
1787 _ecore_key_grabs_num--;
1788 if (_ecore_key_grabs_num <= 0)
1790 free(_ecore_key_grabs);
1791 _ecore_key_grabs = NULL;
1794 t = realloc(_ecore_key_grabs,
1795 _ecore_key_grabs_num * sizeof(Window));
1797 _ecore_key_grabs = t;
1803 ecore_x_window_key_ungrab(Ecore_X_Window win,
1808 KeyCode keycode = 0;
1811 unsigned int locks[8];
1814 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1815 if (!strncmp(key, "Keycode-", 8))
1816 keycode = atoi(key + 8);
1819 keysym = XStringToKeysym(key);
1820 if (keysym == NoSymbol)
1823 keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key));
1829 m = _ecore_x_event_modifier(mod);
1834 locks[1] = ECORE_X_LOCK_CAPS;
1835 locks[2] = ECORE_X_LOCK_NUM;
1836 locks[3] = ECORE_X_LOCK_SCROLL;
1837 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1838 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1839 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1840 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1841 for (i = 0; i < 8; i++)
1842 XUngrabKey(_ecore_x_disp, keycode, m | locks[i], win);
1843 _ecore_x_sync_magic_send(2, win);
1847 * Send client message with given type and format 32.
1849 * @param win The window the message is sent to.
1850 * @param type The client message type.
1851 * @param mask The mask of the message to be sent.
1852 * @param d0 The client message data item 1
1853 * @param d1 The client message data item 2
1854 * @param d2 The client message data item 3
1855 * @param d3 The client message data item 4
1856 * @param d4 The client message data item 5
1858 * @return @c EINA_TRUE on success @c EINA_FALSE otherwise.
1861 ecore_x_client_message32_send(Ecore_X_Window win,
1863 Ecore_X_Event_Mask mask,
1872 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1873 xev.xclient.window = win;
1874 xev.xclient.type = ClientMessage;
1875 xev.xclient.message_type = type;
1876 xev.xclient.format = 32;
1877 xev.xclient.data.l[0] = d0;
1878 xev.xclient.data.l[1] = d1;
1879 xev.xclient.data.l[2] = d2;
1880 xev.xclient.data.l[3] = d3;
1881 xev.xclient.data.l[4] = d4;
1883 return XSendEvent(_ecore_x_disp, win, False, mask, &xev) ? EINA_TRUE : EINA_FALSE;
1887 * Send client message with given type and format 8.
1889 * @param win The window the message is sent to.
1890 * @param type The client message type.
1891 * @param data Data to be sent.
1892 * @param len Number of data bytes, max @c 20.
1894 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
1897 ecore_x_client_message8_send(Ecore_X_Window win,
1904 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1905 xev.xclient.window = win;
1906 xev.xclient.type = ClientMessage;
1907 xev.xclient.message_type = type;
1908 xev.xclient.format = 8;
1912 memcpy(xev.xclient.data.b, data, len);
1913 memset(xev.xclient.data.b + len, 0, 20 - len);
1915 return XSendEvent(_ecore_x_disp, win, False, NoEventMask, &xev) ? EINA_TRUE : EINA_FALSE;
1919 ecore_x_mouse_move_send(Ecore_X_Window win,
1924 XWindowAttributes att;
1928 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1929 XGetWindowAttributes(_ecore_x_disp, win, &att);
1930 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1931 xev.xmotion.type = MotionNotify;
1932 xev.xmotion.window = win;
1933 xev.xmotion.root = att.root;
1934 xev.xmotion.subwindow = win;
1935 xev.xmotion.time = _ecore_x_event_last_time;
1938 xev.xmotion.x_root = rx;
1939 xev.xmotion.y_root = ry;
1940 xev.xmotion.state = 0;
1941 xev.xmotion.is_hint = 0;
1942 xev.xmotion.same_screen = 1;
1943 return XSendEvent(_ecore_x_disp, win, True, PointerMotionMask, &xev) ? EINA_TRUE : EINA_FALSE;
1947 ecore_x_mouse_down_send(Ecore_X_Window win,
1953 XWindowAttributes att;
1957 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1958 XGetWindowAttributes(_ecore_x_disp, win, &att);
1959 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1960 xev.xbutton.type = ButtonPress;
1961 xev.xbutton.window = win;
1962 xev.xbutton.root = att.root;
1963 xev.xbutton.subwindow = win;
1964 xev.xbutton.time = _ecore_x_event_last_time;
1967 xev.xbutton.x_root = rx;
1968 xev.xbutton.y_root = ry;
1969 xev.xbutton.state = 1 << b;
1970 xev.xbutton.button = b;
1971 xev.xbutton.same_screen = 1;
1972 return XSendEvent(_ecore_x_disp, win, True, ButtonPressMask, &xev) ? EINA_TRUE : EINA_FALSE;
1976 ecore_x_mouse_up_send(Ecore_X_Window win,
1982 XWindowAttributes att;
1986 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1987 XGetWindowAttributes(_ecore_x_disp, win, &att);
1988 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1989 xev.xbutton.type = ButtonRelease;
1990 xev.xbutton.window = win;
1991 xev.xbutton.root = att.root;
1992 xev.xbutton.subwindow = win;
1993 xev.xbutton.time = _ecore_x_event_last_time;
1996 xev.xbutton.x_root = rx;
1997 xev.xbutton.y_root = ry;
1998 xev.xbutton.state = 0;
1999 xev.xbutton.button = b;
2000 xev.xbutton.same_screen = 1;
2001 return XSendEvent(_ecore_x_disp, win, True, ButtonReleaseMask, &xev) ? EINA_TRUE : EINA_FALSE;
2005 ecore_x_mouse_in_send(Ecore_X_Window win,
2010 XWindowAttributes att;
2014 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2015 XGetWindowAttributes(_ecore_x_disp, win, &att);
2016 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
2017 xev.xcrossing.type = EnterNotify;
2018 xev.xcrossing.window = win;
2019 xev.xcrossing.root = att.root;
2020 xev.xcrossing.subwindow = win;
2021 xev.xcrossing.time = _ecore_x_event_last_time;
2022 xev.xcrossing.x = x;
2023 xev.xcrossing.y = y;
2024 xev.xcrossing.x_root = rx;
2025 xev.xcrossing.y_root = ry;
2026 xev.xcrossing.mode = NotifyNormal;
2027 xev.xcrossing.detail = NotifyNonlinear;
2028 xev.xcrossing.same_screen = 1;
2029 xev.xcrossing.focus = 0;
2030 xev.xcrossing.state = 0;
2031 return XSendEvent(_ecore_x_disp, win, True, EnterWindowMask, &xev) ? EINA_TRUE : EINA_FALSE;
2035 ecore_x_mouse_out_send(Ecore_X_Window win,
2040 XWindowAttributes att;
2044 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2045 XGetWindowAttributes(_ecore_x_disp, win, &att);
2046 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
2047 xev.xcrossing.type = LeaveNotify;
2048 xev.xcrossing.window = win;
2049 xev.xcrossing.root = att.root;
2050 xev.xcrossing.subwindow = win;
2051 xev.xcrossing.time = _ecore_x_event_last_time;
2052 xev.xcrossing.x = x;
2053 xev.xcrossing.y = y;
2054 xev.xcrossing.x_root = rx;
2055 xev.xcrossing.y_root = ry;
2056 xev.xcrossing.mode = NotifyNormal;
2057 xev.xcrossing.detail = NotifyNonlinear;
2058 xev.xcrossing.same_screen = 1;
2059 xev.xcrossing.focus = 0;
2060 xev.xcrossing.state = 0;
2061 return XSendEvent(_ecore_x_disp, win, True, LeaveWindowMask, &xev) ? EINA_TRUE : EINA_FALSE;
2065 ecore_x_focus_reset(void)
2067 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2068 XSetInputFocus(_ecore_x_disp, PointerRoot, RevertToPointerRoot, CurrentTime);
2072 ecore_x_events_allow_all(void)
2074 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2075 XAllowEvents(_ecore_x_disp, AsyncBoth, CurrentTime);
2079 ecore_x_pointer_last_xy_get(int *x,
2083 *x = _ecore_x_event_last_root_x;
2086 *y = _ecore_x_event_last_root_y;
2090 ecore_x_pointer_xy_get(Ecore_X_Window win,
2095 int rx, ry, wx, wy, ret;
2098 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2099 ret = XQueryPointer(_ecore_x_disp, win, &rwin, &cwin,
2100 &rx, &ry, &wx, &wy, &mask);
2109 * Retrieve the Visual ID from a given Visual.
2111 * @param visual The Visual to get the ID for.
2113 * @return The visual id.
2117 ecore_x_visual_id_get(Ecore_X_Visual visual)
2119 return XVisualIDFromVisual(visual);
2123 * Retrieve the default Visual.
2125 * @param disp The Display to get the Default Visual from
2126 * @param screen The Screen.
2128 * @return The default visual.
2132 ecore_x_default_visual_get(Ecore_X_Display *disp,
2133 Ecore_X_Screen *screen)
2135 return DefaultVisual(disp, ecore_x_screen_index_get(screen));
2139 * Retrieve the default Colormap.
2141 * @param disp The Display to get the Default Colormap from
2142 * @param screen The Screen.
2144 * @return The default colormap.
2147 EAPI Ecore_X_Colormap
2148 ecore_x_default_colormap_get(Ecore_X_Display *disp,
2149 Ecore_X_Screen *screen)
2151 return DefaultColormap(disp, ecore_x_screen_index_get(screen));
2155 * Retrieve the default depth.
2157 * @param disp The Display to get the Default Depth from
2158 * @param screen The Screen.
2160 * @return The default depth.
2164 ecore_x_default_depth_get(Ecore_X_Display *disp,
2165 Ecore_X_Screen *screen)
2167 return DefaultDepth(disp, ecore_x_screen_index_get(screen));
2171 ecore_x_xkb_select_group(int group)
2174 XkbLockGroup(_ecore_x_disp, XkbUseCoreKbd, group);
2178 /*****************************************************************************/
2179 /*****************************************************************************/
2180 /*****************************************************************************/
2183 _ecore_x_event_modifier(unsigned int state)
2187 if (state & ECORE_EVENT_MODIFIER_SHIFT)
2188 xmodifiers |= ECORE_X_MODIFIER_SHIFT;
2190 if (state & ECORE_EVENT_MODIFIER_CTRL)
2191 xmodifiers |= ECORE_X_MODIFIER_CTRL;
2193 if (state & ECORE_EVENT_MODIFIER_ALT)
2194 xmodifiers |= ECORE_X_MODIFIER_ALT;
2196 if (state & ECORE_EVENT_MODIFIER_WIN)
2197 xmodifiers |= ECORE_X_MODIFIER_WIN;
2199 if (state & ECORE_EVENT_MODIFIER_ALTGR)
2200 xmodifiers |= ECORE_X_MODIFIER_ALTGR;
2202 if (state & ECORE_EVENT_LOCK_SCROLL)
2203 xmodifiers |= ECORE_X_LOCK_SCROLL;
2205 if (state & ECORE_EVENT_LOCK_NUM)
2206 xmodifiers |= ECORE_X_LOCK_NUM;
2208 if (state & ECORE_EVENT_LOCK_CAPS)
2209 xmodifiers |= ECORE_X_LOCK_CAPS;
2211 if (state & ECORE_EVENT_LOCK_SHIFT)
2212 xmodifiers |= ECORE_X_LOCK_SHIFT;