xinerama support
[mikachu/openbox.git] / openbox / extensions.c
1 #include "openbox.h"
2 #include "geom.h"
3 #include "extensions.h"
4 #include "screen.h"
5
6 gboolean extensions_xkb       = FALSE;
7 int      extensions_xkb_event_basep;
8 gboolean extensions_shape     = FALSE;
9 int      extensions_shape_event_basep;
10 gboolean extensions_xinerama  = FALSE;
11 int      extensions_xinerama_event_basep;
12 gboolean extensions_xinerama_active = FALSE;
13 gboolean extensions_randr     = FALSE;
14 int      extensions_randr_event_basep;
15 gboolean extensions_vidmode   = FALSE;
16 int      extensions_vidmode_event_basep;
17
18 void extensions_query_all()
19 {
20     int junk;
21     (void)junk;
22      
23 #ifdef XKB
24     extensions_xkb =
25         XkbQueryExtension(ob_display, &junk, &extensions_xkb_event_basep,
26                           &junk, NULL, NULL);
27 #endif
28
29 #ifdef SHAPE
30     extensions_shape =
31         XShapeQueryExtension(ob_display, &extensions_shape_event_basep,
32                              &junk);
33 #endif
34
35 #ifdef XINERAMA
36     extensions_xinerama =
37         XineramaQueryExtension(ob_display, &extensions_xinerama_event_basep,
38                                &junk);
39     extensions_xinerama_active = XineramaIsActive(ob_display);
40 #endif
41
42 #ifdef XRANDR
43     extensions_randr =
44         XRRQueryExtension(ob_display, &extensions_randr_event_basep,
45                           &junk);
46 #endif
47
48 #ifdef VIDMODE
49     extensions_vidmode =
50         XF86VidModeQueryExtension(ob_display, &extensions_vidmode_event_basep,
51                                   &junk);
52 #endif
53 }
54
55 void extensions_xinerama_screens(Rect **xin_areas, guint *nxin)
56 {
57     guint i;
58     gint l, r, t, b;
59 #ifdef XINERAMA
60     if (extensions_xinerama_active) {
61         guint i;
62         gint n;
63         XineramaScreenInfo *info = XineramaQueryScreens(ob_display, &n);
64         *nxin = n;
65         *xin_areas = g_new(Rect, *nxin + 1);
66         for (i = 0; i < *nxin; ++i)
67             RECT_SET((*xin_areas)[i], info[i].x_org, info[i].y_org,
68                      info[i].width, info[i].height);
69     } else
70 #endif
71     {
72         *nxin = 1;
73         *xin_areas = g_new(Rect, *nxin + 1);
74         RECT_SET((*xin_areas)[0], 0, 0,
75                  screen_physical_size.width, screen_physical_size.height);
76     }
77
78     /* returns one extra with the total area in it */
79     l = (*xin_areas)[0].x;
80     t = (*xin_areas)[0].y;
81     r = (*xin_areas)[0].x + (*xin_areas)[0].width - 1;
82     b = (*xin_areas)[0].y + (*xin_areas)[0].height - 1;
83     for (i = 1; i < *nxin; ++i) {
84         l = MIN(l, (*xin_areas)[i].x);
85         t = MIN(l, (*xin_areas)[i].y);
86         r = MIN(r, (*xin_areas)[0].x + (*xin_areas)[0].width - 1);
87         b = MIN(b, (*xin_areas)[0].y + (*xin_areas)[0].height - 1);
88     }
89     RECT_SET((*xin_areas)[*nxin], l, t, r - l + 1, b - t + 1);
90 }