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 */
215 _ecore_x_modifiers_get(void)
217 /* everything has these... unless its like a pda... :) */
218 ECORE_X_MODIFIER_SHIFT = _ecore_x_key_mask_get(XK_Shift_L);
219 ECORE_X_MODIFIER_CTRL = _ecore_x_key_mask_get(XK_Control_L);
221 /* apple's xdarwin has no alt!!!! */
222 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Alt_L);
223 if (!ECORE_X_MODIFIER_ALT)
224 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Meta_L);
226 if (!ECORE_X_MODIFIER_ALT)
227 ECORE_X_MODIFIER_ALT = _ecore_x_key_mask_get(XK_Super_L);
229 /* the windows key... a valid modifier :) */
230 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Super_L);
231 if (!ECORE_X_MODIFIER_WIN)
232 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Mode_switch);
234 if (!ECORE_X_MODIFIER_WIN)
235 ECORE_X_MODIFIER_WIN = _ecore_x_key_mask_get(XK_Meta_L);
237 if (ECORE_X_MODIFIER_WIN == ECORE_X_MODIFIER_ALT)
238 ECORE_X_MODIFIER_WIN = 0;
240 if (ECORE_X_MODIFIER_ALT == ECORE_X_MODIFIER_CTRL)
241 ECORE_X_MODIFIER_ALT = 0;
243 ECORE_X_LOCK_SCROLL = _ecore_x_key_mask_get(XK_Scroll_Lock);
244 ECORE_X_LOCK_NUM = _ecore_x_key_mask_get(XK_Num_Lock);
245 ECORE_X_LOCK_CAPS = _ecore_x_key_mask_get(XK_Caps_Lock);
246 ECORE_X_LOCK_SHIFT = _ecore_x_key_mask_get(XK_Shift_Lock);
250 * @defgroup Ecore_X_Init_Group X Library Init and Shutdown Functions
252 * Functions that start and shut down the Ecore X Library.
256 * Initialize the X display connection to the given display.
258 * @param name Display target name. If @c NULL, the default display is
260 * @return The number of times the library has been initialized without
261 * being shut down. 0 is returned if an error occurs.
262 * @ingroup Ecore_X_Init_Group
265 ecore_x_init(const char *name)
268 int shape_err_base = 0;
270 int screensaver_base = 0;
271 int screensaver_err_base = 0;
272 #endif /* ifdef ECORE_XSS */
274 int sync_err_base = 0;
277 int randr_err_base = 0;
278 #endif /* ifdef ECORE_XRANDR */
281 int fixes_err_base = 0;
282 #endif /* ifdef ECORE_XFIXES */
285 int damage_err_base = 0;
286 #endif /* ifdef ECORE_XDAMAGE */
287 #ifdef ECORE_XGESTURE
288 int gesture_base = 0;
289 int gesture_err_base = 0;
290 #endif /* ifdef ECORE_XGESTURE */
292 if (++_ecore_x_init_count != 1)
293 return _ecore_x_init_count;
295 LOGFN(__FILE__, __LINE__, __FUNCTION__);
298 #endif /* ifdef LOGRT */
301 _ecore_xlib_log_dom = eina_log_domain_register
302 ("ecore_x", ECORE_XLIB_DEFAULT_LOG_COLOR);
303 if (_ecore_xlib_log_dom < 0)
306 "Impossible to create a log domain for the Ecore Xlib module.");
307 return --_ecore_x_init_count;
312 if (!ecore_event_init())
315 #ifdef EVAS_FRAME_QUEUING
317 #endif /* ifdef EVAS_FRAME_QUEUING */
318 _ecore_x_disp = XOpenDisplay((char *)name);
320 goto shutdown_ecore_event;
322 _ecore_x_error_handler_init();
323 _ecore_x_event_handlers_num = LASTEvent;
325 #define ECORE_X_EVENT_HANDLERS_GROW(ext_base, ext_num_events) \
327 if (_ecore_x_event_handlers_num < (ext_base + ext_num_events)) { \
328 _ecore_x_event_handlers_num = (ext_base + ext_num_events); } \
331 if (XShapeQueryExtension(_ecore_x_disp, &shape_base, &shape_err_base))
332 _ecore_x_event_shape_id = shape_base;
334 ECORE_X_EVENT_HANDLERS_GROW(shape_base, ShapeNumberEvents);
337 if (XScreenSaverQueryExtension(_ecore_x_disp, &screensaver_base,
338 &screensaver_err_base))
339 _ecore_x_event_screensaver_id = screensaver_base;
341 ECORE_X_EVENT_HANDLERS_GROW(screensaver_base, ScreenSaverNumberEvents);
342 #endif /* ifdef ECORE_XSS */
344 if (XSyncQueryExtension(_ecore_x_disp, &sync_base, &sync_err_base))
348 _ecore_x_event_sync_id = sync_base;
349 if (!XSyncInitialize(_ecore_x_disp, &major, &minor))
350 _ecore_x_event_sync_id = 0;
353 ECORE_X_EVENT_HANDLERS_GROW(sync_base, XSyncNumberEvents);
356 if (XRRQueryExtension(_ecore_x_disp, &randr_base, &randr_err_base))
357 _ecore_x_event_randr_id = randr_base;
359 ECORE_X_EVENT_HANDLERS_GROW(randr_base, RRNumberEvents);
360 #endif /* ifdef ECORE_XRANDR */
363 if (XFixesQueryExtension(_ecore_x_disp, &fixes_base, &fixes_err_base))
364 _ecore_x_event_fixes_selection_id = fixes_base;
366 ECORE_X_EVENT_HANDLERS_GROW(fixes_base, XFixesNumberEvents);
367 #endif /* ifdef ECORE_XFIXES */
370 if (XDamageQueryExtension(_ecore_x_disp, &damage_base, &damage_err_base))
371 _ecore_x_event_damage_id = damage_base;
373 ECORE_X_EVENT_HANDLERS_GROW(damage_base, XDamageNumberEvents);
374 #endif /* ifdef ECORE_XDAMAGE */
376 #ifdef ECORE_XGESTURE
377 if (XGestureQueryExtension(_ecore_x_disp, &gesture_base, &gesture_err_base))
378 _ecore_x_event_gesture_id = gesture_base;
380 ECORE_X_EVENT_HANDLERS_GROW(gesture_base, GestureNumberEvents);
381 #endif /* ifdef ECORE_XGESTURE */
383 _ecore_x_event_handlers = calloc(_ecore_x_event_handlers_num, sizeof(void *));
384 if (!_ecore_x_event_handlers)
388 _ecore_x_xcursor = XcursorSupportsARGB(_ecore_x_disp) ? EINA_TRUE : EINA_FALSE;
389 #endif /* ifdef ECORE_XCURSOR */
390 _ecore_x_event_handlers[AnyXEvent] = _ecore_x_event_handle_any_event;
391 _ecore_x_event_handlers[KeyPress] = _ecore_x_event_handle_key_press;
392 _ecore_x_event_handlers[KeyRelease] = _ecore_x_event_handle_key_release;
393 _ecore_x_event_handlers[ButtonPress] = _ecore_x_event_handle_button_press;
394 _ecore_x_event_handlers[ButtonRelease] =
395 _ecore_x_event_handle_button_release;
396 _ecore_x_event_handlers[MotionNotify] = _ecore_x_event_handle_motion_notify;
397 _ecore_x_event_handlers[EnterNotify] = _ecore_x_event_handle_enter_notify;
398 _ecore_x_event_handlers[LeaveNotify] = _ecore_x_event_handle_leave_notify;
399 _ecore_x_event_handlers[FocusIn] = _ecore_x_event_handle_focus_in;
400 _ecore_x_event_handlers[FocusOut] = _ecore_x_event_handle_focus_out;
401 _ecore_x_event_handlers[KeymapNotify] = _ecore_x_event_handle_keymap_notify;
402 _ecore_x_event_handlers[Expose] = _ecore_x_event_handle_expose;
403 _ecore_x_event_handlers[GraphicsExpose] =
404 _ecore_x_event_handle_graphics_expose;
405 _ecore_x_event_handlers[VisibilityNotify] =
406 _ecore_x_event_handle_visibility_notify;
407 _ecore_x_event_handlers[CreateNotify] = _ecore_x_event_handle_create_notify;
408 _ecore_x_event_handlers[DestroyNotify] =
409 _ecore_x_event_handle_destroy_notify;
410 _ecore_x_event_handlers[UnmapNotify] = _ecore_x_event_handle_unmap_notify;
411 _ecore_x_event_handlers[MapNotify] = _ecore_x_event_handle_map_notify;
412 _ecore_x_event_handlers[MapRequest] = _ecore_x_event_handle_map_request;
413 _ecore_x_event_handlers[ReparentNotify] =
414 _ecore_x_event_handle_reparent_notify;
415 _ecore_x_event_handlers[ConfigureNotify] =
416 _ecore_x_event_handle_configure_notify;
417 _ecore_x_event_handlers[ConfigureRequest] =
418 _ecore_x_event_handle_configure_request;
419 _ecore_x_event_handlers[GravityNotify] =
420 _ecore_x_event_handle_gravity_notify;
421 _ecore_x_event_handlers[ResizeRequest] =
422 _ecore_x_event_handle_resize_request;
423 _ecore_x_event_handlers[CirculateNotify] =
424 _ecore_x_event_handle_circulate_notify;
425 _ecore_x_event_handlers[CirculateRequest] =
426 _ecore_x_event_handle_circulate_request;
427 _ecore_x_event_handlers[PropertyNotify] =
428 _ecore_x_event_handle_property_notify;
429 _ecore_x_event_handlers[SelectionClear] =
430 _ecore_x_event_handle_selection_clear;
431 _ecore_x_event_handlers[SelectionRequest] =
432 _ecore_x_event_handle_selection_request;
433 _ecore_x_event_handlers[SelectionNotify] =
434 _ecore_x_event_handle_selection_notify;
435 _ecore_x_event_handlers[ColormapNotify] =
436 _ecore_x_event_handle_colormap_notify;
437 _ecore_x_event_handlers[ClientMessage] =
438 _ecore_x_event_handle_client_message;
439 _ecore_x_event_handlers[MappingNotify] =
440 _ecore_x_event_handle_mapping_notify;
442 _ecore_x_event_handlers[GenericEvent] = _ecore_x_event_handle_generic_event;
443 #endif /* ifdef GenericEvent */
445 if (_ecore_x_event_shape_id)
446 _ecore_x_event_handlers[_ecore_x_event_shape_id] =
447 _ecore_x_event_handle_shape_change;
449 if (_ecore_x_event_screensaver_id)
450 _ecore_x_event_handlers[_ecore_x_event_screensaver_id] =
451 _ecore_x_event_handle_screensaver_notify;
453 if (_ecore_x_event_sync_id)
455 _ecore_x_event_handlers[_ecore_x_event_sync_id + XSyncCounterNotify] =
456 _ecore_x_event_handle_sync_counter;
457 _ecore_x_event_handlers[_ecore_x_event_sync_id + XSyncAlarmNotify] =
458 _ecore_x_event_handle_sync_alarm;
462 if (_ecore_x_event_randr_id)
464 _ecore_x_event_handlers[_ecore_x_event_randr_id +
465 RRScreenChangeNotify] =
466 _ecore_x_event_handle_randr_change;
467 _ecore_x_event_handlers[_ecore_x_event_randr_id +
468 RRNotify] = _ecore_x_event_handle_randr_notify;
471 #endif /* ifdef ECORE_XRANDR */
473 if (_ecore_x_event_fixes_selection_id)
474 _ecore_x_event_handlers[_ecore_x_event_fixes_selection_id] =
475 _ecore_x_event_handle_fixes_selection_notify;
477 #endif /* ifdef ECORE_XFIXES */
479 if (_ecore_x_event_damage_id)
480 _ecore_x_event_handlers[_ecore_x_event_damage_id] =
481 _ecore_x_event_handle_damage_notify;
483 #endif /* ifdef ECORE_XDAMAGE */
485 // set x autorepeat detection to on. that means instead of
486 // press-release-press-release-press-release
488 // press-press-press-press-press-release
492 XkbSetDetectableAutoRepeat(_ecore_x_disp, 1, &works);
495 #endif /* ifdef ECORE_XKB */
497 #ifdef ECORE_XGESTURE
498 if (_ecore_x_event_gesture_id)
500 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyFlick] =
501 _ecore_x_event_handle_gesture_notify_flick;
502 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyPan] =
503 _ecore_x_event_handle_gesture_notify_pan;
504 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyPinchRotation] =
505 _ecore_x_event_handle_gesture_notify_pinchrotation;
506 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyTap] =
507 _ecore_x_event_handle_gesture_notify_tap;
508 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyTapNHold] =
509 _ecore_x_event_handle_gesture_notify_tapnhold;
510 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyHold] =
511 _ecore_x_event_handle_gesture_notify_hold;
512 _ecore_x_event_handlers[_ecore_x_event_gesture_id + GestureNotifyGroup] =
513 _ecore_x_event_handle_gesture_notify_group;
516 #endif /* ifdef ECORE_XGESTURE */
518 if (!ECORE_X_EVENT_ANY)
520 ECORE_X_EVENT_ANY = ecore_event_type_new();
521 ECORE_X_EVENT_MOUSE_IN = ecore_event_type_new();
522 ECORE_X_EVENT_MOUSE_OUT = ecore_event_type_new();
523 ECORE_X_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
524 ECORE_X_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
525 ECORE_X_EVENT_WINDOW_KEYMAP = ecore_event_type_new();
526 ECORE_X_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
527 ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE = ecore_event_type_new();
528 ECORE_X_EVENT_WINDOW_CREATE = ecore_event_type_new();
529 ECORE_X_EVENT_WINDOW_DESTROY = ecore_event_type_new();
530 ECORE_X_EVENT_WINDOW_HIDE = ecore_event_type_new();
531 ECORE_X_EVENT_WINDOW_SHOW = ecore_event_type_new();
532 ECORE_X_EVENT_WINDOW_SHOW_REQUEST = ecore_event_type_new();
533 ECORE_X_EVENT_WINDOW_REPARENT = ecore_event_type_new();
534 ECORE_X_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
535 ECORE_X_EVENT_WINDOW_CONFIGURE_REQUEST = ecore_event_type_new();
536 ECORE_X_EVENT_WINDOW_GRAVITY = ecore_event_type_new();
537 ECORE_X_EVENT_WINDOW_RESIZE_REQUEST = ecore_event_type_new();
538 ECORE_X_EVENT_WINDOW_STACK = ecore_event_type_new();
539 ECORE_X_EVENT_WINDOW_STACK_REQUEST = ecore_event_type_new();
540 ECORE_X_EVENT_WINDOW_PROPERTY = ecore_event_type_new();
541 ECORE_X_EVENT_WINDOW_COLORMAP = ecore_event_type_new();
542 ECORE_X_EVENT_WINDOW_MAPPING = ecore_event_type_new();
543 ECORE_X_EVENT_MAPPING_CHANGE = ecore_event_type_new();
544 ECORE_X_EVENT_SELECTION_CLEAR = ecore_event_type_new();
545 ECORE_X_EVENT_SELECTION_REQUEST = ecore_event_type_new();
546 ECORE_X_EVENT_SELECTION_NOTIFY = ecore_event_type_new();
547 ECORE_X_EVENT_CLIENT_MESSAGE = ecore_event_type_new();
548 ECORE_X_EVENT_WINDOW_SHAPE = ecore_event_type_new();
549 ECORE_X_EVENT_SCREENSAVER_NOTIFY = ecore_event_type_new();
550 ECORE_X_EVENT_GESTURE_NOTIFY_FLICK = ecore_event_type_new();
551 ECORE_X_EVENT_GESTURE_NOTIFY_PAN = ecore_event_type_new();
552 ECORE_X_EVENT_GESTURE_NOTIFY_PINCHROTATION = ecore_event_type_new();
553 ECORE_X_EVENT_GESTURE_NOTIFY_TAP = ecore_event_type_new();
554 ECORE_X_EVENT_GESTURE_NOTIFY_TAPNHOLD = ecore_event_type_new();
555 ECORE_X_EVENT_GESTURE_NOTIFY_HOLD = ecore_event_type_new();
556 ECORE_X_EVENT_GESTURE_NOTIFY_GROUP = ecore_event_type_new();
557 ECORE_X_EVENT_SYNC_COUNTER = ecore_event_type_new();
558 ECORE_X_EVENT_SYNC_ALARM = ecore_event_type_new();
559 ECORE_X_EVENT_SCREEN_CHANGE = ecore_event_type_new();
560 ECORE_X_EVENT_RANDR_CRTC_CHANGE = ecore_event_type_new();
561 ECORE_X_EVENT_RANDR_OUTPUT_CHANGE = ecore_event_type_new();
562 ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY = ecore_event_type_new();
563 ECORE_X_EVENT_DAMAGE_NOTIFY = ecore_event_type_new();
565 ECORE_X_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
567 ECORE_X_EVENT_DESKTOP_CHANGE = ecore_event_type_new();
568 ECORE_X_EVENT_WINDOW_MOVE_RESIZE_REQUEST = ecore_event_type_new();
569 ECORE_X_EVENT_WINDOW_STATE_REQUEST = ecore_event_type_new();
570 ECORE_X_EVENT_FRAME_EXTENTS_REQUEST = ecore_event_type_new();
571 ECORE_X_EVENT_PING = ecore_event_type_new();
573 ECORE_X_EVENT_STARTUP_SEQUENCE_NEW = ecore_event_type_new();
574 ECORE_X_EVENT_STARTUP_SEQUENCE_CHANGE = ecore_event_type_new();
575 ECORE_X_EVENT_STARTUP_SEQUENCE_REMOVE = ecore_event_type_new();
577 ECORE_X_EVENT_GENERIC = ecore_event_type_new();
580 _ecore_x_modifiers_get();
582 _ecore_x_fd_handler_handle =
583 ecore_main_fd_handler_add(ConnectionNumber(_ecore_x_disp),
585 _ecore_x_fd_handler, _ecore_x_disp,
586 _ecore_x_fd_handler_buf, _ecore_x_disp);
587 if (!_ecore_x_fd_handler_handle)
588 goto free_event_handlers;
590 _ecore_x_atoms_init();
592 /* Set up the ICCCM hints */
593 ecore_x_icccm_init();
595 /* Set up the _NET_... hints */
596 ecore_x_netwm_init();
598 /* old e hints init */
601 /* This is just to be anal about naming conventions */
603 _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_DELETE_REQUEST] =
604 ECORE_X_ATOM_WM_DELETE_WINDOW;
605 _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_TAKE_FOCUS] =
606 ECORE_X_ATOM_WM_TAKE_FOCUS;
607 _ecore_x_atoms_wm_protocols[ECORE_X_NET_WM_PROTOCOL_PING] =
608 ECORE_X_ATOM_NET_WM_PING;
609 _ecore_x_atoms_wm_protocols[ECORE_X_NET_WM_PROTOCOL_SYNC_REQUEST] =
610 ECORE_X_ATOM_NET_WM_SYNC_REQUEST;
612 _ecore_x_selection_data_init();
614 _ecore_x_fixes_init();
615 _ecore_x_damage_init();
616 _ecore_x_composite_init();
617 _ecore_x_dpms_init();
618 _ecore_x_randr_init();
619 _ecore_x_gesture_init();
620 _ecore_x_input_init();
621 _ecore_x_events_init();
623 _ecore_x_private_win = ecore_x_window_override_new(0, -77, -777, 123, 456);
625 return _ecore_x_init_count;
628 free(_ecore_x_event_handlers);
629 _ecore_x_event_handlers = NULL;
631 XCloseDisplay(_ecore_x_disp);
632 _ecore_x_fd_handler_handle = NULL;
633 _ecore_x_disp = NULL;
634 shutdown_ecore_event:
635 ecore_event_shutdown();
639 eina_log_domain_unregister(_ecore_xlib_log_dom);
640 _ecore_xlib_log_dom = -1;
643 return --_ecore_x_init_count;
647 _ecore_x_shutdown(int close_display)
649 if (--_ecore_x_init_count != 0)
650 return _ecore_x_init_count;
653 return _ecore_x_init_count;
655 LOGFN(__FILE__, __LINE__, __FUNCTION__);
657 ecore_main_fd_handler_del(_ecore_x_fd_handler_handle);
659 XCloseDisplay(_ecore_x_disp);
662 close(ConnectionNumber(_ecore_x_disp));
663 // FIXME: may have to clean up x display internal here
664 // getting segv here? hmmm. odd. disable
665 // XFree(_ecore_x_disp);
668 free(_ecore_x_event_handlers);
669 _ecore_x_fd_handler_handle = NULL;
670 _ecore_x_disp = NULL;
671 _ecore_x_event_handlers = NULL;
672 _ecore_x_events_shutdown();
673 _ecore_x_input_shutdown();
674 _ecore_x_selection_shutdown();
675 _ecore_x_dnd_shutdown();
676 ecore_x_netwm_shutdown();
678 ecore_event_shutdown();
681 eina_log_domain_unregister(_ecore_xlib_log_dom);
682 _ecore_xlib_log_dom = -1;
685 return _ecore_x_init_count;
689 * Shuts down the Ecore X library.
691 * In shutting down the library, the X display connection is terminated
692 * and any event handlers for it are removed.
694 * @return The number of times the library has been initialized without
695 * being shut down. 0 is returned if an error occurs.
696 * @ingroup Ecore_X_Init_Group
699 ecore_x_shutdown(void)
701 return _ecore_x_shutdown(1);
705 * Shuts down the Ecore X library.
707 * As ecore_x_shutdown, except do not close Display, only connection.
709 * @ingroup Ecore_X_Init_Group
712 ecore_x_disconnect(void)
714 return _ecore_x_shutdown(0);
718 * @defgroup Ecore_X_Display_Attr_Group X Display Attributes
720 * Functions that set and retrieve X display attributes.
724 * Retrieves the Ecore_X_Display handle used for the current X connection.
725 * @return The current X display.
726 * @ingroup Ecore_X_Display_Attr_Group
728 EAPI Ecore_X_Display *
729 ecore_x_display_get(void)
731 return (Ecore_X_Display *)_ecore_x_disp;
735 * Retrieves the X display file descriptor.
736 * @return The current X display file descriptor.
737 * @ingroup Ecore_X_Display_Attr_Group
742 LOGFN(__FILE__, __LINE__, __FUNCTION__);
743 return ConnectionNumber(_ecore_x_disp);
747 * Retrieves the Ecore_X_Screen handle used for the current X connection.
748 * @return The current default screen.
749 * @ingroup Ecore_X_Display_Attr_Group
751 EAPI Ecore_X_Screen *
752 ecore_x_default_screen_get(void)
754 LOGFN(__FILE__, __LINE__, __FUNCTION__);
755 return (Ecore_X_Screen *)DefaultScreenOfDisplay(_ecore_x_disp);
759 * Retrieves the size of an Ecore_X_Screen.
760 * @param screen the handle to the screen to query.
761 * @param w where to return the width. May be NULL. Returns 0 on errors.
762 * @param h where to return the height. May be NULL. Returns 0 on errors.
763 * @ingroup Ecore_X_Display_Attr_Group
764 * @see ecore_x_default_screen_get()
769 ecore_x_screen_size_get(const Ecore_X_Screen *screen,
773 Screen *s = (Screen *)screen;
774 LOGFN(__FILE__, __LINE__, __FUNCTION__);
778 if (w) *w = s->width;
779 if (h) *h = s->height;
783 * Retrieves the number of screens.
785 * @return The count of the number of screens.
786 * @ingroup Ecore_X_Display_Attr_Group
791 ecore_x_screen_count_get(void)
793 LOGFN(__FILE__, __LINE__, __FUNCTION__);
795 return ScreenCount(_ecore_x_disp);
799 * Retrieves the index number of the given screen.
801 * @param screen The screen for which the index will be retrieved.
802 * @return The index number of the screen.
803 * @ingroup Ecore_X_Display_Attr_Group
808 ecore_x_screen_index_get(const Ecore_X_Screen *screen)
810 return XScreenNumberOfScreen((Screen *)screen);
814 * Retrieves the screen based on index number.
816 * @param index The index that will be used to retrieve the screen.
817 * @return The Ecore_X_Screen at this index.
818 * @ingroup Ecore_X_Display_Attr_Group
822 EAPI Ecore_X_Screen *
823 ecore_x_screen_get(int index)
825 return XScreenOfDisplay(_ecore_x_disp, index);
829 * Sets the timeout for a double and triple clicks to be flagged.
831 * This sets the time between clicks before the double_click flag is
832 * set in a button down event. If 3 clicks occur within double this
833 * time, the triple_click flag is also set.
835 * @param t The time in seconds
836 * @ingroup Ecore_X_Display_Attr_Group
839 ecore_x_double_click_time_set(double t)
844 _ecore_x_double_click_time = t;
848 * Retrieves the double and triple click flag timeout.
850 * See @ref ecore_x_double_click_time_set for more information.
852 * @return The timeout for double clicks in seconds.
853 * @ingroup Ecore_X_Display_Attr_Group
856 ecore_x_double_click_time_get(void)
858 return _ecore_x_double_click_time;
862 * @defgroup Ecore_X_Flush_Group X Synchronization Functions
864 * Functions that ensure that all commands that have been issued by the
865 * Ecore X library have been sent to the server.
869 * Sends all X commands in the X Display buffer.
870 * @ingroup Ecore_X_Flush_Group
875 LOGFN(__FILE__, __LINE__, __FUNCTION__);
876 XFlush(_ecore_x_disp);
880 * Flushes the command buffer and waits until all requests have been
881 * processed by the server.
882 * @ingroup Ecore_X_Flush_Group
887 LOGFN(__FILE__, __LINE__, __FUNCTION__);
888 XSync(_ecore_x_disp, False);
892 * Kill all clients with subwindows under a given window.
894 * You can kill all clients connected to the X server by using
895 * @ref ecore_x_window_root_list to get a list of root windows, and
896 * then passing each root window to this function.
898 * @param root The window whose children will be killed.
901 ecore_x_killall(Ecore_X_Window root)
906 Window *children_r = NULL;
907 unsigned int num_children = 0;
909 LOGFN(__FILE__, __LINE__, __FUNCTION__);
910 XGrabServer(_ecore_x_disp);
911 /* Tranverse window tree starting from root, and drag each
912 * before the firing squad */
913 while (XQueryTree(_ecore_x_disp, root, &root_r, &parent_r,
914 &children_r, &num_children) && (num_children > 0))
916 for (j = 0; j < num_children; ++j)
918 XKillClient(_ecore_x_disp, children_r[j]);
923 XUngrabServer(_ecore_x_disp);
924 XSync(_ecore_x_disp, False);
928 * Kill a specific client
930 * You can kill a specific client owning window @p win
932 * @param win Window of the client to be killed
935 ecore_x_kill(Ecore_X_Window win)
937 LOGFN(__FILE__, __LINE__, __FUNCTION__);
938 XKillClient(_ecore_x_disp, win);
942 * Return the last event time
945 ecore_x_current_time_get(void)
947 return _ecore_x_event_last_time;
951 * Return the screen DPI
953 * This is a simplistic call to get DPI. It does not account for differing
954 * DPI in the x amd y axes nor does it account for multihead or xinerama and
955 * xrander where different parts of the screen may have different DPI etc.
957 * @return the general screen DPI (dots/pixels per inch).
960 ecore_x_dpi_get(void)
964 LOGFN(__FILE__, __LINE__, __FUNCTION__);
965 s = DefaultScreenOfDisplay(_ecore_x_disp);
969 return (((s->width * 254) / s->mwidth) + 5) / 10;
973 * Invoke the standard system beep to alert users
975 * @param percent The volume at which the bell rings. Must be in the range
976 * [-100,+100]. If percent >= 0, the final volume will be:
977 * base - [(base * percent) / 100] + percent
978 * Otherwise, it's calculated as:
979 * base + [(base * percent) / 100]
980 * where @c base is the bell's base volume as set by XChangeKeyboardControl(3).
982 * @returns @c EINA_TRUE on success, @c EINA_FALSE otherwise.
985 ecore_x_bell(int percent)
989 ret = XBell(_ecore_x_disp, percent);
997 _ecore_x_fd_handler(void *data,
998 Ecore_Fd_Handler *fd_handler __UNUSED__)
1010 /* Filter event for XIM */
1011 if (XFilterEvent(&ev, ev.xkey.window))
1014 #endif /* ifdef ENABLE_XIM */
1016 if ((ev.type >= 0) && (ev.type < _ecore_x_event_handlers_num))
1018 if (_ecore_x_event_handlers[AnyXEvent])
1019 _ecore_x_event_handlers[AnyXEvent] (&ev);
1021 if (_ecore_x_event_handlers[ev.type])
1022 _ecore_x_event_handlers[ev.type] (&ev);
1025 return ECORE_CALLBACK_RENEW;
1029 _ecore_x_fd_handler_buf(void *data,
1030 Ecore_Fd_Handler *fd_handler __UNUSED__)
1036 return ECORE_CALLBACK_RENEW;
1038 return ECORE_CALLBACK_CANCEL;
1042 _ecore_x_key_mask_get(KeySym sym)
1044 XModifierKeymap *mod;
1047 const int masks[8] =
1049 ShiftMask, LockMask, ControlMask,
1050 Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
1053 mod = XGetModifierMapping(_ecore_x_disp);
1054 if ((mod) && (mod->max_keypermod > 0))
1055 for (i = 0; i < (8 * mod->max_keypermod); i++)
1057 for (j = 0; j < 8; j++)
1059 sym2 = XKeycodeToKeysym(_ecore_x_disp, mod->modifiermap[i], j);
1067 mask = masks[i / mod->max_keypermod];
1068 if (mod->modifiermap)
1069 XFree(mod->modifiermap);
1078 if (mod->modifiermap)
1079 XFree(mod->modifiermap);
1087 /*****************************************************************************/
1088 /*****************************************************************************/
1089 /*****************************************************************************/
1090 /* FIXME: these funcs need categorising */
1091 /*****************************************************************************/
1094 * Get a list of all the root windows on the server.
1096 * @note The returned array will need to be freed after use.
1097 * @param num_ret Pointer to integer to put number of windows returned in.
1098 * @return An array of all the root windows. @c NULL is returned if memory
1099 * could not be allocated for the list, or if @p num_ret is @c NULL.
1101 EAPI Ecore_X_Window *
1102 ecore_x_window_root_list(int *num_ret)
1105 Ecore_X_Window *roots;
1107 int xp_base, xp_err_base;
1108 #endif /* ifdef ECORE_XPRINT */
1115 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1117 num = ScreenCount(_ecore_x_disp);
1118 if (XpQueryExtension(_ecore_x_disp, &xp_base, &xp_err_base))
1123 ps = XpQueryScreens(_ecore_x_disp, &psnum);
1129 for (i = 0; i < num; i++)
1131 for (j = 0; j < psnum; j++)
1133 if (ScreenOfDisplay(_ecore_x_disp, i) == ps[j])
1137 roots = malloc(MAX((num - overlap) * sizeof(Window), 1));
1143 for (i = 0; i < num; i++)
1148 for (j = 0; j < psnum; j++)
1150 if (ScreenOfDisplay(_ecore_x_disp, i) == ps[j])
1158 roots[k] = RootWindow(_ecore_x_disp, i);
1169 roots = malloc(num * sizeof(Window));
1174 for (i = 0; i < num; i++)
1175 roots[i] = 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);
1189 #else /* ifdef ECORE_XPRINT */
1190 num = ScreenCount(_ecore_x_disp);
1191 roots = malloc(num * sizeof(Window));
1196 for (i = 0; i < num; i++)
1197 roots[i] = RootWindow(_ecore_x_disp, i);
1198 #endif /* ifdef ECORE_XPRINT */
1203 ecore_x_window_root_first_get(void)
1205 return RootWindow(_ecore_x_disp, 0);
1208 Ecore_X_Window root, *roots = NULL;
1210 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1211 roots = ecore_x_window_root_list(&num);
1212 if (!(roots)) return 0;
1224 static void _ecore_x_window_manage_error(void *data);
1226 static int _ecore_x_window_manage_failed = 0;
1228 _ecore_x_window_manage_error(void *data __UNUSED__)
1230 if ((ecore_x_error_request_get() == X_ChangeWindowAttributes) &&
1231 (ecore_x_error_code_get() == BadAccess))
1232 _ecore_x_window_manage_failed = 1;
1236 ecore_x_window_manage(Ecore_X_Window win)
1238 XWindowAttributes att;
1240 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1241 if (XGetWindowAttributes(_ecore_x_disp, win, &att) != True)
1245 _ecore_x_window_manage_failed = 0;
1246 ecore_x_error_handler_set(_ecore_x_window_manage_error, NULL);
1247 XSelectInput(_ecore_x_disp, win,
1250 PropertyChangeMask |
1251 ResizeRedirectMask |
1252 SubstructureRedirectMask |
1253 SubstructureNotifyMask |
1254 StructureNotifyMask |
1257 att.your_event_mask);
1259 ecore_x_error_handler_set(NULL, NULL);
1260 if (_ecore_x_window_manage_failed)
1262 _ecore_x_window_manage_failed = 0;
1270 ecore_x_window_container_manage(Ecore_X_Window win)
1272 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1273 XSelectInput(_ecore_x_disp, win,
1274 SubstructureRedirectMask |
1275 SubstructureNotifyMask);
1279 ecore_x_window_client_manage(Ecore_X_Window win)
1281 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1282 XSelectInput(_ecore_x_disp, win,
1283 PropertyChangeMask |
1284 // ResizeRedirectMask |
1286 ColormapChangeMask |
1287 VisibilityChangeMask |
1288 StructureNotifyMask |
1289 SubstructureNotifyMask
1291 XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
1295 ecore_x_window_sniff(Ecore_X_Window win)
1297 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1298 XSelectInput(_ecore_x_disp, win,
1299 PropertyChangeMask |
1300 SubstructureNotifyMask);
1304 ecore_x_window_client_sniff(Ecore_X_Window win)
1306 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1307 XSelectInput(_ecore_x_disp, win,
1308 PropertyChangeMask |
1310 ColormapChangeMask |
1311 VisibilityChangeMask |
1312 StructureNotifyMask |
1313 SubstructureNotifyMask);
1314 XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
1318 ecore_x_window_attributes_get(Ecore_X_Window win,
1319 Ecore_X_Window_Attributes *att_ret)
1321 XWindowAttributes att;
1323 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1324 if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
1327 memset(att_ret, 0, sizeof(Ecore_X_Window_Attributes));
1328 att_ret->root = att.root;
1331 att_ret->w = att.width;
1332 att_ret->h = att.height;
1333 att_ret->border = att.border_width;
1334 att_ret->depth = att.depth;
1335 if (att.map_state != IsUnmapped)
1336 att_ret->visible = 1;
1338 if (att.map_state == IsViewable)
1339 att_ret->viewable = 1;
1341 if (att.override_redirect)
1342 att_ret->override = 1;
1344 if (att.class == InputOnly)
1345 att_ret->input_only = 1;
1348 att_ret->save_under = 1;
1350 att_ret->event_mask.mine = att.your_event_mask;
1351 att_ret->event_mask.all = att.all_event_masks;
1352 att_ret->event_mask.no_propagate = att.do_not_propagate_mask;
1353 att_ret->window_gravity = att.win_gravity;
1354 att_ret->pixel_gravity = att.bit_gravity;
1355 att_ret->colormap = att.colormap;
1356 att_ret->visual = att.visual;
1361 ecore_x_window_save_set_add(Ecore_X_Window win)
1363 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1364 XAddToSaveSet(_ecore_x_disp, win);
1368 ecore_x_window_save_set_del(Ecore_X_Window win)
1370 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1371 XRemoveFromSaveSet(_ecore_x_disp, win);
1374 EAPI Ecore_X_Window *
1375 ecore_x_window_children_get(Ecore_X_Window win,
1378 Ecore_X_Window *windows = NULL;
1379 Window root_ret = 0, parent_ret = 0, *children_ret = NULL;
1380 unsigned int children_ret_num = 0;
1382 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1383 if (!XQueryTree(_ecore_x_disp, win, &root_ret, &parent_ret, &children_ret,
1389 windows = malloc(children_ret_num * sizeof(Ecore_X_Window));
1394 for (i = 0; i < children_ret_num; i++)
1395 windows[i] = children_ret[i];
1396 *num = children_ret_num;
1399 XFree(children_ret);
1406 ecore_x_pointer_control_set(int accel_num,
1410 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1411 return XChangePointerControl(_ecore_x_disp, 1, 1,
1412 accel_num, accel_denom, threshold) ? EINA_TRUE : EINA_FALSE;
1416 ecore_x_pointer_control_get(int *accel_num,
1420 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1421 return XGetPointerControl(_ecore_x_disp,
1422 accel_num, accel_denom, threshold) ? EINA_TRUE : EINA_FALSE;
1426 ecore_x_pointer_mapping_set(unsigned char *map,
1429 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1430 return (XSetPointerMapping(_ecore_x_disp, map, nmap) == MappingSuccess) ? EINA_TRUE : EINA_FALSE;
1434 ecore_x_pointer_mapping_get(unsigned char *map,
1437 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1438 return XGetPointerMapping(_ecore_x_disp, map, nmap) ? EINA_TRUE : EINA_FALSE;
1442 ecore_x_pointer_grab(Ecore_X_Window win)
1444 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1445 if (XGrabPointer(_ecore_x_disp, win, False,
1446 ButtonPressMask | ButtonReleaseMask |
1447 EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1448 GrabModeAsync, GrabModeAsync,
1449 None, None, CurrentTime) == GrabSuccess)
1456 ecore_x_pointer_confine_grab(Ecore_X_Window win)
1458 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1459 if (XGrabPointer(_ecore_x_disp, win, False,
1460 ButtonPressMask | ButtonReleaseMask |
1461 EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1462 GrabModeAsync, GrabModeAsync,
1463 win, None, CurrentTime) == GrabSuccess)
1470 ecore_x_pointer_ungrab(void)
1472 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1473 XUngrabPointer(_ecore_x_disp, CurrentTime);
1477 ecore_x_pointer_warp(Ecore_X_Window win,
1481 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1482 return XWarpPointer(_ecore_x_disp, None, win, 0, 0, 0, 0, x, y) ? EINA_TRUE : EINA_FALSE;
1486 ecore_x_keyboard_grab(Ecore_X_Window win)
1488 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1489 if (XGrabKeyboard(_ecore_x_disp, win, False,
1490 GrabModeAsync, GrabModeAsync,
1491 CurrentTime) == GrabSuccess)
1498 ecore_x_keyboard_ungrab(void)
1500 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1501 XUngrabKeyboard(_ecore_x_disp, CurrentTime);
1507 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1508 _ecore_x_grab_count++;
1509 if (_ecore_x_grab_count == 1)
1510 XGrabServer(_ecore_x_disp);
1514 ecore_x_ungrab(void)
1516 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1517 _ecore_x_grab_count--;
1518 if (_ecore_x_grab_count < 0)
1519 _ecore_x_grab_count = 0;
1521 if (_ecore_x_grab_count == 0)
1522 XUngrabServer(_ecore_x_disp);
1525 int _ecore_window_grabs_num = 0;
1526 Window *_ecore_window_grabs = NULL;
1527 Eina_Bool (*_ecore_window_grab_replay_func)(void *data,
1530 void *_ecore_window_grab_replay_data;
1533 ecore_x_passive_grab_replay_func_set(Eina_Bool (*func)(void *data,
1538 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1539 _ecore_window_grab_replay_func = func;
1540 _ecore_window_grab_replay_data = data;
1544 ecore_x_window_button_grab(Ecore_X_Window win,
1546 Ecore_X_Event_Mask event_mask,
1552 unsigned int locks[8];
1556 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1561 m = _ecore_x_event_modifier(mod);
1566 locks[1] = ECORE_X_LOCK_CAPS;
1567 locks[2] = ECORE_X_LOCK_NUM;
1568 locks[3] = ECORE_X_LOCK_SCROLL;
1569 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1570 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1571 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1572 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1574 for (i = 0; i < 8; i++)
1575 XGrabButton(_ecore_x_disp, b, m | locks[i],
1576 win, False, ev, GrabModeSync, GrabModeAsync, None, None);
1577 _ecore_window_grabs_num++;
1578 t = realloc(_ecore_window_grabs,
1579 _ecore_window_grabs_num * sizeof(Window));
1581 _ecore_window_grabs = t;
1582 _ecore_window_grabs[_ecore_window_grabs_num - 1] = win;
1586 _ecore_x_sync_magic_send(int val,
1587 Ecore_X_Window swin)
1591 xev.xclient.type = ClientMessage;
1592 xev.xclient.serial = 0;
1593 xev.xclient.send_event = True;
1594 xev.xclient.display = _ecore_x_disp;
1595 xev.xclient.window = _ecore_x_private_win;
1596 xev.xclient.format = 32;
1597 xev.xclient.message_type = 27777;
1598 xev.xclient.data.l[0] = 0x7162534;
1599 xev.xclient.data.l[1] = 0x10000000 + val;
1600 xev.xclient.data.l[2] = swin;
1601 XSendEvent(_ecore_x_disp, _ecore_x_private_win, False, NoEventMask, &xev);
1605 _ecore_x_window_grab_remove(Ecore_X_Window win)
1610 if (_ecore_window_grabs_num > 0)
1612 for (i = 0; i < _ecore_window_grabs_num; i++)
1615 _ecore_window_grabs[i - 1] = _ecore_window_grabs[i];
1617 if ((!shuffle) && (_ecore_window_grabs[i] == win))
1622 _ecore_window_grabs_num--;
1623 if (_ecore_window_grabs_num <= 0)
1625 free(_ecore_window_grabs);
1626 _ecore_window_grabs = NULL;
1629 t = realloc(_ecore_window_grabs,
1630 _ecore_window_grabs_num *
1633 _ecore_window_grabs = t;
1639 ecore_x_window_button_ungrab(Ecore_X_Window win,
1646 unsigned int locks[8];
1649 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1654 m = _ecore_x_event_modifier(mod);
1659 locks[1] = ECORE_X_LOCK_CAPS;
1660 locks[2] = ECORE_X_LOCK_NUM;
1661 locks[3] = ECORE_X_LOCK_SCROLL;
1662 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1663 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1664 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1665 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1666 for (i = 0; i < 8; i++)
1667 XUngrabButton(_ecore_x_disp, b, m | locks[i], win);
1668 _ecore_x_sync_magic_send(1, win);
1671 int _ecore_key_grabs_num = 0;
1672 Window *_ecore_key_grabs = NULL;
1675 ecore_x_window_key_grab(Ecore_X_Window win,
1680 KeyCode keycode = 0;
1683 unsigned int locks[8];
1687 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1688 if (!strncmp(key, "Keycode-", 8))
1689 keycode = atoi(key + 8);
1692 keysym = XStringToKeysym(key);
1693 if (keysym == NoSymbol)
1696 keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key));
1702 m = _ecore_x_event_modifier(mod);
1707 locks[1] = ECORE_X_LOCK_CAPS;
1708 locks[2] = ECORE_X_LOCK_NUM;
1709 locks[3] = ECORE_X_LOCK_SCROLL;
1710 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1711 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1712 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1713 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1714 for (i = 0; i < 8; i++)
1715 XGrabKey(_ecore_x_disp, keycode, m | locks[i],
1716 win, False, GrabModeSync, GrabModeAsync);
1717 _ecore_key_grabs_num++;
1718 t = realloc(_ecore_key_grabs,
1719 _ecore_key_grabs_num * sizeof(Window));
1721 _ecore_key_grabs = t;
1722 _ecore_key_grabs[_ecore_key_grabs_num - 1] = win;
1726 _ecore_x_key_grab_remove(Ecore_X_Window win)
1731 if (_ecore_key_grabs_num > 0)
1733 for (i = 0; i < _ecore_key_grabs_num; i++)
1736 _ecore_key_grabs[i - 1] = _ecore_key_grabs[i];
1738 if ((!shuffle) && (_ecore_key_grabs[i] == win))
1743 _ecore_key_grabs_num--;
1744 if (_ecore_key_grabs_num <= 0)
1746 free(_ecore_key_grabs);
1747 _ecore_key_grabs = NULL;
1750 t = realloc(_ecore_key_grabs,
1751 _ecore_key_grabs_num * sizeof(Window));
1753 _ecore_key_grabs = t;
1759 ecore_x_window_key_ungrab(Ecore_X_Window win,
1764 KeyCode keycode = 0;
1767 unsigned int locks[8];
1770 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1771 if (!strncmp(key, "Keycode-", 8))
1772 keycode = atoi(key + 8);
1775 keysym = XStringToKeysym(key);
1776 if (keysym == NoSymbol)
1779 keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key));
1785 m = _ecore_x_event_modifier(mod);
1790 locks[1] = ECORE_X_LOCK_CAPS;
1791 locks[2] = ECORE_X_LOCK_NUM;
1792 locks[3] = ECORE_X_LOCK_SCROLL;
1793 locks[4] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM;
1794 locks[5] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_SCROLL;
1795 locks[6] = ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1796 locks[7] = ECORE_X_LOCK_CAPS | ECORE_X_LOCK_NUM | ECORE_X_LOCK_SCROLL;
1797 for (i = 0; i < 8; i++)
1798 XUngrabKey(_ecore_x_disp, keycode, m | locks[i], win);
1799 _ecore_x_sync_magic_send(2, win);
1803 * Send client message with given type and format 32.
1805 * @param win The window the message is sent to.
1806 * @param type The client message type.
1807 * @param mask The mask of the message to be sent.
1808 * @param d0 The client message data item 1
1809 * @param d1 The client message data item 2
1810 * @param d2 The client message data item 3
1811 * @param d3 The client message data item 4
1812 * @param d4 The client message data item 5
1814 * @return @c EINA_TRUE on success @c EINA_FALSE otherwise.
1817 ecore_x_client_message32_send(Ecore_X_Window win,
1819 Ecore_X_Event_Mask mask,
1828 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1829 xev.xclient.window = win;
1830 xev.xclient.type = ClientMessage;
1831 xev.xclient.message_type = type;
1832 xev.xclient.format = 32;
1833 xev.xclient.data.l[0] = d0;
1834 xev.xclient.data.l[1] = d1;
1835 xev.xclient.data.l[2] = d2;
1836 xev.xclient.data.l[3] = d3;
1837 xev.xclient.data.l[4] = d4;
1839 return XSendEvent(_ecore_x_disp, win, False, mask, &xev) ? EINA_TRUE : EINA_FALSE;
1843 * Send client message with given type and format 8.
1845 * @param win The window the message is sent to.
1846 * @param type The client message type.
1847 * @param data Data to be sent.
1848 * @param len Number of data bytes, max @c 20.
1850 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
1853 ecore_x_client_message8_send(Ecore_X_Window win,
1860 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1861 xev.xclient.window = win;
1862 xev.xclient.type = ClientMessage;
1863 xev.xclient.message_type = type;
1864 xev.xclient.format = 8;
1868 memcpy(xev.xclient.data.b, data, len);
1869 memset(xev.xclient.data.b + len, 0, 20 - len);
1871 return XSendEvent(_ecore_x_disp, win, False, NoEventMask, &xev) ? EINA_TRUE : EINA_FALSE;
1875 ecore_x_mouse_move_send(Ecore_X_Window win,
1880 XWindowAttributes att;
1884 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1885 XGetWindowAttributes(_ecore_x_disp, win, &att);
1886 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1887 xev.xmotion.type = MotionNotify;
1888 xev.xmotion.window = win;
1889 xev.xmotion.root = att.root;
1890 xev.xmotion.subwindow = win;
1891 xev.xmotion.time = _ecore_x_event_last_time;
1894 xev.xmotion.x_root = rx;
1895 xev.xmotion.y_root = ry;
1896 xev.xmotion.state = 0;
1897 xev.xmotion.is_hint = 0;
1898 xev.xmotion.same_screen = 1;
1899 return XSendEvent(_ecore_x_disp, win, True, PointerMotionMask, &xev) ? EINA_TRUE : EINA_FALSE;
1903 ecore_x_mouse_down_send(Ecore_X_Window win,
1909 XWindowAttributes att;
1913 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1914 XGetWindowAttributes(_ecore_x_disp, win, &att);
1915 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1916 xev.xbutton.type = ButtonPress;
1917 xev.xbutton.window = win;
1918 xev.xbutton.root = att.root;
1919 xev.xbutton.subwindow = win;
1920 xev.xbutton.time = _ecore_x_event_last_time;
1923 xev.xbutton.x_root = rx;
1924 xev.xbutton.y_root = ry;
1925 xev.xbutton.state = 1 << b;
1926 xev.xbutton.button = b;
1927 xev.xbutton.same_screen = 1;
1928 return XSendEvent(_ecore_x_disp, win, True, ButtonPressMask, &xev) ? EINA_TRUE : EINA_FALSE;
1932 ecore_x_mouse_up_send(Ecore_X_Window win,
1938 XWindowAttributes att;
1942 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1943 XGetWindowAttributes(_ecore_x_disp, win, &att);
1944 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1945 xev.xbutton.type = ButtonRelease;
1946 xev.xbutton.window = win;
1947 xev.xbutton.root = att.root;
1948 xev.xbutton.subwindow = win;
1949 xev.xbutton.time = _ecore_x_event_last_time;
1952 xev.xbutton.x_root = rx;
1953 xev.xbutton.y_root = ry;
1954 xev.xbutton.state = 0;
1955 xev.xbutton.button = b;
1956 xev.xbutton.same_screen = 1;
1957 return XSendEvent(_ecore_x_disp, win, True, ButtonReleaseMask, &xev) ? EINA_TRUE : EINA_FALSE;
1961 ecore_x_mouse_in_send(Ecore_X_Window win,
1966 XWindowAttributes att;
1970 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1971 XGetWindowAttributes(_ecore_x_disp, win, &att);
1972 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
1973 xev.xcrossing.type = EnterNotify;
1974 xev.xcrossing.window = win;
1975 xev.xcrossing.root = att.root;
1976 xev.xcrossing.subwindow = win;
1977 xev.xcrossing.time = _ecore_x_event_last_time;
1978 xev.xcrossing.x = x;
1979 xev.xcrossing.y = y;
1980 xev.xcrossing.x_root = rx;
1981 xev.xcrossing.y_root = ry;
1982 xev.xcrossing.mode = NotifyNormal;
1983 xev.xcrossing.detail = NotifyNonlinear;
1984 xev.xcrossing.same_screen = 1;
1985 xev.xcrossing.focus = 0;
1986 xev.xcrossing.state = 0;
1987 return XSendEvent(_ecore_x_disp, win, True, EnterWindowMask, &xev) ? EINA_TRUE : EINA_FALSE;
1991 ecore_x_mouse_out_send(Ecore_X_Window win,
1996 XWindowAttributes att;
2000 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2001 XGetWindowAttributes(_ecore_x_disp, win, &att);
2002 XTranslateCoordinates(_ecore_x_disp, win, att.root, x, y, &rx, &ry, &tw);
2003 xev.xcrossing.type = LeaveNotify;
2004 xev.xcrossing.window = win;
2005 xev.xcrossing.root = att.root;
2006 xev.xcrossing.subwindow = win;
2007 xev.xcrossing.time = _ecore_x_event_last_time;
2008 xev.xcrossing.x = x;
2009 xev.xcrossing.y = y;
2010 xev.xcrossing.x_root = rx;
2011 xev.xcrossing.y_root = ry;
2012 xev.xcrossing.mode = NotifyNormal;
2013 xev.xcrossing.detail = NotifyNonlinear;
2014 xev.xcrossing.same_screen = 1;
2015 xev.xcrossing.focus = 0;
2016 xev.xcrossing.state = 0;
2017 return XSendEvent(_ecore_x_disp, win, True, LeaveWindowMask, &xev) ? EINA_TRUE : EINA_FALSE;
2021 ecore_x_focus_reset(void)
2023 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2024 XSetInputFocus(_ecore_x_disp, PointerRoot, RevertToPointerRoot, CurrentTime);
2028 ecore_x_events_allow_all(void)
2030 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2031 XAllowEvents(_ecore_x_disp, AsyncBoth, CurrentTime);
2035 ecore_x_pointer_last_xy_get(int *x,
2039 *x = _ecore_x_event_last_root_x;
2042 *y = _ecore_x_event_last_root_y;
2046 ecore_x_pointer_xy_get(Ecore_X_Window win,
2051 int rx, ry, wx, wy, ret;
2054 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2055 ret = XQueryPointer(_ecore_x_disp, win, &rwin, &cwin,
2056 &rx, &ry, &wx, &wy, &mask);
2065 * Retrieve the Visual ID from a given Visual.
2067 * @param visual The Visual to get the ID for.
2069 * @return The visual id.
2073 ecore_x_visual_id_get(Ecore_X_Visual visual)
2075 return XVisualIDFromVisual(visual);
2079 * Retrieve the default Visual.
2081 * @param disp The Display to get the Default Visual from
2082 * @param screen The Screen.
2084 * @return The default visual.
2088 ecore_x_default_visual_get(Ecore_X_Display *disp,
2089 Ecore_X_Screen *screen)
2091 return DefaultVisual(disp, ecore_x_screen_index_get(screen));
2095 * Retrieve the default Colormap.
2097 * @param disp The Display to get the Default Colormap from
2098 * @param screen The Screen.
2100 * @return The default colormap.
2103 EAPI Ecore_X_Colormap
2104 ecore_x_default_colormap_get(Ecore_X_Display *disp,
2105 Ecore_X_Screen *screen)
2107 return DefaultColormap(disp, ecore_x_screen_index_get(screen));
2111 * Retrieve the default depth.
2113 * @param disp The Display to get the Default Depth from
2114 * @param screen The Screen.
2116 * @return The default depth.
2120 ecore_x_default_depth_get(Ecore_X_Display *disp,
2121 Ecore_X_Screen *screen)
2123 return DefaultDepth(disp, ecore_x_screen_index_get(screen));
2126 /*****************************************************************************/
2127 /*****************************************************************************/
2128 /*****************************************************************************/
2131 _ecore_x_event_modifier(unsigned int state)
2135 if (state & ECORE_EVENT_MODIFIER_SHIFT)
2136 xmodifiers |= ECORE_X_MODIFIER_SHIFT;
2138 if (state & ECORE_EVENT_MODIFIER_CTRL)
2139 xmodifiers |= ECORE_X_MODIFIER_CTRL;
2141 if (state & ECORE_EVENT_MODIFIER_ALT)
2142 xmodifiers |= ECORE_X_MODIFIER_ALT;
2144 if (state & ECORE_EVENT_MODIFIER_WIN)
2145 xmodifiers |= ECORE_X_MODIFIER_WIN;
2147 if (state & ECORE_EVENT_LOCK_SCROLL)
2148 xmodifiers |= ECORE_X_LOCK_SCROLL;
2150 if (state & ECORE_EVENT_LOCK_NUM)
2151 xmodifiers |= ECORE_X_LOCK_NUM;
2153 if (state & ECORE_EVENT_LOCK_CAPS)
2154 xmodifiers |= ECORE_X_LOCK_CAPS;
2156 if (state & ECORE_EVENT_LOCK_SHIFT)
2157 xmodifiers |= ECORE_X_LOCK_SHIFT;