1 /* 2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt.X11; 27 28 import java.awt.Point; 29 import java.awt.Window; 30 import java.awt.GraphicsEnvironment; 31 import java.awt.GraphicsDevice; 32 import java.awt.peer.MouseInfoPeer; 33 34 import sun.awt.AWTAccessor; 35 36 public class XMouseInfoPeer implements MouseInfoPeer { 37 38 /** 39 * Package-private constructor to prevent instantiation. 40 */ 41 XMouseInfoPeer() { 42 } 43 44 public int fillPointWithCoords(Point point) { 45 long display = XToolkit.getDisplay(); 46 GraphicsEnvironment ge = GraphicsEnvironment. 47 getLocalGraphicsEnvironment(); 48 GraphicsDevice[] gds = ge.getScreenDevices(); 49 int gdslen = gds.length; 50 51 XToolkit.awtLock(); 52 try { 53 for (int i = 0; i < gdslen; i++) { 54 long screenRoot = XlibWrapper.RootWindow(display, i); 55 boolean pointerFound = XlibWrapper.XQueryPointer( 56 display, screenRoot, 57 XlibWrapper.larg1, // root_return 58 XlibWrapper.larg2, // child_return 59 XlibWrapper.larg3, // xr_return 60 XlibWrapper.larg4, // yr_return 61 XlibWrapper.larg5, // xw_return 62 XlibWrapper.larg6, // yw_return 63 XlibWrapper.larg7); // mask_return 64 if (pointerFound) { 65 point.x = Native.getInt(XlibWrapper.larg3); 66 point.y = Native.getInt(XlibWrapper.larg4); 67 return i; 68 } 69 } 70 } finally { 71 XToolkit.awtUnlock(); 72 } 73 74 // this should never happen 75 assert false : "No pointer found in the system."; 76 return 0; 77 } 78 79 @SuppressWarnings("deprecation") 80 public boolean isWindowUnderMouse(Window w) { 81 82 long display = XToolkit.getDisplay(); 83 84 // java.awt.Component.findUnderMouseInWindow checks that 85 // the peer is non-null by checking that the component 86 // is showing. 87 XWindow peer = AWTAccessor.getComponentAccessor().getPeer(w); 88 long contentWindow = peer.getContentWindow(); 89 long parent = XlibUtil.getParentWindow(contentWindow); 90 91 XToolkit.awtLock(); 92 try 93 { 94 boolean windowOnTheSameScreen = XlibWrapper.XQueryPointer(display, parent, 95 XlibWrapper.larg1, // root_return 96 XlibWrapper.larg8, // child_return 97 XlibWrapper.larg3, // root_x_return 98 XlibWrapper.larg4, // root_y_return 99 XlibWrapper.larg5, // win_x_return 100 XlibWrapper.larg6, // win_y_return 101 XlibWrapper.larg7); // mask_return 102 long siblingWindow = Native.getWindow(XlibWrapper.larg8); 103 return (siblingWindow == contentWindow && windowOnTheSameScreen); 104 } 105 finally 106 { 107 XToolkit.awtUnlock(); 108 } 109 } 110 }