jdk/src/solaris/classes/sun/awt/X11/XMouseInfoPeer.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 2003-2006 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any 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.GraphicsConfiguration;
       
    32 import java.awt.GraphicsDevice;
       
    33 import java.awt.peer.MouseInfoPeer;
       
    34 
       
    35 public class XMouseInfoPeer implements MouseInfoPeer {
       
    36 
       
    37     /**
       
    38      * Package-private constructor to prevent instantiation.
       
    39      */
       
    40     XMouseInfoPeer() {
       
    41     }
       
    42 
       
    43     public int fillPointWithCoords(Point point) {
       
    44         long display = XToolkit.getDisplay();
       
    45         GraphicsEnvironment ge = GraphicsEnvironment.
       
    46                                      getLocalGraphicsEnvironment();
       
    47         GraphicsDevice[] gds = ge.getScreenDevices();
       
    48         int gdslen = gds.length;
       
    49 
       
    50         XToolkit.awtLock();
       
    51         try {
       
    52             for (int i = 0; i < gdslen; i++) {
       
    53                 long screenRoot = XlibWrapper.RootWindow(display, i);
       
    54                 boolean pointerFound = XlibWrapper.XQueryPointer(
       
    55                                            display, screenRoot,
       
    56                                            XlibWrapper.larg1,  // root_return
       
    57                                            XlibWrapper.larg2,  // child_return
       
    58                                            XlibWrapper.larg3,  // xr_return
       
    59                                            XlibWrapper.larg4,  // yr_return
       
    60                                            XlibWrapper.larg5,  // xw_return
       
    61                                            XlibWrapper.larg6,  // yw_return
       
    62                                            XlibWrapper.larg7); // mask_return
       
    63                 if (pointerFound) {
       
    64                     point.x = Native.getInt(XlibWrapper.larg3);
       
    65                     point.y = Native.getInt(XlibWrapper.larg4);
       
    66                     return i;
       
    67                 }
       
    68             }
       
    69         } finally {
       
    70             XToolkit.awtUnlock();
       
    71         }
       
    72 
       
    73         // this should never happen
       
    74         assert false : "No pointer found in the system.";
       
    75         return 0;
       
    76     }
       
    77 
       
    78     public boolean isWindowUnderMouse(Window w) {
       
    79 
       
    80         long display = XToolkit.getDisplay();
       
    81 
       
    82         // java.awt.Component.findUnderMouseInWindow checks that
       
    83         // the peer is non-null by checking that the component
       
    84         // is showing.
       
    85 
       
    86         long contentWindow = ((XWindow)w.getPeer()).getContentWindow();
       
    87         long parent = XlibUtil.getParentWindow(contentWindow);
       
    88 
       
    89         XToolkit.awtLock();
       
    90         try
       
    91         {
       
    92             boolean windowOnTheSameScreen = XlibWrapper.XQueryPointer(display, parent,
       
    93                                   XlibWrapper.larg1, // root_return
       
    94                                   XlibWrapper.larg8, // child_return
       
    95                                   XlibWrapper.larg3, // root_x_return
       
    96                                   XlibWrapper.larg4, // root_y_return
       
    97                                   XlibWrapper.larg5, // win_x_return
       
    98                                   XlibWrapper.larg6, // win_y_return
       
    99                                   XlibWrapper.larg7); //  mask_return
       
   100             long siblingWindow = Native.getWindow(XlibWrapper.larg8);
       
   101             return (siblingWindow == contentWindow && windowOnTheSameScreen);
       
   102         }
       
   103         finally
       
   104         {
       
   105             XToolkit.awtUnlock();
       
   106         }
       
   107     }
       
   108 }