aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_x/xcb/ecore_xcb_xinerama.c
blob: 37a2339e9bc32a272401dd4e2ead25fc0200bbd5 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "ecore_xcb_private.h"
#ifdef ECORE_XCB_XINERAMA
# include <xcb/xinerama.h>
#endif

/* local variables */
static Eina_Bool _xinerama_avail = EINA_FALSE;
static Eina_Bool _xinerama_active = EINA_FALSE;

void
_ecore_xcb_xinerama_init(void)
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);

#ifdef ECORE_XCB_XINERAMA
   xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_xinerama_id);
#endif
}

void
_ecore_xcb_xinerama_finalize(void)
{
#ifdef ECORE_XCB_XINERAMA
   const xcb_query_extension_reply_t *ext_reply;
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);

#ifdef ECORE_XCB_XINERAMA
   ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_xinerama_id);
   if ((ext_reply) && (ext_reply->present))
     {
        xcb_xinerama_query_version_cookie_t cookie;
        xcb_xinerama_query_version_reply_t *reply;

        cookie =
          xcb_xinerama_query_version_unchecked(_ecore_xcb_conn,
                                               XCB_XINERAMA_MAJOR_VERSION,
                                               XCB_XINERAMA_MINOR_VERSION);
        reply =
          xcb_xinerama_query_version_reply(_ecore_xcb_conn, cookie, NULL);
        if (reply)
          {
             _xinerama_avail = EINA_TRUE;
             // NB: Do we need to compare version numbers here ?
             free(reply);
          }

        if (_xinerama_avail)
          {
             xcb_xinerama_is_active_cookie_t acookie;
             xcb_xinerama_is_active_reply_t *areply;

             acookie = xcb_xinerama_is_active_unchecked(_ecore_xcb_conn);
             areply =
               xcb_xinerama_is_active_reply(_ecore_xcb_conn, acookie, NULL);
             if (areply)
               {
                  _xinerama_active = areply->state;
                  free(areply);
               }
          }
     }
#endif
}

EAPI int
ecore_x_xinerama_screen_count_get(void)
{
   int count = 0;
#ifdef ECORE_XCB_XINERAMA
   xcb_xinerama_query_screens_cookie_t cookie;
   xcb_xinerama_query_screens_reply_t *reply;
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   if (!_xinerama_avail) return 0;

#ifdef ECORE_XCB_XINERAMA
   cookie = xcb_xinerama_query_screens_unchecked(_ecore_xcb_conn);
   reply =
     xcb_xinerama_query_screens_reply(_ecore_xcb_conn, cookie, NULL);
   if (!reply) return 0;
   count = reply->number;
#endif

   return count;
}

EAPI Eina_Bool
ecore_x_xinerama_screen_geometry_get(int  screen,
                                     int *x,
                                     int *y,
                                     int *w,
                                     int *h)
{
#ifdef ECORE_XCB_XINERAMA
   xcb_xinerama_query_screens_cookie_t cookie;
   xcb_xinerama_query_screens_reply_t *reply;
   xcb_xinerama_screen_info_t *info;
#endif

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   if (x) *x = 0;
   if (y) *y = 0;
   if (w) *w = ((xcb_screen_t *)_ecore_xcb_screen)->width_in_pixels;
   if (h) *h = ((xcb_screen_t *)_ecore_xcb_screen)->height_in_pixels;

   if (!_xinerama_avail) return EINA_FALSE;

#ifdef ECORE_XCB_XINERAMA
   cookie = xcb_xinerama_query_screens_unchecked(_ecore_xcb_conn);
   reply =
     xcb_xinerama_query_screens_reply(_ecore_xcb_conn, cookie, NULL);
   if (!reply) return EINA_FALSE;

   info = xcb_xinerama_query_screens_screen_info(reply);
   if (!info)
     {
        free(reply);
        return EINA_FALSE;
     }

   if (x) *x = info[screen].x_org;
   if (y) *y = info[screen].y_org;
   if (w) *w = info[screen].width;
   if (h) *h = info[screen].height;

   free(reply);
   return EINA_TRUE;
#endif

   return EINA_FALSE;
}