[ecore] merged svn latest code (svn54830)
[profile/ivi/ecore.git] / src / lib / ecore_x / xlib / ecore_x_randr.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include "ecore_x_private.h"
6 #include "ecore_x_randr.h"
7
8 static Eina_Bool _randr_available = EINA_FALSE;
9 #ifdef ECORE_XRANDR
10 static int _randr_major, _randr_minor;
11 int _randr_version;
12 #define RANDR_1_1 ((1 << 16) | 1)
13 #define RANDR_1_2 ((1 << 16) | 2)
14 #define RANDR_1_3 ((1 << 16) | 3)
15
16 #define RANDR_VALIDATE_ROOT(screen, \
17                             root) ((screen = \
18                                        XRRRootToScreen(_ecore_x_disp, \
19                                                        root)) != -1)
20
21 #define Ecore_X_Randr_Unset -1
22
23 XRRScreenResources * (*_ecore_x_randr_get_screen_resources)(Display * dpy,
24                                                             Window window);
25
26 #endif /* ifdef ECORE_XRANDR */
27
28 void
29 _ecore_x_randr_init(void)
30 {
31 #ifdef ECORE_XRANDR
32    _randr_major = 1;
33    _randr_minor = 3;
34    _randr_version = 0;
35
36    _ecore_x_disp = _ecore_x_disp;
37    _ecore_x_randr_get_screen_resources = NULL;
38    if (XRRQueryVersion(_ecore_x_disp, &_randr_major, &_randr_minor))
39    {
40       _randr_version = (_randr_major << 16) | _randr_minor;
41       if (_randr_version >= RANDR_1_3)
42          _ecore_x_randr_get_screen_resources = XRRGetScreenResourcesCurrent;
43       else if (_randr_version == RANDR_1_2)
44          _ecore_x_randr_get_screen_resources = XRRGetScreenResources;
45
46       _randr_available = EINA_TRUE;
47    }
48    else
49       _randr_available = EINA_FALSE;
50
51 #else
52    _randr_available = EINA_FALSE;
53 #endif
54 }
55
56 /*
57  * @brief query whether randr is available or not
58  * @return EINA_TRUE, if extension is available, else EINA_FALSE
59  */
60 EAPI Eina_Bool
61 ecore_x_randr_query(void)
62 {
63    return _randr_available;
64 }
65
66 /*
67  * @return version of the RandRR extension supported by the server or,
68  * in case RandRR extension is not available, Ecore_X_Randr_Unset (=-1).
69  * bit version information: 31   MAJOR   16 | 15   MINOR   0
70  */
71 EAPI int
72 ecore_x_randr_version_get(void)
73 {
74 #ifdef ECORE_XRANDR
75    LOGFN(__FILE__, __LINE__, __FUNCTION__);
76    if (_randr_available)
77    {
78       return _randr_version;
79    }
80    else
81    {
82       return Ecore_X_Randr_Unset;
83    }
84 #endif
85    return -1;
86 }
87
88 Eina_Bool
89 _ecore_x_randr_root_validate(Ecore_X_Window root)
90 {
91 #ifdef ECORE_XRANDR
92    Ecore_X_Randr_Screen scr = -1;
93    if (root && RANDR_VALIDATE_ROOT(scr, root))
94       return EINA_TRUE;
95    else
96       return EINA_FALSE;
97
98 #else
99    return EINA_FALSE;
100 #endif
101 }