f96c4cf5d9e7fe2e6a1cfa3d03da5cc51541ec4d
[framework/uifw/ecore.git] / src / lib / ecore_x / xcb / ecore_xcb_mwm.c
1 /*
2  * Various MWM related functions.
3  * 
4  * This is ALL the code involving anything MWM related. for both WM and
5  * client.
6  */
7
8 #include "ecore_xcb_private.h"
9 #include "Ecore_X_Atoms.h"
10
11
12 /**
13  * @defgroup Ecore_X_MWM_Group MWM related functions.
14  *
15  * Functions related to MWM.
16  */
17
18 #define ECORE_X_MWM_HINTS_FUNCTIONS           (1 << 0)
19 #define ECORE_X_MWM_HINTS_DECORATIONS         (1 << 1)
20 #define ECORE_X_MWM_HINTS_INPUT_MODE          (1 << 2)
21 #define ECORE_X_MWM_HINTS_STATUS              (1 << 3)
22
23 typedef struct _mwmhints
24 {
25    uint32_t flags;
26    uint32_t functions;
27    uint32_t decorations;
28    int32_t  inputmode;
29    uint32_t status;
30 }
31 MWMHints;
32
33
34 /**
35  * Sends the GetProperty request.
36  * @param window Window whose MWM hints are requested.
37  * @ingroup Ecore_X_MWM_Group
38  */
39 EAPI void
40 ecore_x_mwm_hints_get_prefetch(Ecore_X_Window window)
41 {
42    xcb_get_property_cookie_t cookie;
43
44    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
45                                        window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
46                                        ECORE_X_ATOM_MOTIF_WM_HINTS,
47                                        ECORE_X_ATOM_MOTIF_WM_HINTS,
48                                        0, LONG_MAX);
49    _ecore_xcb_cookie_cache(cookie.sequence);
50 }
51
52
53 /**
54  * Gets the reply of the GetProperty request sent by ecore_x_mwm_hints_get_prefetch().
55  * @ingroup Ecore_X_MWM_Group
56  */
57 EAPI void
58 ecore_x_mwm_hints_get_fetch(void)
59 {
60    xcb_get_property_cookie_t cookie;
61    xcb_get_property_reply_t *reply;
62
63    cookie.sequence = _ecore_xcb_cookie_get();
64    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
65    _ecore_xcb_reply_cache(reply);
66 }
67
68 /**
69  * To document.
70  * @param  window Unused.
71  * @param  fhint To document.
72  * @param  dhint To document.
73  * @param  ihint To document.
74  * @return       1 on success, 0 otherwise.
75  *
76  * To use this function, you must call before, and in order,
77  * ecore_x_mwm_hints_get_prefetch(), which sends the GetProperty request,
78  * then ecore_x_mwm_hints_get_fetch(), which gets the reply.
79  * @ingroup Ecore_X_MWM_Group
80  */
81 EAPI int
82 ecore_x_mwm_hints_get(Ecore_X_Window          window __UNUSED__,
83                       Ecore_X_MWM_Hint_Func  *fhint,
84                       Ecore_X_MWM_Hint_Decor *dhint,
85                       Ecore_X_MWM_Hint_Input *ihint)
86 {
87    MWMHints                 *mwmhints = NULL;
88    int                       ret = 0;
89    xcb_get_property_reply_t *reply;
90
91    reply = _ecore_xcb_reply_get();
92    if (!reply)
93       return 0;
94
95    if ((reply->format != 32) ||
96        (reply->value_len == 0))
97       return 0;
98
99    mwmhints = xcb_get_property_value(reply);
100    if (reply->value_len >= 4)
101      {
102         if (dhint)
103           {
104              if (mwmhints->flags & ECORE_X_MWM_HINTS_DECORATIONS)
105                *dhint = mwmhints->decorations;
106              else
107                *dhint = ECORE_X_MWM_HINT_DECOR_ALL;
108           }
109         if (fhint)
110           {
111              if (mwmhints->flags & ECORE_X_MWM_HINTS_FUNCTIONS)
112                *fhint = mwmhints->functions;
113              else
114                *fhint = ECORE_X_MWM_HINT_FUNC_ALL;
115           }
116         if (ihint)
117           {
118              if (mwmhints->flags & ECORE_X_MWM_HINTS_INPUT_MODE)
119                *ihint = mwmhints->inputmode;
120              else
121                *ihint = ECORE_X_MWM_HINT_INPUT_MODELESS;
122           }
123         ret = 1;
124      }
125
126    return ret;
127 }
128
129 /**
130  * Sets the borderless flag of a window using MWM.
131  * @param window     The window.
132  * @param borderless The borderless flag.
133  * @ingroup Ecore_X_MWM_Group
134  */
135 EAPI void
136 ecore_x_mwm_borderless_set(Ecore_X_Window window,
137                            int            borderless)
138 {
139    uint32_t data[5] = {0, 0, 0, 0, 0};
140
141    data[0] = 2; /* just set the decorations hint! */
142    data[2] = !borderless;
143    
144    if (window == 0) window = ((xcb_screen_t *)_ecore_xcb_screen)->root;
145    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, window,
146                        ECORE_X_ATOM_MOTIF_WM_HINTS, ECORE_X_ATOM_MOTIF_WM_HINTS,
147                        32, 5, data);
148 }
149