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 */
53 static int _ecore_x_event_handlers_num = 0;
54 static void (**_ecore_x_event_handlers) (XEvent * event) = NULL;
56 static int _ecore_x_init_count = 0;
57 static int _ecore_x_grab_count = 0;
59 Display *_ecore_x_disp = NULL;
60 double _ecore_x_double_click_time = 0.25;
61 Time _ecore_x_event_last_time = 0;
62 Window _ecore_x_event_last_win = 0;
63 int _ecore_x_event_last_root_x = 0;
64 int _ecore_x_event_last_root_y = 0;
65 Eina_Bool _ecore_x_xcursor = EINA_FALSE;
67 Ecore_X_Window _ecore_x_private_win = 0;
69 Ecore_X_Atom _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_NUM];
71 EAPI int ECORE_X_EVENT_ANY = 0;
72 EAPI int ECORE_X_EVENT_MOUSE_IN = 0;
73 EAPI int ECORE_X_EVENT_MOUSE_OUT = 0;
74 EAPI int ECORE_X_EVENT_WINDOW_FOCUS_IN = 0;
75 EAPI int ECORE_X_EVENT_WINDOW_FOCUS_OUT = 0;
76 EAPI int ECORE_X_EVENT_WINDOW_KEYMAP = 0;
77 EAPI int ECORE_X_EVENT_WINDOW_DAMAGE = 0;
78 EAPI int ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE = 0;
79 EAPI int ECORE_X_EVENT_WINDOW_CREATE = 0;
80 EAPI int ECORE_X_EVENT_WINDOW_DESTROY = 0;
81 EAPI int ECORE_X_EVENT_WINDOW_HIDE = 0;
82 EAPI int ECORE_X_EVENT_WINDOW_SHOW = 0;
83 EAPI int ECORE_X_EVENT_WINDOW_SHOW_REQUEST = 0;
84 EAPI int ECORE_X_EVENT_WINDOW_REPARENT = 0;
85 EAPI int ECORE_X_EVENT_WINDOW_CONFIGURE = 0;
86 EAPI int ECORE_X_EVENT_WINDOW_CONFIGURE_REQUEST = 0;
87 EAPI int ECORE_X_EVENT_WINDOW_GRAVITY = 0;
88 EAPI int ECORE_X_EVENT_WINDOW_RESIZE_REQUEST = 0;
89 EAPI int ECORE_X_EVENT_WINDOW_STACK = 0;
90 EAPI int ECORE_X_EVENT_WINDOW_STACK_REQUEST = 0;
91 EAPI int ECORE_X_EVENT_WINDOW_PROPERTY = 0;
92 EAPI int ECORE_X_EVENT_WINDOW_COLORMAP = 0;
93 EAPI int ECORE_X_EVENT_WINDOW_MAPPING = 0;
94 EAPI int ECORE_X_EVENT_MAPPING_CHANGE = 0;
95 EAPI int ECORE_X_EVENT_SELECTION_CLEAR = 0;
96 EAPI int ECORE_X_EVENT_SELECTION_REQUEST = 0;
97 EAPI int ECORE_X_EVENT_SELECTION_NOTIFY = 0;
98 EAPI int ECORE_X_EVENT_FIXES_SELECTION_NOTIFY = 0;
99 EAPI int ECORE_X_EVENT_CLIENT_MESSAGE = 0;
100 EAPI int ECORE_X_EVENT_WINDOW_SHAPE = 0;
101 EAPI int ECORE_X_EVENT_SCREENSAVER_NOTIFY = 0;
102 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_FLICK;
103 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_PAN;
104 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_PINCHROTATION;
105 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_TAP;
106 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_TAPNHOLD;
107 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_HOLD;
108 EAPI int ECORE_X_EVENT_GESTURE_NOTIFY_GROUP;
109 EAPI int ECORE_X_EVENT_SYNC_COUNTER = 0;
110 EAPI int ECORE_X_EVENT_SYNC_ALARM = 0;
111 EAPI int ECORE_X_EVENT_SCREEN_CHANGE = 0;
112 EAPI int ECORE_X_EVENT_DAMAGE_NOTIFY = 0;
113 EAPI int ECORE_X_EVENT_RANDR_CRTC_CHANGE = 0;
114 EAPI int ECORE_X_EVENT_RANDR_OUTPUT_CHANGE = 0;
115 EAPI int ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY = 0;
116 EAPI int ECORE_X_EVENT_WINDOW_DELETE_REQUEST = 0;
117 EAPI int ECORE_X_EVENT_WINDOW_MOVE_RESIZE_REQUEST = 0;
118 EAPI int ECORE_X_EVENT_WINDOW_STATE_REQUEST = 0;
119 EAPI int ECORE_X_EVENT_FRAME_EXTENTS_REQUEST = 0;
120 EAPI int ECORE_X_EVENT_PING = 0;
121 EAPI int ECORE_X_EVENT_DESKTOP_CHANGE = 0;
123 EAPI int ECORE_X_EVENT_STARTUP_SEQUENCE_NEW = 0;
124 EAPI int ECORE_X_EVENT_STARTUP_SEQUENCE_CHANGE = 0;
125 EAPI int ECORE_X_EVENT_STARTUP_SEQUENCE_REMOVE = 0;
127 EAPI int ECORE_X_EVENT_GENERIC = 0;
129 int ECORE_X_MODIFIER_SHIFT = 0;
130 int ECORE_X_MODIFIER_CTRL = 0;
131 int ECORE_X_MODIFIER_ALT = 0;
132 int ECORE_X_MODIFIER_WIN = 0;
134 EAPI int ECORE_X_LOCK_SCROLL = 0;
135 EAPI int ECORE_X_LOCK_NUM = 0;
136 EAPI int ECORE_X_LOCK_CAPS = 0;
137 EAPI int ECORE_X_LOCK_SHIFT = 0;
140 static double t0 = 0.0;
141 static Status (*_logrt_real_reply)(Display *disp,
144 Bool discard) = NULL;
150 lib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
152 lib = dlopen("libX11.so.6", RTLD_GLOBAL | RTLD_LAZY);
155 lib = dlopen("libX11.so.6.3", RTLD_GLOBAL | RTLD_LAZY);
158 lib = dlopen("libX11.so.6.3.0", RTLD_GLOBAL | RTLD_LAZY);
160 _logrt_real_reply = dlsym(lib, "_XReply");
161 t0 = ecore_time_get();
165 _XReply(Display *disp,
174 n = backtrace(bt, 128);
177 sym = backtrace_symbols(bt, n);
178 printf("ROUNDTRIP: %4.4f :", ecore_time_get() - t0);
181 for (i = n - 1; i > 0; i--)
183 char *fname = strchr(sym[i], '(');
186 char *tsym = alloca(strlen(fname) + 1);
188 strcpy(tsym, fname + 1);
189 end = strchr(tsym, '+');
209 return _logrt_real_reply(disp, rep, extra, discard);
212 #endif /* ifdef LOGRT */
214 /* wrapper to use XkbKeycodeToKeysym when possible */
216 _ecore_x_XKeycodeToKeysym(Display *display, KeyCode keycode, int idx)
219 return XkbKeycodeToKeysym(display, keycode, 0, idx);
221 return XKeycodeToKeysym(display, keycode, idx);
225 _ecore_x_modifiers_get(void)
227 /* everything has these... unless its like a pda... :) */
228 ECORE_X_MODIFIER_SHIFT = _ecore_x_key_mask_get(XK_Shift_L);
229 ECORE_X_MODIFIER_CTRL = _ecore_x_key_mask_get(XK_Control_L);
231 /* apple's xdarwin has no alt!!!! */
232 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Alt_L);
233 if (!ECORE_X_MODIFIER_ALT)
234 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Meta_L);
236 if (!ECORE_X_MODIFIER_ALT)
237 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Super_L);
239 /* the windows key... a valid modifier :) */
240 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Super_L);
241 if (!ECORE_X_MODIFIER_WIN)
242 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Mode_switch);
244 if (!ECORE_X_MODIFIER_WIN)
245 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Meta_L);
247 if (ECORE_X_MODIFIER_WIN == ECORE_X_MODIFIER_ALT)
248 ECORE_X_MODIFIER_WIN = 0;
250 if (ECORE_X_MODIFIER_ALT == ECORE_X_MODIFIER_CTRL)
251 ECORE_X_MODIFIER_ALT = 0;
253 ECORE_X_LOCK_SCROLL = _ecore_x_key_mask_get(XK_Scroll_Lock);
254 ECORE_X_LOCK_NUM = _ecore_x_key_mask_get(XK_Num_Lock);
255 ECORE_X_LOCK_CAPS = _ecore_x_key_mask_get(XK_Caps_Lock);
256 ECORE_X_LOCK_SHIFT = _ecore_x_key_mask_get(XK_Shift_Lock);
260 * @defgroup Ecore_X_Init_Group X Library Init and Shutdown Functions
262 * Functions that start and shut down the Ecore X Library.
266 * Initialize the X display connection to the given display.
268 * @param name Display target name. If @c NULL, the default display is
270 * @return The number of times the library has been initialized without
271 * being shut down. 0 is returned if an error occurs.
272 * @ingroup Ecore_X_Init_Group
275 ecore_x_init(const char *name)
278 int shape_err_base = 0;
280 int screensaver_base = 0;
281 int screensaver_err_base = 0;
282 #endif /* ifdef ECORE_XSS */
284 int sync_err_base = 0;
287 int randr_err_base = 0;
288 #endif /* ifdef ECORE_XRANDR */
291 int fixes_err_base = 0;
292 #endif /* ifdef ECORE_XFIXES */
295 int damage_err_base = 0;
296 #endif /* ifdef ECORE_XDAMAGE */
297 #ifdef ECORE_XGESTURE
298 int gesture_base = 0;
299 int gesture_err_base = 0;
300 #endif /* ifdef ECORE_XGESTURE */
302 if (++_ecore_x_init_count != 1)
303 return _ecore_x_init_count;
305 LOGFN(__FILE__, __LINE__, __FUNCTION__);
308 #endif /* ifdef LOGRT */
311 _ecore_xlib_log_dom = eina_log_domain_register
312 ("ecore_x", ECORE_XLIB_DEFAULT_LOG_COLOR);
313 if (_ecore_xlib_log_dom < 0)
316 "Impossible to create a log domain for the Ecore Xlib module.");
317 return --_ecore_x_init_count;
322 if (!ecore_event_init())
325 #ifdef EVAS_FRAME_QUEUING
327 #endif /* ifdef EVAS_FRAME_QUEUING */
328 _ecore_x_disp = XOpenDisplay((char *)name);
330 goto shutdown_ecore_event;
332 _ecore_x_error_handler_init();
333 _ecore_x_event_handlers_num = LASTEvent;
335 #define ECORE_X_EVENT_HANDLERS_GROW(ext_base, ext_num_events) \
337 if (_ecore_x_event_handlers_num < (ext_base + ext_num_events)) { \
338 _ecore_x_event_handlers_num = (ext_base + ext_num_events); } \
341 if (XShapeQueryExtension(_ecore_x_disp, &shape_base, &shape_err_base))
342 _ecore_x_event_shape_id = shape_base;
344 ECORE_X_EVENT_HANDLERS_GROW(shape_base, ShapeNumberEvents);
347 if (XScreenSaverQueryExtension(_ecore_x_disp, &screensaver_base,
348 &screensaver_err_base))
349 _ecore_x_event_screensaver_id = screensaver_base;
351 ECORE_X_EVENT_HANDLERS_GROW(screensaver_base, ScreenSaverNumberEvents);
352 #endif /* ifdef ECORE_XSS */
354 if (XSyncQueryExtension(_ecore_x_disp, &sync_base, &sync_err_base))
358 _ecore_x_event_sync_id = sync_base;
359 if (!XSyncInitialize(_ecore_x_disp, &major, &minor))
360 _ecore_x_event_sync_id = 0;
363 ECORE_X_EVENT_HANDLERS_GROW(sync_base, XSyncNumberEvents);
366 if (XRRQueryExtension(_ecore_x_disp, &randr_base, &randr_err_base))
367 _ecore_x_event_randr_id = randr_base;
369 ECORE_X_EVENT_HANDLERS_GROW(randr_base, RRNumberEvents);
370 #endif /* ifdef ECORE_XRANDR */
373 if (XFixesQueryExtension(_ecore_x_disp, &fixes_base, &fixes_err_base))
374 _ecore_x_event_fixes_selection_id = fixes_base;
376 ECORE_X_EVENT_HANDLERS_GROW(fixes_base, XFixesNumberEvents);
377 #endif /* ifdef ECORE_XFIXES */
380 if (XDamageQueryExtension(_ecore_x_disp, &damage_base, &damage_err_base))
381 _ecore_x_event_damage_id = damage_base;
383 ECORE_X_EVENT_HANDLERS_GROW(damage_base, XDamageNumberEvents);
384 #endif /* ifdef ECORE_XDAMAGE */
386 #ifdef ECORE_XGESTURE
387 if (XGestureQueryExtension(_ecore_x_disp, &gesture_base, &gesture_err_base))
388 _ecore_x_event_gesture_id = gesture_base;
390 ECORE_X_EVENT_HANDLERS_GROW(gesture_base, GestureNumberEvents);
391 #endif /* ifdef ECORE_XGESTURE */
393 _ecore_x_event_handlers = calloc(_ecore_x_event_handlers_num, sizeof(void *));
394 if (!_ecore_x_event_handlers)
398 _ecore_x_xcursor = XcursorSupportsARGB(_ecore_x_disp) ? EINA_TRUE : EINA_FALSE;
399 #endif /* ifdef ECORE_XCURSOR */
400 _ecore_x_event_handlers[AnyXEvent] = _ecore_x_event_handle_any_event;
401 _ecore_x_event_handlers[KeyPress] = _ecore_x_event_handle_key_press;
402 _ecore_x_event_handlers[KeyRelease] = _ecore_x_event_handle_key_release;
403 _ecore_x_event_handlers[ButtonPress] = _ecore_x_event_handle_button_press;
404 _ecore_x_event_handlers[ButtonRelease] =
405 _ecore_x_event_handle_button_release;
406 _ecore_x_event_handlers[MotionNotify] = _ecore_x_event_handle_motion_notify;
407 _ecore_x_event_handlers[EnterNotify] = _ecore_x_event_handle_enter_notify;
408 _ecore_x_event_handlers[LeaveNotify] = _ecore_x_event_handle_leave_notify;
409 _ecore_x_event_handlers[FocusIn] = _ecore_x_event_handle_focus_in;
410 _ecore_x_event_handlers[FocusOut] = _ecore_x_event_handle_focus_out;
411 _ecore_x_event_handlers[KeymapNotify] = _ecore_x_event_handle_keymap_notify;
412 _ecore_x_event_handlers[Expose] = _ecore_x_event_handle_expose;
413 _ecore_x_event_handlers[GraphicsExpose] =
414 _ecore_x_event_handle_graphics_expose;
415 _ecore_x_event_handlers[VisibilityNotify] =
416 _ecore_x_event_handle_visibility_notify;
417 _ecore_x_event_handlers[CreateNotify] = _ecore_x_event_handle_create_notify;
418 _ecore_x_event_handlers[DestroyNotify] =
419 _ecore_x_event_handle_destroy_notify;
420 _ecore_x_event_handlers[UnmapNotify] = _ecore_x_event_handle_unmap_notify;
421 _ecore_x_event_handlers[MapNotify] = _ecore_x_event_handle_map_notify;
422 _ecore_x_event_handlers[MapRequest] = _ecore_x_event_handle_map_request;
423 _ecore_x_event_handlers[ReparentNotify] =
424 _ecore_x_event_handle_reparent_notify;
425 _ecore_x_event_handlers[ConfigureNotify] =
426 _ecore_x_event_handle_configure_notify;
427 _ecore_x_event_handlers[ConfigureRequest] =
428 _ecore_x_event_handle_configure_request;
429 _ecore_x_event_handlers[GravityNotify] =
430 _ecore_x_event_handle_gravity_notify;
431 _ecore_x_event_handlers[ResizeRequest] =
432 _ecore_x_event_handle_resize_request;
433 _ecore_x_event_handlers[CirculateNotify] =
434 _ecore_x_event_handle_circulate_notify;
435 _ecore_x_event_handlers[CirculateRequest] =
436 _ecore_x_event_handle_circulate_request;
437 _ecore_x_event_handlers[PropertyNotify] =
438 _ecore_x_event_handle_property_notify;
439 _ecore_x_event_handlers[SelectionClear] =
440 _ecore_x_event_handle_selection_clear;
441 _ecore_x_event_handlers[SelectionRequest] =
442 _ecore_x_event_handle_selection_request;
443 _ecore_x_event_handlers[SelectionNotify] =
444 _ecore_x_event_handle_selection_notify;
445 _ecore_x_event_handlers[ColormapNotify] =
446 _ecore_x_event_handle_colormap_notify;
447 _ecore_x_event_handlers[ClientMessage] =
448 _ecore_x_event_handle_client_message;
449 _ecore_x_event_handlers[MappingNotify] =
450 _ecore_x_event_handle_mapping_notify;
452 _ecore_x_event_handlers[GenericEvent] = _ecore_x_event_handle_generic_event;
453 #endif /* ifdef GenericEvent */
455 if (_ecore_x_event_shape_id)
456 _ecore_x_event_handlers[_ecore_x_event_shape_id] =
457 _ecore_x_event_handle_shape_change;
459 if (_ecore_x_event_screensaver_id)
460 _ecore_x_event_handlers[_ecore_x_event_screensaver_id] =
461 _ecore_x_event_handle_screensaver_notify;
463 if (_ecore_x_event_sync_id)
465 _ecore_x_event_handlers[_ecore_x_event_sync_id + XSyncCounterNotify] =
466 _ecore_x_event_handle_sync_counter;
467 _ecore_x_event_handlers[_ecore_x_event_sync_id + XSyncAlarmNotify] =
468 _ecore_x_event_handle_sync_alarm;
472 if (_ecore_x_event_randr_id)
474 _ecore_x_event_handlers[_ecore_x_event_randr_id +
475 RRScreenChangeNotify] =
476 _ecore_x_event_handle_randr_change;
477 _ecore_x_event_handlers[_ecore_x_event_randr_id +
478 RRNotify] = _ecore_x_event_handle_randr_notify;
481 #endif /* ifdef ECORE_XRANDR */
483 if (_ecore_x_event_fixes_selection_id)
484 _ecore_x_event_handlers[_ecore_x_event_fixes_selection_id] =
485 _ecore_x_event_handle_fixes_selection_notify;
487 #endif /* ifdef ECORE_XFIXES */
489 if (_ecore_x_event_damage_id)
490 _ecore_x_event_handlers[_ecore_x_event_damage_id] =
491 _ecore_x_event_handle_damage_notify;
493 #endif /* ifdef ECORE_XDAMAGE */
495 // set x autorepeat detection to on. that means instead of
496 // press-release-press-release-press-release
498 // press-press-press-press-press-release
502 XkbSetDetectableAutoRepeat(_ecore_x_disp, 1, &works);
505 #endif /* ifdef ECORE_XKB */
507 #ifdef ECORE_XGESTURE
508 if (_ecore_x_event_gesture_id)
510 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyFlick] =
511 _ecore_x_event_handle_gesture_notify_flick;
512 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyPan] =
513 _ecore_x_event_handle_gesture_notify_pan;
514 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyPinchRotation] =
515 _ecore_x_event_handle_gesture_notify_pinchrotation;
516 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyTap] =
517 _ecore_x_event_handle_gesture_notify_tap;
518 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyTapNHold] =
519 _ecore_x_event_handle_gesture_notify_tapnhold;
520 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyHold] =
521 _ecore_x_event_handle_gesture_notify_hold;
522 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyGroup] =
523 _ecore_x_event_handle_gesture_notify_group;
526 #endif /* ifdef ECORE_XGESTURE */
528 if (!ECORE_X_EVENT_ANY)
530 ECORE_X_EVENT_ANY = ecore_event_type_new();
531 ECORE_X_EVENT_MOUSE_IN = ecore_event_type_new();
532 ECORE_X_EVENT_MOUSE_OUT = ecore_event_type_new();
533 ECORE_X_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
534 ECORE_X_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
535 ECORE_X_EVENT_WINDOW_KEYMAP = ecore_event_type_new();
536 ECORE_X_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
537 ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE = ecore_event_type_new();
538 ECORE_X_EVENT_WINDOW_CREATE = ecore_event_type_new();
539 ECORE_X_EVENT_WINDOW_DESTROY = ecore_event_type_new();
540 ECORE_X_EVENT_WINDOW_HIDE = ecore_event_type_new();
541 ECORE_X_EVENT_WINDOW_SHOW = ecore_event_type_new();
542 ECORE_X_EVENT_WINDOW_SHOW_REQUEST = ecore_event_type_new();
543 ECORE_X_EVENT_WINDOW_REPARENT = ecore_event_type_new();
544 ECORE_X_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
545 ECORE_X_EVENT_WINDOW_CONFIGURE_REQUEST = ecore_event_type_new();
546 ECORE_X_EVENT_WINDOW_GRAVITY = ecore_event_type_new();
547 ECORE_X_EVENT_WINDOW_RESIZE_REQUEST = ecore_event_type_new();
548 ECORE_X_EVENT_WINDOW_STACK = ecore_event_type_new();
549 ECORE_X_EVENT_WINDOW_STACK_REQUEST = ecore_event_type_new();
550 ECORE_X_EVENT_WINDOW_PROPERTY = ecore_event_type_new();
551 ECORE_X_EVENT_WINDOW_COLORMAP = ecore_event_type_new();
552 ECORE_X_EVENT_WINDOW_MAPPING = ecore_event_type_new();
553 ECORE_X_EVENT_MAPPING_CHANGE = ecore_event_type_new();
554 ECORE_X_EVENT_SELECTION_CLEAR = ecore_event_type_new();
555 ECORE_X_EVENT_SELECTION_REQUEST = ecore_event_type_new();
556 ECORE_X_EVENT_SELECTION_NOTIFY = ecore_event_type_new();
557 ECORE_X_EVENT_CLIENT_MESSAGE = ecore_event_type_new();
558 ECORE_X_EVENT_WINDOW_SHAPE = ecore_event_type_new();
559 ECORE_X_EVENT_SCREENSAVER_NOTIFY = ecore_event_type_new();
560 ECORE_X_EVENT_GESTURE_NOTIFY_FLICK = ecore_event_type_new();
561 ECORE_X_EVENT_GESTURE_NOTIFY_PAN = ecore_event_type_new();
562 ECORE_X_EVENT_GESTURE_NOTIFY_PINCHROTATION = ecore_event_type_new();
563 ECORE_X_EVENT_GESTURE_NOTIFY_TAP = ecore_event_type_new();
564 ECORE_X_EVENT_GESTURE_NOTIFY_TAPNHOLD = ecore_event_type_new();
565 ECORE_X_EVENT_GESTURE_NOTIFY_HOLD = ecore_event_type_new();
566 ECORE_X_EVENT_GESTURE_NOTIFY_GROUP = ecore_event_type_new();
567 ECORE_X_EVENT_SYNC_COUNTER = ecore_event_type_new();
568 ECORE_X_EVENT_SYNC_ALARM = ecore_event_type_new();
569 ECORE_X_EVENT_SCREEN_CHANGE = ecore_event_type_new();
570 ECORE_X_EVENT_RANDR_CRTC_CHANGE = ecore_event_type_new();
571 ECORE_X_EVENT_RANDR_OUTPUT_CHANGE = ecore_event_type_new();
572 ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY = ecore_event_type_new();
573 ECORE_X_EVENT_DAMAGE_NOTIFY = ecore_event_type_new();
575 ECORE_X_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
577 ECORE_X_EVENT_DESKTOP_CHANGE = ecore_event_type_new();
578 ECORE_X_EVENT_WINDOW_MOVE_RESIZE_REQUEST = ecore_event_type_new();
579 ECORE_X_EVENT_WINDOW_STATE_REQUEST = ecore_event_type_new();
580 ECORE_X_EVENT_FRAME_EXTENTS_REQUEST = ecore_event_type_new();
581 ECORE_X_EVENT_PING = ecore_event_type_new();
583 ECORE_X_EVENT_STARTUP_SEQUENCE_NEW = ecore_event_type_new();
584 ECORE_X_EVENT_STARTUP_SEQUENCE_CHANGE = ecore_event_type_new();
585 ECORE_X_EVENT_STARTUP_SEQUENCE_REMOVE = ecore_event_type_new();
587 ECORE_X_EVENT_GENERIC = ecore_event_type_new();
590 _ecore_x_modifiers_get();
592 _ecore_x_fd_handler_handle =
593 ecore_main_fd_handler_add(ConnectionNumber(_ecore_x_disp),
595 _ecore_x_fd_handler, _ecore_x_disp,
596 _ecore_x_fd_handler_buf, _ecore_x_disp);
597 if (!_ecore_x_fd_handler_handle)
598 goto free_event_handlers;
600 _ecore_x_atoms_init();
602 /* Set up the ICCCM hints */
603 ecore_x_icccm_init();
605 /* Set up the _NET_... hints */
606 ecore_x_netwm_init();
608 /* old e hints init */
611 /* This is just to be anal about naming conventions */
613 _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_DELETE_REQUEST] =
614 ECORE_X_ATOM_WM_DELETE_WINDOW;
615 _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_TAKE_FOCUS] =
616 ECORE_X_ATOM_WM_TAKE_FOCUS;
617 _ecore_x_atoms_wm_protocols[ECORE_X_NET_WM_PROTOCOL_PING] =
618 ECORE_X_ATOM_NET_WM_PING;
619 _ecore_x_atoms_wm_protocols[ECORE_X_NET_WM_PROTOCOL_SYNC_REQUEST] =
620 ECORE_X_ATOM_NET_WM_SYNC_REQUEST;
622 _ecore_x_selection_data_init();
624 _ecore_x_fixes_init();
625 _ecore_x_damage_init();
626 _ecore_x_composite_init();
627 _ecore_x_dpms_init();
628 _ecore_x_randr_init();
629 _ecore_x_gesture_init();
630 _ecore_x_input_init();
631 _ecore_x_events_init();
633 _ecore_x_private_win = ecore_x_window_override_new(0, -77, -777, 123, 456);
635 return _ecore_x_init_count;
638 free(_ecore_x_event_handlers);
639 _ecore_x_event_handlers = NULL;
641 XCloseDisplay(_ecore_x_disp);
642 _ecore_x_fd_handler_handle = NULL;
643 _ecore_x_disp = NULL;
644 shutdown_ecore_event:
645 ecore_event_shutdown();
649 eina_log_domain_unregister(_ecore_xlib_log_dom);
650 _ecore_xlib_log_dom = -1;
653 return --_ecore_x_init_count;
657 _ecore_x_shutdown(int close_display)
659 if (--_ecore_x_init_count != 0)
660 return _ecore_x_init_count;
663 return _ecore_x_init_count;
665 LOGFN(__FILE__, __LINE__, __FUNCTION__);
667 ecore_main_fd_handler_del(_ecore_x_fd_handler_handle);
669 XCloseDisplay(_ecore_x_disp);
672 close(ConnectionNumber(_ecore_x_disp));
673 // FIXME: may have to clean up x display internal here
674 // getting segv here? hmmm. odd. disable
675 // XFree(_ecore_x_disp);
678 free(_ecore_x_event_handlers);
679 _ecore_x_fd_handler_handle = NULL;
680 _ecore_x_disp = NULL;
681 _ecore_x_event_handlers = NULL;
682 _ecore_x_events_shutdown();
683 _ecore_x_input_shutdown();
684 _ecore_x_selection_shutdown();
685 _ecore_x_dnd_shutdown();
686 ecore_x_netwm_shutdown();
688 ecore_event_shutdown();
691 eina_log_domain_unregister(_ecore_xlib_log_dom);
692 _ecore_xlib_log_dom = -1;
695 return _ecore_x_init_count;
699 * Shuts down the Ecore X library.
701 * In shutting down the library, the X display connection is terminated
702 * and any event handlers for it are removed.
704 * @return The number of times the library has been initialized without
705 * being shut down. 0 is returned if an error occurs.
706 * @ingroup Ecore_X_Init_Group
709 ecore_x_shutdown(void)
711 return _ecore_x_shutdown(1);
715 * Shuts down the Ecore X library.
717 * As ecore_x_shutdown, except do not close Display, only connection.
719 * @ingroup Ecore_X_Init_Group
722 ecore_x_disconnect(void)
724 return _ecore_x_shutdown(0);
728 * @defgroup Ecore_X_Display_Attr_Group X Display Attributes
730 * Functions that set and retrieve X display attributes.
734 * Retrieves the Ecore_X_Display handle used for the current X connection.
735 * @return The current X display.
736 * @ingroup Ecore_X_Display_Attr_Group
738 EAPI Ecore_X_Display *
739 ecore_x_display_get(void)
741 return (Ecore_X_Display *)_ecore_x_disp;
745 * Retrieves the X display file descriptor.
746 * @return The current X display file descriptor.
747 * @ingroup Ecore_X_Display_Attr_Group
752 LOGFN(__FILE__, __LINE__, __FUNCTION__);
753 return ConnectionNumber(_ecore_x_disp);
757 * Retrieves the Ecore_X_Screen handle used for the current X connection.
758 * @return The current default screen.
759 * @ingroup Ecore_X_Display_Attr_Group
761 EAPI Ecore_X_Screen *
762 ecore_x_default_screen_get(void)
764 LOGFN(__FILE__, __LINE__, __FUNCTION__);
765 return (Ecore_X_Screen *)DefaultScreenOfDisplay(_ecore_x_disp);
769 * Retrieves the size of an Ecore_X_Screen.
770 * @param screen the handle to the screen to query.
771 * @param w where to return the width. May be NULL. Returns 0 on errors.
772 * @param h where to return the height. May be NULL. Returns 0 on errors.
773 * @ingroup Ecore_X_Display_Attr_Group
774 * @see ecore_x_default_screen_get()
779 ecore_x_screen_size_get(const Ecore_X_Screen *screen,
783 Screen *s = (Screen *)screen;
784 LOGFN(__FILE__, __LINE__, __FUNCTION__);
788 if (w) *w = s->width;
789 if (h) *h = s->height;
793 * Retrieves the number of screens.
795 * @return The count of the number of screens.
796 * @ingroup Ecore_X_Display_Attr_Group
801 ecore_x_screen_count_get(void)
803 LOGFN(__FILE__, __LINE__, __FUNCTION__);
805 return ScreenCount(_ecore_x_disp);
809 * Retrieves the index number of the given screen.
811 * @param screen The screen for which the index will be retrieved.
812 * @return The index number of the screen.
813 * @ingroup Ecore_X_Display_Attr_Group
818 ecore_x_screen_index_get(const Ecore_X_Screen *screen)
820 return XScreenNumberOfScreen((Screen *)screen);
824 * Retrieves the screen based on index number.
826 * @param idx The index that will be used to retrieve the screen.
827 * @return The Ecore_X_Screen at this index.
828 * @ingroup Ecore_X_Display_Attr_Group
832 EAPI Ecore_X_Screen *
833 ecore_x_screen_get(int idx)
835 return XScreenOfDisplay(_ecore_x_disp, idx);
839 * Sets the timeout for a double and triple clicks to be flagged.
841 * This sets the time between clicks before the double_click flag is
842 * set in a button down event. If 3 clicks occur within double this
843 * time, the triple_click flag is also set.
845 * @param t The time in seconds
846 * @ingroup Ecore_X_Display_Attr_Group
849 ecore_x_double_click_time_set(double t)
854 _ecore_x_double_click_time = t;
858 * Retrieves the double and triple click flag timeout.
860 * See @ref ecore_x_double_click_time_set for more information.
862 * @return The timeout for double clicks in seconds.
863 * @ingroup Ecore_X_Display_Attr_Group
866 ecore_x_double_click_time_get(void)
868 return _ecore_x_double_click_time;
872 * @defgroup Ecore_X_Flush_Group X Synchronization Functions
874 * Functions that ensure that all commands that have been issued by the
875 * Ecore X library have been sent to the server.
879 * Sends all X commands in the X Display buffer.
880 * @ingroup Ecore_X_Flush_Group
885 LOGFN(__FILE__, __LINE__, __FUNCTION__);
886 XFlush(_ecore_x_disp);
890 * Flushes the command buffer and waits until all requests have been
891 * processed by the server.
892 * @ingroup Ecore_X_Flush_Group
897 LOGFN(__FILE__, __LINE__, __FUNCTION__);
898 XSync(_ecore_x_disp, False);
902 * Kill all clients with subwindows under a given window.
904 * You can kill all clients connected to the X server by using
905 * @ref ecore_x_window_root_list to get a list of root windows, and
906 * then passing each root window to this function.
908 * @param root The window whose children will be killed.
911 ecore_x_killall(Ecore_X_Window root)
916 Window *children_r = NULL;
917 unsigned int num_children = 0;
919 LOGFN(__FILE__, __LINE__, __FUNCTION__);
920 XGrabServer(_ecore_x_disp);
921 /* Tranverse window tree starting from root, and drag each
922 * before the firing squad */
923 while (XQueryTree(_ecore_x_disp, root, &root_r, &parent_r,
924 &children_r, &num_children) && (num_children > 0))
926 for (j = 0; j < num_children; ++j)
928 XKillClient(_ecore_x_disp, children_r[j]);
933 XUngrabServer(_ecore_x_disp);
934 XSync(_ecore_x_disp, False);
938 * Kill a specific client
940 * You can kill a specific client owning window @p win
942 * @param win Window of the client to be killed
945 ecore_x_kill(Ecore_X_Window win)
947 LOGFN(__FILE__, __LINE__, __FUNCTION__);
948 XKillClient(_ecore_x_disp, win);
952 * Return the last event time
955 ecore_x_current_time_get(void)
957 return _ecore_x_event_last_time;
961 * Return the screen DPI
963 * This is a simplistic call to get DPI. It does not account for differing
964 * DPI in the x amd y axes nor does it account for multihead or xinerama and
965 * xrander where different parts of the screen may have different DPI etc.
967 * @return the general screen DPI (dots/pixels per inch).
970 ecore_x_dpi_get(void)
974 LOGFN(__FILE__, __LINE__, __FUNCTION__);
975 s = DefaultScreenOfDisplay(_ecore_x_disp);
979 return (((s->width * 254) / s->mwidth) + 5) / 10;
983 * Invoke the standard system beep to alert users
985 * @param percent The volume at which the bell rings. Must be in the range
986 * [-100,+100]. If percent >= 0, the final volume will be:
987 * base - [(base * percent) / 100] + percent
988 * Otherwise, it's calculated as:
989 * base + [(base * percent) / 100]
990 * where @c base is the bell's base volume as set by XChangeKeyboardControl(3).
992 * @returns @c EINA_TRUE on success, @c EINA_FALSE otherwise.
995 ecore_x_bell(int percent)
999 ret = XBell(_ecore_x_disp, percent);
1000 if (ret == BadValue)
1007 _ecore_x_fd_handler(void *data,
1008 Ecore_Fd_Handler *fd_handler __UNUSED__)
1020 /* Filter event for XIM */
1021 if (XFilterEvent(&ev, ev.xkey.window))
1024 #endif /* ifdef ENABLE_XIM */
1026 if ((ev.type >= 0) && (ev.type < _ecore_x_event_handlers_num))
1028 if (_ecore_x_event_handlers[AnyXEvent])
1029 _ecore_x_event_handlers[AnyXEvent] (&ev);
1031 if (_ecore_x_event_handlers[ev.type])
1032 _ecore_x_event_handlers[ev.type] (&ev);
1035 return ECORE_CALLBACK_RENEW;
1039 _ecore_x_fd_handler_buf(void *data,
1040 Ecore_Fd_Handler *fd_handler __UNUSED__)
1046 return ECORE_CALLBACK_RENEW;
1048 return ECORE_CALLBACK_CANCEL;
1052 _ecore_x_key_mask_get(KeySym sym)
1054 XModifierKeymap *mod;
1057 const int masks[8] =
1059 ShiftMask, LockMask, ControlMask,
1060 Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
1063 mod = XGetModifierMapping(_ecore_x_disp);
1064 if ((mod) && (mod->max_keypermod > 0))
1065 for (i = 0; i < (8 * mod->max_keypermod); i++)
1067 for (j = 0; j < 8; j++)
1069 sym2 = _ecore_x_XKeycodeToKeysym(_ecore_x_disp,
1070 mod->modifiermap[i], j);
1078 mask = masks[i / mod->max_keypermod];
1079 if (mod->modifiermap)
1080 XFree(mod->modifiermap);
1089 if (mod->modifiermap)
1090 XFree(mod->modifiermap);
1098 /*****************************************************************************/
1099 /*****************************************************************************/
1100 /*****************************************************************************/
1101 /* FIXME: these funcs need categorising */
1102 /*****************************************************************************/
1105 * Get a list of all the root windows on the server.
1107 * @note The returned array will need to be freed after use.
1108 * @param num_ret Pointer to integer to put number of windows returned in.
1109 * @return An array of all the root windows. @c NULL is returned if memory
1110 * could not be allocated for the list, or if @p num_ret is @c NULL.
1112 EAPI Ecore_X_Window *
1113 ecore_x_window_root_list(int *num_ret)
1116 Ecore_X_Window *roots;
1118 int xp_base, xp_err_base;
1119 #endif /* ifdef ECORE_XPRINT */
1126 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1128 num = ScreenCount(_ecore_x_disp);
1129 if (XpQueryExtension(_ecore_x_disp, &xp_base, &xp_err_base))
1134 ps = XpQueryScreens(_ecore_x_disp, &psnum);
1140 for (i = 0; i < num; i++)
1142 for (j = 0; j < psnum; j++)
1144 if (ScreenOfDisplay(_ecore_x_disp, i) == ps[j])
1148 roots = malloc(MAX((num - overlap) * sizeof(Window), 1));
1154 for (i = 0; i < num; i++)
1159 for (j = 0; j < psnum; j++)
1161 if (ScreenOfDisplay(_ecore_x_disp, i) == ps[j])
1169 roots[k] = RootWindow(_ecore_x_disp, i);
1180 roots = malloc(num * sizeof(Window));
1185 for (i = 0; i < num; i++)
1186 roots[i] = RootWindow(_ecore_x_disp, i);
1191 roots = malloc(num * sizeof(Window));
1196 for (i = 0; i < num; i++)
1197 roots[i] = RootWindow(_ecore_x_disp, i);
1200 #else /* ifdef ECORE_XPRINT */
1201 num = ScreenCount(_ecore_x_disp);
1202 roots = malloc(num * sizeof(Window));
1207 for (i = 0; i < num; i++)
1208 roots[i] = RootWindow(_ecore_x_disp, i);
1209 #endif /* ifdef ECORE_XPRINT */
1214 ecore_x_window_root_first_get(void)
1216 return RootWindow(_ecore_x_disp, 0);
1219 Ecore_X_Window root, *roots = NULL;
1221 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1222 roots = ecore_x_window_root_list(&num);
1223 if (!(roots)) return 0;
1235 static void _ecore_x_window_manage_error(void *data);
1237 static int _ecore_x_window_manage_failed = 0;
1239 _ecore_x_window_manage_error(void *data __UNUSED__)
1241 if ((ecore_x_error_request_get() == X_ChangeWindowAttributes) &&
1242 (ecore_x_error_code_get() == BadAccess))
1243 _ecore_x_window_manage_failed = 1;
1247 ecore_x_window_manage(Ecore_X_Window win)
1249 XWindowAttributes att;
1251 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1252 if (XGetWindowAttributes(_ecore_x_disp, win, &att) != True)
1256 _ecore_x_window_manage_failed = 0;
1257 ecore_x_error_handler_set(_ecore_x_window_manage_error, NULL);
1258 XSelectInput(_ecore_x_disp, win,
1261 PropertyChangeMask |
1262 ResizeRedirectMask |
1263 SubstructureRedirectMask |
1264 SubstructureNotifyMask |
1265 StructureNotifyMask |
1268 att.your_event_mask);
1270 ecore_x_error_handler_set(NULL, NULL);
1271 if (_ecore_x_window_manage_failed)
1273 _ecore_x_window_manage_failed = 0;
1281 ecore_x_window_container_manage(Ecore_X_Window win)
1283 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1284 XSelectInput(_ecore_x_disp, win,
1285 SubstructureRedirectMask |
1286 SubstructureNotifyMask);
1290 ecore_x_window_client_manage(Ecore_X_Window win)
1292 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1293 XSelectInput(_ecore_x_disp, win,
1294 PropertyChangeMask |
1295 // ResizeRedirectMask |
1297 ColormapChangeMask |
1298 VisibilityChangeMask |
1299 StructureNotifyMask |
1300 SubstructureNotifyMask
1302 XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
1306 ecore_x_window_sniff(Ecore_X_Window win)
1308 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1309 XSelectInput(_ecore_x_disp, win,
1310 PropertyChangeMask |
1311 SubstructureNotifyMask);
1315 ecore_x_window_client_sniff(Ecore_X_Window win)
1317 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1318 XSelectInput(_ecore_x_disp, win,
1319 PropertyChangeMask |
1321 ColormapChangeMask |
1322 VisibilityChangeMask |
1323 StructureNotifyMask |
1324 SubstructureNotifyMask);
1325 XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
1329 ecore_x_window_attributes_get(Ecore_X_Window win,
1330 Ecore_X_Window_Attributes *att_ret)
1332 XWindowAttributes att;
1334 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1335 if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
1338 memset(att_ret, 0, sizeof(Ecore_X_Window_Attributes));
1339 att_ret->root = att.root;
1342 att_ret->w = att.width;
1343 att_ret->h = att.height;
1344 att_ret->border = att.border_width;
1345 att_ret->depth = att.depth;
1346 if (att.map_state != IsUnmapped)
1347 att_ret->visible = 1;
1349 if (att.map_state == IsViewable)
1350 att_ret->viewable = 1;
1352 if (att.override_redirect)
1353 att_ret->override = 1;
1355 if (att.class == InputOnly)
1356 att_ret->input_only = 1;
1359 att_ret->save_under = 1;
1361 att_ret->event_mask.mine = att.your_event_mask;
1362 att_ret->event_mask.all = att.all_event_masks;
1363 att_ret->event_mask.no_propagate = att.do_not_propagate_mask;
1364 att_ret->window_gravity = att.win_gravity;
1365 att_ret->pixel_gravity = att.bit_gravity;
1366 att_ret->colormap = att.colormap;
1367 att_ret->visual = att.visual;
1372 ecore_x_window_save_set_add(Ecore_X_Window win)
1374 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1375 XAddToSaveSet(_ecore_x_disp, win);
1379 ecore_x_window_save_set_del(Ecore_X_Window win)
1381 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1382 XRemoveFromSaveSet(_ecore_x_disp, win);
1385 EAPI Ecore_X_Window *
1386 ecore_x_window_children_get(Ecore_X_Window win,
1389 Ecore_X_Window *windows = NULL;
1390 Window root_ret = 0, parent_ret = 0, *children_ret = NULL;
1391 unsigned int children_ret_num = 0;
1393 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1394 if (!XQueryTree(_ecore_x_disp, win, &root_ret, &parent_ret, &children_ret,
1400 windows = malloc(children_ret_num * sizeof(Ecore_X_Window));
1405 for (i = 0; i < children_ret_num; i++)
1406 windows[i] = children_ret[i];
1407 *num = children_ret_num;
1410 XFree(children_ret);
1417 ecore_x_pointer_control_set(int accel_num,
1421 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1422 return XChangePointerControl(_ecore_x_disp, 1, 1,
1423 accel_num, accel_denom, threshold) ? EINA_TRUE : EINA_FALSE;
1427 ecore_x_pointer_control_get(int *accel_num,
1431 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1432 return XGetPointerControl(_ecore_x_disp,
1433 accel_num, accel_denom, threshold) ? EINA_TRUE : EINA_FALSE;
1437 ecore_x_pointer_mapping_set(unsigned char *map,
1440 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1441 return (XSetPointerMapping(_ecore_x_disp, map, nmap) == MappingSuccess) ? EINA_TRUE : EINA_FALSE;
1445 ecore_x_pointer_mapping_get(unsigned char *map,
1448 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1449 return XGetPointerMapping(_ecore_x_disp, map, nmap) ? EINA_TRUE : EINA_FALSE;
1453 ecore_x_pointer_grab(Ecore_X_Window win)
1455 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1456 if (XGrabPointer(_ecore_x_disp, win, False,
1457 ButtonPressMask | ButtonReleaseMask |
1458 EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1459 GrabModeAsync, GrabModeAsync,
1460 None, None, CurrentTime) == GrabSuccess)
1467 ecore_x_pointer_confine_grab(Ecore_X_Window win)
1469 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1470 if (XGrabPointer(_ecore_x_disp, win, False,
1471 ButtonPressMask | ButtonReleaseMask |
1472 EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1473 GrabModeAsync, GrabModeAsync,
1474 win, None, CurrentTime) == GrabSuccess)
1481 ecore_x_pointer_ungrab(void)
1483 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1484 XUngrabPointer(_ecore_x_disp, CurrentTime);
1488 ecore_x_pointer_warp(Ecore_X_Window win,
1492 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1493 return XWarpPointer(_ecore_x_disp, None, win, 0, 0, 0, 0, x, y) ? EINA_TRUE : EINA_FALSE;
1497 ecore_x_keyboard_grab(Ecore_X_Window win)
1499 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1500 if (XGrabKeyboard(_ecore_x_disp, win, False,
1501 GrabModeAsync, GrabModeAsync,
1502 CurrentTime) == GrabSuccess)
1509 ecore_x_keyboard_ungrab(void)
1511 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1512 XUngrabKeyboard(_ecore_x_disp, CurrentTime);
1518 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1519 _ecore_x_grab_count++;
1520 if (_ecore_x_grab_count == 1)
1521 XGrabServer(_ecore_x_disp);
1525 ecore_x_ungrab(void)
1527 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1528 _ecore_x_grab_count--;
1529 if (_ecore_x_grab_count < 0)
1530 _ecore_x_grab_count = 0;
1532 if (_ecore_x_grab_count == 0)
1533 XUngrabServer(_ecore_x_disp);
1536 int _ecore_window_grabs_num = 0;
1537 Window *_ecore_window_grabs = NULL;
1538 Eina_Bool (*_ecore_window_grab_replay_func)(void *data,
1541 void *_ecore_window_grab_replay_data;
1544 ecore_x_passive_grab_replay_func_set(Eina_Bool (*func)(void *data,
1549 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1550 _ecore_window_grab_replay_func = func;
1551 _ecore_window_grab_replay_data = data;
1555 ecore_x_window_button_grab(Ecore_X_Window win,
1557 Ecore_X_Event_Mask event_mask,
1563 unsigned int locks[8];
1567 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1572 m = _ecore_x_event_modifier(mod);
1577 locks[1] = ECORE_X_LOCK_CAPS;
1578 locks[2] = ECORE_X_LOCK_NUM;
1579 locks[3] = ECORE_X_LOCK_SCROLL;
1580 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1581 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1582 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1583 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1585 for (i = 0; i < 8; i++)
1586 XGrabButton(_ecore_x_disp, b, m | locks[i],
1587 win, False, ev, GrabModeSync, GrabModeAsync, None, None);
1588 _ecore_window_grabs_num++;
1589 t = realloc(_ecore_window_grabs,
1590 _ecore_window_grabs_num * sizeof(Window));
1592 _ecore_window_grabs = t;
1593 _ecore_window_grabs[_ecore_window_grabs_num - 1] = win;
1597 _ecore_x_sync_magic_send(int val,
1598 Ecore_X_Window swin)
1602 xev.xclient.type = ClientMessage;
1603 xev.xclient.serial = 0;
1604 xev.xclient.send_event = True;
1605 xev.xclient.display = _ecore_x_disp;
1606 xev.xclient.window = _ecore_x_private_win;
1607 xev.xclient.format = 32;
1608 xev.xclient.message_type = 27777;
1609 xev.xclient.data.l[0] = 0x7162534;
1610 xev.xclient.data.l[1] = 0x10000000 + val;
1611 xev.xclient.data.l[2] = swin;
1612 XSendEvent(_ecore_x_disp, _ecore_x_private_win, False, NoEventMask, &xev);
1616 _ecore_x_window_grab_remove(Ecore_X_Window win)
1621 if (_ecore_window_grabs_num > 0)
1623 for (i = 0; i < _ecore_window_grabs_num; i++)
1626 _ecore_window_grabs[i - 1] = _ecore_window_grabs[i];
1628 if ((!shuffle) && (_ecore_window_grabs[i] == win))
1633 _ecore_window_grabs_num--;
1634 if (_ecore_window_grabs_num <= 0)
1636 free(_ecore_window_grabs);
1637 _ecore_window_grabs = NULL;
1640 t = realloc(_ecore_window_grabs,
1641 _ecore_window_grabs_num *
1644 _ecore_window_grabs = t;
1650 ecore_x_window_button_ungrab(Ecore_X_Window win,
1657 unsigned int locks[8];
1660 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1665 m = _ecore_x_event_modifier(mod);
1670 locks[1] = ECORE_X_LOCK_CAPS;
1671 locks[2] = ECORE_X_LOCK_NUM;
1672 locks[3] = ECORE_X_LOCK_SCROLL;
1673 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1674 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1675 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1676 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1677 for (i = 0; i < 8; i++)
1678 XUngrabButton(_ecore_x_disp, b, m | locks[i], win);
1679 _ecore_x_sync_magic_send(1, win);
1682 int _ecore_key_grabs_num = 0;
1683 Window *_ecore_key_grabs = NULL;
1686 ecore_x_window_key_grab(Ecore_X_Window win,
1691 KeyCode keycode = 0;
1694 unsigned int locks[8];
1698 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1699 if (!strncmp(key, "Keycode-", 8))
1700 keycode = atoi(key + 8);
1703 keysym = XStringToKeysym(key);
1704 if (keysym == NoSymbol)
1707 keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key));
1713 m = _ecore_x_event_modifier(mod);
1718 locks[1] = ECORE_X_LOCK_CAPS;
1719 locks[2] = ECORE_X_LOCK_NUM;
1720 locks[3] = ECORE_X_LOCK_SCROLL;
1721 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1722 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1723 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1724 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1725 for (i = 0; i < 8; i++)
1726 XGrabKey(_ecore_x_disp, keycode, m | locks[i],
1727 win, False, GrabModeSync, GrabModeAsync);
1728 _ecore_key_grabs_num++;
1729 t = realloc(_ecore_key_grabs,
1730 _ecore_key_grabs_num * sizeof(Window));
1732 _ecore_key_grabs = t;
1733 _ecore_key_grabs[_ecore_key_grabs_num - 1] = win;
1737 _ecore_x_key_grab_remove(Ecore_X_Window win)
1742 if (_ecore_key_grabs_num > 0)
1744 for (i = 0; i < _ecore_key_grabs_num; i++)
1747 _ecore_key_grabs[i - 1] = _ecore_key_grabs[i];
1749 if ((!shuffle) && (_ecore_key_grabs[i] == win))
1754 _ecore_key_grabs_num--;
1755 if (_ecore_key_grabs_num <= 0)
1757 free(_ecore_key_grabs);
1758 _ecore_key_grabs = NULL;
1761 t = realloc(_ecore_key_grabs,
1762 _ecore_key_grabs_num * sizeof(Window));
1764 _ecore_key_grabs = t;
1770 ecore_x_window_key_ungrab(Ecore_X_Window win,
1775 KeyCode keycode = 0;
1778 unsigned int locks[8];
1781 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1782 if (!strncmp(key, "Keycode-", 8))
1783 keycode = atoi(key + 8);
1786 keysym = XStringToKeysym(key);
1787 if (keysym == NoSymbol)
1790 keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key));
1796 m = _ecore_x_event_modifier(mod);
1801 locks[1] = ECORE_X_LOCK_CAPS;
1802 locks[2] = ECORE_X_LOCK_NUM;
1803 locks[3] = ECORE_X_LOCK_SCROLL;
1804 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1805 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1806 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1807 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1808 for (i = 0; i < 8; i++)
1809 XUngrabKey(_ecore_x_disp, keycode, m | locks[i], win);
1810 _ecore_x_sync_magic_send(2, win);
1814 * Send client message with given type and format 32.
1816 * @param win The window the message is sent to.
1817 * @param type The client message type.
1818 * @param mask The mask of the message to be sent.
1819 * @param d0 The client message data item 1
1820 * @param d1 The client message data item 2
1821 * @param d2 The client message data item 3
1822 * @param d3 The client message data item 4
1823 * @param d4 The client message data item 5
1825 * @return @c EINA_TRUE on success @c EINA_FALSE otherwise.
1828 ecore_x_client_message32_send(Ecore_X_Window win,
1830 Ecore_X_Event_Mask mask,
1839 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1840 xev.xclient.window = win;
1841 xev.xclient.type = ClientMessage;
1842 xev.xclient.message_type = type;
1843 xev.xclient.format = 32;
1844 xev.xclient.data.l[0] = d0;
1845 xev.xclient.data.l[1] = d1;
1846 xev.xclient.data.l[2] = d2;
1847 xev.xclient.data.l[3] = d3;
1848 xev.xclient.data.l[4] = d4;
1850 return XSendEvent(_ecore_x_disp, win, False, mask, &xev) ? EINA_TRUE : EINA_FALSE;
1854 * Send client message with given type and format 8.
1856 * @param win The window the message is sent to.
1857 * @param type The client message type.
1858 * @param data Data to be sent.
1859 * @param len Number of data bytes, max @c 20.
1861 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
1864 ecore_x_client_message8_send(Ecore_X_Window win,
1871 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1872 xev.xclient.window = win;
1873 xev.xclient.type = ClientMessage;
1874 xev.xclient.message_type = type;
1875 xev.xclient.format = 8;
1879 memcpy(xev.xclient.data.b, data, len);
1880 memset(xev.xclient.data.b + len, 0, 20 - len);
1882 return XSendEvent(_ecore_x_disp, win, False, NoEventMask, &xev) ? EINA_TRUE : EINA_FALSE;
1886 ecore_x_mouse_move_send(Ecore_X_Window win,
1891 XWindowAttributes att;
1895 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1896 XGetWindowAttributes(_ecore_x_disp, win, &att);
1897 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1898 xev.xmotion.type = MotionNotify;
1899 xev.xmotion.window = win;
1900 xev.xmotion.root = att.root;
1901 xev.xmotion.subwindow = win;
1902 xev.xmotion.time = _ecore_x_event_last_time;
1905 xev.xmotion.x_root = rx;
1906 xev.xmotion.y_root = ry;
1907 xev.xmotion.state = 0;
1908 xev.xmotion.is_hint = 0;
1909 xev.xmotion.same_screen = 1;
1910 return XSendEvent(_ecore_x_disp, win, True, PointerMotionMask, &xev) ? EINA_TRUE : EINA_FALSE;
1914 ecore_x_mouse_down_send(Ecore_X_Window win,
1920 XWindowAttributes att;
1924 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1925 XGetWindowAttributes(_ecore_x_disp, win, &att);
1926 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1927 xev.xbutton.type = ButtonPress;
1928 xev.xbutton.window = win;
1929 xev.xbutton.root = att.root;
1930 xev.xbutton.subwindow = win;
1931 xev.xbutton.time = _ecore_x_event_last_time;
1934 xev.xbutton.x_root = rx;
1935 xev.xbutton.y_root = ry;
1936 xev.xbutton.state = 1 << b;
1937 xev.xbutton.button = b;
1938 xev.xbutton.same_screen = 1;
1939 return XSendEvent(_ecore_x_disp, win, True, ButtonPressMask, &xev) ? EINA_TRUE : EINA_FALSE;
1943 ecore_x_mouse_up_send(Ecore_X_Window win,
1949 XWindowAttributes att;
1953 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1954 XGetWindowAttributes(_ecore_x_disp, win, &att);
1955 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1956 xev.xbutton.type = ButtonRelease;
1957 xev.xbutton.window = win;
1958 xev.xbutton.root = att.root;
1959 xev.xbutton.subwindow = win;
1960 xev.xbutton.time = _ecore_x_event_last_time;
1963 xev.xbutton.x_root = rx;
1964 xev.xbutton.y_root = ry;
1965 xev.xbutton.state = 0;
1966 xev.xbutton.button = b;
1967 xev.xbutton.same_screen = 1;
1968 return XSendEvent(_ecore_x_disp, win, True, ButtonReleaseMask, &xev) ? EINA_TRUE : EINA_FALSE;
1972 ecore_x_mouse_in_send(Ecore_X_Window win,
1977 XWindowAttributes att;
1981 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1982 XGetWindowAttributes(_ecore_x_disp, win, &att);
1983 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1984 xev.xcrossing.type = EnterNotify;
1985 xev.xcrossing.window = win;
1986 xev.xcrossing.root = att.root;
1987 xev.xcrossing.subwindow = win;
1988 xev.xcrossing.time = _ecore_x_event_last_time;
1989 xev.xcrossing.x = x;
1990 xev.xcrossing.y = y;
1991 xev.xcrossing.x_root = rx;
1992 xev.xcrossing.y_root = ry;
1993 xev.xcrossing.mode = NotifyNormal;
1994 xev.xcrossing.detail = NotifyNonlinear;
1995 xev.xcrossing.same_screen = 1;
1996 xev.xcrossing.focus = 0;
1997 xev.xcrossing.state = 0;
1998 return XSendEvent(_ecore_x_disp, win, True, EnterWindowMask, &xev) ? EINA_TRUE : EINA_FALSE;
2002 ecore_x_mouse_out_send(Ecore_X_Window win,
2007 XWindowAttributes att;
2011 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2012 XGetWindowAttributes(_ecore_x_disp, win, &att);
2013 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
2014 xev.xcrossing.type = LeaveNotify;
2015 xev.xcrossing.window = win;
2016 xev.xcrossing.root = att.root;
2017 xev.xcrossing.subwindow = win;
2018 xev.xcrossing.time = _ecore_x_event_last_time;
2019 xev.xcrossing.x = x;
2020 xev.xcrossing.y = y;
2021 xev.xcrossing.x_root = rx;
2022 xev.xcrossing.y_root = ry;
2023 xev.xcrossing.mode = NotifyNormal;
2024 xev.xcrossing.detail = NotifyNonlinear;
2025 xev.xcrossing.same_screen = 1;
2026 xev.xcrossing.focus = 0;
2027 xev.xcrossing.state = 0;
2028 return XSendEvent(_ecore_x_disp, win, True, LeaveWindowMask, &xev) ? EINA_TRUE : EINA_FALSE;
2032 ecore_x_focus_reset(void)
2034 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2035 XSetInputFocus(_ecore_x_disp, PointerRoot, RevertToPointerRoot, CurrentTime);
2039 ecore_x_events_allow_all(void)
2041 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2042 XAllowEvents(_ecore_x_disp, AsyncBoth, CurrentTime);
2046 ecore_x_pointer_last_xy_get(int *x,
2050 *x = _ecore_x_event_last_root_x;
2053 *y = _ecore_x_event_last_root_y;
2057 ecore_x_pointer_xy_get(Ecore_X_Window win,
2062 int rx, ry, wx, wy, ret;
2065 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2066 ret = XQueryPointer(_ecore_x_disp, win, &rwin, &cwin,
2067 &rx, &ry, &wx, &wy, &mask);
2076 * Retrieve the Visual ID from a given Visual.
2078 * @param visual The Visual to get the ID for.
2080 * @return The visual id.
2084 ecore_x_visual_id_get(Ecore_X_Visual visual)
2086 return XVisualIDFromVisual(visual);
2090 * Retrieve the default Visual.
2092 * @param disp The Display to get the Default Visual from
2093 * @param screen The Screen.
2095 * @return The default visual.
2099 ecore_x_default_visual_get(Ecore_X_Display *disp,
2100 Ecore_X_Screen *screen)
2102 return DefaultVisual(disp, ecore_x_screen_index_get(screen));
2106 * Retrieve the default Colormap.
2108 * @param disp The Display to get the Default Colormap from
2109 * @param screen The Screen.
2111 * @return The default colormap.
2114 EAPI Ecore_X_Colormap
2115 ecore_x_default_colormap_get(Ecore_X_Display *disp,
2116 Ecore_X_Screen *screen)
2118 return DefaultColormap(disp, ecore_x_screen_index_get(screen));
2122 * Retrieve the default depth.
2124 * @param disp The Display to get the Default Depth from
2125 * @param screen The Screen.
2127 * @return The default depth.
2131 ecore_x_default_depth_get(Ecore_X_Display *disp,
2132 Ecore_X_Screen *screen)
2134 return DefaultDepth(disp, ecore_x_screen_index_get(screen));
2137 /*****************************************************************************/
2138 /*****************************************************************************/
2139 /*****************************************************************************/
2142 _ecore_x_event_modifier(unsigned int state)
2146 if (state & ECORE_EVENT_MODIFIER_SHIFT)
2147 xmodifiers |= ECORE_X_MODIFIER_SHIFT;
2149 if (state & ECORE_EVENT_MODIFIER_CTRL)
2150 xmodifiers |= ECORE_X_MODIFIER_CTRL;
2152 if (state & ECORE_EVENT_MODIFIER_ALT)
2153 xmodifiers |= ECORE_X_MODIFIER_ALT;
2155 if (state & ECORE_EVENT_MODIFIER_WIN)
2156 xmodifiers |= ECORE_X_MODIFIER_WIN;
2158 if (state & ECORE_EVENT_LOCK_SCROLL)
2159 xmodifiers |= ECORE_X_LOCK_SCROLL;
2161 if (state & ECORE_EVENT_LOCK_NUM)
2162 xmodifiers |= ECORE_X_LOCK_NUM;
2164 if (state & ECORE_EVENT_LOCK_CAPS)
2165 xmodifiers |= ECORE_X_LOCK_CAPS;
2167 if (state & ECORE_EVENT_LOCK_SHIFT)
2168 xmodifiers |= ECORE_X_LOCK_SHIFT;