aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr.c
blob: d4d834f290f08d81ee1bd763131bd37caad78ecd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include "ecore_x_private.h"
#include "ecore_x_randr.h"

static Eina_Bool _randr_available = EINA_FALSE;
#ifdef ECORE_XRANDR
static int _randr_major, _randr_minor;
int _randr_version;
#define RANDR_1_1           ((1 << 16) | 1)
#define RANDR_1_2           ((1 << 16) | 2)
#define RANDR_1_3           ((1 << 16) | 3)

#define RANDR_VALIDATE_ROOT(screen,                                  \
                            root) ((screen =                         \
                                      XRRRootToScreen(_ecore_x_disp, \
                                                      root)) != -1)

#define Ecore_X_Randr_Unset -1

XRRScreenResources *(*_ecore_x_randr_get_screen_resources)(Display * dpy,
                                                           Window window);

#endif /* ifdef ECORE_XRANDR */

void
_ecore_x_randr_init(void)
{
#ifdef ECORE_XRANDR
   _randr_major = 1;
   _randr_minor = 3;
   _randr_version = 0;

   _ecore_x_randr_get_screen_resources = NULL;
   if (XRRQueryVersion(_ecore_x_disp, &_randr_major, &_randr_minor))
     {
        _randr_version = (_randr_major << 16) | _randr_minor;
        if (_randr_version >= RANDR_1_3)
          _ecore_x_randr_get_screen_resources = XRRGetScreenResourcesCurrent;
        else if (_randr_version == RANDR_1_2)
          _ecore_x_randr_get_screen_resources = XRRGetScreenResources;

        _randr_available = EINA_TRUE;
     }
   else
     _randr_available = EINA_FALSE;

#else
   _randr_available = EINA_FALSE;
#endif
}

/*
 * @brief query whether randr is available or not
 * @return EINA_TRUE, if extension is available, else EINA_FALSE
 */
EAPI Eina_Bool
ecore_x_randr_query(void)
{
   return _randr_available;
}

/*
 * @return version of the RandRR extension supported by the server or,
 * in case RandRR extension is not available, Ecore_X_Randr_Unset (=-1).
 * bit version information: 31   MAJOR   16 | 15   MINOR   0
 */
EAPI int
ecore_x_randr_version_get(void)
{
#ifdef ECORE_XRANDR
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   if (_randr_available)
     {
        return _randr_version;
     }
   else
     {
        return Ecore_X_Randr_Unset;
     }
#else
   return -1;
#endif
}

Eina_Bool
_ecore_x_randr_root_validate(Ecore_X_Window root)
{
#ifdef ECORE_XRANDR
   Ecore_X_Randr_Screen scr = -1;
   if (root && RANDR_VALIDATE_ROOT(scr, root))
     return EINA_TRUE;
   else
     return EINA_FALSE;

#else
   return EINA_FALSE;
#endif
}