eolian: rename is_ref API to is_ptr to match syntax
[platform/upstream/efl.git] / src / lib / ecore_x / xcb / ecore_xcb_netwm.c
1 #include "ecore_xcb_private.h"
2
3 /* local function prototypes */
4 /* static void _ecore_xcb_netwm_startup_info_free(void *data); */
5 static Ecore_X_Atom        _ecore_xcb_netwm_window_type_atom_get(Ecore_X_Window_Type type);
6 static Ecore_X_Window_Type _ecore_xcb_netwm_window_type_type_get(Ecore_X_Atom atom);
7 static Ecore_X_Atom        _ecore_xcb_netwm_window_state_atom_get(Ecore_X_Window_State state);
8 static Ecore_X_Atom        _ecore_xcb_netwm_action_atom_get(Ecore_X_Action action);
9
10 /* local variables */
11 //static Eina_Hash *_startup_info = NULL;
12
13 /* local structures */
14 typedef struct _Ecore_Xcb_Startup_Info Ecore_Xcb_Startup_Info;
15 struct _Ecore_Xcb_Startup_Info
16 {
17    Ecore_X_Window win;
18    int            init, size;
19    char          *buffer;
20    int            length;
21
22    /* sequence info fields */
23    char          *id, *name;
24    int            screen;
25    char          *bin, *icon;
26    int            desktop, timestamp;
27    char          *description, *wmclass;
28    int            silent;
29 };
30
31 EAPI void
32 ecore_x_netwm_init(void)
33 {
34    LOGFN(__FILE__, __LINE__, __FUNCTION__);
35
36 //   _startup_info =
37 //     eina_hash_string_superfast_new(_ecore_xcb_netwm_startup_info_free);
38 }
39
40 EAPI void
41 ecore_x_netwm_shutdown(void)
42 {
43    LOGFN(__FILE__, __LINE__, __FUNCTION__);
44
45 //   if (_startup_info) eina_hash_free(_startup_info);
46 //   _startup_info = NULL;
47 }
48
49 EAPI Eina_Bool
50 ecore_x_netwm_pid_get(Ecore_X_Window win,
51                       int           *pid)
52 {
53    uint32_t tmp;
54
55    LOGFN(__FILE__, __LINE__, __FUNCTION__);
56
57    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_PID, &tmp, 1))
58      return EINA_FALSE;
59
60    if (pid) *pid = tmp;
61
62    return EINA_TRUE;
63 }
64
65 EAPI void
66 ecore_x_netwm_pid_set(Ecore_X_Window win,
67                       int            pid)
68 {
69    unsigned int tmp;
70
71    LOGFN(__FILE__, __LINE__, __FUNCTION__);
72
73    tmp = pid;
74    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_PID, &tmp, 1);
75 }
76
77 EAPI Eina_Bool
78 ecore_x_netwm_window_type_get(Ecore_X_Window       win,
79                               Ecore_X_Window_Type *type)
80 {
81    Ecore_X_Atom *atoms;
82    int num = 0;
83
84    LOGFN(__FILE__, __LINE__, __FUNCTION__);
85
86    if (type) *type = ECORE_X_WINDOW_TYPE_NORMAL;
87
88    num =
89      ecore_x_window_prop_atom_list_get(win,
90                                        ECORE_X_ATOM_NET_WM_WINDOW_TYPE, &atoms);
91    if ((type) && (num >= 1) && (atoms))
92      *type = _ecore_xcb_netwm_window_type_type_get(atoms[0]);
93
94    if (atoms) free(atoms);
95
96    if (num >= 1) return EINA_TRUE;
97    return EINA_FALSE;
98 }
99
100 EAPI void
101 ecore_x_netwm_window_type_set(Ecore_X_Window      win,
102                               Ecore_X_Window_Type type)
103 {
104    Ecore_X_Atom atom;
105
106    LOGFN(__FILE__, __LINE__, __FUNCTION__);
107
108    atom = _ecore_xcb_netwm_window_type_atom_get(type);
109    ecore_x_window_prop_atom_set(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE, &atom, 1);
110 }
111
112 EAPI int
113 ecore_x_netwm_window_types_get(Ecore_X_Window        win,
114                                Ecore_X_Window_Type **types)
115 {
116    int num = 0, i = 0;
117    Ecore_X_Atom *atoms = NULL;
118    Ecore_X_Window_Type *atoms2 = NULL;
119
120    LOGFN(__FILE__, __LINE__, __FUNCTION__);
121
122    if (types) *types = NULL;
123    num =
124      ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
125                                        &atoms);
126    if ((num <= 0) || (!atoms))
127      {
128         if (atoms) free(atoms);
129         return 0;
130      }
131
132    atoms2 = malloc(num * sizeof(Ecore_X_Window_Type));
133    if (!atoms2)
134      {
135         if (atoms) free(atoms);
136         return 0;
137      }
138
139    for (i = 0; i < num; i++)
140      atoms2[i] = _ecore_xcb_netwm_window_type_type_get(atoms[i]);
141    if (atoms) free(atoms);
142
143    if (types)
144      *types = atoms2;
145    else
146      free(atoms2);
147
148    return num;
149 }
150
151 EAPI int
152 ecore_x_netwm_name_get(Ecore_X_Window win,
153                        char         **name)
154 {
155    LOGFN(__FILE__, __LINE__, __FUNCTION__);
156
157    if (name)
158      *name = ecore_x_window_prop_string_get(win, ECORE_X_ATOM_NET_WM_NAME);
159    return 1;
160 }
161
162 EAPI void
163 ecore_x_netwm_name_set(Ecore_X_Window win,
164                        const char    *name)
165 {
166    LOGFN(__FILE__, __LINE__, __FUNCTION__);
167
168    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_NAME, name);
169 }
170
171 EAPI void
172 ecore_x_netwm_opacity_set(Ecore_X_Window win,
173                           unsigned int   opacity)
174 {
175    LOGFN(__FILE__, __LINE__, __FUNCTION__);
176
177    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_WINDOW_OPACITY,
178                                   &opacity, 1);
179 }
180
181 EAPI Eina_Bool
182 ecore_x_netwm_opacity_get(Ecore_X_Window win,
183                           unsigned int  *opacity)
184 {
185    unsigned int tmp = 0;
186
187    LOGFN(__FILE__, __LINE__, __FUNCTION__);
188
189    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_WINDOW_OPACITY,
190                                        &tmp, 1))
191      return EINA_FALSE;
192
193    if (opacity) *opacity = tmp;
194
195    return EINA_TRUE;
196 }
197
198 EAPI void
199 ecore_x_netwm_wm_identify(Ecore_X_Window root,
200                           Ecore_X_Window check,
201                           const char    *wm_name)
202 {
203    LOGFN(__FILE__, __LINE__, __FUNCTION__);
204
205    ecore_x_window_prop_window_set(check, ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK,
206                                   &check, 1);
207    ecore_x_window_prop_string_set(check, ECORE_X_ATOM_NET_WM_NAME, wm_name);
208    ecore_x_window_prop_string_set(root, ECORE_X_ATOM_NET_WM_NAME, wm_name);
209    ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK,
210                                   &check, 1);
211 }
212
213 EAPI void
214 ecore_x_netwm_supported_set(Ecore_X_Window root,
215                             Ecore_X_Atom  *supported,
216                             int            num)
217 {
218    LOGFN(__FILE__, __LINE__, __FUNCTION__);
219
220    ecore_x_window_prop_atom_set(root, ECORE_X_ATOM_NET_SUPPORTED,
221                                 supported, num);
222 }
223
224 EAPI Eina_Bool
225 ecore_x_netwm_supported_get(Ecore_X_Window root,
226                             Ecore_X_Atom **supported,
227                             int           *num)
228 {
229    int num_ret = 0;
230
231    LOGFN(__FILE__, __LINE__, __FUNCTION__);
232
233    if (num) *num = 0;
234    if (supported) *supported = NULL;
235
236    num_ret =
237      ecore_x_window_prop_atom_list_get(root, ECORE_X_ATOM_NET_SUPPORTED,
238                                        supported);
239    if (num_ret <= 0) return EINA_FALSE;
240    if (num) *num = num_ret;
241
242    return EINA_TRUE;
243 }
244
245 EAPI void
246 ecore_x_netwm_desk_count_set(Ecore_X_Window root,
247                              unsigned int   n_desks)
248 {
249    LOGFN(__FILE__, __LINE__, __FUNCTION__);
250
251    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_NUMBER_OF_DESKTOPS,
252                                   &n_desks, 1);
253 }
254
255 EAPI void
256 ecore_x_netwm_desk_roots_set(Ecore_X_Window  root,
257                              Ecore_X_Window *vroots,
258                              unsigned int    n_desks)
259 {
260    LOGFN(__FILE__, __LINE__, __FUNCTION__);
261
262    ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_VIRTUAL_ROOTS,
263                                   vroots, n_desks);
264 }
265
266 EAPI void
267 ecore_x_netwm_desk_names_set(Ecore_X_Window root,
268                              const char   **names,
269                              unsigned int   n_desks)
270 {
271    char ss[32], *buf = NULL, *t = NULL;
272    const char *s;
273    uint32_t len = 0, i, l;
274
275    LOGFN(__FILE__, __LINE__, __FUNCTION__);
276    CHECK_XCB_CONN;
277
278    for (i = 0; i < n_desks; i++)
279      {
280         s = ((names) ? names[i] : NULL);
281         if (!s)
282           {
283              /* Default to "Desk-<number>" */
284               sprintf(ss, "Desk-%d", i);
285               s = ss;
286           }
287
288         l = strlen(s) + 1;
289         t = realloc(buf, len + 1);
290         if (t)
291           {
292              buf = t;
293              memcpy(buf + len, s, l);
294           }
295         len += l;
296      }
297
298    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, root,
299                        ECORE_X_ATOM_NET_DESKTOP_NAMES,
300                        ECORE_X_ATOM_UTF8_STRING, 8, len, (const void *)buf);
301 //   ecore_x_flush();
302    free(buf);
303 }
304
305 EAPI void
306 ecore_x_netwm_desk_size_set(Ecore_X_Window root,
307                             unsigned int   width,
308                             unsigned int   height)
309 {
310    uint32_t size[2];
311
312    LOGFN(__FILE__, __LINE__, __FUNCTION__);
313
314    size[0] = width;
315    size[1] = height;
316    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_DESKTOP_GEOMETRY,
317                                   size, 2);
318 }
319
320 EAPI void
321 ecore_x_netwm_desk_viewports_set(Ecore_X_Window root,
322                                  unsigned int  *origins,
323                                  unsigned int   n_desks)
324 {
325    LOGFN(__FILE__, __LINE__, __FUNCTION__);
326
327    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_DESKTOP_VIEWPORT,
328                                   origins, (2 * n_desks));
329 }
330
331 EAPI void
332 ecore_x_netwm_desk_layout_set(Ecore_X_Window root,
333                               int            orientation,
334                               int            columns,
335                               int            rows,
336                               int            starting_corner)
337 {
338    unsigned int layout[4];
339
340    LOGFN(__FILE__, __LINE__, __FUNCTION__);
341
342    layout[0] = orientation;
343    layout[1] = columns;
344    layout[2] = rows;
345    layout[3] = starting_corner;
346    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_DESKTOP_LAYOUT,
347                                   layout, 4);
348 }
349
350 EAPI void
351 ecore_x_netwm_desk_workareas_set(Ecore_X_Window root,
352                                  unsigned int  *areas,
353                                  unsigned int   n_desks)
354 {
355    LOGFN(__FILE__, __LINE__, __FUNCTION__);
356
357    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_WORKAREA, areas,
358                                   4 * n_desks);
359 }
360
361 EAPI unsigned int *
362 ecore_x_netwm_desk_workareas_get(Ecore_X_Window root, unsigned int *n_desks)
363 {
364    int ret;
365    unsigned int *areas = NULL;
366    
367    if (!root) root = ((xcb_screen_t *)_ecore_xcb_screen)->root;
368    
369    ret = ecore_x_window_prop_card32_list_get(root, ECORE_X_ATOM_NET_WORKAREA,
370                                              &areas);
371    if (!areas)
372      {
373         if (n_desks) *n_desks = 0;
374         return 0;
375      }
376    if (n_desks) *n_desks = ret / 4;
377    return areas;
378 }
379
380 EAPI void
381 ecore_x_netwm_desk_current_set(Ecore_X_Window root,
382                                unsigned int   desk)
383 {
384    LOGFN(__FILE__, __LINE__, __FUNCTION__);
385
386    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_CURRENT_DESKTOP,
387                                   &desk, 1);
388 }
389
390 EAPI void
391 ecore_x_netwm_showing_desktop_set(Ecore_X_Window root,
392                                   Eina_Bool      on)
393 {
394    unsigned int val = 0;
395
396    LOGFN(__FILE__, __LINE__, __FUNCTION__);
397
398    val = ((on) ? 1 : 0);
399    ecore_x_window_prop_card32_set(root, ECORE_X_ATOM_NET_SHOWING_DESKTOP,
400                                   &val, 1);
401 }
402
403 EAPI int
404 ecore_x_netwm_startup_id_get(Ecore_X_Window win,
405                              char         **id)
406 {
407    LOGFN(__FILE__, __LINE__, __FUNCTION__);
408
409    if (id)
410      {
411         *id =
412           ecore_x_window_prop_string_get(win, ECORE_X_ATOM_NET_STARTUP_ID);
413      }
414
415    return 1;
416 }
417
418 EAPI void
419 ecore_x_netwm_startup_id_set(Ecore_X_Window win,
420                              const char    *id)
421 {
422    LOGFN(__FILE__, __LINE__, __FUNCTION__);
423
424    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_STARTUP_ID, id);
425 }
426
427 EAPI void
428 ecore_x_netwm_state_request_send(Ecore_X_Window       win,
429                                  Ecore_X_Window       root,
430                                  Ecore_X_Window_State s1,
431                                  Ecore_X_Window_State s2,
432                                  Eina_Bool            set)
433 {
434    xcb_client_message_event_t ev;
435
436    LOGFN(__FILE__, __LINE__, __FUNCTION__);
437    CHECK_XCB_CONN;
438
439    if (!win) return;
440    if (!root) root = ((xcb_screen_t *)_ecore_xcb_screen)->root;
441
442    ev.response_type = XCB_CLIENT_MESSAGE;
443    ev.format = 32;
444    ev.window = win;
445    ev.type = ECORE_X_ATOM_NET_WM_STATE;
446    ev.data.data32[0] = !!set;
447    ev.data.data32[1] = _ecore_xcb_netwm_window_state_atom_get(s1);
448    ev.data.data32[2] = _ecore_xcb_netwm_window_state_atom_get(s2);
449    /* 1 == normal client, if used in a pager this should be 2 */
450    ev.data.data32[3] = 1;
451    ev.data.data32[4] = 0;
452
453    xcb_send_event(_ecore_xcb_conn, 0, root,
454                   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
455                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), (const char *)&ev);
456 //   ecore_x_flush();
457 }
458
459 EAPI void
460 ecore_x_netwm_window_state_set(Ecore_X_Window        win,
461                                Ecore_X_Window_State *state,
462                                unsigned int          num)
463 {
464    Ecore_X_Atom *set;
465    unsigned int i = 0;
466
467    LOGFN(__FILE__, __LINE__, __FUNCTION__);
468
469    if (!num)
470      {
471         ecore_x_window_prop_property_del(win, ECORE_X_ATOM_NET_WM_STATE);
472         return;
473      }
474
475    set = malloc(num * sizeof(Ecore_X_Atom));
476    if (!set) return;
477
478    for (i = 0; i < num; i++)
479      set[i] = _ecore_xcb_netwm_window_state_atom_get(state[i]);
480
481    ecore_x_window_prop_atom_set(win, ECORE_X_ATOM_NET_WM_STATE, set, num);
482    free(set);
483 }
484
485 EAPI Eina_Bool
486 ecore_x_netwm_window_state_get(Ecore_X_Window         win,
487                                Ecore_X_Window_State **state,
488                                unsigned int          *num)
489 {
490    Ecore_X_Atom *atoms;
491    int ret = 0;
492
493    LOGFN(__FILE__, __LINE__, __FUNCTION__);
494
495    if (num) *num = 0;
496    if (state) *state = NULL;
497
498    ret =
499      ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_STATE, &atoms);
500
501    if (ret <= 0) return EINA_FALSE;
502
503    if (state)
504      {
505         *state = malloc(ret * sizeof(Ecore_X_Window_State));
506         if (*state)
507           {
508              int i = 0;
509
510              for (i = 0; i < ret; i++)
511                (*state)[i] = _ecore_xcb_netwm_window_state_get(atoms[i]);
512              if (num) *num = ret;
513           }
514      }
515
516    free(atoms);
517
518    return EINA_TRUE;
519 }
520
521 EAPI void
522 ecore_x_netwm_client_active_set(Ecore_X_Window root,
523                                 Ecore_X_Window win)
524 {
525    LOGFN(__FILE__, __LINE__, __FUNCTION__);
526
527    ecore_x_window_prop_window_set(root,
528                                   ECORE_X_ATOM_NET_ACTIVE_WINDOW, &win, 1);
529 }
530
531 EAPI void
532 ecore_x_netwm_client_active_request(Ecore_X_Window root,
533                                     Ecore_X_Window win,
534                                     int            type,
535                                     Ecore_X_Window current_win)
536 {
537    xcb_client_message_event_t ev;
538
539    LOGFN(__FILE__, __LINE__, __FUNCTION__);
540    CHECK_XCB_CONN;
541
542    if (!root) root = ((xcb_screen_t *)_ecore_xcb_screen)->root;
543
544    ev.response_type = XCB_CLIENT_MESSAGE;
545    ev.format = 32;
546    ev.window = win;
547    ev.type = ECORE_X_ATOM_NET_ACTIVE_WINDOW;
548    ev.data.data32[0] = type;
549    ev.data.data32[1] = XCB_CURRENT_TIME;
550    ev.data.data32[2] = current_win;
551    ev.data.data32[3] = 0;
552    ev.data.data32[4] = 0;
553
554    xcb_send_event(_ecore_xcb_conn, 0, root,
555                   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
556                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), (const char *)&ev);
557 //   ecore_x_flush();
558 }
559
560 EAPI void
561 ecore_x_netwm_client_list_set(Ecore_X_Window  root,
562                               Ecore_X_Window *p_clients,
563                               unsigned int    n_clients)
564 {
565    LOGFN(__FILE__, __LINE__, __FUNCTION__);
566
567    ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_CLIENT_LIST,
568                                   p_clients, n_clients);
569 }
570
571 EAPI void
572 ecore_x_netwm_client_list_stacking_set(Ecore_X_Window  root,
573                                        Ecore_X_Window *p_clients,
574                                        unsigned int    n_clients)
575 {
576    LOGFN(__FILE__, __LINE__, __FUNCTION__);
577
578    ecore_x_window_prop_window_set(root, ECORE_X_ATOM_NET_CLIENT_LIST_STACKING,
579                                   p_clients, n_clients);
580 }
581
582 EAPI Eina_Bool
583 ecore_x_screen_is_composited(int screen)
584 {
585    char buff[32];
586    xcb_get_selection_owner_cookie_t ocookie;
587    xcb_get_selection_owner_reply_t *oreply;
588    xcb_intern_atom_cookie_t acookie;
589    xcb_intern_atom_reply_t *areply;
590    Ecore_X_Window win;
591    Ecore_X_Atom atom;
592
593    LOGFN(__FILE__, __LINE__, __FUNCTION__);
594    CHECK_XCB_CONN;
595
596    snprintf(buff, sizeof(buff), "_NET_WM_CM_S%i", screen);
597    acookie = xcb_intern_atom_unchecked(_ecore_xcb_conn, 1, strlen(buff), buff);
598    areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
599    if (!areply) return EINA_FALSE;
600    atom = areply->atom;
601    free(areply);
602    if (atom == XCB_NONE) return EINA_FALSE;
603    ocookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, atom);
604    oreply = xcb_get_selection_owner_reply(_ecore_xcb_conn, ocookie, NULL);
605    if (!oreply) return EINA_FALSE;
606    win = oreply->owner;
607    free(oreply);
608    return (win != XCB_NONE) ? EINA_TRUE : EINA_FALSE;
609 }
610
611 EAPI void
612 ecore_x_screen_is_composited_set(int            screen,
613                                  Ecore_X_Window win)
614 {
615    Ecore_X_Atom atom;
616    xcb_intern_atom_cookie_t acookie;
617    xcb_intern_atom_reply_t *areply;
618    char buff[32];
619
620    LOGFN(__FILE__, __LINE__, __FUNCTION__);
621    CHECK_XCB_CONN;
622
623    snprintf(buff, sizeof(buff), "_NET_WM_CM_S%i", screen);
624    acookie = xcb_intern_atom_unchecked(_ecore_xcb_conn, 0, strlen(buff), buff);
625    areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
626    if (!areply) return;
627    atom = areply->atom;
628    free(areply);
629    xcb_set_selection_owner(_ecore_xcb_conn, win, atom,
630                            _ecore_xcb_events_last_time_get());
631 }
632
633 EAPI void
634 ecore_x_netwm_ping_send(Ecore_X_Window win)
635 {
636    xcb_client_message_event_t ev;
637
638    LOGFN(__FILE__, __LINE__, __FUNCTION__);
639    CHECK_XCB_CONN;
640
641    if (!win) return;
642
643    ev.response_type = XCB_CLIENT_MESSAGE;
644    ev.format = 32;
645    ev.window = win;
646    ev.type = ECORE_X_ATOM_WM_PROTOCOLS;
647    ev.data.data32[0] = ECORE_X_ATOM_NET_WM_PING;
648    ev.data.data32[1] = ecore_x_current_time_get();
649    ev.data.data32[2] = win;
650    ev.data.data32[3] = 0;
651    ev.data.data32[4] = 0;
652
653    xcb_send_event(_ecore_xcb_conn, 0, win,
654                   XCB_EVENT_MASK_NO_EVENT, (const char *)&ev);
655 //   ecore_x_flush();
656 }
657
658 EAPI void
659 ecore_x_netwm_frame_size_set(Ecore_X_Window win,
660                              int            fl,
661                              int            fr,
662                              int            ft,
663                              int            fb)
664 {
665    uint32_t frames[4];
666
667    LOGFN(__FILE__, __LINE__, __FUNCTION__);
668
669    frames[0] = fl;
670    frames[1] = fr;
671    frames[2] = ft;
672    frames[3] = fb;
673    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_FRAME_EXTENTS,
674                                   frames, 4);
675 }
676
677 EAPI Eina_Bool
678 ecore_x_netwm_frame_size_get(Ecore_X_Window win,
679                              int           *fl,
680                              int           *fr,
681                              int           *ft,
682                              int           *fb)
683 {
684    int ret = 0;
685    unsigned int frames[4];
686
687    LOGFN(__FILE__, __LINE__, __FUNCTION__);
688
689    ret = ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_FRAME_EXTENTS,
690                                         frames, 4);
691    if (ret != 4) return EINA_FALSE;
692
693    if (fl) *fl = frames[0];
694    if (fr) *fr = frames[1];
695    if (ft) *ft = frames[2];
696    if (fb) *fb = frames[3];
697
698    return EINA_TRUE;
699 }
700
701 EAPI void
702 ecore_x_netwm_sync_request_send(Ecore_X_Window win,
703                                 unsigned int   serial)
704 {
705    xcb_client_message_event_t ev;
706
707    LOGFN(__FILE__, __LINE__, __FUNCTION__);
708    CHECK_XCB_CONN;
709
710    if (!win) return;
711
712    /* FIXME: Maybe need XSyncIntToValue ?? */
713    memset(&ev, 0, sizeof(xcb_client_message_event_t));
714
715    ev.response_type = XCB_CLIENT_MESSAGE;
716    ev.format = 32;
717    ev.window = win;
718    ev.type = ECORE_X_ATOM_WM_PROTOCOLS;
719    ev.data.data32[0] = ECORE_X_ATOM_NET_WM_SYNC_REQUEST;
720    ev.data.data32[1] = _ecore_xcb_events_last_time_get();
721    ev.data.data32[2] = serial;
722    ev.data.data32[3] = 0;
723    ev.data.data32[4] = 0;
724
725    xcb_send_event(_ecore_xcb_conn, 0, win,
726                   XCB_EVENT_MASK_NO_EVENT, (const char *)&ev);
727 //   ecore_x_flush();
728 }
729
730 EAPI void
731 ecore_x_netwm_desktop_set(Ecore_X_Window win,
732                           unsigned int   desk)
733 {
734    LOGFN(__FILE__, __LINE__, __FUNCTION__);
735
736    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_DESKTOP, &desk, 1);
737 }
738
739 EAPI Eina_Bool
740 ecore_x_netwm_desktop_get(Ecore_X_Window win,
741                           unsigned int  *desk)
742 {
743    unsigned int tmp = 0;
744
745    LOGFN(__FILE__, __LINE__, __FUNCTION__);
746
747    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_DESKTOP,
748                                        &tmp, 1))
749      return EINA_FALSE;
750
751    if (desk) *desk = tmp;
752
753    return EINA_TRUE;
754 }
755
756 EAPI void
757 ecore_x_netwm_desktop_request_send(Ecore_X_Window win,
758                                    Ecore_X_Window root,
759                                    unsigned int   desktop)
760 {
761    xcb_client_message_event_t ev;
762
763    LOGFN(__FILE__, __LINE__, __FUNCTION__);
764    CHECK_XCB_CONN;
765
766    if (!root) root = ((xcb_screen_t *)_ecore_xcb_screen)->root;
767
768    memset(&ev, 0, sizeof(xcb_client_message_event_t));
769
770    ev.response_type = XCB_CLIENT_MESSAGE;
771    ev.format = 32;
772    ev.window = win;
773    ev.type = ECORE_X_ATOM_NET_WM_DESKTOP;
774    ev.data.data32[0] = desktop;
775
776    xcb_send_event(_ecore_xcb_conn, 0, root,
777                   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
778                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), (const char *)&ev);
779 //   ecore_x_flush();
780 }
781
782 EAPI void
783 ecore_x_netwm_moveresize_request_send(Ecore_X_Window win,
784                                       int x,
785                                       int y,
786                                       Ecore_X_Netwm_Direction direction,
787                                       unsigned int button)
788 {
789    xcb_client_message_event_t ev;
790
791    LOGFN(__FILE__, __LINE__, __FUNCTION__);
792    CHECK_XCB_CONN;
793
794    memset(&ev, 0, sizeof(xcb_client_message_event_t));
795
796    ev.response_type = XCB_CLIENT_MESSAGE;
797    ev.format = 32;
798    ev.window = win;
799    ev.type = ECORE_X_ATOM_NET_WM_MOVERESIZE;
800    ev.data.data32[0] = x;
801    ev.data.data32[1] = y;
802    ev.data.data32[2] = direction;
803    ev.data.data32[3] = button;
804    ev.data.data32[4] = 1;
805
806    xcb_send_event(_ecore_xcb_conn, 0, win,
807                   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
808                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), (const char *)&ev);
809 }
810
811 EAPI void
812 ecore_x_netwm_handled_icons_set(Ecore_X_Window win)
813 {
814    LOGFN(__FILE__, __LINE__, __FUNCTION__);
815
816    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_HANDLED_ICONS,
817                                   NULL, 0);
818 }
819
820 EAPI Eina_Bool
821 ecore_x_netwm_handled_icons_get(Ecore_X_Window win)
822 {
823    LOGFN(__FILE__, __LINE__, __FUNCTION__);
824
825    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_HANDLED_ICONS,
826                                        NULL, 0))
827      return EINA_FALSE;
828
829    return EINA_TRUE;
830 }
831
832 EAPI int
833 ecore_x_netwm_icon_name_get(Ecore_X_Window win,
834                             char         **name)
835 {
836    LOGFN(__FILE__, __LINE__, __FUNCTION__);
837
838    if (name)
839      {
840         *name =
841           ecore_x_window_prop_string_get(win, ECORE_X_ATOM_NET_WM_ICON_NAME);
842      }
843
844    return 1;
845 }
846
847 EAPI void
848 ecore_x_netwm_icon_name_set(Ecore_X_Window win,
849                             const char    *name)
850 {
851    LOGFN(__FILE__, __LINE__, __FUNCTION__);
852
853    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_ICON_NAME, name);
854 }
855
856 EAPI void
857 ecore_x_netwm_icons_set(Ecore_X_Window win,
858                         Ecore_X_Icon *icon,
859                         int num)
860 {
861    unsigned int *data, *p, *p2;
862    unsigned int i, size, x, y;
863    
864    LOGFN(__FILE__, __LINE__, __FUNCTION__);
865    size = 0;
866    for (i = 0; i < (unsigned int)num; i++)
867      {
868         size += 2 + (icon[i].width * icon[i].height);
869      }
870    data = malloc(size * sizeof(unsigned int));
871    if (!data) return;
872    p = data;
873    for (i = 0; i < (unsigned int)num; i++)
874      {
875         p[0] = icon[i].width;
876         p[1] = icon[i].height;
877         p += 2;
878         p2 = icon[i].data;
879         for (y = 0; y < icon[i].height; y++)
880           {
881              for (x = 0; x < icon[i].width; x++)
882                {
883                   unsigned int r, g, b, a;
884                   
885                   a = (*p2 >> 24) & 0xff;
886                   r = (*p2 >> 16) & 0xff;
887                   g = (*p2 >> 8 ) & 0xff;
888                   b = (*p2      ) & 0xff;
889                   if ((a > 0) && (a < 255))
890                     {
891                        r = (r * 255) / a;
892                        g = (g * 255) / a;
893                        b = (b * 255) / a;
894                     }
895                   *p = (a << 24) | (r << 16) | (g << 8) | b;
896                   p++;
897                   p2++;
898                }
899           }
900      }
901    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_ICON,
902                                   data, size);
903    free(data);
904 }
905
906 EAPI Eina_Bool
907 ecore_x_netwm_icons_get(Ecore_X_Window win,
908                         Ecore_X_Icon **icon,
909                         int           *num)
910 {
911    int num_ret = 0;
912    unsigned int i = 0, len = 0, icons = 0;
913    unsigned int *data, *p, *src;
914
915    LOGFN(__FILE__, __LINE__, __FUNCTION__);
916
917    if (num) *num = 0;
918    if (icon) *icon = NULL;
919
920    num_ret =
921      ecore_x_window_prop_card32_list_get(win, ECORE_X_ATOM_NET_WM_ICON, &data);
922
923    if ((num_ret <= 0) || (!data))
924      {
925         if (data) free(data);
926         return EINA_FALSE;
927      }
928    if (num_ret < 2)
929      {
930         if (data) free(data);
931         return EINA_FALSE;
932      }
933
934    icons = 0;
935    p = data;
936    while (p)
937      {
938         len = (p[0] * p[1]);
939         p += (len + 2);
940         if ((p - data) > num_ret)
941           {
942              if (data) free(data);
943              return EINA_FALSE;
944           }
945         icons++;
946         if ((p - data) == num_ret) p = NULL;
947      }
948    if (num) *num = icons;
949    if (!icon)
950      {
951         if (data) free(data);
952         return EINA_TRUE;
953      }
954
955    *icon = malloc(icons * sizeof(Ecore_X_Icon));
956    if (!(*icon))
957      {
958         if (data) free(data);
959         return EINA_FALSE;
960      }
961
962    /* Fetch the icons */
963    p = data;
964    for (i = 0; i < icons; i++)
965      {
966         unsigned int *ps, *pd, *pe;
967
968         len = p[0] * p[1];
969         ((*icon)[i]).width = p[0];
970         ((*icon)[i]).height = p[1];
971         src = &(p[2]);
972         ((*icon)[i]).data = malloc(len * sizeof(unsigned int));
973         if (!((*icon)[i]).data)
974           {
975              while (i)
976                free(((*icon)[--i]).data);
977              free(*icon);
978              free(data);
979              return EINA_FALSE;
980           }
981
982         pd = ((*icon)[i]).data;
983         ps = src;
984         pe = ps + len;
985         for (; ps < pe; ps++)
986           {
987              unsigned int r, g, b, a;
988
989              a = (*ps >> 24) & 0xff;
990              r = (((*ps >> 16) & 0xff) * a) / 255;
991              g = (((*ps >> 8) & 0xff) * a) / 255;
992              b = (((*ps) & 0xff) * a) / 255;
993              *pd = (a << 24) | (r << 16) | (g << 8) | (b);
994              pd++;
995           }
996         p += (len + 2);
997      }
998
999    if (data) free(data);
1000    return EINA_TRUE;
1001 }
1002
1003 EAPI void
1004 ecore_x_netwm_icon_geometry_set(Ecore_X_Window win,
1005                                 int            x,
1006                                 int            y,
1007                                 int            w,
1008                                 int            h)
1009 {
1010    unsigned int geom[4];
1011
1012    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1013
1014    geom[0] = x;
1015    geom[1] = y;
1016    geom[2] = w;
1017    geom[3] = h;
1018    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_ICON_GEOMETRY,
1019                                   geom, 4);
1020 }
1021
1022 EAPI Eina_Bool
1023 ecore_x_netwm_icon_geometry_get(Ecore_X_Window win,
1024                                 int           *x,
1025                                 int           *y,
1026                                 int           *w,
1027                                 int           *h)
1028 {
1029    int ret = 0;
1030    unsigned int geom[4];
1031
1032    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1033
1034    ret =
1035      ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_ICON_GEOMETRY,
1036                                     geom, 4);
1037    if (ret != 4) return EINA_FALSE;
1038    if (x) *x = geom[0];
1039    if (y) *y = geom[1];
1040    if (w) *w = geom[2];
1041    if (h) *h = geom[3];
1042
1043    return EINA_TRUE;
1044 }
1045
1046 EAPI void
1047 ecore_x_netwm_strut_set(Ecore_X_Window win,
1048                         int            l,
1049                         int            r,
1050                         int            t,
1051                         int            b)
1052 {
1053    unsigned int strut[4];
1054
1055    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1056
1057    strut[0] = l;
1058    strut[1] = r;
1059    strut[2] = t;
1060    strut[3] = b;
1061    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_STRUT, strut, 4);
1062 }
1063
1064 EAPI Eina_Bool
1065 ecore_x_netwm_strut_get(Ecore_X_Window win,
1066                         int           *l,
1067                         int           *r,
1068                         int           *t,
1069                         int           *b)
1070 {
1071    unsigned int strut[4];
1072    int ret = 0;
1073
1074    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1075
1076    ret =
1077      ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_STRUT, strut, 4);
1078    if (ret != 4) return EINA_FALSE;
1079
1080    if (l) *l = strut[0];
1081    if (r) *r = strut[1];
1082    if (t) *t = strut[2];
1083    if (b) *b = strut[3];
1084
1085    return EINA_TRUE;
1086 }
1087
1088 EAPI void
1089 ecore_x_netwm_strut_partial_set(Ecore_X_Window win,
1090                                 int            left,
1091                                 int            right,
1092                                 int            top,
1093                                 int            bottom,
1094                                 int            left_start_y,
1095                                 int            left_end_y,
1096                                 int            right_start_y,
1097                                 int            right_end_y,
1098                                 int            top_start_x,
1099                                 int            top_end_x,
1100                                 int            bottom_start_x,
1101                                 int            bottom_end_x)
1102 {
1103    unsigned int strut[12];
1104
1105    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1106
1107    strut[0] = left;
1108    strut[1] = right;
1109    strut[2] = top;
1110    strut[3] = bottom;
1111    strut[4] = left_start_y;
1112    strut[5] = left_end_y;
1113    strut[6] = right_start_y;
1114    strut[7] = right_end_y;
1115    strut[8] = top_start_x;
1116    strut[9] = top_end_x;
1117    strut[10] = bottom_start_x;
1118    strut[11] = bottom_end_x;
1119    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_STRUT_PARTIAL,
1120                                   strut, 12);
1121 }
1122
1123 EAPI Eina_Bool
1124 ecore_x_netwm_strut_partial_get(Ecore_X_Window win,
1125                                 int           *left,
1126                                 int           *right,
1127                                 int           *top,
1128                                 int           *bottom,
1129                                 int           *left_start_y,
1130                                 int           *left_end_y,
1131                                 int           *right_start_y,
1132                                 int           *right_end_y,
1133                                 int           *top_start_x,
1134                                 int           *top_end_x,
1135                                 int           *bottom_start_x,
1136                                 int           *bottom_end_x)
1137 {
1138    unsigned int strut[12];
1139    int ret = 0;
1140
1141    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1142
1143    ret =
1144      ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_STRUT_PARTIAL,
1145                                     strut, 12);
1146    if (ret != 12) return EINA_FALSE;
1147
1148    if (left) *left = strut[0];
1149    if (right) *right = strut[1];
1150    if (top) *top = strut[2];
1151    if (bottom) *bottom = strut[3];
1152    if (left_start_y) *left_start_y = strut[4];
1153    if (left_end_y) *left_end_y = strut[5];
1154    if (right_start_y) *right_start_y = strut[6];
1155    if (right_end_y) *right_end_y = strut[7];
1156    if (top_start_x) *top_start_x = strut[8];
1157    if (top_end_x) *top_end_x = strut[9];
1158    if (bottom_start_x) *bottom_start_x = strut[10];
1159    if (bottom_end_x) *bottom_end_x = strut[11];
1160
1161    return EINA_TRUE;
1162 }
1163
1164 EAPI void
1165 ecore_x_netwm_user_time_set(Ecore_X_Window win,
1166                             unsigned int   t)
1167 {
1168    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1169
1170    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_USER_TIME, &t, 1);
1171 }
1172
1173 EAPI Eina_Bool
1174 ecore_x_netwm_user_time_get(Ecore_X_Window win,
1175                             unsigned int  *t)
1176 {
1177    unsigned int tmp;
1178
1179    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1180
1181    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_USER_TIME,
1182                                        &tmp, 1))
1183      return EINA_FALSE;
1184
1185    if (t) *t = tmp;
1186
1187    return EINA_TRUE;
1188 }
1189
1190 EAPI void
1191 ecore_x_netwm_visible_name_set(Ecore_X_Window win,
1192                                const char    *name)
1193 {
1194    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1195
1196    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_VISIBLE_NAME,
1197                                   name);
1198 }
1199
1200 EAPI int
1201 ecore_x_netwm_visible_name_get(Ecore_X_Window win,
1202                                char         **name)
1203 {
1204    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1205
1206    if (name)
1207      *name = ecore_x_window_prop_string_get(win,
1208                                             ECORE_X_ATOM_NET_WM_VISIBLE_NAME);
1209    return 1;
1210 }
1211
1212 EAPI void
1213 ecore_x_netwm_visible_icon_name_set(Ecore_X_Window win,
1214                                     const char    *name)
1215 {
1216    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1217
1218    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_VISIBLE_ICON_NAME,
1219                                   name);
1220 }
1221
1222 EAPI int
1223 ecore_x_netwm_visible_icon_name_get(Ecore_X_Window win,
1224                                     char         **name)
1225 {
1226    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1227
1228    if (name)
1229      {
1230         *name =
1231           ecore_x_window_prop_string_get(win,
1232                                          ECORE_X_ATOM_NET_WM_VISIBLE_ICON_NAME);
1233      }
1234
1235    return 1;
1236 }
1237
1238 EAPI Eina_Bool
1239 ecore_x_netwm_sync_counter_get(Ecore_X_Window        win,
1240                                Ecore_X_Sync_Counter *counter)
1241 {
1242    unsigned int tmp;
1243
1244    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1245
1246    if (!ecore_x_window_prop_card32_get(win,
1247                                        ECORE_X_ATOM_NET_WM_SYNC_REQUEST_COUNTER,
1248                                        &tmp, 1))
1249      return EINA_FALSE;
1250
1251    if (counter) *counter = tmp;
1252
1253    return EINA_TRUE;
1254 }
1255
1256 EAPI Eina_Bool
1257 ecore_x_netwm_allowed_action_isset(Ecore_X_Window win,
1258                                    Ecore_X_Action action)
1259 {
1260    int num = 0, i = 0;
1261    Ecore_X_Atom *atoms, atom;
1262    Eina_Bool ret = EINA_FALSE;
1263
1264    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1265
1266    num =
1267      ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
1268                                        &atoms);
1269    if (num <= 0) return EINA_FALSE;
1270
1271    atom = _ecore_xcb_netwm_action_atom_get(action);
1272    for (i = 0; i < num; i++)
1273      {
1274         if (atoms[i] == atom)
1275           {
1276              ret = EINA_TRUE;
1277              break;
1278           }
1279      }
1280
1281    if (atoms) free(atoms);
1282    return ret;
1283 }
1284
1285 EAPI Eina_Bool
1286 ecore_x_netwm_allowed_action_get(Ecore_X_Window   win,
1287                                  Ecore_X_Action **action,
1288                                  unsigned int    *num)
1289 {
1290    Ecore_X_Atom *atoms;
1291    int num_ret = 0;
1292
1293    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1294
1295    if (num) *num = 0;
1296    if (action) *action = NULL;
1297
1298    num_ret =
1299      ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
1300                                        &atoms);
1301    if (num_ret <= 0) return EINA_FALSE;
1302    if (action)
1303      {
1304         *action = malloc(num_ret * sizeof(Ecore_X_Action));
1305         if (*action)
1306           {
1307              int i = 0;
1308
1309              for (i = 0; i < num_ret; i++)
1310                (*action)[i] = _ecore_xcb_netwm_action_atom_get(atoms[i]);
1311           }
1312         if (num) *num = num_ret;
1313      }
1314    free(atoms);
1315    return EINA_TRUE;
1316 }
1317
1318 EAPI void
1319 ecore_x_netwm_allowed_action_set(Ecore_X_Window  win,
1320                                  Ecore_X_Action *action,
1321                                  unsigned int    num)
1322 {
1323    Ecore_X_Atom *set;
1324    unsigned int i = 0;
1325
1326    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1327
1328    if (!num)
1329      {
1330         ecore_x_window_prop_property_del(win,
1331                                          ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS);
1332         return;
1333      }
1334
1335    set = malloc(num * sizeof(Ecore_X_Atom));
1336    if (!set) return;
1337
1338    for (i = 0; i < num; i++)
1339      set[i] = _ecore_xcb_netwm_action_atom_get(action[i]);
1340
1341    ecore_x_window_prop_atom_set(win, ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
1342                                 set, num);
1343    free(set);
1344 }
1345
1346 /* local functions */
1347 int
1348 _ecore_xcb_netwm_startup_info_begin(Ecore_X_Window win EINA_UNUSED,
1349                                     uint8_t        data EINA_UNUSED)
1350 {
1351    // TODO: TBD
1352      return 1;
1353 }
1354
1355 int
1356 _ecore_xcb_netwm_startup_info(Ecore_X_Window win EINA_UNUSED,
1357                               uint8_t        data EINA_UNUSED)
1358 {
1359    // TODO: TBD
1360      return 1;
1361 }
1362
1363 /* static void  */
1364 /* _ecore_xcb_netwm_startup_info_free(void *data)  */
1365 /* { */
1366 /*    Ecore_Xcb_Startup_Info *info; */
1367
1368 /*    LOGFN(__FILE__, __LINE__, __FUNCTION__); */
1369
1370 /*    if (!(info = data)) return; */
1371 /*    if (info->buffer) free(info->buffer); */
1372 /*    if (info->id) free(info->id); */
1373 /*    if (info->name) free(info->name); */
1374 /*    if (info->bin) free(info->bin); */
1375 /*    if (info->icon) free(info->icon); */
1376 /*    if (info->description) free(info->description); */
1377 /*    if (info->wmclass) free(info->wmclass); */
1378 /*    free(info); */
1379 /* } */
1380
1381 static Ecore_X_Atom
1382 _ecore_xcb_netwm_window_type_atom_get(Ecore_X_Window_Type type)
1383 {
1384    switch (type)
1385      {
1386       case ECORE_X_WINDOW_TYPE_DESKTOP:
1387         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DESKTOP;
1388
1389       case ECORE_X_WINDOW_TYPE_DOCK:
1390         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DOCK;
1391
1392       case ECORE_X_WINDOW_TYPE_TOOLBAR:
1393         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLBAR;
1394
1395       case ECORE_X_WINDOW_TYPE_MENU:
1396         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_MENU;
1397
1398       case ECORE_X_WINDOW_TYPE_UTILITY:
1399         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_UTILITY;
1400
1401       case ECORE_X_WINDOW_TYPE_SPLASH:
1402         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_SPLASH;
1403
1404       case ECORE_X_WINDOW_TYPE_DIALOG:
1405         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DIALOG;
1406
1407       case ECORE_X_WINDOW_TYPE_NORMAL:
1408         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NORMAL;
1409
1410       case ECORE_X_WINDOW_TYPE_DROPDOWN_MENU:
1411         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
1412
1413       case ECORE_X_WINDOW_TYPE_POPUP_MENU:
1414         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_POPUP_MENU;
1415
1416       case ECORE_X_WINDOW_TYPE_TOOLTIP:
1417         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLTIP;
1418
1419       case ECORE_X_WINDOW_TYPE_NOTIFICATION:
1420         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NOTIFICATION;
1421
1422       case ECORE_X_WINDOW_TYPE_COMBO:
1423         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_COMBO;
1424
1425       case ECORE_X_WINDOW_TYPE_DND:
1426         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DND;
1427
1428       default:
1429         return 0;
1430      }
1431 }
1432
1433 static Ecore_X_Window_Type
1434 _ecore_xcb_netwm_window_type_type_get(Ecore_X_Atom atom)
1435 {
1436    if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DESKTOP)
1437      return ECORE_X_WINDOW_TYPE_DESKTOP;
1438    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DOCK)
1439      return ECORE_X_WINDOW_TYPE_DOCK;
1440    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLBAR)
1441      return ECORE_X_WINDOW_TYPE_TOOLBAR;
1442    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_MENU)
1443      return ECORE_X_WINDOW_TYPE_MENU;
1444    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_UTILITY)
1445      return ECORE_X_WINDOW_TYPE_UTILITY;
1446    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_SPLASH)
1447      return ECORE_X_WINDOW_TYPE_SPLASH;
1448    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DIALOG)
1449      return ECORE_X_WINDOW_TYPE_DIALOG;
1450    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NORMAL)
1451      return ECORE_X_WINDOW_TYPE_NORMAL;
1452    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DROPDOWN_MENU)
1453      return ECORE_X_WINDOW_TYPE_DROPDOWN_MENU;
1454    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_POPUP_MENU)
1455      return ECORE_X_WINDOW_TYPE_POPUP_MENU;
1456    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLTIP)
1457      return ECORE_X_WINDOW_TYPE_TOOLTIP;
1458    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NOTIFICATION)
1459      return ECORE_X_WINDOW_TYPE_NOTIFICATION;
1460    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_COMBO)
1461      return ECORE_X_WINDOW_TYPE_COMBO;
1462    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DND)
1463      return ECORE_X_WINDOW_TYPE_DND;
1464    else
1465      return ECORE_X_WINDOW_TYPE_UNKNOWN;
1466 }
1467
1468 static Ecore_X_Atom
1469 _ecore_xcb_netwm_window_state_atom_get(Ecore_X_Window_State state)
1470 {
1471    switch (state)
1472      {
1473       case ECORE_X_WINDOW_STATE_MODAL:
1474         return ECORE_X_ATOM_NET_WM_STATE_MODAL;
1475
1476       case ECORE_X_WINDOW_STATE_STICKY:
1477         return ECORE_X_ATOM_NET_WM_STATE_STICKY;
1478
1479       case ECORE_X_WINDOW_STATE_MAXIMIZED_VERT:
1480         return ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_VERT;
1481
1482       case ECORE_X_WINDOW_STATE_MAXIMIZED_HORZ:
1483         return ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_HORZ;
1484
1485       case ECORE_X_WINDOW_STATE_SHADED:
1486         return ECORE_X_ATOM_NET_WM_STATE_SHADED;
1487
1488       case ECORE_X_WINDOW_STATE_SKIP_TASKBAR:
1489         return ECORE_X_ATOM_NET_WM_STATE_SKIP_TASKBAR;
1490
1491       case ECORE_X_WINDOW_STATE_SKIP_PAGER:
1492         return ECORE_X_ATOM_NET_WM_STATE_SKIP_PAGER;
1493
1494       case ECORE_X_WINDOW_STATE_HIDDEN:
1495         return ECORE_X_ATOM_NET_WM_STATE_HIDDEN;
1496
1497       case ECORE_X_WINDOW_STATE_FULLSCREEN:
1498         return ECORE_X_ATOM_NET_WM_STATE_FULLSCREEN;
1499
1500       case ECORE_X_WINDOW_STATE_ABOVE:
1501         return ECORE_X_ATOM_NET_WM_STATE_ABOVE;
1502
1503       case ECORE_X_WINDOW_STATE_BELOW:
1504         return ECORE_X_ATOM_NET_WM_STATE_BELOW;
1505
1506       case ECORE_X_WINDOW_STATE_DEMANDS_ATTENTION:
1507         return ECORE_X_ATOM_NET_WM_STATE_DEMANDS_ATTENTION;
1508
1509       default:
1510         return 0;
1511      }
1512 }
1513
1514 Ecore_X_Window_State
1515 _ecore_xcb_netwm_window_state_get(Ecore_X_Atom atom)
1516 {
1517    if (atom == ECORE_X_ATOM_NET_WM_STATE_MODAL)
1518      return ECORE_X_WINDOW_STATE_MODAL;
1519    else if (atom == ECORE_X_ATOM_NET_WM_STATE_STICKY)
1520      return ECORE_X_WINDOW_STATE_STICKY;
1521    else if (atom == ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_VERT)
1522      return ECORE_X_WINDOW_STATE_MAXIMIZED_VERT;
1523    else if (atom == ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_HORZ)
1524      return ECORE_X_WINDOW_STATE_MAXIMIZED_HORZ;
1525    else if (atom == ECORE_X_ATOM_NET_WM_STATE_SHADED)
1526      return ECORE_X_WINDOW_STATE_SHADED;
1527    else if (atom == ECORE_X_ATOM_NET_WM_STATE_SKIP_TASKBAR)
1528      return ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
1529    else if (atom == ECORE_X_ATOM_NET_WM_STATE_SKIP_PAGER)
1530      return ECORE_X_WINDOW_STATE_SKIP_PAGER;
1531    else if (atom == ECORE_X_ATOM_NET_WM_STATE_HIDDEN)
1532      return ECORE_X_WINDOW_STATE_HIDDEN;
1533    else if (atom == ECORE_X_ATOM_NET_WM_STATE_FULLSCREEN)
1534      return ECORE_X_WINDOW_STATE_FULLSCREEN;
1535    else if (atom == ECORE_X_ATOM_NET_WM_STATE_ABOVE)
1536      return ECORE_X_WINDOW_STATE_ABOVE;
1537    else if (atom == ECORE_X_ATOM_NET_WM_STATE_BELOW)
1538      return ECORE_X_WINDOW_STATE_BELOW;
1539    else if (atom == ECORE_X_ATOM_NET_WM_STATE_DEMANDS_ATTENTION)
1540      return ECORE_X_WINDOW_STATE_DEMANDS_ATTENTION;
1541    else
1542      return ECORE_X_WINDOW_STATE_UNKNOWN;
1543 }
1544
1545 static Ecore_X_Atom
1546 _ecore_xcb_netwm_action_atom_get(Ecore_X_Action action)
1547 {
1548    switch (action)
1549      {
1550       case ECORE_X_ACTION_MOVE:
1551         return ECORE_X_ATOM_NET_WM_ACTION_MOVE;
1552
1553       case ECORE_X_ACTION_RESIZE:
1554         return ECORE_X_ATOM_NET_WM_ACTION_RESIZE;
1555
1556       case ECORE_X_ACTION_MINIMIZE:
1557         return ECORE_X_ATOM_NET_WM_ACTION_MINIMIZE;
1558
1559       case ECORE_X_ACTION_SHADE:
1560         return ECORE_X_ATOM_NET_WM_ACTION_SHADE;
1561
1562       case ECORE_X_ACTION_STICK:
1563         return ECORE_X_ATOM_NET_WM_ACTION_STICK;
1564
1565       case ECORE_X_ACTION_MAXIMIZE_HORZ:
1566         return ECORE_X_ATOM_NET_WM_ACTION_MAXIMIZE_HORZ;
1567
1568       case ECORE_X_ACTION_MAXIMIZE_VERT:
1569         return ECORE_X_ATOM_NET_WM_ACTION_MAXIMIZE_VERT;
1570
1571       case ECORE_X_ACTION_FULLSCREEN:
1572         return ECORE_X_ATOM_NET_WM_ACTION_FULLSCREEN;
1573
1574       case ECORE_X_ACTION_CHANGE_DESKTOP:
1575         return ECORE_X_ATOM_NET_WM_ACTION_CHANGE_DESKTOP;
1576
1577       case ECORE_X_ACTION_CLOSE:
1578         return ECORE_X_ATOM_NET_WM_ACTION_CLOSE;
1579
1580       case ECORE_X_ACTION_ABOVE:
1581         return ECORE_X_ATOM_NET_WM_ACTION_ABOVE;
1582
1583       case ECORE_X_ACTION_BELOW:
1584         return ECORE_X_ATOM_NET_WM_ACTION_BELOW;
1585
1586       default:
1587         return 0;
1588      }
1589 }
1590