d692c9198669f497cb07e7c596a937baffc2af39
[profile/ivi/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  * @defgroup Ecore_X_MWM_Group MWM related functions.
13  *
14  * Functions related to MWM.
15  */
16
17 #define ECORE_X_MWM_HINTS_FUNCTIONS   (1 << 0)
18 #define ECORE_X_MWM_HINTS_DECORATIONS (1 << 1)
19 #define ECORE_X_MWM_HINTS_INPUT_MODE  (1 << 2)
20 #define ECORE_X_MWM_HINTS_STATUS      (1 << 3)
21
22 typedef struct _mwmhints
23 {
24    uint32_t flags;
25    uint32_t functions;
26    uint32_t decorations;
27    int32_t  inputmode;
28    uint32_t status;
29 }
30 MWMHints;
31
32 /**
33  * Sends the GetProperty request.
34  * @param window Window whose MWM hints are requested.
35  * @ingroup Ecore_X_MWM_Group
36  */
37 EAPI void
38 ecore_x_mwm_hints_get_prefetch(Ecore_X_Window window)
39 {
40    xcb_get_property_cookie_t cookie;
41
42    cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0,
43                                        window ? window : ((xcb_screen_t *)_ecore_xcb_screen)->root,
44                                        ECORE_X_ATOM_MOTIF_WM_HINTS,
45                                        ECORE_X_ATOM_MOTIF_WM_HINTS,
46                                        0, LONG_MAX);
47    _ecore_xcb_cookie_cache(cookie.sequence);
48 } /* ecore_x_mwm_hints_get_prefetch */
49
50 /**
51  * Gets the reply of the GetProperty request sent by ecore_x_mwm_hints_get_prefetch().
52  * @ingroup Ecore_X_MWM_Group
53  */
54 EAPI void
55 ecore_x_mwm_hints_get_fetch(void)
56 {
57    xcb_get_property_cookie_t cookie;
58    xcb_get_property_reply_t *reply;
59
60    cookie.sequence = _ecore_xcb_cookie_get();
61    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
62    _ecore_xcb_reply_cache(reply);
63 } /* ecore_x_mwm_hints_get_fetch */
64
65 /**
66  * To document.
67  * @param  window Unused.
68  * @param  fhint To document.
69  * @param  dhint To document.
70  * @param  ihint To document.
71  * @return       1 on success, 0 otherwise.
72  *
73  * To use this function, you must call before, and in order,
74  * ecore_x_mwm_hints_get_prefetch(), which sends the GetProperty request,
75  * then ecore_x_mwm_hints_get_fetch(), which gets the reply.
76  * @ingroup Ecore_X_MWM_Group
77  */
78 EAPI int
79 ecore_x_mwm_hints_get(Ecore_X_Window window   __UNUSED__,
80                       Ecore_X_MWM_Hint_Func  *fhint,
81                       Ecore_X_MWM_Hint_Decor *dhint,
82                       Ecore_X_MWM_Hint_Input *ihint)
83 {
84    MWMHints *mwmhints = NULL;
85    int ret = 0;
86    xcb_get_property_reply_t *reply;
87
88    reply = _ecore_xcb_reply_get();
89    if (!reply)
90       return 0;
91
92    if ((reply->format != 32) ||
93        (reply->value_len == 0))
94       return 0;
95
96    mwmhints = xcb_get_property_value(reply);
97    if (reply->value_len >= 4)
98      {
99         if (dhint)
100           {
101              if (mwmhints->flags & ECORE_X_MWM_HINTS_DECORATIONS)
102                 *dhint = mwmhints->decorations;
103              else
104                 *dhint = ECORE_X_MWM_HINT_DECOR_ALL;
105           }
106
107         if (fhint)
108           {
109              if (mwmhints->flags & ECORE_X_MWM_HINTS_FUNCTIONS)
110                 *fhint = mwmhints->functions;
111              else
112                 *fhint = ECORE_X_MWM_HINT_FUNC_ALL;
113           }
114
115         if (ihint)
116           {
117              if (mwmhints->flags & ECORE_X_MWM_HINTS_INPUT_MODE)
118                 *ihint = mwmhints->inputmode;
119              else
120                 *ihint = ECORE_X_MWM_HINT_INPUT_MODELESS;
121           }
122
123         ret = 1;
124      }
125
126    return ret;
127 } /* ecore_x_mwm_hints_get */
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)
145       window = ((xcb_screen_t *)_ecore_xcb_screen)->root;
146
147    xcb_change_property(_ecore_xcb_conn, XCB_PROP_MODE_REPLACE, window,
148                        ECORE_X_ATOM_MOTIF_WM_HINTS, ECORE_X_ATOM_MOTIF_WM_HINTS,
149                        32, 5, data);
150 } /* ecore_x_mwm_borderless_set */
151