blob: 368ccab8cdd0ea624edeb07b0d0b2c476f302b9c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 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#ifdef HEADLESS
27 #error This file should not be included in headless library
28#endif
29
30#include "awt_p.h"
31#include "awt_Component.h"
32
33#include <jni.h>
34#include <jni_util.h>
35
36extern int awt_numScreens;
37extern AwtScreenDataPtr x11Screens;
38extern struct ComponentIDs componentIDs;
39extern struct MComponentPeerIDs mComponentPeerIDs;
40
41/*
42 * Class: sun_awt_DefaultMouseInfoPeer
43 * Method: fillPointWithCoords
44 * Signature: (Ljava/awt/Point)I
45 */
46JNIEXPORT jint JNICALL
47Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls,
48 jobject point)
49{
50 static jclass pointClass = NULL;
51 jclass pointClassLocal;
52 static jfieldID xID, yID;
53 Window rootWindow, childWindow;
54 int i;
55 int32_t xr, yr, xw, yw;
56 uint32_t keys;
57 BOOL pointerFound;
58
59 AWT_LOCK();
60 if (pointClass == NULL) {
61 pointClassLocal = (*env)->FindClass(env, "java/awt/Point");
62 DASSERT(pointClassLocal != NULL);
63 if (pointClassLocal == NULL) {
64 AWT_UNLOCK();
65 return (jint)0;
66 }
67 pointClass = (jclass)(*env)->NewGlobalRef(env, pointClassLocal);
68 (*env)->DeleteLocalRef(env, pointClassLocal);
69 xID = (*env)->GetFieldID(env, pointClass, "x", "I");
70 yID = (*env)->GetFieldID(env, pointClass, "y", "I");
71 }
72
73 for (i = 0; i < awt_numScreens; i++) {
74 pointerFound = XQueryPointer(awt_display, x11Screens[i].root,
75 &rootWindow, &childWindow,
76 &xr, &yr, &xw, &yw, &keys);
77 if (pointerFound) {
78 (*env)->SetIntField(env, point, xID, xr);
79 (*env)->SetIntField(env, point, yID, yr);
80 AWT_UNLOCK();
81 return (jint)i;
82 }
83 }
84 /* This should never happen */
85 DASSERT(FALSE);
86 AWT_UNLOCK();
87 return (jint)0;
88}
89
90/*
91 * Class: sun_awt_DefaultMouseInfoPeer
92 * Method: isWindowUnderMouse
93 * Signature: (Ljava/awt/Window)Z
94 */
95JNIEXPORT jboolean JNICALL Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse
96 (JNIEnv * env, jclass cls, jobject window)
97{
98 Window rootWindow = None, parentWindow = None, siblingWindow = None;
99 Window * children = NULL;
100 int i = 0;
101 int is_the_same_screen = 0;
102 int32_t xr = 0, yr = 0, xw = 0, yw = 0;
103 uint32_t keys = 0;
104 uint32_t nchildren = 0;
105 BOOL pointerFound = 0;
106 struct FrameData *wdata = NULL;
107 jobject winPeer = NULL;
108
109 if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
110 return JNI_FALSE;
111 }
112 winPeer = (*env)->GetObjectField(env, window, componentIDs.peer);
113 if (JNU_IsNull(env, winPeer)) {
114 return JNI_FALSE;
115 }
116
117 wdata = (struct FrameData *)
118 JNU_GetLongFieldAsPtr(env, winPeer, mComponentPeerIDs.pData);
119 (*env)->DeleteLocalRef(env, winPeer);
120
121 if (wdata == NULL) {
122 return JNI_FALSE;
123 }
124
125 AWT_LOCK();
126
127 XQueryTree(awt_display, XtWindow(wdata->winData.comp.widget),
128 &rootWindow, &parentWindow, &children, &nchildren);
129
130 is_the_same_screen = XQueryPointer(awt_display, parentWindow,
131 &rootWindow, &siblingWindow, &xr, &yr, &xw, &yw, &keys);
132
133 if (siblingWindow == XtWindow(wdata->winData.comp.widget) && is_the_same_screen) {
134 AWT_UNLOCK();
135 return JNI_TRUE;
136 }
137
138 AWT_UNLOCK();
139 return JNI_FALSE ;
140
141}