2 * Window Maker window manager
4 * Copyright (c) 1997-2001 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
35 #include <X11/extensions/Xinerama.h>
39 wInitXinerama(WScreen
*scr
)
41 scr
->xine_primary_head
= 0;
43 scr
->xine_screens
= XineramaQueryScreens(dpy
, &scr
->xine_count
);
51 wGetRectPlacementInfo(WScreen
*scr
, WMRect rect
, int *flags
)
54 unsigned long area
, totalArea
;
58 int rw
= rect
.size
.width
;
59 int rh
= rect
.size
.height
;
61 wassertrv(flags
!=NULL
, 0);
69 if (scr
->xine_count
<= 1) {
72 a
= calcIntersectionArea(rx
, ry
, rw
, rh
,
73 0, 0, scr
->scr_width
, scr
->scr_height
);
77 } else if (a
!= rw
*rh
) {
78 *flags
|= XFLAG_PARTIAL
;
81 return scr
->xine_primary_head
;
85 for (i
= 0; i
< scr
->xine_count
; i
++) {
88 a
= calcIntersectionArea(rx
, ry
, rw
, rh
,
89 scr
->xine_screens
[i
].x_org
,
90 scr
->xine_screens
[i
].y_org
,
91 scr
->xine_screens
[i
].width
,
92 scr
->xine_screens
[i
].height
);
97 *flags
|= XFLAG_MULTIPLE
;
104 *flags
|= XFLAG_DEAD
;
105 best
= wGetHeadForPointerLocation(scr
);
106 } else if ( totalArea
!= rw
*rh
)
107 *flags
|= XFLAG_PARTIAL
;
115 /* get the head that covers most of the rectangle */
117 wGetHeadForRect(WScreen
*scr
, WMRect rect
)
125 int rw
= rect
.size
.width
;
126 int rh
= rect
.size
.height
;
128 if (!scr
->xine_count
)
129 return scr
->xine_primary_head
;
134 for (i
= 0; i
< scr
->xine_count
; i
++) {
137 a
= calcIntersectionArea(rx
, ry
, rw
, rh
,
138 scr
->xine_screens
[i
].x_org
,
139 scr
->xine_screens
[i
].y_org
,
140 scr
->xine_screens
[i
].width
,
141 scr
->xine_screens
[i
].height
);
150 * in case rect is in dead space, return valid head
153 best
= wGetHeadForPointerLocation(scr
);
156 #else /* !XINERAMA */
157 return scr
->xine_primary_head
;
158 #endif /* !XINERAMA */
163 wGetHeadForWindow(WWindow
*wwin
)
167 rect
.pos
.x
= wwin
->frame_x
;
168 rect
.pos
.y
= wwin
->frame_y
;
169 rect
.size
.width
= wwin
->frame
->core
->width
;
170 rect
.size
.height
= wwin
->frame
->core
->height
;
172 return wGetHeadForRect(wwin
->screen_ptr
, rect
);
177 int wGetHeadForPoint(WScreen *scr, WMPoint point, int *flags)
182 if ( flags == NULL) {
188 for (i = 0; i < scr->xine_count; i++) {
192 xx = scr->xine_screens[i].x_org + scr->xine_screens[i].width;
193 yy = scr->xine_screens[i].y_org + scr->xine_screens[i].height;
194 if (point.x >= scr->xine_screens[i].x_org &&
195 point.y >= scr->xine_screens[i].y_org &&
196 point.x < xx && point.y < yy) {
200 XineramaScreenInfo *xsi = &scr->xine_screens[i];
202 if ((unsigned)(point.x - xsi->x_org) < xsi->width &&
203 (unsigned)(point.y - xsi->y_org) < xsi->height)
208 *flags |= XFLAG_DEAD;
210 return scr->xine_primary_head;
217 wGetHeadForPoint(WScreen
*scr
, WMPoint point
)
222 for (i
= 0; i
< scr
->xine_count
; i
++) {
223 XineramaScreenInfo
*xsi
= &scr
->xine_screens
[i
];
225 if ((unsigned)(point
.x
- xsi
->x_org
) < xsi
->width
&&
226 (unsigned)(point
.y
- xsi
->y_org
) < xsi
->height
)
229 #endif /* XINERAMA */
230 return scr
->xine_primary_head
;
235 wGetHeadForPointerLocation(WScreen
*scr
)
242 if (!scr
->xine_count
)
243 return scr
->xine_primary_head
;
245 if (!XQueryPointer(dpy
, scr
->root_win
, &bla
, &bla
,
249 return scr
->xine_primary_head
;
251 return wGetHeadForPoint(scr
, point
);
254 /* get the dimensions of the head */
256 wGetRectForHead(WScreen
*scr
, int head
)
261 if (head
< scr
->xine_count
) {
262 rect
.pos
.x
= scr
->xine_screens
[head
].x_org
;
263 rect
.pos
.y
= scr
->xine_screens
[head
].y_org
;
264 rect
.size
.width
= scr
->xine_screens
[head
].width
;
265 rect
.size
.height
= scr
->xine_screens
[head
].height
;
267 #endif /* XINERAMA */
271 rect
.size
.width
= scr
->scr_width
;
272 rect
.size
.height
= scr
->scr_height
;
281 wGetUsableAreaForHead(WScreen
*scr
, int head
, WArea
*totalAreaPtr
)
283 WArea totalArea
, usableArea
= scr
->totalUsableArea
;
284 WMRect rect
= wGetRectForHead(scr
, head
);
286 totalArea
.x1
= rect
.pos
.x
;
287 totalArea
.y1
= rect
.pos
.y
;
288 totalArea
.x2
= totalArea
.x1
+ rect
.size
.width
;
289 totalArea
.y2
= totalArea
.y1
+ rect
.size
.height
;
291 if (totalAreaPtr
!= NULL
) *totalAreaPtr
= totalArea
;
293 usableArea
.x1
= WMAX(totalArea
.x1
, usableArea
.x1
);
294 usableArea
.y1
= WMAX(totalArea
.y1
, usableArea
.y1
);
295 usableArea
.x2
= WMIN(totalArea
.x2
, usableArea
.x2
);
296 usableArea
.y2
= WMIN(totalArea
.y2
, usableArea
.y2
);
303 wGetPointToCenterRectInHead(WScreen
*scr
, int head
, int width
, int height
)
306 WMRect rect
= wGetRectForHead(scr
, head
);
308 p
.x
= rect
.pos
.x
+ (rect
.size
.width
- width
)/2;
309 p
.y
= rect
.pos
.y
+ (rect
.size
.height
- height
)/2;