Tizen 2.0 Release
[profile/ivi/ecore.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    Ecore_X_Window win;
589    static Ecore_X_Atom atom = XCB_NONE;
590
591    LOGFN(__FILE__, __LINE__, __FUNCTION__);
592    CHECK_XCB_CONN;
593
594    snprintf(buff, sizeof(buff), "_NET_WM_CM_S%i", screen);
595
596    if (atom == XCB_NONE)
597      {
598         xcb_intern_atom_cookie_t acookie;
599         xcb_intern_atom_reply_t *areply;
600
601         acookie =
602           xcb_intern_atom_unchecked(_ecore_xcb_conn, 0, strlen(buff), buff);
603         areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
604         if (!areply) return EINA_FALSE;
605         atom = areply->atom;
606         free(areply);
607      }
608    if (atom == XCB_NONE) return EINA_FALSE;
609
610    ocookie = xcb_get_selection_owner_unchecked(_ecore_xcb_conn, atom);
611    oreply = xcb_get_selection_owner_reply(_ecore_xcb_conn, ocookie, NULL);
612    if (!oreply) return EINA_FALSE;
613    win = oreply->owner;
614    free(oreply);
615
616    return (win != XCB_NONE) ? EINA_TRUE : EINA_FALSE;
617 }
618
619 EAPI void
620 ecore_x_screen_is_composited_set(int            screen,
621                                  Ecore_X_Window win)
622 {
623    static Ecore_X_Atom atom = XCB_NONE;
624    char buff[32];
625
626    LOGFN(__FILE__, __LINE__, __FUNCTION__);
627    CHECK_XCB_CONN;
628
629    snprintf(buff, sizeof(buff), "_NET_WM_CM_S%i", screen);
630    if (atom == XCB_NONE)
631      {
632         xcb_intern_atom_cookie_t acookie;
633         xcb_intern_atom_reply_t *areply;
634
635         acookie =
636           xcb_intern_atom_unchecked(_ecore_xcb_conn, 0, strlen(buff), buff);
637         areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
638         if (!areply) return;
639         atom = areply->atom;
640         free(areply);
641      }
642    if (atom == XCB_NONE) return;
643    xcb_set_selection_owner(_ecore_xcb_conn, win, atom,
644                            _ecore_xcb_events_last_time_get());
645 }
646
647 EAPI void
648 ecore_x_netwm_ping_send(Ecore_X_Window win)
649 {
650    xcb_client_message_event_t ev;
651
652    LOGFN(__FILE__, __LINE__, __FUNCTION__);
653    CHECK_XCB_CONN;
654
655    if (!win) return;
656
657    ev.response_type = XCB_CLIENT_MESSAGE;
658    ev.format = 32;
659    ev.window = win;
660    ev.type = ECORE_X_ATOM_WM_PROTOCOLS;
661    ev.data.data32[0] = ECORE_X_ATOM_NET_WM_PING;
662    ev.data.data32[1] = ecore_x_current_time_get();
663    ev.data.data32[2] = win;
664    ev.data.data32[3] = 0;
665    ev.data.data32[4] = 0;
666
667    xcb_send_event(_ecore_xcb_conn, 0, win,
668                   XCB_EVENT_MASK_NO_EVENT, (const char *)&ev);
669 //   ecore_x_flush();
670 }
671
672 EAPI void
673 ecore_x_netwm_frame_size_set(Ecore_X_Window win,
674                              int            fl,
675                              int            fr,
676                              int            ft,
677                              int            fb)
678 {
679    uint32_t frames[4];
680
681    LOGFN(__FILE__, __LINE__, __FUNCTION__);
682
683    frames[0] = fl;
684    frames[1] = fr;
685    frames[2] = ft;
686    frames[3] = fb;
687    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_FRAME_EXTENTS,
688                                   frames, 4);
689 }
690
691 EAPI Eina_Bool
692 ecore_x_netwm_frame_size_get(Ecore_X_Window win,
693                              int           *fl,
694                              int           *fr,
695                              int           *ft,
696                              int           *fb)
697 {
698    int ret = 0;
699    unsigned int frames[4];
700
701    LOGFN(__FILE__, __LINE__, __FUNCTION__);
702
703    ret = ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_FRAME_EXTENTS,
704                                         frames, 4);
705    if (ret != 4) return EINA_FALSE;
706
707    if (fl) *fl = frames[0];
708    if (fr) *fr = frames[1];
709    if (ft) *ft = frames[2];
710    if (fb) *fb = frames[3];
711
712    return EINA_TRUE;
713 }
714
715 EAPI void
716 ecore_x_netwm_sync_request_send(Ecore_X_Window win,
717                                 unsigned int   serial)
718 {
719    xcb_client_message_event_t ev;
720
721    LOGFN(__FILE__, __LINE__, __FUNCTION__);
722    CHECK_XCB_CONN;
723
724    if (!win) return;
725
726    /* FIXME: Maybe need XSyncIntToValue ?? */
727    memset(&ev, 0, sizeof(xcb_client_message_event_t));
728
729    ev.response_type = XCB_CLIENT_MESSAGE;
730    ev.format = 32;
731    ev.window = win;
732    ev.type = ECORE_X_ATOM_WM_PROTOCOLS;
733    ev.data.data32[0] = ECORE_X_ATOM_NET_WM_SYNC_REQUEST;
734    ev.data.data32[1] = _ecore_xcb_events_last_time_get();
735    ev.data.data32[2] = serial;
736    ev.data.data32[3] = 0;
737    ev.data.data32[4] = 0;
738
739    xcb_send_event(_ecore_xcb_conn, 0, win,
740                   XCB_EVENT_MASK_NO_EVENT, (const char *)&ev);
741 //   ecore_x_flush();
742 }
743
744 EAPI void
745 ecore_x_netwm_desktop_set(Ecore_X_Window win,
746                           unsigned int   desk)
747 {
748    LOGFN(__FILE__, __LINE__, __FUNCTION__);
749
750    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_DESKTOP, &desk, 1);
751 }
752
753 EAPI Eina_Bool
754 ecore_x_netwm_desktop_get(Ecore_X_Window win,
755                           unsigned int  *desk)
756 {
757    unsigned int tmp = 0;
758
759    LOGFN(__FILE__, __LINE__, __FUNCTION__);
760
761    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_DESKTOP,
762                                        &tmp, 1))
763      return EINA_FALSE;
764
765    if (desk) *desk = tmp;
766
767    return EINA_TRUE;
768 }
769
770 EAPI void
771 ecore_x_netwm_desktop_request_send(Ecore_X_Window win,
772                                    Ecore_X_Window root,
773                                    unsigned int   desktop)
774 {
775    xcb_client_message_event_t ev;
776
777    LOGFN(__FILE__, __LINE__, __FUNCTION__);
778    CHECK_XCB_CONN;
779
780    if (!root) root = ((xcb_screen_t *)_ecore_xcb_screen)->root;
781
782    memset(&ev, 0, sizeof(xcb_client_message_event_t));
783
784    ev.response_type = XCB_CLIENT_MESSAGE;
785    ev.format = 32;
786    ev.window = win;
787    ev.type = ECORE_X_ATOM_NET_WM_DESKTOP;
788    ev.data.data32[0] = desktop;
789
790    xcb_send_event(_ecore_xcb_conn, 0, root,
791                   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
792                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), (const char *)&ev);
793 //   ecore_x_flush();
794 }
795
796 EAPI void
797 ecore_x_netwm_moveresize_request_send(Ecore_X_Window win,
798                                       int x,
799                                       int y,
800                                       Ecore_X_Netwm_Direction direction,
801                                       unsigned int button)
802 {
803    xcb_client_message_event_t ev;
804
805    LOGFN(__FILE__, __LINE__, __FUNCTION__);
806    CHECK_XCB_CONN;
807
808    memset(&ev, 0, sizeof(xcb_client_message_event_t));
809
810    ev.response_type = XCB_CLIENT_MESSAGE;
811    ev.format = 32;
812    ev.window = win;
813    ev.type = ECORE_X_ATOM_NET_WM_MOVERESIZE;
814    ev.data.data32[0] = x;
815    ev.data.data32[1] = y;
816    ev.data.data32[2] = direction;
817    ev.data.data32[3] = button;
818    ev.data.data32[4] = 1;
819
820    xcb_send_event(_ecore_xcb_conn, 0, win,
821                   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
822                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), (const char *)&ev);
823 }
824
825 EAPI void
826 ecore_x_netwm_handled_icons_set(Ecore_X_Window win)
827 {
828    LOGFN(__FILE__, __LINE__, __FUNCTION__);
829
830    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_HANDLED_ICONS,
831                                   NULL, 0);
832 }
833
834 EAPI Eina_Bool
835 ecore_x_netwm_handled_icons_get(Ecore_X_Window win)
836 {
837    LOGFN(__FILE__, __LINE__, __FUNCTION__);
838
839    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_HANDLED_ICONS,
840                                        NULL, 0))
841      return EINA_FALSE;
842
843    return EINA_TRUE;
844 }
845
846 EAPI int
847 ecore_x_netwm_icon_name_get(Ecore_X_Window win,
848                             char         **name)
849 {
850    LOGFN(__FILE__, __LINE__, __FUNCTION__);
851
852    if (name)
853      {
854         *name =
855           ecore_x_window_prop_string_get(win, ECORE_X_ATOM_NET_WM_ICON_NAME);
856      }
857
858    return 1;
859 }
860
861 EAPI void
862 ecore_x_netwm_icon_name_set(Ecore_X_Window win,
863                             const char    *name)
864 {
865    LOGFN(__FILE__, __LINE__, __FUNCTION__);
866
867    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_ICON_NAME, name);
868 }
869
870 EAPI void
871 ecore_x_netwm_icons_set(Ecore_X_Window win,
872                         Ecore_X_Icon *icon,
873                         int num)
874 {
875    unsigned int *data, *p, *p2;
876    unsigned int i, size, x, y;
877    
878    LOGFN(__FILE__, __LINE__, __FUNCTION__);
879    size = 0;
880    for (i = 0; i < (unsigned int)num; i++)
881      {
882         size += 2 + (icon[i].width * icon[i].height);
883      }
884    data = malloc(size * sizeof(unsigned int));
885    if (!data) return;
886    p = data;
887    for (i = 0; i < (unsigned int)num; i++)
888      {
889         p[0] = icon[i].width;
890         p[1] = icon[i].height;
891         p += 2;
892         p2 = icon[i].data;
893         for (y = 0; y < icon[i].height; y++)
894           {
895              for (x = 0; x < icon[i].width; x++)
896                {
897                   unsigned int r, g, b, a;
898                   
899                   a = (*p2 >> 24) & 0xff;
900                   r = (*p2 >> 16) & 0xff;
901                   g = (*p2 >> 8 ) & 0xff;
902                   b = (*p2      ) & 0xff;
903                   if ((a > 0) && (a < 255))
904                     {
905                        r = (r * 255) / a;
906                        g = (g * 255) / a;
907                        b = (b * 255) / a;
908                     }
909                   *p = (a << 24) | (r << 16) | (g << 8) | b;
910                   p++;
911                   p2++;
912                }
913           }
914      }
915    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_ICON,
916                                   data, size);
917    free(data);
918 }
919
920 EAPI Eina_Bool
921 ecore_x_netwm_icons_get(Ecore_X_Window win,
922                         Ecore_X_Icon **icon,
923                         int           *num)
924 {
925    int num_ret = 0;
926    unsigned int i = 0, len = 0, icons = 0;
927    unsigned int *data, *p, *src;
928
929    LOGFN(__FILE__, __LINE__, __FUNCTION__);
930
931    if (num) *num = 0;
932    if (icon) *icon = NULL;
933
934    num_ret =
935      ecore_x_window_prop_card32_list_get(win, ECORE_X_ATOM_NET_WM_ICON, &data);
936
937    if ((num_ret <= 0) || (!data))
938      {
939         if (data) free(data);
940         return EINA_FALSE;
941      }
942    if (num_ret < 2)
943      {
944         if (data) free(data);
945         return EINA_FALSE;
946      }
947
948    icons = 0;
949    p = data;
950    while (p)
951      {
952         len = (p[0] * p[1]);
953         p += (len + 2);
954         if ((p - data) > num_ret)
955           {
956              if (data) free(data);
957              return EINA_FALSE;
958           }
959         icons++;
960         if ((p - data) == num_ret) p = NULL;
961      }
962    if (num) *num = icons;
963    if (!icon)
964      {
965         if (data) free(data);
966         return EINA_TRUE;
967      }
968
969    *icon = malloc(icons * sizeof(Ecore_X_Icon));
970    if (!(*icon))
971      {
972         if (data) free(data);
973         return EINA_FALSE;
974      }
975
976    /* Fetch the icons */
977    p = data;
978    for (i = 0; i < icons; i++)
979      {
980         unsigned int *ps, *pd, *pe;
981
982         len = p[0] * p[1];
983         ((*icon)[i]).width = p[0];
984         ((*icon)[i]).height = p[1];
985         src = &(p[2]);
986         ((*icon)[i]).data = malloc(len * sizeof(unsigned int));
987         if (!((*icon)[i]).data)
988           {
989              while (i)
990                free(((*icon)[--i]).data);
991              free(*icon);
992              free(data);
993              return EINA_FALSE;
994           }
995
996         pd = ((*icon)[i]).data;
997         ps = src;
998         pe = ps + len;
999         for (; ps < pe; ps++)
1000           {
1001              unsigned int r, g, b, a;
1002
1003              a = (*ps >> 24) & 0xff;
1004              r = (((*ps >> 16) & 0xff) * a) / 255;
1005              g = (((*ps >> 8) & 0xff) * a) / 255;
1006              b = (((*ps) & 0xff) * a) / 255;
1007              *pd = (a << 24) | (r << 16) | (g << 8) | (b);
1008              pd++;
1009           }
1010         p += (len + 2);
1011      }
1012
1013    if (data) free(data);
1014    return EINA_TRUE;
1015 }
1016
1017 EAPI void
1018 ecore_x_netwm_icon_geometry_set(Ecore_X_Window win,
1019                                 int            x,
1020                                 int            y,
1021                                 int            w,
1022                                 int            h)
1023 {
1024    unsigned int geom[4];
1025
1026    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1027
1028    geom[0] = x;
1029    geom[1] = y;
1030    geom[2] = w;
1031    geom[3] = h;
1032    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_ICON_GEOMETRY,
1033                                   geom, 4);
1034 }
1035
1036 EAPI Eina_Bool
1037 ecore_x_netwm_icon_geometry_get(Ecore_X_Window win,
1038                                 int           *x,
1039                                 int           *y,
1040                                 int           *w,
1041                                 int           *h)
1042 {
1043    int ret = 0;
1044    unsigned int geom[4];
1045
1046    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1047
1048    ret =
1049      ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_ICON_GEOMETRY,
1050                                     geom, 4);
1051    if (ret != 4) return EINA_FALSE;
1052    if (x) *x = geom[0];
1053    if (y) *y = geom[1];
1054    if (w) *w = geom[2];
1055    if (h) *h = geom[3];
1056
1057    return EINA_TRUE;
1058 }
1059
1060 EAPI void
1061 ecore_x_netwm_strut_set(Ecore_X_Window win,
1062                         int            l,
1063                         int            r,
1064                         int            t,
1065                         int            b)
1066 {
1067    unsigned int strut[4];
1068
1069    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1070
1071    strut[0] = l;
1072    strut[1] = r;
1073    strut[2] = t;
1074    strut[3] = b;
1075    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_STRUT, strut, 4);
1076 }
1077
1078 EAPI Eina_Bool
1079 ecore_x_netwm_strut_get(Ecore_X_Window win,
1080                         int           *l,
1081                         int           *r,
1082                         int           *t,
1083                         int           *b)
1084 {
1085    unsigned int strut[4];
1086    int ret = 0;
1087
1088    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1089
1090    ret =
1091      ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_STRUT, strut, 4);
1092    if (ret != 4) return EINA_FALSE;
1093
1094    if (l) *l = strut[0];
1095    if (r) *r = strut[1];
1096    if (t) *t = strut[2];
1097    if (b) *b = strut[3];
1098
1099    return EINA_TRUE;
1100 }
1101
1102 EAPI void
1103 ecore_x_netwm_strut_partial_set(Ecore_X_Window win,
1104                                 int            left,
1105                                 int            right,
1106                                 int            top,
1107                                 int            bottom,
1108                                 int            left_start_y,
1109                                 int            left_end_y,
1110                                 int            right_start_y,
1111                                 int            right_end_y,
1112                                 int            top_start_x,
1113                                 int            top_end_x,
1114                                 int            bottom_start_x,
1115                                 int            bottom_end_x)
1116 {
1117    unsigned int strut[12];
1118
1119    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1120
1121    strut[0] = left;
1122    strut[1] = right;
1123    strut[2] = top;
1124    strut[3] = bottom;
1125    strut[4] = left_start_y;
1126    strut[5] = left_end_y;
1127    strut[6] = right_start_y;
1128    strut[7] = right_end_y;
1129    strut[8] = top_start_x;
1130    strut[9] = top_end_x;
1131    strut[10] = bottom_start_x;
1132    strut[11] = bottom_end_x;
1133    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_STRUT_PARTIAL,
1134                                   strut, 12);
1135 }
1136
1137 EAPI Eina_Bool
1138 ecore_x_netwm_strut_partial_get(Ecore_X_Window win,
1139                                 int           *left,
1140                                 int           *right,
1141                                 int           *top,
1142                                 int           *bottom,
1143                                 int           *left_start_y,
1144                                 int           *left_end_y,
1145                                 int           *right_start_y,
1146                                 int           *right_end_y,
1147                                 int           *top_start_x,
1148                                 int           *top_end_x,
1149                                 int           *bottom_start_x,
1150                                 int           *bottom_end_x)
1151 {
1152    unsigned int strut[12];
1153    int ret = 0;
1154
1155    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1156
1157    ret =
1158      ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_STRUT_PARTIAL,
1159                                     strut, 12);
1160    if (ret != 12) return EINA_FALSE;
1161
1162    if (left) *left = strut[0];
1163    if (right) *right = strut[1];
1164    if (top) *top = strut[2];
1165    if (bottom) *bottom = strut[3];
1166    if (left_start_y) *left_start_y = strut[4];
1167    if (left_end_y) *left_end_y = strut[5];
1168    if (right_start_y) *right_start_y = strut[6];
1169    if (right_end_y) *right_end_y = strut[7];
1170    if (top_start_x) *top_start_x = strut[8];
1171    if (top_end_x) *top_end_x = strut[9];
1172    if (bottom_start_x) *bottom_start_x = strut[10];
1173    if (bottom_end_x) *bottom_end_x = strut[11];
1174
1175    return EINA_TRUE;
1176 }
1177
1178 EAPI void
1179 ecore_x_netwm_user_time_set(Ecore_X_Window win,
1180                             unsigned int   t)
1181 {
1182    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1183
1184    ecore_x_window_prop_card32_set(win, ECORE_X_ATOM_NET_WM_USER_TIME, &t, 1);
1185 }
1186
1187 EAPI Eina_Bool
1188 ecore_x_netwm_user_time_get(Ecore_X_Window win,
1189                             unsigned int  *t)
1190 {
1191    unsigned int tmp;
1192
1193    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1194
1195    if (!ecore_x_window_prop_card32_get(win, ECORE_X_ATOM_NET_WM_USER_TIME,
1196                                        &tmp, 1))
1197      return EINA_FALSE;
1198
1199    if (t) *t = tmp;
1200
1201    return EINA_TRUE;
1202 }
1203
1204 EAPI void
1205 ecore_x_netwm_visible_name_set(Ecore_X_Window win,
1206                                const char    *name)
1207 {
1208    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1209
1210    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_VISIBLE_NAME,
1211                                   name);
1212 }
1213
1214 EAPI int
1215 ecore_x_netwm_visible_name_get(Ecore_X_Window win,
1216                                char         **name)
1217 {
1218    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1219
1220    if (name)
1221      *name = ecore_x_window_prop_string_get(win,
1222                                             ECORE_X_ATOM_NET_WM_VISIBLE_NAME);
1223    return 1;
1224 }
1225
1226 EAPI void
1227 ecore_x_netwm_visible_icon_name_set(Ecore_X_Window win,
1228                                     const char    *name)
1229 {
1230    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1231
1232    ecore_x_window_prop_string_set(win, ECORE_X_ATOM_NET_WM_VISIBLE_ICON_NAME,
1233                                   name);
1234 }
1235
1236 EAPI int
1237 ecore_x_netwm_visible_icon_name_get(Ecore_X_Window win,
1238                                     char         **name)
1239 {
1240    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1241
1242    if (name)
1243      {
1244         *name =
1245           ecore_x_window_prop_string_get(win,
1246                                          ECORE_X_ATOM_NET_WM_VISIBLE_ICON_NAME);
1247      }
1248
1249    return 1;
1250 }
1251
1252 EAPI Eina_Bool
1253 ecore_x_netwm_sync_counter_get(Ecore_X_Window        win,
1254                                Ecore_X_Sync_Counter *counter)
1255 {
1256    unsigned int tmp;
1257
1258    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1259
1260    if (!ecore_x_window_prop_card32_get(win,
1261                                        ECORE_X_ATOM_NET_WM_SYNC_REQUEST_COUNTER,
1262                                        &tmp, 1))
1263      return EINA_FALSE;
1264
1265    if (counter) *counter = tmp;
1266
1267    return EINA_TRUE;
1268 }
1269
1270 EAPI Eina_Bool
1271 ecore_x_netwm_allowed_action_isset(Ecore_X_Window win,
1272                                    Ecore_X_Action action)
1273 {
1274    int num = 0, i = 0;
1275    Ecore_X_Atom *atoms, atom;
1276    Eina_Bool ret = EINA_FALSE;
1277
1278    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1279
1280    num =
1281      ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_WINDOW_TYPE,
1282                                        &atoms);
1283    if (num <= 0) return EINA_FALSE;
1284
1285    atom = _ecore_xcb_netwm_action_atom_get(action);
1286    for (i = 0; i < num; i++)
1287      {
1288         if (atoms[i] == atom)
1289           {
1290              ret = EINA_TRUE;
1291              break;
1292           }
1293      }
1294
1295    if (atoms) free(atoms);
1296    return ret;
1297 }
1298
1299 EAPI Eina_Bool
1300 ecore_x_netwm_allowed_action_get(Ecore_X_Window   win,
1301                                  Ecore_X_Action **action,
1302                                  unsigned int    *num)
1303 {
1304    Ecore_X_Atom *atoms;
1305    int num_ret = 0;
1306
1307    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1308
1309    if (num) *num = 0;
1310    if (action) *action = NULL;
1311
1312    num_ret =
1313      ecore_x_window_prop_atom_list_get(win, ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
1314                                        &atoms);
1315    if (num_ret <= 0) return EINA_FALSE;
1316    if (action)
1317      {
1318         *action = malloc(num_ret * sizeof(Ecore_X_Action));
1319         if (*action)
1320           {
1321              int i = 0;
1322
1323              for (i = 0; i < num_ret; i++)
1324                (*action)[i] = _ecore_xcb_netwm_action_atom_get(atoms[i]);
1325           }
1326         if (num) *num = num_ret;
1327      }
1328    free(atoms);
1329    return EINA_TRUE;
1330 }
1331
1332 EAPI void
1333 ecore_x_netwm_allowed_action_set(Ecore_X_Window  win,
1334                                  Ecore_X_Action *action,
1335                                  unsigned int    num)
1336 {
1337    Ecore_X_Atom *set;
1338    unsigned int i = 0;
1339
1340    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1341
1342    if (!num)
1343      {
1344         ecore_x_window_prop_property_del(win,
1345                                          ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS);
1346         return;
1347      }
1348
1349    set = malloc(num * sizeof(Ecore_X_Atom));
1350    if (!set) return;
1351
1352    for (i = 0; i < num; i++)
1353      set[i] = _ecore_xcb_netwm_action_atom_get(action[i]);
1354
1355    ecore_x_window_prop_atom_set(win, ECORE_X_ATOM_NET_WM_ALLOWED_ACTIONS,
1356                                 set, num);
1357    free(set);
1358 }
1359
1360 /* local functions */
1361 int
1362 _ecore_xcb_netwm_startup_info_begin(Ecore_X_Window win __UNUSED__,
1363                                     uint8_t        data __UNUSED__)
1364 {
1365    // TODO: TBD
1366      return 1;
1367 }
1368
1369 int
1370 _ecore_xcb_netwm_startup_info(Ecore_X_Window win __UNUSED__,
1371                               uint8_t        data __UNUSED__)
1372 {
1373    // TODO: TBD
1374      return 1;
1375 }
1376
1377 /* static void  */
1378 /* _ecore_xcb_netwm_startup_info_free(void *data)  */
1379 /* { */
1380 /*    Ecore_Xcb_Startup_Info *info; */
1381
1382 /*    LOGFN(__FILE__, __LINE__, __FUNCTION__); */
1383
1384 /*    if (!(info = data)) return; */
1385 /*    if (info->buffer) free(info->buffer); */
1386 /*    if (info->id) free(info->id); */
1387 /*    if (info->name) free(info->name); */
1388 /*    if (info->bin) free(info->bin); */
1389 /*    if (info->icon) free(info->icon); */
1390 /*    if (info->description) free(info->description); */
1391 /*    if (info->wmclass) free(info->wmclass); */
1392 /*    free(info); */
1393 /* } */
1394
1395 static Ecore_X_Atom
1396 _ecore_xcb_netwm_window_type_atom_get(Ecore_X_Window_Type type)
1397 {
1398    switch (type)
1399      {
1400       case ECORE_X_WINDOW_TYPE_DESKTOP:
1401         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DESKTOP;
1402
1403       case ECORE_X_WINDOW_TYPE_DOCK:
1404         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DOCK;
1405
1406       case ECORE_X_WINDOW_TYPE_TOOLBAR:
1407         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLBAR;
1408
1409       case ECORE_X_WINDOW_TYPE_MENU:
1410         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_MENU;
1411
1412       case ECORE_X_WINDOW_TYPE_UTILITY:
1413         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_UTILITY;
1414
1415       case ECORE_X_WINDOW_TYPE_SPLASH:
1416         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_SPLASH;
1417
1418       case ECORE_X_WINDOW_TYPE_DIALOG:
1419         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DIALOG;
1420
1421       case ECORE_X_WINDOW_TYPE_NORMAL:
1422         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NORMAL;
1423
1424       case ECORE_X_WINDOW_TYPE_DROPDOWN_MENU:
1425         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
1426
1427       case ECORE_X_WINDOW_TYPE_POPUP_MENU:
1428         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_POPUP_MENU;
1429
1430       case ECORE_X_WINDOW_TYPE_TOOLTIP:
1431         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLTIP;
1432
1433       case ECORE_X_WINDOW_TYPE_NOTIFICATION:
1434         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NOTIFICATION;
1435
1436       case ECORE_X_WINDOW_TYPE_COMBO:
1437         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_COMBO;
1438
1439       case ECORE_X_WINDOW_TYPE_DND:
1440         return ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DND;
1441
1442       default:
1443         return 0;
1444      }
1445 }
1446
1447 static Ecore_X_Window_Type
1448 _ecore_xcb_netwm_window_type_type_get(Ecore_X_Atom atom)
1449 {
1450    if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DESKTOP)
1451      return ECORE_X_WINDOW_TYPE_DESKTOP;
1452    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DOCK)
1453      return ECORE_X_WINDOW_TYPE_DOCK;
1454    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLBAR)
1455      return ECORE_X_WINDOW_TYPE_TOOLBAR;
1456    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_MENU)
1457      return ECORE_X_WINDOW_TYPE_MENU;
1458    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_UTILITY)
1459      return ECORE_X_WINDOW_TYPE_UTILITY;
1460    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_SPLASH)
1461      return ECORE_X_WINDOW_TYPE_SPLASH;
1462    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DIALOG)
1463      return ECORE_X_WINDOW_TYPE_DIALOG;
1464    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NORMAL)
1465      return ECORE_X_WINDOW_TYPE_NORMAL;
1466    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DROPDOWN_MENU)
1467      return ECORE_X_WINDOW_TYPE_DROPDOWN_MENU;
1468    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_POPUP_MENU)
1469      return ECORE_X_WINDOW_TYPE_POPUP_MENU;
1470    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_TOOLTIP)
1471      return ECORE_X_WINDOW_TYPE_TOOLTIP;
1472    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_NOTIFICATION)
1473      return ECORE_X_WINDOW_TYPE_NOTIFICATION;
1474    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_COMBO)
1475      return ECORE_X_WINDOW_TYPE_COMBO;
1476    else if (atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE_DND)
1477      return ECORE_X_WINDOW_TYPE_DND;
1478    else
1479      return ECORE_X_WINDOW_TYPE_UNKNOWN;
1480 }
1481
1482 static Ecore_X_Atom
1483 _ecore_xcb_netwm_window_state_atom_get(Ecore_X_Window_State state)
1484 {
1485    switch (state)
1486      {
1487       case ECORE_X_WINDOW_STATE_MODAL:
1488         return ECORE_X_ATOM_NET_WM_STATE_MODAL;
1489
1490       case ECORE_X_WINDOW_STATE_STICKY:
1491         return ECORE_X_ATOM_NET_WM_STATE_STICKY;
1492
1493       case ECORE_X_WINDOW_STATE_MAXIMIZED_VERT:
1494         return ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_VERT;
1495
1496       case ECORE_X_WINDOW_STATE_MAXIMIZED_HORZ:
1497         return ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_HORZ;
1498
1499       case ECORE_X_WINDOW_STATE_SHADED:
1500         return ECORE_X_ATOM_NET_WM_STATE_SHADED;
1501
1502       case ECORE_X_WINDOW_STATE_SKIP_TASKBAR:
1503         return ECORE_X_ATOM_NET_WM_STATE_SKIP_TASKBAR;
1504
1505       case ECORE_X_WINDOW_STATE_SKIP_PAGER:
1506         return ECORE_X_ATOM_NET_WM_STATE_SKIP_PAGER;
1507
1508       case ECORE_X_WINDOW_STATE_HIDDEN:
1509         return ECORE_X_ATOM_NET_WM_STATE_HIDDEN;
1510
1511       case ECORE_X_WINDOW_STATE_FULLSCREEN:
1512         return ECORE_X_ATOM_NET_WM_STATE_FULLSCREEN;
1513
1514       case ECORE_X_WINDOW_STATE_ABOVE:
1515         return ECORE_X_ATOM_NET_WM_STATE_ABOVE;
1516
1517       case ECORE_X_WINDOW_STATE_BELOW:
1518         return ECORE_X_ATOM_NET_WM_STATE_BELOW;
1519
1520       case ECORE_X_WINDOW_STATE_DEMANDS_ATTENTION:
1521         return ECORE_X_ATOM_NET_WM_STATE_DEMANDS_ATTENTION;
1522
1523       default:
1524         return 0;
1525      }
1526 }
1527
1528 Ecore_X_Window_State
1529 _ecore_xcb_netwm_window_state_get(Ecore_X_Atom atom)
1530 {
1531    if (atom == ECORE_X_ATOM_NET_WM_STATE_MODAL)
1532      return ECORE_X_WINDOW_STATE_MODAL;
1533    else if (atom == ECORE_X_ATOM_NET_WM_STATE_STICKY)
1534      return ECORE_X_WINDOW_STATE_STICKY;
1535    else if (atom == ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_VERT)
1536      return ECORE_X_WINDOW_STATE_MAXIMIZED_VERT;
1537    else if (atom == ECORE_X_ATOM_NET_WM_STATE_MAXIMIZED_HORZ)
1538      return ECORE_X_WINDOW_STATE_MAXIMIZED_HORZ;
1539    else if (atom == ECORE_X_ATOM_NET_WM_STATE_SHADED)
1540      return ECORE_X_WINDOW_STATE_SHADED;
1541    else if (atom == ECORE_X_ATOM_NET_WM_STATE_SKIP_TASKBAR)
1542      return ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
1543    else if (atom == ECORE_X_ATOM_NET_WM_STATE_SKIP_PAGER)
1544      return ECORE_X_WINDOW_STATE_SKIP_PAGER;
1545    else if (atom == ECORE_X_ATOM_NET_WM_STATE_HIDDEN)
1546      return ECORE_X_WINDOW_STATE_HIDDEN;
1547    else if (atom == ECORE_X_ATOM_NET_WM_STATE_FULLSCREEN)
1548      return ECORE_X_WINDOW_STATE_FULLSCREEN;
1549    else if (atom == ECORE_X_ATOM_NET_WM_STATE_ABOVE)
1550      return ECORE_X_WINDOW_STATE_ABOVE;
1551    else if (atom == ECORE_X_ATOM_NET_WM_STATE_BELOW)
1552      return ECORE_X_WINDOW_STATE_BELOW;
1553    else if (atom == ECORE_X_ATOM_NET_WM_STATE_DEMANDS_ATTENTION)
1554      return ECORE_X_WINDOW_STATE_DEMANDS_ATTENTION;
1555    else
1556      return ECORE_X_WINDOW_STATE_UNKNOWN;
1557 }
1558
1559 static Ecore_X_Atom
1560 _ecore_xcb_netwm_action_atom_get(Ecore_X_Action action)
1561 {
1562    switch (action)
1563      {
1564       case ECORE_X_ACTION_MOVE:
1565         return ECORE_X_ATOM_NET_WM_ACTION_MOVE;
1566
1567       case ECORE_X_ACTION_RESIZE:
1568         return ECORE_X_ATOM_NET_WM_ACTION_RESIZE;
1569
1570       case ECORE_X_ACTION_MINIMIZE:
1571         return ECORE_X_ATOM_NET_WM_ACTION_MINIMIZE;
1572
1573       case ECORE_X_ACTION_SHADE:
1574         return ECORE_X_ATOM_NET_WM_ACTION_SHADE;
1575
1576       case ECORE_X_ACTION_STICK:
1577         return ECORE_X_ATOM_NET_WM_ACTION_STICK;
1578
1579       case ECORE_X_ACTION_MAXIMIZE_HORZ:
1580         return ECORE_X_ATOM_NET_WM_ACTION_MAXIMIZE_HORZ;
1581
1582       case ECORE_X_ACTION_MAXIMIZE_VERT:
1583         return ECORE_X_ATOM_NET_WM_ACTION_MAXIMIZE_VERT;
1584
1585       case ECORE_X_ACTION_FULLSCREEN:
1586         return ECORE_X_ATOM_NET_WM_ACTION_FULLSCREEN;
1587
1588       case ECORE_X_ACTION_CHANGE_DESKTOP:
1589         return ECORE_X_ATOM_NET_WM_ACTION_CHANGE_DESKTOP;
1590
1591       case ECORE_X_ACTION_CLOSE:
1592         return ECORE_X_ATOM_NET_WM_ACTION_CLOSE;
1593
1594       case ECORE_X_ACTION_ABOVE:
1595         return ECORE_X_ATOM_NET_WM_ACTION_ABOVE;
1596
1597       case ECORE_X_ACTION_BELOW:
1598         return ECORE_X_ATOM_NET_WM_ACTION_BELOW;
1599
1600       default:
1601         return 0;
1602      }
1603 }
1604