Tizen 2.1 base
[framework/uifw/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_randr_get_screen_resources = NULL;
37    if (XRRQueryVersion(_ecore_x_disp, &_randr_major, &_randr_minor))
38      {
39         _randr_version = (_randr_major << 16) | _randr_minor;
40         if (_randr_version >= RANDR_1_3)
41           _ecore_x_randr_get_screen_resources = XRRGetScreenResourcesCurrent;
42         else if (_randr_version == RANDR_1_2)
43           _ecore_x_randr_get_screen_resources = XRRGetScreenResources;
44
45         _randr_available = EINA_TRUE;
46      }
47    else
48      _randr_available = EINA_FALSE;
49
50 #else
51    _randr_available = EINA_FALSE;
52 #endif
53 }
54
55 /*
56  * @brief Query whether randr is available or not.
57  *
58  * @return @c EINA_TRUE, if extension is available, @c EINA_FALSE otherwise.
59  */
60 EAPI Eina_Bool
61 ecore_x_randr_query(void)
62 {
63    return _randr_available;
64 }
65
66 /*
67  * @return version of the RandR extension supported by the server or, in case
68  * RandR 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 #else
85    return -1;
86 #endif
87 }
88
89 Eina_Bool
90 _ecore_x_randr_root_validate(Ecore_X_Window root)
91 {
92 #ifdef ECORE_XRANDR
93    Ecore_X_Randr_Screen scr = -1;
94    if (root && RANDR_VALIDATE_ROOT(scr, root))
95      return EINA_TRUE;
96    else
97      return EINA_FALSE;
98
99 #else
100    return EINA_FALSE;
101 #endif
102 }
103