001: /*
002: * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.X11;
027:
028: import java.awt.Point;
029: import java.awt.Window;
030: import java.awt.GraphicsEnvironment;
031: import java.awt.GraphicsConfiguration;
032: import java.awt.GraphicsDevice;
033: import java.awt.peer.MouseInfoPeer;
034:
035: public class XMouseInfoPeer implements MouseInfoPeer {
036:
037: /**
038: * Package-private constructor to prevent instantiation.
039: */
040: XMouseInfoPeer() {
041: }
042:
043: public int fillPointWithCoords(Point point) {
044: long display = XToolkit.getDisplay();
045: GraphicsEnvironment ge = GraphicsEnvironment
046: .getLocalGraphicsEnvironment();
047: GraphicsDevice[] gds = ge.getScreenDevices();
048: int gdslen = gds.length;
049:
050: XToolkit.awtLock();
051: try {
052: for (int i = 0; i < gdslen; i++) {
053: long screenRoot = XlibWrapper.RootWindow(display, i);
054: boolean pointerFound = XlibWrapper.XQueryPointer(
055: display, screenRoot, XlibWrapper.larg1, // root_return
056: XlibWrapper.larg2, // child_return
057: XlibWrapper.larg3, // xr_return
058: XlibWrapper.larg4, // yr_return
059: XlibWrapper.larg5, // xw_return
060: XlibWrapper.larg6, // yw_return
061: XlibWrapper.larg7); // mask_return
062: if (pointerFound) {
063: point.x = Native.getInt(XlibWrapper.larg3);
064: point.y = Native.getInt(XlibWrapper.larg4);
065: return i;
066: }
067: }
068: } finally {
069: XToolkit.awtUnlock();
070: }
071:
072: // this should never happen
073: assert false : "No pointer found in the system.";
074: return 0;
075: }
076:
077: public boolean isWindowUnderMouse(Window w) {
078:
079: long display = XToolkit.getDisplay();
080:
081: // java.awt.Component.findUnderMouseInWindow checks that
082: // the peer is non-null by checking that the component
083: // is showing.
084:
085: long contentWindow = ((XWindow) w.getPeer()).getContentWindow();
086: long parent = XlibUtil.getParentWindow(contentWindow);
087:
088: XToolkit.awtLock();
089: try {
090: boolean windowOnTheSameScreen = XlibWrapper.XQueryPointer(
091: display, parent, XlibWrapper.larg1, // root_return
092: XlibWrapper.larg8, // child_return
093: XlibWrapper.larg3, // root_x_return
094: XlibWrapper.larg4, // root_y_return
095: XlibWrapper.larg5, // win_x_return
096: XlibWrapper.larg6, // win_y_return
097: XlibWrapper.larg7); // mask_return
098: long siblingWindow = Native.getWindow(XlibWrapper.larg8);
099: return (siblingWindow == contentWindow && windowOnTheSameScreen);
100: } finally {
101: XToolkit.awtUnlock();
102: }
103: }
104: }
|