59ab579e58a49d5a2da218a77bbe6d0f0e5cfa1a
[platform/upstream/efl.git] / src / lib / ecore_x / xcb / ecore_xcb_mwm.c
1 #include "ecore_xcb_private.h"
2 //#include "Ecore_X_Atoms.h"
3
4 #define ECORE_X_MWM_HINTS_FUNCTIONS   (1 << 0)
5 #define ECORE_X_MWM_HINTS_DECORATIONS (1 << 1)
6 #define ECORE_X_MWM_HINTS_INPUT_MODE  (1 << 2)
7 #define ECORE_X_MWM_HINTS_STATUS      (1 << 3)
8
9 typedef struct _mwmhints
10 {
11    uint32_t flags;
12    uint32_t functions;
13    uint32_t decorations;
14    int32_t  inputmode;
15    uint32_t status;
16 } MWMHints;
17
18 /**
19  * @defgroup Ecore_X_MWM_Group MWM related functions.
20  * @ingroup Ecore_X_Group
21  *
22  * Functions related to MWM.
23  */
24
25 /**
26  * Sets the borderless flag of a window using MWM.
27  *
28  * @param win The window.
29  * @param borderless The borderless flag.
30  *
31  * @ingroup Ecore_X_MWM_Group
32  */
33 EAPI void
34 ecore_x_mwm_borderless_set(Ecore_X_Window win,
35                            Eina_Bool      borderless)
36 {
37    uint32_t data[5] = { 0, 0, 0, 0, 0 };
38
39    LOGFN(__FILE__, __LINE__, __FUNCTION__);
40
41    data[0] = 2;
42    data[2] = !borderless;
43
44    ecore_x_window_prop_property_set(win,
45                                     ECORE_X_ATOM_MOTIF_WM_HINTS,
46                                     ECORE_X_ATOM_MOTIF_WM_HINTS, 32,
47                                     (void *)data, 5);
48 }
49
50 EAPI Eina_Bool
51 ecore_x_mwm_hints_get(Ecore_X_Window          win,
52                       Ecore_X_MWM_Hint_Func  *fhint,
53                       Ecore_X_MWM_Hint_Decor *dhint,
54                       Ecore_X_MWM_Hint_Input *ihint)
55 {
56    xcb_get_property_cookie_t cookie;
57    xcb_get_property_reply_t *reply;
58    MWMHints *mwmhints = NULL;
59    int ret = EINA_FALSE;
60
61    LOGFN(__FILE__, __LINE__, __FUNCTION__);
62    CHECK_XCB_CONN;
63
64    cookie =
65      xcb_get_property_unchecked(_ecore_xcb_conn, 0, win,
66                                 ECORE_X_ATOM_MOTIF_WM_HINTS,
67                                 ECORE_X_ATOM_MOTIF_WM_HINTS, 0, UINT_MAX);
68    reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
69    if (!reply) return EINA_FALSE;
70    if ((reply->format != 32) || (reply->value_len == 0))
71      {
72         free(reply);
73         return EINA_FALSE;
74      }
75
76    mwmhints = xcb_get_property_value(reply);
77    if (reply->value_len >= 4)
78      {
79         if (dhint)
80           {
81              if (mwmhints->flags & ECORE_X_MWM_HINTS_DECORATIONS)
82                *dhint = mwmhints->decorations;
83              else
84                *dhint = ECORE_X_MWM_HINT_DECOR_ALL;
85           }
86         if (fhint)
87           {
88              if (mwmhints->flags & ECORE_X_MWM_HINTS_FUNCTIONS)
89                *fhint = mwmhints->functions;
90              else
91                *fhint = ECORE_X_MWM_HINT_FUNC_ALL;
92           }
93         if (ihint)
94           {
95              if (mwmhints->flags & ECORE_X_MWM_HINTS_INPUT_MODE)
96                *ihint = mwmhints->inputmode;
97              else
98                *ihint = ECORE_X_MWM_HINT_INPUT_MODELESS;
99           }
100         ret = EINA_TRUE;
101      }
102    free(reply);
103    return ret;
104 }
105