1 /*
2 * Copyright (c) 2002, 2019, 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
1107 * perhaps different values of keysyms.
1108 * XXX: not anymore at the moment, but I'll still keep them as arrays
1109 * for a while. If in the course of testing we will be satisfied with
1110 * a current single result from awt_x11inputmethod_lookupString, we'll
1111 * change this.
1112 */
1113 jlong testbuf[2];
1114
1115 testbuf[1]=0;
1116
1117 boo = awt_x11inputmethod_lookupString((XKeyPressedEvent*)jlong_to_ptr(event), &keysym);
1118 testbuf[0] = keysym;
1119
1120 (*env)->SetLongArrayRegion(env, keysymArray, 0, 2, (jlong *)(testbuf));
1121 return boo ? JNI_TRUE : JNI_FALSE;
1122 }
1123
1124
1125 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
1126
1127 /*
1128 * Class: Java_sun_awt_X11_XWindow_getNativeColor
1129 * Method: getNativeColor
1130 * Signature (Ljava/awt/Color;Ljava/awt/GraphicsConfiguration;)I
1131 */
1132 JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindow_getNativeColor
1133 (JNIEnv *env, jobject this, jobject color, jobject gc_object) {
1134 AwtGraphicsConfigDataPtr adata;
1135 /* fire warning because JNU_GetLongFieldAsPtr casts jlong to (void *) */
1136 adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, gc_object, x11GraphicsConfigIDs.aData);
1137 return awtJNI_GetColorForVis(env, color, adata);
1138 }
1139
1140 /* syncTopLevelPos() is necessary to insure that the window manager has in
1141 * fact moved us to our final position relative to the reParented WM window.
1142 * We have noted a timing window which our shell has not been moved so we
1143 * screw up the insets thinking they are 0,0. Wait (for a limited period of
1144 * time to let the WM hava a chance to move us
1145 */
1146 void syncTopLevelPos( Display *d, Window w, XWindowAttributes *winAttr ) {
1147 int32_t i = 0;
1148 do {
1149 XGetWindowAttributes( d, w, winAttr );
1150 /* Sometimes we get here before the WM has updated the
1151 ** window data struct with the correct position. Loop
1152 ** until we get a non-zero position.
1153 */
1154 if ((winAttr->x != 0) || (winAttr->y != 0)) {
1155 break;
1156 }
1157 else {
1158 /* What we really want here is to sync with the WM,
1159 ** but there's no explicit way to do this, so we
1160 ** call XSync for a delay.
1161 */
1162 XSync(d, False);
1163 }
1164 } while (i++ < 50);
1165 }
1166
1167 static Window getTopWindow(Window win, Window *rootWin)
1168 {
1169 Window root=None, current_window=win, parent=None, *ignore_children=NULL;
1170 Window prev_window=None;
1171 unsigned int ignore_uint=0;
1172 Status status = 0;
1173
1174 if (win == None) return None;
1175 do {
1176 status = XQueryTree(awt_display,
1177 current_window,
1178 &root,
1179 &parent,
1180 &ignore_children,
1181 &ignore_uint);
1182 XFree(ignore_children);
1183 if (status == 0) return None;
1184 prev_window = current_window;
1185 current_window = parent;
1186 } while (parent != root);
1187 *rootWin = root;
1188 return prev_window;
1189 }
1190
1191 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XWindow_getTopWindow
1192 (JNIEnv *env, jclass clazz, jlong win, jlong rootWin) {
1193 return getTopWindow((Window) win, (Window*) jlong_to_ptr(rootWin));
1194 }
1195
1196 static void
1197 getWMInsets
1198 (Window window, int *left, int *top, int *right, int *bottom, int *border) {
1199 // window is event->xreparent.window
1200 Window topWin = None, rootWin = None, containerWindow = None;
1201 XWindowAttributes winAttr, topAttr;
1202 int screenX, screenY;
1203 topWin = getTopWindow(window, &rootWin);
1204 syncTopLevelPos(awt_display, topWin, &topAttr);
1205 // (screenX, screenY) is (0,0) of the reparented window
1206 // converted to screen coordinates.
1207 XTranslateCoordinates(awt_display, window, rootWin,
1208 0,0, &screenX, &screenY, &containerWindow);
1209 *left = screenX - topAttr.x - topAttr.border_width;
1210 *top = screenY - topAttr.y - topAttr.border_width;
1211 XGetWindowAttributes(awt_display, window, &winAttr);
1212 *right = topAttr.width - ((winAttr.width) + *left);
1213 *bottom = topAttr.height - ((winAttr.height) + *top);
1214 *border = topAttr.border_width;
1215 }
1216
1217 JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWMInsets
1218 (JNIEnv *env, jclass clazz, jlong window, jlong left, jlong top, jlong right, jlong bottom, jlong border) {
1219 getWMInsets((Window) window,
1220 (int*) jlong_to_ptr(left),
1221 (int*) jlong_to_ptr(top),
1222 (int*) jlong_to_ptr(right),
1223 (int*) jlong_to_ptr(bottom),
1224 (int*) jlong_to_ptr(border));
1225 }
1226
1227 static void
1228 getWindowBounds
1229 (Window window, int *x, int *y, int *width, int *height) {
1230 XWindowAttributes winAttr;
1231 XSync(awt_display, False);
1232 XGetWindowAttributes(awt_display, window, &winAttr);
1233 *x = winAttr.x;
1234 *y = winAttr.y;
1235 *width = winAttr.width;
1236 *height = winAttr.height;
1237 }
1238
1239 JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWindowBounds
1240 (JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
1241 getWindowBounds((Window) window, (int*) jlong_to_ptr(x), (int*) jlong_to_ptr(y),
1242 (int*) jlong_to_ptr(width), (int*) jlong_to_ptr(height));
1243 }
1244
1245 JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_setSizeHints
1246 (JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
1247 XSizeHints *size_hints = XAllocSizeHints();
1248 size_hints->flags = USPosition | PPosition | PSize;
1249 size_hints->x = (int)x;
1250 size_hints->y = (int)y;
1251 size_hints->width = (int)width;
1252 size_hints->height = (int)height;
1253 XSetWMNormalHints(awt_display, (Window)window, size_hints);
1254 XFree((char*)size_hints);
1255 }
1256
1257
1258 JNIEXPORT void JNICALL
1259 Java_sun_awt_X11_XWindow_initIDs
1260 (JNIEnv *env, jclass clazz)
1261 {
1262 char *ptr = NULL;
1263 windowID = (*env)->GetFieldID(env, clazz, "window", "J");
1264 CHECK_NULL(windowID);
|
1 /*
2 * Copyright (c) 2002, 2020, 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
1107 * perhaps different values of keysyms.
1108 * XXX: not anymore at the moment, but I'll still keep them as arrays
1109 * for a while. If in the course of testing we will be satisfied with
1110 * a current single result from awt_x11inputmethod_lookupString, we'll
1111 * change this.
1112 */
1113 jlong testbuf[2];
1114
1115 testbuf[1]=0;
1116
1117 boo = awt_x11inputmethod_lookupString((XKeyPressedEvent*)jlong_to_ptr(event), &keysym);
1118 testbuf[0] = keysym;
1119
1120 (*env)->SetLongArrayRegion(env, keysymArray, 0, 2, (jlong *)(testbuf));
1121 return boo ? JNI_TRUE : JNI_FALSE;
1122 }
1123
1124
1125 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
1126
1127 /* syncTopLevelPos() is necessary to insure that the window manager has in
1128 * fact moved us to our final position relative to the reParented WM window.
1129 * We have noted a timing window which our shell has not been moved so we
1130 * screw up the insets thinking they are 0,0. Wait (for a limited period of
1131 * time to let the WM hava a chance to move us
1132 */
1133 void syncTopLevelPos( Display *d, Window w, XWindowAttributes *winAttr ) {
1134 int32_t i = 0;
1135 do {
1136 XGetWindowAttributes( d, w, winAttr );
1137 /* Sometimes we get here before the WM has updated the
1138 ** window data struct with the correct position. Loop
1139 ** until we get a non-zero position.
1140 */
1141 if ((winAttr->x != 0) || (winAttr->y != 0)) {
1142 break;
1143 }
1144 else {
1145 /* What we really want here is to sync with the WM,
1146 ** but there's no explicit way to do this, so we
1147 ** call XSync for a delay.
1148 */
1149 XSync(d, False);
1150 }
1151 } while (i++ < 50);
1152 }
1153
1154 JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_setSizeHints
1155 (JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
1156 XSizeHints *size_hints = XAllocSizeHints();
1157 size_hints->flags = USPosition | PPosition | PSize;
1158 size_hints->x = (int)x;
1159 size_hints->y = (int)y;
1160 size_hints->width = (int)width;
1161 size_hints->height = (int)height;
1162 XSetWMNormalHints(awt_display, (Window)window, size_hints);
1163 XFree((char*)size_hints);
1164 }
1165
1166
1167 JNIEXPORT void JNICALL
1168 Java_sun_awt_X11_XWindow_initIDs
1169 (JNIEnv *env, jclass clazz)
1170 {
1171 char *ptr = NULL;
1172 windowID = (*env)->GetFieldID(env, clazz, "window", "J");
1173 CHECK_NULL(windowID);
|