1 /*
2  * Copyright (c) 2002, 2014, 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.security.AccessController;
29 
30 import jdk.internal.misc.Unsafe;
31 import sun.security.action.GetPropertyAction;
32 
33 final class XlibWrapper {
34 
35     static Unsafe unsafe = Unsafe.getUnsafe();
36     // strange constants
37     static final int MAXSIZE = 32767;
38     static final int MINSIZE = 1;
39 
40     // define a private constructor here to prevent this class and all
41     // its descendants from being created
XlibWrapper()42     private XlibWrapper()
43     {
44     }
45 
46 /*
47    Display *XOpenDisplay(display_name)
48    char *display_name;
49 
50 */
51     static final String[] eventToString =
52     {"<none:0>", "<none:1>", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease",
53      "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut",
54      "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify",
55      "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest",
56      "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify",
57      "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify",
58      "SelectionClear", "SelectionRequest", "SelectionNotify", "ColormapNotify",
59      "ClientMessage", "MappingNotify", "LASTEvent"};
60 
XFree(long ptr)61     static native void XFree(long ptr);
memcpy(long dest_ptr, long src_ptr, long length)62     static native void memcpy(long dest_ptr, long src_ptr, long length);
getAddress(Object o)63     static native long getAddress(Object o);
copyIntArray(long dest_ptr, Object array, int size_bytes)64     static native void copyIntArray(long dest_ptr, Object array, int size_bytes);
copyLongArray(long dest_ptr, Object array, int size_bytes)65     static native void copyLongArray(long dest_ptr, Object array, int size_bytes);
66 
67     /**
68      * Gets byte string from str_ptr and copies it into byte array
69      * String should be NULL terminated.
70      */
getStringBytes(long str_ptr)71     static native byte[] getStringBytes(long str_ptr);
72 
XOpenDisplay(long display)73     static  native long XOpenDisplay(long display);
74 
XCloseDisplay(long display)75     static  native void XCloseDisplay(long display);
76 
XDisplayString(long display)77     static  native long XDisplayString(long display);
78 
XSetCloseDownMode(long display, int close_mode)79     static  native void XSetCloseDownMode(long display, int close_mode);
80 
DefaultScreen(long display)81     static  native long DefaultScreen(long display);
82 
ScreenOfDisplay(long display, long screen_number)83     static native long ScreenOfDisplay(long display, long screen_number);
84 
DoesBackingStore(long screen)85     static native int DoesBackingStore(long screen);
86 
DisplayWidth(long display, long screen)87     static native  long DisplayWidth(long display, long screen);
DisplayWidthMM(long display, long screen)88     static native  long DisplayWidthMM(long display, long screen);
89 
DisplayHeight(long display, long screen)90     static native long DisplayHeight(long display, long screen);
DisplayHeightMM(long display, long screen)91     static native long DisplayHeightMM(long display, long screen);
92 
RootWindow(long display, long screen_number)93     static  native long RootWindow(long display, long screen_number);
ScreenCount(long display)94     static native int ScreenCount(long display);
95 
96 
97 /*
98    Window XCreateWindow(display, parent, x, y, width, height,
99    border_width, depth,
100    class, visual, valuemask, attributes)
101    Display *display;
102    Window parent;
103    int x, y;
104    unsigned int width, height;
105    unsigned int border_width;
106    int depth;
107    unsigned int class;
108    Visual *visual
109    unsigned long valuemask;
110    XSetWindowAttributes *attributes;
111 */
112 
XCreateWindow(long display, long parent, int x,int y, int width, int height, int border_width, int depth, long wclass, long visual, long valuemask, long attributes)113     static native long XCreateWindow(long display, long parent, int x,int  y, int width, int height, int border_width, int depth, long wclass, long visual, long valuemask, long attributes);
114 
XDestroyWindow(long display, long window)115     static native void XDestroyWindow(long display, long window);
116 
XGrabPointer(long display, long grab_window, int owner_events, int event_mask, int pointer_mode, int keyboard_mode, long confine_to, long cursor, long time)117     static native int XGrabPointer(long display, long grab_window,
118                                    int owner_events, int event_mask, int pointer_mode,
119                                    int keyboard_mode, long confine_to, long cursor, long time);
120 
XUngrabPointer(long display, long time)121     static native void XUngrabPointer(long display, long time);
122 
XGrabKeyboard(long display, long grab_window, int owner_events, int pointer_mode, int keyboard_mode, long time)123     static native int XGrabKeyboard(long display, long grab_window,
124                                     int owner_events, int pointer_mode,
125                                     int keyboard_mode, long time);
126 
XUngrabKeyboard(long display, long time)127     static native void XUngrabKeyboard(long display, long time);
128 
XGrabServer(long display)129     static native void XGrabServer(long display);
XUngrabServer(long display)130     static native void XUngrabServer(long display);
131 
132 /*
133 
134 void XSetWMProperties(display, w, window_name, icon_name,
135 argv, argc, normal_hints, wm_hints, class_hints)
136 Display *display;
137 Window w;
138 XTextProperty *window_name;
139 XTextProperty *icon_name;
140 char **argv;
141 int argc;
142 XSizeHints *normal_hints;
143 XWMHints *wm_hints;
144 XClassHint *class_hints;
145 */
146 
147 /*
148 
149 XMapWindow(display, w)
150 Display *display;
151 Window w;
152 */
153 
XMapWindow(long display, long window)154     static  native void XMapWindow(long display, long window);
XMapRaised(long display, long window)155     static  native void XMapRaised(long display, long window);
XRaiseWindow(long display, long window)156     static  native void XRaiseWindow(long display, long window);
157 
XLowerWindow(long display, long window)158     static native void XLowerWindow(long display, long window);
XRestackWindows(long display, long windows, int length)159     static native void XRestackWindows(long display, long windows, int length);
XConfigureWindow(long display, long window, long value_mask, long values)160     static native void XConfigureWindow(long display, long window,
161             long value_mask, long values);
XSetInputFocus(long display, long window)162     static native void XSetInputFocus(long display, long window);
XSetInputFocus2(long display, long window, long time)163     static native void XSetInputFocus2(long display, long window, long time);
XGetInputFocus(long display)164     static native long XGetInputFocus(long display);
165 
166 /*
167 
168 XUnmapWindow(display, w)
169 Display *display;
170 Window w;
171 */
172 
XUnmapWindow(long display, long window)173     static  native void XUnmapWindow(long display, long window);
174 
175 
176 
177 
178 /*
179   XSelectInput(display, w, event_mask)
180   Display *display;
181   Window w;
182   long event_mask;
183 
184 */
XSelectInput(long display, long window, long event_mask)185     static  native void XSelectInput(long display, long window, long event_mask);
186 
187     /*
188        XNextEvent(display, event_return)
189        Display *display;
190        XEvent *event_return;
191 
192     */
193 
XNextEvent(long display,long ptr)194     static  native void XNextEvent(long display,long ptr);
195 
196     /*
197      XMaskEvent(display, event_mask, event_return)
198            Display *display;
199            long event_mask;
200            XEvent *event_return;
201      */
XMaskEvent(long display, long event_mask, long event_return)202     static native void XMaskEvent(long display, long event_mask, long event_return);
203 
XWindowEvent(long display, long window, long event_mask, long event_return)204     static native void XWindowEvent(long display, long window, long event_mask, long event_return);
205 
206     /*
207       Bool XFilterEvent(event, w)
208            XEvent *event;
209            Window w;
210     */
XFilterEvent(long ptr, long window)211     static native boolean XFilterEvent(long ptr, long window);
212 
213 /*
214      Bool XSupportsLocale()
215 */
XSupportsLocale()216 static native boolean XSupportsLocale();
217 
218 /*
219      char *XSetLocaleModifiers(modifier_list)
220            char *modifier_list;
221 */
XSetLocaleModifiers(String modifier_list)222 static native String XSetLocaleModifiers(String modifier_list);
223 
224 
XTranslateCoordinates( long display, long src_w, long dest_w, long src_x, long src_y, long dest_x_return, long dest_y_return, long child_return)225     static  native int XTranslateCoordinates(
226                                              long display, long src_w, long dest_w,
227                                              long src_x, long src_y,
228                                              long dest_x_return, long dest_y_return,
229                                              long child_return);
230 
231     /*
232        XPeekEvent(display, event_return)
233        Display *display;
234        XEvent *event_return;
235 
236     */
237 
XPeekEvent(long display,long ptr)238     static  native void XPeekEvent(long display,long ptr);
239 
240 /*
241   XFlush(display)
242   Display *display;
243 */
244 
XFlush(long display)245     static native void XFlush(long display);
246 
247 /*
248   XSync(display, discard)
249   Display *display;
250   Bool discard;
251 */
252 
XSync(long display,int discard)253     static native void XSync(long display,int discard);
254 
255 
256 /*    XMoveResizeWindow(display, w, x, y, width, height)
257       Display *display;
258       Window w;
259       int x, y;
260       unsigned int width, height;
261 */
XMoveResizeWindow(long display, long window, int x, int y, int width, int height)262     static native void XMoveResizeWindow(long display, long window, int x, int y, int width, int height);
XResizeWindow(long display, long window, int width, int height)263     static native void XResizeWindow(long display, long window, int width, int height);
XMoveWindow(long display, long window, int x, int y)264     static native void XMoveWindow(long display, long window, int x, int y);
265 
266     /*
267      Bool XQueryPointer(display, w, root_return, child_return,
268      root_x_return, root_y_return,
269                           win_x_return, win_y_return,
270      mask_return)
271            Display *display;
272            Window w;
273            Window *root_return, *child_return;
274            int *root_x_return, *root_y_return;
275            int *win_x_return, *win_y_return;
276            unsigned int *mask_return;
277 */
278 
XQueryPointer(long display, long window, long root_return, long child_return, long root_x_return, long root_y_return, long win_x_return, long win_y_return, long mask_return)279  static native boolean  XQueryPointer (long display, long window, long root_return, long child_return, long root_x_return, long root_y_return, long win_x_return, long win_y_return, long mask_return);
280 
281 /*    XFreeCursor(display, cursor)
282            Display *display;
283            Cursor cursor;
284 */
285 
XFreeCursor(long display, long cursor)286  static native void XFreeCursor(long display, long cursor);
287 
288 /*
289    XSetWindowBackground(display, w, background_pixel)
290    Display *display;
291    Window w;
292    unsigned long background_pixel;
293 */
294 
XSetWindowBackground(long display, long window, long background_pixel)295     static native void XSetWindowBackground(long display, long window, long background_pixel);
296 
XEventsQueued(long display, int mode)297     static native int XEventsQueued(long display, int mode);
298 
299 /*
300   Atom XInternAtom(display, atom_name, only_if_exists)
301   Display *display;
302   char *atom_name;
303   Bool only_if_exists;
304 */
305 
XInternAtoms(long display, String[] names, boolean only_if_exists, long atoms)306     static native int XInternAtoms(long display, String[] names, boolean only_if_exists, long atoms);
307 
SetProperty(long display, long window, long atom, String str)308     static native void SetProperty(long display, long window, long atom, String str);
GetProperty(long display ,long window, long atom)309     static native String GetProperty(long display ,long window, long atom);
InternAtom(long display, String string, int only_if_exists)310     static native long InternAtom(long display, String string, int only_if_exists);
XGetWindowProperty(long display, long window, long atom, long long_offset, long long_length, long delete, long req_type, long actualy_type, long actualy_format, long nitems_ptr, long bytes_after, long data_ptr)311     static native int XGetWindowProperty(long display, long window, long atom,
312                                          long long_offset, long long_length,
313                                          long delete, long req_type, long actualy_type,
314                                          long actualy_format, long nitems_ptr,
315                                          long bytes_after, long data_ptr);
XChangePropertyImpl(long display, long window, long atom, long type, int format, int mode, long data, int nelements)316     static native void XChangePropertyImpl(long display, long window, long atom,
317                                            long type, int format, int mode, long data,
318                                            int nelements);
XChangeProperty(long display, long window, long atom, long type, int format, int mode, long data, int nelements)319     static void XChangeProperty(long display, long window, long atom,
320                                 long type, int format, int mode, long data,
321                                 int nelements) {
322         // TODO: handling of XChangePropertyImpl return value, if not Success - don't cache
323         if (XPropertyCache.isCachingSupported() &&
324             XToolkit.windowToXWindow(window) != null &&
325             WindowPropertyGetter.isCacheableProperty(XAtom.get(atom)) &&
326             mode == XConstants.PropModeReplace)
327         {
328             int length = (format / 8) * nelements;
329             XPropertyCache.storeCache(
330                 new XPropertyCache.PropertyCacheEntry(format,
331                                                       nelements,
332                                                       0,
333                                                       data,
334                                                       length),
335                 window,
336                 XAtom.get(atom));
337         }
338         XChangePropertyImpl(display, window, atom, type, format, mode, data, nelements);
339     }
340 
XChangePropertyS(long display, long window, long atom, long type, int format, int mode, String value)341     static native void XChangePropertyS(long display, long window, long atom,
342                                        long type, int format, int mode, String value);
XDeleteProperty(long display, long window, long atom)343     static native void XDeleteProperty(long display, long window, long atom);
344 
XSetTransientFor(long display, long window, long transient_for_window)345     static native void XSetTransientFor(long display, long window, long transient_for_window);
XSetWMHints(long display, long window, long wmhints)346     static native void XSetWMHints(long display, long window, long wmhints);
XGetWMHints(long display, long window, long wmhints)347     static native void XGetWMHints(long display, long window, long wmhints);
XAllocWMHints()348     static native long XAllocWMHints();
XGetPointerMapping(long display, long map, int buttonNumber)349     static native int XGetPointerMapping(long display, long map, int buttonNumber);
XGetDefault(long display, String program, String option)350     static native String XGetDefault(long display, String program, String option);
getScreenOfWindow(long display, long window)351     static native long getScreenOfWindow(long display, long window);
XScreenNumberOfScreen(long screen)352     static native long XScreenNumberOfScreen(long screen);
XIconifyWindow(long display, long window, long screenNumber)353     static native int XIconifyWindow(long display, long window, long screenNumber);
ServerVendor(long display)354     static native String ServerVendor(long display);
VendorRelease(long display)355     static native int VendorRelease(long display);
IsXsunKPBehavior(long display)356     static native boolean IsXsunKPBehavior(long display);
IsSunKeyboard(long display)357     static native boolean IsSunKeyboard(long display);
IsKanaKeyboard(long display)358     static native boolean IsKanaKeyboard(long display);
359 
XBell(long display, int percent)360     static native void XBell(long display, int percent);
361 
362  /*
363           Cursor XCreateFontCursor(display, shape)
364            Display *display;
365            unsigned int shape;
366 
367            we always pass int as shape param.
368            perhaps later we will need to change type of shape to long.
369 */
370 
XCreateFontCursor(long display, int shape)371     static native int XCreateFontCursor(long display, int shape);
372 
373 /*
374      Pixmap XCreateBitmapFromData(display, d, data, width,
375      height)
376            Display *display;
377            Drawable d;
378            char *data;
379            unsigned int width, height;
380 */
381 
XCreateBitmapFromData(long display, long drawable, long data, int width, int height)382     static native long XCreateBitmapFromData(long display, long drawable, long data, int width, int height);
383 
384  /*
385       XFreePixmap(display, pixmap)
386            Display *display;
387            Pixmap pixmap;
388   */
389 
XFreePixmap(long display, long pixmap)390    static native void XFreePixmap(long display, long pixmap);
391 
392   /*
393      Cursor XCreatePixmapCursor(display, source, mask,
394      foreground_color, background_color, x, y)
395            Display *display;
396            Pixmap source;
397            Pixmap mask;
398            XColor *foreground_color;
399            XColor *background_color;
400            unsigned int x, y;
401     */
XCreatePixmapCursor(long display, long source, long mask, long fore, long back, int x, int y)402    static native long XCreatePixmapCursor(long display, long source, long mask, long fore, long back, int x, int y);
403 
404 
405     /*
406          Status XQueryBestCursor(display, d, width, height,
407      width_return, height_return)
408            Display *display;
409            Drawable d;
410            unsigned int width, height;
411            unsigned int *width_return, *height_return;
412 
413     */
414 
XQueryBestCursor(long display, long drawable, int width, int height, long width_return, long height_return)415     static native boolean XQueryBestCursor(long display, long drawable, int width, int height, long width_return, long height_return);
416 
417 
418     /*
419      Status XAllocColor(display, colormap, screen_in_out)
420            Display *display;
421            Colormap colormap;
422            XColor *screen_in_out;
423   */
424 
XAllocColor( long display, long colormap, long screen_in_out)425     static native boolean XAllocColor( long display, long colormap, long screen_in_out);
426 
427 
SetToolkitErrorHandler()428     static native long SetToolkitErrorHandler();
XSetErrorHandler(long handler)429     static native void XSetErrorHandler(long handler);
CallErrorHandler(long handler, long display, long event_ptr)430     static native int CallErrorHandler(long handler, long display, long event_ptr);
431 
432  /*
433       XChangeWindowAttributes(display, w, valuemask, attributes)
434            Display *display;
435            Window w;
436            unsigned long valuemask;
437            XSetWindowAttributes *attributes;
438   */
439 
XChangeWindowAttributes(long display, long window, long valuemask, long attributes)440     static native void XChangeWindowAttributes(long display, long window, long valuemask, long attributes);
XGetWindowAttributes(long display, long window, long attr_ptr)441     static native int XGetWindowAttributes(long display, long window, long attr_ptr);
XGetGeometry(long display, long drawable, long root_return, long x_return, long y_return, long width_return, long height_return, long border_width_return, long depth_return)442     static native int XGetGeometry(long display, long drawable, long root_return, long x_return, long y_return,
443                                    long width_return, long height_return, long border_width_return, long depth_return);
444 
XGetWMNormalHints(long display, long window, long hints, long supplied_return)445     static native int XGetWMNormalHints(long display, long window, long hints, long supplied_return);
XSetWMNormalHints(long display, long window, long hints)446     static native void XSetWMNormalHints(long display, long window, long hints);
XSetMinMaxHints(long display, long window, int x, int y, int width, int height, long flags)447     static native void XSetMinMaxHints(long display, long window, int x, int y, int width, int height, long flags);
XAllocSizeHints()448     static native long XAllocSizeHints();
449 
XSendEvent(long display, long window, boolean propagate, long event_mask, long event)450     static native int XSendEvent(long display, long window, boolean propagate, long event_mask, long event);
XPutBackEvent(long display, long event)451     static native void XPutBackEvent(long display, long event);
XQueryTree(long display, long window, long root_return, long parent_return, long children_return, long nchildren_return)452     static native int XQueryTree(long display, long window, long root_return, long parent_return, long children_return, long nchildren_return);
XGetVisualInfo(long display, long vinfo_mask, long vinfo_template, long nitems_return)453     static native long XGetVisualInfo(long display, long vinfo_mask, long vinfo_template, long nitems_return);
XReparentWindow(long display, long window, long parent, int x, int y)454     static native void XReparentWindow(long display, long window, long parent, int x, int y);
455 
XConvertSelection(long display, long selection, long target, long property, long requestor, long time)456     static native void XConvertSelection(long display, long selection,
457                                          long target, long property,
458                                          long requestor, long time);
459 
XSetSelectionOwner(long display, long selection, long owner, long time)460     static native void XSetSelectionOwner(long display, long selection,
461                                           long owner, long time);
462 
XGetSelectionOwner(long display, long selection)463     static native long XGetSelectionOwner(long display, long selection);
464 
XGetAtomName(long display, long atom)465     static native String XGetAtomName(long display, long atom);
466 
XMaxRequestSize(long display)467     static native long XMaxRequestSize(long display);
468 
469 
XCreatePixmap(long display, long drawable, int width, int height, int depth)470     static native long XCreatePixmap(long display, long drawable, int width, int height, int depth);
XCreateImage(long display, long visual_ptr, int depth, int format, int offset, long data, int width, int height, int bitmap_pad, int bytes_per_line)471     static native long XCreateImage(long display, long visual_ptr, int depth, int format,
472                                     int offset, long data, int width, int height, int bitmap_pad,
473                                     int bytes_per_line);
XDestroyImage(long image)474     static native void XDestroyImage(long image);
XPutImage(long display, long drawable, long gc, long image, int src_x, int src_y, int dest_x, int dest_y, int width, int height)475     static native void XPutImage(long display, long drawable, long gc, long image,
476                                  int src_x, int src_y, int dest_x, int dest_y,
477                                  int width, int height);
XCreateGC(long display, long drawable, long valuemask, long values)478     static native long XCreateGC(long display, long drawable, long valuemask, long values);
XFreeGC(long display, long gc)479     static native void XFreeGC(long display, long gc);
XSetWindowBackgroundPixmap(long display, long window, long pixmap)480     static native void XSetWindowBackgroundPixmap(long display, long window, long pixmap);
XClearWindow(long display, long window)481     static native void XClearWindow(long display, long window);
XGetIconSizes(long display, long window, long ret_sizes, long ret_count)482     static native int XGetIconSizes(long display, long window, long ret_sizes, long ret_count);
XdbeQueryExtension(long display, long major_version_return, long minor_version_return)483     static native int XdbeQueryExtension(long display, long major_version_return,
484                                          long minor_version_return);
XQueryExtension(long display, String name, long mop_return, long feve_return, long err_return)485     static native boolean XQueryExtension(long display, String name, long mop_return,
486                                          long feve_return, long err_return);
IsKeypadKey(long keysym)487     static native boolean IsKeypadKey(long keysym);
XdbeAllocateBackBufferName(long display, long window, int swap_action)488     static native long XdbeAllocateBackBufferName(long display, long window, int swap_action);
XdbeDeallocateBackBufferName(long display, long buffer)489     static native int XdbeDeallocateBackBufferName(long display, long buffer);
XdbeBeginIdiom(long display)490     static native int XdbeBeginIdiom(long display);
XdbeEndIdiom(long display)491     static native int XdbeEndIdiom(long display);
XdbeSwapBuffers(long display, long swap_info, int num_windows)492     static native int XdbeSwapBuffers(long display, long swap_info, int num_windows);
493 
XQueryKeymap(long display, long vector)494     static native void XQueryKeymap(long display, long vector);
XKeycodeToKeysym(long display, int keycode, int index)495     static native long XKeycodeToKeysym(long display, int keycode, int index);
496 
XKeysymToKeycode(long display, long keysym)497     static native int XKeysymToKeycode(long display, long keysym);
498 
499     // xkb-related
XkbGetEffectiveGroup(long display)500     static native int XkbGetEffectiveGroup(long display);
XkbKeycodeToKeysym(long display, int keycode, int group, int level)501     static native long XkbKeycodeToKeysym(long display, int keycode, int group, int level);
XkbSelectEvents(long display, long device, long bits_to_change, long values_for_bits)502     static native void XkbSelectEvents(long display, long device, long bits_to_change, long values_for_bits);
XkbSelectEventDetails(long display, long device, long event_type, long bits_to_change, long values_for_bits)503     static native void XkbSelectEventDetails(long display, long device, long event_type,
504                                               long bits_to_change, long values_for_bits);
XkbQueryExtension(long display, long opcode_rtrn, long event_rtrn, long error_rtrn, long major_in_out, long minor_in_out)505     static native boolean XkbQueryExtension(long display, long opcode_rtrn, long event_rtrn,
506               long error_rtrn, long major_in_out, long minor_in_out);
XkbLibraryVersion(long lib_major_in_out, long lib_minor_in_out)507     static native boolean XkbLibraryVersion(long lib_major_in_out, long lib_minor_in_out);
XkbGetMap(long display, long which, long device_spec)508     static native long XkbGetMap(long display, long which, long device_spec);
XkbGetUpdatedMap(long display, long which, long xkb)509     static native long XkbGetUpdatedMap(long display, long which, long xkb);
XkbFreeKeyboard(long xkb, long which, boolean free_all)510     static native void XkbFreeKeyboard(long xkb, long which, boolean free_all);
XkbTranslateKeyCode(long xkb, int keycode, long mods, long mods_rtrn, long keysym_rtrn)511     static native boolean XkbTranslateKeyCode(long xkb, int keycode, long mods, long mods_rtrn, long keysym_rtrn);
XkbSetDetectableAutoRepeat(long display, boolean detectable)512     static native void XkbSetDetectableAutoRepeat(long display, boolean detectable);
513 
514 
XConvertCase(long keysym, long keysym_lowercase, long keysym_uppercase)515     static native void XConvertCase(long keysym,
516                                     long keysym_lowercase,
517                                     long keysym_uppercase);
518 
XGetModifierMapping(long display)519     static native long XGetModifierMapping(long display);
XFreeModifiermap(long keymap)520     static native void XFreeModifiermap(long keymap);
XRefreshKeyboardMapping(long event)521     static native void XRefreshKeyboardMapping(long event);
522 
523 
XChangeActivePointerGrab(long display, int mask, long cursor, long time)524     static native void XChangeActivePointerGrab(long display, int mask,
525                                                 long cursor, long time);
526 
527     /*
528       int (*XSynchronize(Display *display, Bool onoff))();
529           display   Specifies the connection to the X server.
530           onoff     Specifies a Boolean value that indicates whether to enable or disable synchronization.
531      */
XSynchronize(long display, boolean onoff)532     static native long XSynchronize(long display, boolean onoff);
533 
534     /**
535      * Extracts an X event that can be processed in a secondary loop.
536      * Should only be called on the toolkit thread.
537      * Returns false if this secondary event was terminated.
538      */
XNextSecondaryLoopEvent(long display, long ptr)539     static native boolean XNextSecondaryLoopEvent(long display, long ptr);
540     /**
541      * Terminates the topmost secondary loop (if any).
542      * Should never be called on the toolkit thread.
543      */
ExitSecondaryLoop()544     static native void ExitSecondaryLoop();
545 
546     /**
547      * Calls XTextPropertyToStringList on the specified byte array and returns
548      * the array of strings.
549      */
XTextPropertyToStringList(byte[] bytes, long encoding_atom)550     static native String[] XTextPropertyToStringList(byte[] bytes, long encoding_atom);
551 
552     /**
553      * XSHAPE extension support.
554      */
XShapeQueryExtension(long display, long event_base_return, long error_base_return)555     static native boolean XShapeQueryExtension(long display, long event_base_return, long error_base_return);
SetRectangularShape(long display, long window, int lox, int loy, int hix, int hiy, sun.java2d.pipe.Region region)556     static native void SetRectangularShape(long display, long window,
557             int lox, int loy, int hix, int hiy,
558             sun.java2d.pipe.Region region);
559     /** Each int in the bitmap array is one pixel with a 32-bit color:
560      *  R, G, B, and Alpha.
561      */
SetBitmapShape(long display, long window, int width, int height, int[] bitmap)562     static native void SetBitmapShape(long display, long window,
563              int width, int height, int[] bitmap);
564 
SetZOrder(long display, long window, long above)565     static native void SetZOrder(long display, long window, long above);
566 
567 /* Global memory area used for X lib parameter passing */
568 
569     static final long lbuffer = unsafe.allocateMemory(64);  // array to hold 8 longs
570     static final long ibuffer = unsafe.allocateMemory(32);  // array to hold 8 ints
571 
572     static final long larg1 = lbuffer;
573     static final long larg2 = larg1+8;
574     static final long larg3 = larg2+8;
575     static final long larg4 = larg3+8;
576     static final long larg5 = larg4+8;
577     static final long larg6 = larg5+8;
578     static final long larg7 = larg6+8;
579     static final long larg8 = larg7+8;
580 
581     static final long iarg1 = ibuffer;
582     static final long iarg2 = iarg1+4;
583     static final long iarg3 = iarg2+4;
584     static final long iarg4 = iarg3+4;
585     static final long iarg5 = iarg4+4;
586     static final long iarg6 = iarg5+4;
587     static final long iarg7 = iarg6+4;
588     static final long iarg8 = iarg7+4;
589 
590 
591     static int dataModel;
592     static final boolean isBuildInternal;
593 
594     static {
595         String dataModelProp = AccessController.doPrivileged(
596             new GetPropertyAction("sun.arch.data.model"));
597         try {
598             dataModel = Integer.parseInt(dataModelProp);
599         } catch (Exception e) {
600             dataModel = 32;
601         }
602 
603         isBuildInternal = getBuildInternal();
604 
605 //      System.loadLibrary("mawt");
606     }
607 
getDataModel()608     static int getDataModel() {
609         return dataModel;
610     }
611 
hintsToString(long flags)612     static String hintsToString(long flags) {
613         StringBuffer buf = new StringBuffer();
614         if ((flags & XUtilConstants.PMaxSize) != 0) {
615             buf.append("PMaxSize ");
616         }
617         if ((flags & XUtilConstants.PMinSize) != 0) {
618             buf.append("PMinSize ");
619         }
620         if ((flags & XUtilConstants.USSize) != 0) {
621             buf.append("USSize ");
622         }
623         if ((flags & XUtilConstants.USPosition) != 0) {
624             buf.append("USPosition ");
625         }
626         if ((flags & XUtilConstants.PPosition) != 0) {
627             buf.append("PPosition ");
628         }
629         if ((flags & XUtilConstants.PSize) != 0) {
630             buf.append("PSize ");
631         }
632         if ((flags & XUtilConstants.PWinGravity) != 0) {
633             buf.append("PWinGravity ");
634         }
635         return buf.toString();
636     }
getEventToString( int type )637     static String getEventToString( int type ) {
638         if( (type >= 0) && (type < eventToString.length)) {
639             return eventToString[type];
640         }else if( type == XToolkit.getXKBBaseEventCode() ) {
641             //XXX TODO various xkb types
642             return "XkbEvent";
643         }
644         return eventToString[0];
645     }
646 
getBuildInternal()647     private static boolean getBuildInternal() {
648         String javaVersion = AccessController.doPrivileged(
649                                  new GetPropertyAction("java.version"));
650         return javaVersion != null && javaVersion.contains("internal");
651     }
652 
PrintXErrorEvent(long display, long event_ptr)653     static native void PrintXErrorEvent(long display, long event_ptr);
654 }
655