< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java

Print this page




  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.




  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 import sun.awt.X11GraphicsDevice;
  34 
  35 import sun.awt.AWTAccessor;
  36 
  37 public class XMouseInfoPeer implements MouseInfoPeer {
  38 
  39     /**
  40      * Package-private constructor to prevent instantiation.
  41      */
  42     XMouseInfoPeer() {
  43     }
  44 
  45     public int fillPointWithCoords(Point point) {
  46         long display = XToolkit.getDisplay();
  47         GraphicsEnvironment ge = GraphicsEnvironment.
  48                                      getLocalGraphicsEnvironment();
  49         GraphicsDevice[] gds = ge.getScreenDevices();
  50         int gdslen = gds.length;
  51 
  52         XToolkit.awtLock();
  53         try {
  54             for (int i = 0; i < gdslen; i++) {
  55                 long screenRoot = XlibWrapper.RootWindow(display, i);
  56                 boolean pointerFound = XlibWrapper.XQueryPointer(
  57                                            display, screenRoot,
  58                                            XlibWrapper.larg1,  // root_return
  59                                            XlibWrapper.larg2,  // child_return
  60                                            XlibWrapper.larg3,  // xr_return
  61                                            XlibWrapper.larg4,  // yr_return
  62                                            XlibWrapper.larg5,  // xw_return
  63                                            XlibWrapper.larg6,  // yw_return
  64                                            XlibWrapper.larg7); // mask_return
  65                 if (pointerFound) {
  66                     point.x = Native.getInt(XlibWrapper.larg3);
  67                     point.y = Native.getInt(XlibWrapper.larg4);
  68                     GraphicsDevice device = gds[i];
  69                     if (device instanceof X11GraphicsDevice) {
  70                         int scale = ((X11GraphicsDevice) device).getScaleFactor();
  71                         point.x = XlibUtil.scaleDown(point.x, scale);
  72                         point.y = XlibUtil.scaleDown(point.y, scale);
  73                     }
  74                     return i;
  75                 }
  76             }
  77         } finally {
  78             XToolkit.awtUnlock();
  79         }
  80 
  81         // this should never happen
  82         assert false : "No pointer found in the system.";
  83         return 0;
  84     }
  85 
  86     @SuppressWarnings("deprecation")
  87     public boolean isWindowUnderMouse(Window w) {
  88 
  89         long display = XToolkit.getDisplay();
  90 
  91         // java.awt.Component.findUnderMouseInWindow checks that
  92         // the peer is non-null by checking that the component
  93         // is showing.


< prev index next >