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

Print this page


   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


 158         return securityWarningEnabled;
 159     }
 160 
 161     static native void awt_output_flush();
 162 
 163     static void  awtFUnlock() {
 164         awtUnlock();
 165         awt_output_flush();
 166     }
 167 
 168 
 169     private native void nativeLoadSystemColors(int[] systemColors);
 170 
 171     static UIDefaults getUIDefaults() {
 172         if (uidefaults == null) {
 173             initUIDefaults();
 174         }
 175         return uidefaults;
 176     }
 177 

 178     public void loadSystemColors(int[] systemColors) {
 179         nativeLoadSystemColors(systemColors);
 180         MotifColorUtilities.loadSystemColors(systemColors);
 181     }
 182 
 183 
 184 
 185     static void initUIDefaults() {
 186         try {
 187             // Load Defaults from MotifLookAndFeel
 188 
 189             // This dummy load is necessary to get SystemColor initialized. !!!!!!
 190             Color c = SystemColor.text;
 191 
 192             LookAndFeel lnf = new XAWTLookAndFeel();
 193             uidefaults = lnf.getDefaults();
 194         }
 195         catch (Exception e)
 196         {
 197             e.printStackTrace();


 250             XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
 251                 @Override
 252                 public void dispatchEvent(XEvent ev) {
 253                     if (ev.get_type() == XConstants.ConfigureNotify) {
 254                         awtUnlock();
 255                         try {
 256                             ((X11GraphicsEnvironment)GraphicsEnvironment.
 257                              getLocalGraphicsEnvironment()).
 258                                 displayChanged();
 259                         } finally {
 260                             awtLock();
 261                         }
 262                     }
 263                 }
 264             });
 265         } finally {
 266             awtUnlock();
 267         }
 268         PrivilegedAction<Void> a = () -> {
 269             Thread shutdownThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), "XToolkt-Shutdown-Thread") {

 270                     public void run() {
 271                         XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
 272                         if (peer != null) {
 273                             peer.dispose();
 274                         }
 275                         if (xs != null) {
 276                             ((XAWTXSettings)xs).dispose();
 277                         }
 278                         freeXKB();
 279                         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 280                             dumpPeers();
 281                         }
 282                     }
 283                 };
 284             shutdownThread.setContextClassLoader(null);
 285             Runtime.getRuntime().addShutdownHook(shutdownThread);
 286             return null;
 287         };
 288         AccessController.doPrivileged(a);
 289     }


 319             }
 320             if (mainClassName == null || mainClassName.equals("")) {
 321                 mainClassName = "AWT";
 322             }
 323             awtAppClassName = getCorrectXIDString(mainClassName);
 324 
 325             init();
 326             XWM.init();
 327 
 328             toolkitThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
 329                 Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, "AWT-XAWT");
 330                 thread.setContextClassLoader(null);
 331                 thread.setPriority(Thread.NORM_PRIORITY + 1);
 332                 thread.setDaemon(true);
 333                 return thread;
 334             });
 335             toolkitThread.start();
 336         }
 337     }
 338 

 339     public ButtonPeer createButton(Button target) {
 340         ButtonPeer peer = new XButtonPeer(target);
 341         targetCreatedPeer(target, peer);
 342         return peer;
 343     }
 344 

 345     public FramePeer createLightweightFrame(LightweightFrame target) {
 346         FramePeer peer = new XLightweightFramePeer(target);
 347         targetCreatedPeer(target, peer);
 348         return peer;
 349     }
 350 

 351     public FramePeer createFrame(Frame target) {
 352         FramePeer peer = new XFramePeer(target);
 353         targetCreatedPeer(target, peer);
 354         return peer;
 355     }
 356 
 357     static void addToWinMap(long window, XBaseWindow xwin)
 358     {
 359         synchronized(winMap) {
 360             winMap.put(Long.valueOf(window),xwin);
 361         }
 362     }
 363 
 364     static void removeFromWinMap(long window, XBaseWindow xwin) {
 365         synchronized(winMap) {
 366             winMap.remove(Long.valueOf(window));
 367         }
 368     }
 369     static XBaseWindow windowToXWindow(long window) {
 370         synchronized(winMap) {


 512             }
 513         }
 514         if (dispatchers != null) {
 515             Iterator<XEventDispatcher> iter = dispatchers.iterator();
 516             while (iter.hasNext()) {
 517                 XEventDispatcher disp = iter.next();
 518                 disp.dispatchEvent(ev);
 519             }
 520         }
 521         notifyListeners(ev);
 522     }
 523 
 524     static void processException(Throwable thr) {
 525         if (log.isLoggable(PlatformLogger.Level.WARNING)) {
 526             log.warning("Exception on Toolkit thread", thr);
 527         }
 528     }
 529 
 530     static native void awt_toolkit_init();
 531 

 532     public void run() {
 533         awt_toolkit_init();
 534         run(PRIMARY_LOOP);
 535     }
 536 
 537     public void run(boolean loop)
 538     {
 539         XEvent ev = new XEvent();
 540         while(true) {
 541             // Fix for 6829923: we should gracefully handle toolkit thread interruption
 542             if (Thread.currentThread().isInterrupted()) {
 543                 // We expect interruption from the AppContext.dispose() method only.
 544                 // If the thread is interrupted from another place, let's skip it
 545                 // for compatibility reasons. Probably some time later we'll remove
 546                 // the check for AppContext.isDisposed() and will unconditionally
 547                 // break the loop here.
 548                 if (AppContext.getAppContext().isDisposed()) {
 549                     break;
 550                 }
 551             }


 652                     screenHeight = pattr.get_height();
 653                 } finally {
 654                     pattr.dispose();
 655                 }
 656             } finally {
 657                 awtUnlock();
 658             }
 659         }
 660     }
 661 
 662     static int getDefaultScreenWidth() {
 663         initScreenSize();
 664         return screenWidth;
 665     }
 666 
 667     static int getDefaultScreenHeight() {
 668         initScreenSize();
 669         return screenHeight;
 670     }
 671 

 672     protected int getScreenWidth() {
 673         return getDefaultScreenWidth();
 674     }
 675 

 676     protected int getScreenHeight() {
 677         return getDefaultScreenHeight();
 678     }
 679 
 680     private static Rectangle getWorkArea(long root)
 681     {
 682         XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
 683 
 684         long native_ptr = Native.allocateLongArray(4);
 685         try
 686         {
 687             boolean workareaPresent = XA_NET_WORKAREA.getAtomData(root,
 688                 XAtom.XA_CARDINAL, native_ptr, 4);
 689             if (workareaPresent)
 690             {
 691                 int rootX = (int)Native.getLong(native_ptr, 0);
 692                 int rootY = (int)Native.getLong(native_ptr, 1);
 693                 int rootWidth = (int)Native.getLong(native_ptr, 2);
 694                 int rootHeight = (int)Native.getLong(native_ptr, 3);
 695 
 696                 return new Rectangle(rootX, rootY, rootWidth, rootHeight);
 697             }
 698         }
 699         finally
 700         {
 701             XlibWrapper.unsafe.freeMemory(native_ptr);
 702         }
 703 
 704         return null;
 705     }
 706 
 707     /*
 708      * If we're running in non-Xinerama environment and the current
 709      * window manager supports _NET protocol then the screen insets
 710      * are calculated using _NET_WM_WORKAREA property of the root
 711      * window.
 712      * Otherwise, i. e. if Xinerama is on or _NET_WM_WORKAREA is
 713      * not set, we try to calculate the insets ourselves using
 714      * getScreenInsetsManually method.
 715      */

 716     public Insets getScreenInsets(GraphicsConfiguration gc)
 717     {
 718         XNETProtocol netProto = XWM.getWM().getNETProtocol();
 719         if ((netProto == null) || !netProto.active())
 720         {
 721             return super.getScreenInsets(gc);
 722         }
 723 
 724         XToolkit.awtLock();
 725         try
 726         {
 727             X11GraphicsConfig x11gc = (X11GraphicsConfig)gc;
 728             X11GraphicsDevice x11gd = (X11GraphicsDevice)x11gc.getDevice();
 729             long root = XlibUtil.getRootWindow(x11gd.getScreen());
 730             Rectangle rootBounds = XlibUtil.getWindowGeometry(root);
 731 
 732             X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
 733                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 734             if (!x11ge.runningXinerama())
 735             {


 883         peer.disableBackgroundErase();
 884     }
 885     */
 886 
 887     // Need this for XMenuItemPeer.
 888     protected static Object targetToPeer(Object target) {
 889         Object p=null;
 890         if (target != null && !GraphicsEnvironment.isHeadless()) {
 891             p = specialPeerMap.get(target);
 892         }
 893         if (p != null) return p;
 894         else
 895             return SunToolkit.targetToPeer(target);
 896     }
 897 
 898     // Need this for XMenuItemPeer.
 899     protected static void targetDisposedPeer(Object target, Object peer) {
 900         SunToolkit.targetDisposedPeer(target, peer);
 901     }
 902 

 903     public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
 904         return new XRobotPeer(screen.getDefaultConfiguration());
 905     }
 906 
 907 
 908   /*
 909      * On X, support for dynamic layout on resizing is governed by the
 910      * window manager.  If the window manager supports it, it happens
 911      * automatically.  The setter method for this property is
 912      * irrelevant on X.
 913      */

 914     public void setDynamicLayout(boolean b) {
 915         dynamicLayoutSetting = b;
 916     }
 917 

 918     protected boolean isDynamicLayoutSet() {
 919         return dynamicLayoutSetting;
 920     }
 921 
 922     /* Called from isDynamicLayoutActive() and from
 923      * lazilyLoadDynamicLayoutSupportedProperty()
 924      */
 925     protected boolean isDynamicLayoutSupported() {
 926         return XWM.getWM().supportsDynamicLayout();
 927     }
 928 

 929     public boolean isDynamicLayoutActive() {
 930         return isDynamicLayoutSupported();
 931     }
 932 
 933 

 934     public FontPeer getFontPeer(String name, int style){
 935         return new XFontPeer(name, style);
 936     }
 937 

 938     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
 939         final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
 940         if (f != null) {
 941             return f.createDragSourceContextPeer(dge);
 942         }
 943 
 944         return XDragSourceContextPeer.createDragSourceContextPeer(dge);
 945     }
 946 

 947     @SuppressWarnings("unchecked")
 948     public <T extends DragGestureRecognizer> T
 949     createDragGestureRecognizer(Class<T> recognizerClass,
 950                     DragSource ds,
 951                     Component c,
 952                     int srcActions,
 953                     DragGestureListener dgl)
 954     {
 955         final LightweightFrame f = SunToolkit.getLightweightFrame(c);
 956         if (f != null) {
 957             return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
 958         }
 959 
 960         if (MouseDragGestureRecognizer.class.equals(recognizerClass))
 961             return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
 962         else
 963             return null;
 964     }
 965 

 966     public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
 967         XCheckboxMenuItemPeer peer = new XCheckboxMenuItemPeer(target);
 968         //vb157120: looks like we don't need to map menu items
 969         //in new menus implementation
 970         //targetCreatedPeer(target, peer);
 971         return peer;
 972     }
 973 

 974     public MenuItemPeer createMenuItem(MenuItem target) {
 975         XMenuItemPeer peer = new XMenuItemPeer(target);
 976         //vb157120: looks like we don't need to map menu items
 977         //in new menus implementation
 978         //targetCreatedPeer(target, peer);
 979         return peer;
 980     }
 981 

 982     public TextFieldPeer createTextField(TextField target) {
 983         TextFieldPeer  peer = new XTextFieldPeer(target);
 984         targetCreatedPeer(target, peer);
 985         return peer;
 986     }
 987 

 988     public LabelPeer createLabel(Label target) {
 989         LabelPeer  peer = new XLabelPeer(target);
 990         targetCreatedPeer(target, peer);
 991         return peer;
 992     }
 993 

 994     public ListPeer createList(java.awt.List target) {
 995         ListPeer peer = new XListPeer(target);
 996         targetCreatedPeer(target, peer);
 997         return peer;
 998     }
 999 

1000     public CheckboxPeer createCheckbox(Checkbox target) {
1001         CheckboxPeer peer = new XCheckboxPeer(target);
1002         targetCreatedPeer(target, peer);
1003         return peer;
1004     }
1005 

1006     public ScrollbarPeer createScrollbar(Scrollbar target) {
1007         XScrollbarPeer peer = new XScrollbarPeer(target);
1008         targetCreatedPeer(target, peer);
1009         return peer;
1010     }
1011 

1012     public ScrollPanePeer createScrollPane(ScrollPane target) {
1013         XScrollPanePeer peer = new XScrollPanePeer(target);
1014         targetCreatedPeer(target, peer);
1015         return peer;
1016     }
1017 

1018     public TextAreaPeer createTextArea(TextArea target) {
1019         TextAreaPeer peer = new XTextAreaPeer(target);
1020         targetCreatedPeer(target, peer);
1021         return peer;
1022     }
1023 

1024     public ChoicePeer createChoice(Choice target) {
1025         XChoicePeer peer = new XChoicePeer(target);
1026         targetCreatedPeer(target, peer);
1027         return peer;
1028     }
1029 

1030     public CanvasPeer createCanvas(Canvas target) {
1031         XCanvasPeer peer = (isXEmbedServerRequested() ? new XEmbedCanvasPeer(target) : new XCanvasPeer(target));
1032         targetCreatedPeer(target, peer);
1033         return peer;
1034     }
1035 

1036     public PanelPeer createPanel(Panel target) {
1037         PanelPeer peer = new XPanelPeer(target);
1038         targetCreatedPeer(target, peer);
1039         return peer;
1040     }
1041 

1042     public WindowPeer createWindow(Window target) {
1043         WindowPeer peer = new XWindowPeer(target);
1044         targetCreatedPeer(target, peer);
1045         return peer;
1046     }
1047 

1048     public DialogPeer createDialog(Dialog target) {
1049         DialogPeer peer = new XDialogPeer(target);
1050         targetCreatedPeer(target, peer);
1051         return peer;
1052     }
1053 
1054     private static Boolean sunAwtDisableGtkFileDialogs = null;
1055 
1056     /**
1057      * Returns the value of "sun.awt.disableGtkFileDialogs" property. Default
1058      * value is {@code false}.
1059      */
1060     public synchronized static boolean getSunAwtDisableGtkFileDialogs() {
1061         if (sunAwtDisableGtkFileDialogs == null) {
1062             sunAwtDisableGtkFileDialogs = AccessController.doPrivileged(
1063                                               new GetBooleanAction("sun.awt.disableGtkFileDialogs"));
1064         }
1065         return sunAwtDisableGtkFileDialogs.booleanValue();
1066     }
1067 

1068     public FileDialogPeer createFileDialog(FileDialog target) {
1069         FileDialogPeer peer = null;
1070         // The current GtkFileChooser is available from GTK+ 2.4
1071         if (!getSunAwtDisableGtkFileDialogs() && checkGtkVersion(2, 4, 0)) {
1072             peer = new GtkFileDialogPeer(target);
1073         } else {
1074             peer = new XFileDialogPeer(target);
1075         }
1076         targetCreatedPeer(target, peer);
1077         return peer;
1078     }
1079 

1080     public MenuBarPeer createMenuBar(MenuBar target) {
1081         XMenuBarPeer peer = new XMenuBarPeer(target);
1082         targetCreatedPeer(target, peer);
1083         return peer;
1084     }
1085 

1086     public MenuPeer createMenu(Menu target) {
1087         XMenuPeer peer = new XMenuPeer(target);
1088         //vb157120: looks like we don't need to map menu items
1089         //in new menus implementation
1090         //targetCreatedPeer(target, peer);
1091         return peer;
1092     }
1093 

1094     public PopupMenuPeer createPopupMenu(PopupMenu target) {
1095         XPopupMenuPeer peer = new XPopupMenuPeer(target);
1096         targetCreatedPeer(target, peer);
1097         return peer;
1098     }
1099 

1100     public synchronized MouseInfoPeer getMouseInfoPeer() {
1101         if (xPeer == null) {
1102             xPeer = new XMouseInfoPeer();
1103         }
1104         return xPeer;
1105     }
1106 
1107     public XEmbeddedFramePeer createEmbeddedFrame(XEmbeddedFrame target)
1108     {
1109         XEmbeddedFramePeer peer = new XEmbeddedFramePeer(target);
1110         targetCreatedPeer(target, peer);
1111         return peer;
1112     }
1113 
1114     XEmbedChildProxyPeer createEmbedProxy(XEmbedChildProxy target) {
1115         XEmbedChildProxyPeer peer = new XEmbedChildProxyPeer(target);
1116         targetCreatedPeer(target, peer);
1117         return peer;
1118     }
1119 

1120     public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() throws HeadlessException {
1121         return XKeyboardFocusManagerPeer.getInstance();
1122     }
1123 
1124     /**
1125      * Returns a new custom cursor.
1126      */

1127     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
1128       throws IndexOutOfBoundsException {
1129         return new XCustomCursor(cursor, hotSpot, name);
1130     }
1131 

1132     public TrayIconPeer createTrayIcon(TrayIcon target)
1133       throws HeadlessException, AWTException
1134     {
1135         TrayIconPeer peer = new XTrayIconPeer(target);
1136         targetCreatedPeer(target, peer);
1137         return peer;
1138     }
1139 

1140     public SystemTrayPeer createSystemTray(SystemTray target) throws HeadlessException {
1141         SystemTrayPeer peer = new XSystemTrayPeer(target);
1142         return peer;
1143     }
1144 

1145     public boolean isTraySupported() {
1146         XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
1147         if (peer != null) {
1148             return peer.isAvailable();
1149         }
1150         return false;
1151     }
1152 
1153     @Override
1154     public DataTransferer getDataTransferer() {
1155         return XDataTransferer.getInstanceImpl();
1156     }
1157 
1158     /**
1159      * Returns the supported cursor size
1160      */

1161     public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
1162         return XCustomCursor.getBestCursorSize(
1163                                                java.lang.Math.max(1,preferredWidth), java.lang.Math.max(1,preferredHeight));
1164     }
1165 
1166 

1167     public int getMaximumCursorColors() {
1168         return 2;  // Black and white.
1169     }
1170 

1171     public Map<TextAttribute, ?> mapInputMethodHighlight( InputMethodHighlight highlight) {
1172         return XInputMethod.mapInputMethodHighlight(highlight);
1173     }
1174     @Override
1175     public boolean getLockingKeyState(int key) {
1176         if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
1177                key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
1178             throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
1179         }
1180         awtLock();
1181         try {
1182             return getModifierState( key );
1183         } finally {
1184             awtUnlock();
1185         }
1186     }
1187 

1188     public  Clipboard getSystemClipboard() {
1189         SecurityManager security = System.getSecurityManager();
1190         if (security != null) {
1191             security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1192         }
1193         synchronized (this) {
1194             if (clipboard == null) {
1195                 clipboard = new XClipboard("System", "CLIPBOARD");
1196             }
1197         }
1198         return clipboard;
1199     }
1200 

1201     public Clipboard getSystemSelection() {
1202         SecurityManager security = System.getSecurityManager();
1203         if (security != null) {
1204             security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1205         }
1206         synchronized (this) {
1207             if (selection == null) {
1208                 selection = new XClipboard("Selection", "PRIMARY");
1209             }
1210         }
1211         return selection;
1212     }
1213 

1214     public void beep() {
1215         awtLock();
1216         try {
1217             XlibWrapper.XBell(getDisplay(), 0);
1218             XlibWrapper.XFlush(getDisplay());
1219         } finally {
1220             awtUnlock();
1221         }
1222     }
1223 

1224     public PrintJob getPrintJob(final Frame frame, final String doctitle,
1225                                 final Properties props) {
1226 
1227         if (frame == null) {
1228             throw new NullPointerException("frame must not be null");
1229         }
1230 
1231         PrintJob2D printJob = new PrintJob2D(frame, doctitle, props);
1232 
1233         if (printJob.printDialog() == false) {
1234             printJob = null;
1235         }
1236         return printJob;
1237     }
1238 

1239     public PrintJob getPrintJob(final Frame frame, final String doctitle,
1240                 final JobAttributes jobAttributes,
1241                 final PageAttributes pageAttributes)
1242     {
1243         if (frame == null) {
1244             throw new NullPointerException("frame must not be null");
1245         }
1246 
1247         PrintJob2D printJob = new PrintJob2D(frame, doctitle,
1248                                              jobAttributes, pageAttributes);
1249 
1250         if (printJob.printDialog() == false) {
1251             printJob = null;
1252         }
1253 
1254         return printJob;
1255     }
1256 
1257     static void XSync() {
1258         awtLock();
1259         try {
1260             XlibWrapper.XSync(getDisplay(),0);
1261         } finally {
1262             awtUnlock();
1263         }
1264     }
1265 

1266     public int getScreenResolution() {
1267         long display = getDisplay();
1268         awtLock();
1269         try {
1270             return (int) ((XlibWrapper.DisplayWidth(display,
1271                 XlibWrapper.DefaultScreen(display)) * 25.4) /
1272                     XlibWrapper.DisplayWidthMM(display,
1273                 XlibWrapper.DefaultScreen(display)));
1274         } finally {
1275             awtUnlock();
1276         }
1277     }
1278 
1279     static native long getDefaultXColormap();
1280     static native long getDefaultScreenData();
1281 
1282     static ColorModel screenmodel;
1283 
1284     static ColorModel getStaticColorModel() {
1285         if (screenmodel == null) {
1286             screenmodel = config.getColorModel ();
1287         }
1288         return screenmodel;
1289     }
1290 

1291     public ColorModel getColorModel() {
1292         return getStaticColorModel();
1293     }
1294 
1295     /**
1296      * Returns a new input method adapter descriptor for native input methods.
1297      */

1298     public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
1299         return new XInputMethodDescriptor();
1300     }
1301 
1302     /**
1303      * Returns whether enableInputMethods should be set to true for peered
1304      * TextComponent instances on this platform. True by default.
1305      */
1306     @Override
1307     public boolean enableInputMethodsForTextComponent() {
1308         return true;
1309     }
1310 
1311     static int getMultiClickTime() {
1312         if (awt_multiclick_time == 0) {
1313             initializeMultiClickTime();
1314         }
1315         return awt_multiclick_time;
1316     }
1317     static void initializeMultiClickTime() {


1329                            a second, so we need to multiply by 100 to convert to
1330                            milliseconds */
1331                         awt_multiclick_time = (int)Long.parseLong(multiclick_time_query) * 100;
1332                     } else {
1333                         awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1334                     }
1335                 }
1336             } catch (NumberFormatException nf) {
1337                 awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1338             } catch (NullPointerException npe) {
1339                 awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1340             }
1341         } finally {
1342             awtUnlock();
1343         }
1344         if (awt_multiclick_time == 0) {
1345             awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1346         }
1347     }
1348 

1349     public boolean isFrameStateSupported(int state)
1350       throws HeadlessException
1351     {
1352         if (state == Frame.NORMAL || state == Frame.ICONIFIED) {
1353             return true;
1354         } else {
1355             return XWM.getWM().supportsExtendedState(state);
1356         }
1357     }
1358 
1359     static void dumpPeers() {
1360         if (log.isLoggable(PlatformLogger.Level.FINE)) {
1361             log.fine("Mapped windows:");
1362             winMap.forEach((k, v) -> {
1363                 log.fine(k + "->" + v);
1364                 if (v instanceof XComponentPeer) {
1365                     Component target = (Component)((XComponentPeer)v).getTarget();
1366                     log.fine("\ttarget: " + target);
1367                 }
1368             });


1371 
1372             log.fine("Mapped special peers:");
1373             specialPeerMap.forEach((k, v) -> {
1374                 log.fine(k + "->" + v);
1375             });
1376 
1377             log.fine("Mapped dispatchers:");
1378             winToDispatcher.forEach((k, v) -> {
1379                 log.fine(k + "->" + v);
1380             });
1381         }
1382     }
1383 
1384     /* Protected with awt_lock. */
1385     private static boolean initialized;
1386     private static boolean timeStampUpdated;
1387     private static long timeStamp;
1388 
1389     private static final XEventDispatcher timeFetcher =
1390     new XEventDispatcher() {

1391             public void dispatchEvent(XEvent ev) {
1392                 switch (ev.get_type()) {
1393                   case XConstants.PropertyNotify:
1394                       XPropertyEvent xpe = ev.get_xproperty();
1395 
1396                       awtLock();
1397                       try {
1398                           timeStamp = xpe.get_time();
1399                           timeStampUpdated = true;
1400                           awtLockNotifyAll();
1401                       } finally {
1402                           awtUnlock();
1403                       }
1404 
1405                       break;
1406                 }
1407             }
1408         };
1409 
1410     private static XAtom _XA_JAVA_TIME_PROPERTY_ATOM;


1439                     finally {
1440                         event.dispose();
1441                     }
1442                 }
1443                 else {
1444                     while (!timeStampUpdated) {
1445                         awtLockWait();
1446                     }
1447                 }
1448             } catch (InterruptedException ie) {
1449             // Note: the returned timeStamp can be incorrect in this case.
1450                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
1451                     log.fine("Catched exception, timeStamp may not be correct (ie = " + ie + ")");
1452                 }
1453             }
1454         } finally {
1455             awtUnlock();
1456         }
1457         return timeStamp;
1458     }

1459     protected void initializeDesktopProperties() {
1460         desktopProperties.put("DnD.Autoscroll.initialDelay",
1461                               Integer.valueOf(50));
1462         desktopProperties.put("DnD.Autoscroll.interval",
1463                               Integer.valueOf(50));
1464         desktopProperties.put("DnD.Autoscroll.cursorHysteresis",
1465                               Integer.valueOf(5));
1466         desktopProperties.put("Shell.shellFolderManager",
1467                               "sun.awt.shell.ShellFolderManager");
1468         // Don't want to call getMultiClickTime() if we are headless
1469         if (!GraphicsEnvironment.isHeadless()) {
1470             desktopProperties.put("awt.multiClickInterval",
1471                                   Integer.valueOf(getMultiClickTime()));
1472             desktopProperties.put("awt.mouse.numButtons",
1473                                   Integer.valueOf(getNumberOfButtons()));
1474         }
1475     }
1476 
1477     /**
1478      * This method runs through the XPointer and XExtendedPointer array.


1497                     numberOfButtons -= 2;
1498                 } else if (numberOfButtons == 4 || numberOfButtons ==5){
1499                     numberOfButtons = 3;
1500                 }
1501             }
1502             //Assume don't have to re-query the number again and again.
1503             return numberOfButtons;
1504         } finally {
1505             awtUnlock();
1506         }
1507     }
1508 
1509     static int getNumberOfButtonsForMask() {
1510         return Math.min(XConstants.MAX_BUTTONS, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons());
1511     }
1512 
1513     private final static String prefix  = "DnD.Cursor.";
1514     private final static String postfix = ".32x32";
1515     private static final String dndPrefix  = "DnD.";
1516 

1517     protected Object lazilyLoadDesktopProperty(String name) {
1518         if (name.startsWith(prefix)) {
1519             String cursorName = name.substring(prefix.length(), name.length()) + postfix;
1520 
1521             try {
1522                 return Cursor.getSystemCustomCursor(cursorName);
1523             } catch (AWTException awte) {
1524                 throw new RuntimeException("cannot load system cursor: " + cursorName, awte);
1525             }
1526         }
1527 
1528         if (name.equals("awt.dynamicLayoutSupported")) {
1529             return  Boolean.valueOf(isDynamicLayoutSupported());
1530         }
1531 
1532         if (initXSettingsIfNeeded(name)) {
1533             return desktopProperties.get(name);
1534         }
1535 
1536         return super.lazilyLoadDesktopProperty(name);
1537     }
1538 

1539     public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
1540         if (name == null) {
1541             // See JavaDoc for the Toolkit.addPropertyChangeListener() method
1542             return;
1543         }
1544         initXSettingsIfNeeded(name);
1545         super.addPropertyChangeListener(name, pcl);
1546     }
1547 
1548     /**
1549      * Initializes XAWTXSettings if a property for a given property name is provided by
1550      * XSettings and they are not initialized yet.
1551      *
1552      * @return true if the method has initialized XAWTXSettings.
1553      */
1554     private boolean initXSettingsIfNeeded(final String propName) {
1555         if (!loadedXSettings &&
1556             (propName.startsWith("gnome.") ||
1557              propName.equals(SunToolkit.DESKTOPFONTHINTS) ||
1558              propName.startsWith(dndPrefix)))


2017 
2018         long current_time_utc = System.currentTimeMillis();
2019         if (log.isLoggable(PlatformLogger.Level.FINER)) {
2020             log.finer("reset_time=" + reset_time_utc + ", current_time=" + current_time_utc
2021                       + ", server_offset=" + server_offset + ", wrap_time=" + WRAP_TIME_MILLIS);
2022         }
2023 
2024         if ((current_time_utc - reset_time_utc) > WRAP_TIME_MILLIS) {
2025             reset_time_utc = System.currentTimeMillis() - getCurrentServerTime();
2026         }
2027 
2028         if (log.isLoggable(PlatformLogger.Level.FINER)) {
2029             log.finer("result = " + (reset_time_utc + server_offset));
2030         }
2031         return reset_time_utc + server_offset;
2032     }
2033 
2034     /**
2035      * @see sun.awt.SunToolkit#needsXEmbedImpl
2036      */

2037     protected boolean needsXEmbedImpl() {
2038         // XToolkit implements supports for XEmbed-client protocol and
2039         // requires the supports from the embedding host for it to work.
2040         return true;
2041     }
2042 

2043     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
2044         return (modalityType == null) ||
2045                (modalityType == Dialog.ModalityType.MODELESS) ||
2046                (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
2047                (modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
2048                (modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
2049     }
2050 

2051     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
2052         return (exclusionType == null) ||
2053                (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
2054                (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
2055                (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
2056     }
2057 
2058     static EventQueue getEventQueue(Object target) {
2059         AppContext appContext = targetToAppContext(target);
2060         if (appContext != null) {
2061             return (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
2062         }
2063         return null;
2064     }
2065 
2066     static void removeSourceEvents(EventQueue queue,
2067                                    Object source,
2068                                    boolean removeAllEvents) {
2069         AWTAccessor.getEventQueueAccessor()
2070             .removeSourceEvents(queue, source, removeAllEvents);
2071     }
2072 

2073     public boolean isAlwaysOnTopSupported() {
2074         for (XLayerProtocol proto : XWM.getWM().getProtocols(XLayerProtocol.class)) {
2075             if (proto.supportsLayer(XLayerProtocol.LAYER_ALWAYS_ON_TOP)) {
2076                 return true;
2077             }
2078         }
2079         return false;
2080     }
2081 

2082     public boolean useBufferPerWindow() {
2083         return XToolkit.getBackingStoreType() == XConstants.NotUseful;
2084     }
2085 
2086     /**
2087      * Returns one of XConstants: NotUseful, WhenMapped or Always.
2088      * If backing store is not available on at least one screen, or
2089      * java2d uses DGA(which conflicts with backing store) on at least one screen,
2090      * or the string system property "sun.awt.backingStore" is neither "Always"
2091      * nor "WhenMapped", then the method returns XConstants.NotUseful.
2092      * Otherwise, if the system property "sun.awt.backingStore" is "WhenMapped",
2093      * then the method returns XConstants.WhenMapped.
2094      * Otherwise (i.e., if the system property "sun.awt.backingStore" is "Always"),
2095      * the method returns XConstants.Always.
2096      */
2097     static int getBackingStoreType() {
2098         return backingStoreType;
2099     }
2100 
2101     private static void setBackingStoreType() {


2370         }
2371     }
2372 
2373     private static long eventNumber;
2374     public static long getEventNumber() {
2375         awtLock();
2376         try {
2377             return eventNumber;
2378         } finally {
2379             awtUnlock();
2380         }
2381     }
2382 
2383     private static XEventDispatcher oops_waiter;
2384     private static boolean oops_updated;
2385     private static boolean oops_move;
2386 
2387     /**
2388      * @inheritDoc
2389      */

2390     protected boolean syncNativeQueue(final long timeout) {
2391         XBaseWindow win = XBaseWindow.getXAWTRootWindow();
2392 
2393         if (oops_waiter == null) {
2394             oops_waiter = new XEventDispatcher() {

2395                     public void dispatchEvent(XEvent e) {
2396                         if (e.get_type() == XConstants.ConfigureNotify) {
2397                             // OOPS ConfigureNotify event catched
2398                             oops_updated = true;
2399                             awtLockNotifyAll();
2400                         }
2401                     }
2402                 };
2403         }
2404 
2405         awtLock();
2406         try {
2407             addEventDispatcher(win.getWindow(), oops_waiter);
2408 
2409             oops_updated = false;
2410             long event_number = getEventNumber();
2411             // Generate OOPS ConfigureNotify event
2412             XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(), oops_move ? 0 : 1, 0);
2413             // Change win position each time to avoid system optimization
2414             oops_move = !oops_move;


2421                 try {
2422                     // Wait for OOPS ConfigureNotify event
2423                     awtLockWait(timeout);
2424                 } catch (InterruptedException e) {
2425                     throw new RuntimeException(e);
2426                 }
2427                 // This "while" is a protection from spurious
2428                 // wake-ups.  However, we shouldn't wait for too long
2429                 if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
2430                     throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
2431                 }
2432             }
2433             // Don't take into account OOPS ConfigureNotify event
2434             return getEventNumber() - event_number > 1;
2435         } finally {
2436             removeEventDispatcher(win.getWindow(), oops_waiter);
2437             eventLog.finer("Exiting syncNativeQueue");
2438             awtUnlock();
2439         }
2440     }

2441     public void grab(Window w) {
2442         final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
2443         if (peer != null) {
2444             ((XWindowPeer) peer).setGrab(true);
2445         }
2446     }
2447 

2448     public void ungrab(Window w) {
2449         final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
2450         if (peer != null) {
2451             ((XWindowPeer) peer).setGrab(false);
2452         }
2453     }
2454     /**
2455      * Returns if the java.awt.Desktop class is supported on the current
2456      * desktop.
2457      * <p>
2458      * The methods of java.awt.Desktop class are supported on the Gnome desktop.
2459      * Check if the running desktop is Gnome by checking the window manager.
2460      */

2461     public boolean isDesktopSupported(){
2462         return XDesktopPeer.isDesktopSupported();
2463     }
2464 

2465     public DesktopPeer createDesktopPeer(Desktop target){
2466         return new XDesktopPeer();
2467     }
2468 

2469     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
2470         return areExtraMouseButtonsEnabled;
2471     }
2472 
2473     @Override
2474     public boolean isWindowOpacitySupported() {
2475         XNETProtocol net_protocol = XWM.getWM().getNETProtocol();
2476 
2477         if (net_protocol == null) {
2478             return false;
2479         }
2480 
2481         return net_protocol.doOpacityProtocol();
2482     }
2483 
2484     @Override
2485     public boolean isWindowShapingSupported() {
2486         return XlibUtil.isShapingSupported();
2487     }
2488 


   1 /*
   2  * Copyright (c) 2002, 2015, 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


 158         return securityWarningEnabled;
 159     }
 160 
 161     static native void awt_output_flush();
 162 
 163     static void  awtFUnlock() {
 164         awtUnlock();
 165         awt_output_flush();
 166     }
 167 
 168 
 169     private native void nativeLoadSystemColors(int[] systemColors);
 170 
 171     static UIDefaults getUIDefaults() {
 172         if (uidefaults == null) {
 173             initUIDefaults();
 174         }
 175         return uidefaults;
 176     }
 177 
 178     @Override
 179     public void loadSystemColors(int[] systemColors) {
 180         nativeLoadSystemColors(systemColors);
 181         MotifColorUtilities.loadSystemColors(systemColors);
 182     }
 183 
 184 
 185 
 186     static void initUIDefaults() {
 187         try {
 188             // Load Defaults from MotifLookAndFeel
 189 
 190             // This dummy load is necessary to get SystemColor initialized. !!!!!!
 191             Color c = SystemColor.text;
 192 
 193             LookAndFeel lnf = new XAWTLookAndFeel();
 194             uidefaults = lnf.getDefaults();
 195         }
 196         catch (Exception e)
 197         {
 198             e.printStackTrace();


 251             XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
 252                 @Override
 253                 public void dispatchEvent(XEvent ev) {
 254                     if (ev.get_type() == XConstants.ConfigureNotify) {
 255                         awtUnlock();
 256                         try {
 257                             ((X11GraphicsEnvironment)GraphicsEnvironment.
 258                              getLocalGraphicsEnvironment()).
 259                                 displayChanged();
 260                         } finally {
 261                             awtLock();
 262                         }
 263                     }
 264                 }
 265             });
 266         } finally {
 267             awtUnlock();
 268         }
 269         PrivilegedAction<Void> a = () -> {
 270             Thread shutdownThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), "XToolkt-Shutdown-Thread") {
 271                     @Override
 272                     public void run() {
 273                         XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
 274                         if (peer != null) {
 275                             peer.dispose();
 276                         }
 277                         if (xs != null) {
 278                             ((XAWTXSettings)xs).dispose();
 279                         }
 280                         freeXKB();
 281                         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 282                             dumpPeers();
 283                         }
 284                     }
 285                 };
 286             shutdownThread.setContextClassLoader(null);
 287             Runtime.getRuntime().addShutdownHook(shutdownThread);
 288             return null;
 289         };
 290         AccessController.doPrivileged(a);
 291     }


 321             }
 322             if (mainClassName == null || mainClassName.equals("")) {
 323                 mainClassName = "AWT";
 324             }
 325             awtAppClassName = getCorrectXIDString(mainClassName);
 326 
 327             init();
 328             XWM.init();
 329 
 330             toolkitThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
 331                 Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, "AWT-XAWT");
 332                 thread.setContextClassLoader(null);
 333                 thread.setPriority(Thread.NORM_PRIORITY + 1);
 334                 thread.setDaemon(true);
 335                 return thread;
 336             });
 337             toolkitThread.start();
 338         }
 339     }
 340 
 341     @Override
 342     public ButtonPeer createButton(Button target) {
 343         ButtonPeer peer = new XButtonPeer(target);
 344         targetCreatedPeer(target, peer);
 345         return peer;
 346     }
 347 
 348     @Override
 349     public FramePeer createLightweightFrame(LightweightFrame target) {
 350         FramePeer peer = new XLightweightFramePeer(target);
 351         targetCreatedPeer(target, peer);
 352         return peer;
 353     }
 354 
 355     @Override
 356     public FramePeer createFrame(Frame target) {
 357         FramePeer peer = new XFramePeer(target);
 358         targetCreatedPeer(target, peer);
 359         return peer;
 360     }
 361 
 362     static void addToWinMap(long window, XBaseWindow xwin)
 363     {
 364         synchronized(winMap) {
 365             winMap.put(Long.valueOf(window),xwin);
 366         }
 367     }
 368 
 369     static void removeFromWinMap(long window, XBaseWindow xwin) {
 370         synchronized(winMap) {
 371             winMap.remove(Long.valueOf(window));
 372         }
 373     }
 374     static XBaseWindow windowToXWindow(long window) {
 375         synchronized(winMap) {


 517             }
 518         }
 519         if (dispatchers != null) {
 520             Iterator<XEventDispatcher> iter = dispatchers.iterator();
 521             while (iter.hasNext()) {
 522                 XEventDispatcher disp = iter.next();
 523                 disp.dispatchEvent(ev);
 524             }
 525         }
 526         notifyListeners(ev);
 527     }
 528 
 529     static void processException(Throwable thr) {
 530         if (log.isLoggable(PlatformLogger.Level.WARNING)) {
 531             log.warning("Exception on Toolkit thread", thr);
 532         }
 533     }
 534 
 535     static native void awt_toolkit_init();
 536 
 537     @Override
 538     public void run() {
 539         awt_toolkit_init();
 540         run(PRIMARY_LOOP);
 541     }
 542 
 543     public void run(boolean loop)
 544     {
 545         XEvent ev = new XEvent();
 546         while(true) {
 547             // Fix for 6829923: we should gracefully handle toolkit thread interruption
 548             if (Thread.currentThread().isInterrupted()) {
 549                 // We expect interruption from the AppContext.dispose() method only.
 550                 // If the thread is interrupted from another place, let's skip it
 551                 // for compatibility reasons. Probably some time later we'll remove
 552                 // the check for AppContext.isDisposed() and will unconditionally
 553                 // break the loop here.
 554                 if (AppContext.getAppContext().isDisposed()) {
 555                     break;
 556                 }
 557             }


 658                     screenHeight = pattr.get_height();
 659                 } finally {
 660                     pattr.dispose();
 661                 }
 662             } finally {
 663                 awtUnlock();
 664             }
 665         }
 666     }
 667 
 668     static int getDefaultScreenWidth() {
 669         initScreenSize();
 670         return screenWidth;
 671     }
 672 
 673     static int getDefaultScreenHeight() {
 674         initScreenSize();
 675         return screenHeight;
 676     }
 677 
 678     @Override
 679     protected int getScreenWidth() {
 680         return getDefaultScreenWidth();
 681     }
 682 
 683     @Override
 684     protected int getScreenHeight() {
 685         return getDefaultScreenHeight();
 686     }
 687 
 688     private static Rectangle getWorkArea(long root)
 689     {
 690         XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
 691 
 692         long native_ptr = Native.allocateLongArray(4);
 693         try
 694         {
 695             boolean workareaPresent = XA_NET_WORKAREA.getAtomData(root,
 696                 XAtom.XA_CARDINAL, native_ptr, 4);
 697             if (workareaPresent)
 698             {
 699                 int rootX = (int)Native.getLong(native_ptr, 0);
 700                 int rootY = (int)Native.getLong(native_ptr, 1);
 701                 int rootWidth = (int)Native.getLong(native_ptr, 2);
 702                 int rootHeight = (int)Native.getLong(native_ptr, 3);
 703 
 704                 return new Rectangle(rootX, rootY, rootWidth, rootHeight);
 705             }
 706         }
 707         finally
 708         {
 709             XlibWrapper.unsafe.freeMemory(native_ptr);
 710         }
 711 
 712         return null;
 713     }
 714 
 715     /*
 716      * If we're running in non-Xinerama environment and the current
 717      * window manager supports _NET protocol then the screen insets
 718      * are calculated using _NET_WM_WORKAREA property of the root
 719      * window.
 720      * Otherwise, i. e. if Xinerama is on or _NET_WM_WORKAREA is
 721      * not set, we try to calculate the insets ourselves using
 722      * getScreenInsetsManually method.
 723      */
 724     @Override
 725     public Insets getScreenInsets(GraphicsConfiguration gc)
 726     {
 727         XNETProtocol netProto = XWM.getWM().getNETProtocol();
 728         if ((netProto == null) || !netProto.active())
 729         {
 730             return super.getScreenInsets(gc);
 731         }
 732 
 733         XToolkit.awtLock();
 734         try
 735         {
 736             X11GraphicsConfig x11gc = (X11GraphicsConfig)gc;
 737             X11GraphicsDevice x11gd = (X11GraphicsDevice)x11gc.getDevice();
 738             long root = XlibUtil.getRootWindow(x11gd.getScreen());
 739             Rectangle rootBounds = XlibUtil.getWindowGeometry(root);
 740 
 741             X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
 742                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 743             if (!x11ge.runningXinerama())
 744             {


 892         peer.disableBackgroundErase();
 893     }
 894     */
 895 
 896     // Need this for XMenuItemPeer.
 897     protected static Object targetToPeer(Object target) {
 898         Object p=null;
 899         if (target != null && !GraphicsEnvironment.isHeadless()) {
 900             p = specialPeerMap.get(target);
 901         }
 902         if (p != null) return p;
 903         else
 904             return SunToolkit.targetToPeer(target);
 905     }
 906 
 907     // Need this for XMenuItemPeer.
 908     protected static void targetDisposedPeer(Object target, Object peer) {
 909         SunToolkit.targetDisposedPeer(target, peer);
 910     }
 911 
 912     @Override
 913     public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
 914         return new XRobotPeer(screen.getDefaultConfiguration());
 915     }
 916 
 917 
 918   /*
 919      * On X, support for dynamic layout on resizing is governed by the
 920      * window manager.  If the window manager supports it, it happens
 921      * automatically.  The setter method for this property is
 922      * irrelevant on X.
 923      */
 924     @Override
 925     public void setDynamicLayout(boolean b) {
 926         dynamicLayoutSetting = b;
 927     }
 928 
 929     @Override
 930     protected boolean isDynamicLayoutSet() {
 931         return dynamicLayoutSetting;
 932     }
 933 
 934     /* Called from isDynamicLayoutActive() and from
 935      * lazilyLoadDynamicLayoutSupportedProperty()
 936      */
 937     protected boolean isDynamicLayoutSupported() {
 938         return XWM.getWM().supportsDynamicLayout();
 939     }
 940 
 941     @Override
 942     public boolean isDynamicLayoutActive() {
 943         return isDynamicLayoutSupported();
 944     }
 945 
 946     @Override
 947     @SuppressWarnings("deprecation")
 948     public FontPeer getFontPeer(String name, int style){
 949         return new XFontPeer(name, style);
 950     }
 951 
 952     @Override
 953     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
 954         final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
 955         if (f != null) {
 956             return f.createDragSourceContextPeer(dge);
 957         }
 958 
 959         return XDragSourceContextPeer.createDragSourceContextPeer(dge);
 960     }
 961 
 962     @Override
 963     @SuppressWarnings("unchecked")
 964     public <T extends DragGestureRecognizer> T
 965     createDragGestureRecognizer(Class<T> recognizerClass,
 966                     DragSource ds,
 967                     Component c,
 968                     int srcActions,
 969                     DragGestureListener dgl)
 970     {
 971         final LightweightFrame f = SunToolkit.getLightweightFrame(c);
 972         if (f != null) {
 973             return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
 974         }
 975 
 976         if (MouseDragGestureRecognizer.class.equals(recognizerClass))
 977             return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
 978         else
 979             return null;
 980     }
 981 
 982     @Override
 983     public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
 984         XCheckboxMenuItemPeer peer = new XCheckboxMenuItemPeer(target);
 985         //vb157120: looks like we don't need to map menu items
 986         //in new menus implementation
 987         //targetCreatedPeer(target, peer);
 988         return peer;
 989     }
 990 
 991     @Override
 992     public MenuItemPeer createMenuItem(MenuItem target) {
 993         XMenuItemPeer peer = new XMenuItemPeer(target);
 994         //vb157120: looks like we don't need to map menu items
 995         //in new menus implementation
 996         //targetCreatedPeer(target, peer);
 997         return peer;
 998     }
 999 
1000     @Override
1001     public TextFieldPeer createTextField(TextField target) {
1002         TextFieldPeer  peer = new XTextFieldPeer(target);
1003         targetCreatedPeer(target, peer);
1004         return peer;
1005     }
1006 
1007     @Override
1008     public LabelPeer createLabel(Label target) {
1009         LabelPeer  peer = new XLabelPeer(target);
1010         targetCreatedPeer(target, peer);
1011         return peer;
1012     }
1013 
1014     @Override
1015     public ListPeer createList(java.awt.List target) {
1016         ListPeer peer = new XListPeer(target);
1017         targetCreatedPeer(target, peer);
1018         return peer;
1019     }
1020 
1021     @Override
1022     public CheckboxPeer createCheckbox(Checkbox target) {
1023         CheckboxPeer peer = new XCheckboxPeer(target);
1024         targetCreatedPeer(target, peer);
1025         return peer;
1026     }
1027 
1028     @Override
1029     public ScrollbarPeer createScrollbar(Scrollbar target) {
1030         XScrollbarPeer peer = new XScrollbarPeer(target);
1031         targetCreatedPeer(target, peer);
1032         return peer;
1033     }
1034 
1035     @Override
1036     public ScrollPanePeer createScrollPane(ScrollPane target) {
1037         XScrollPanePeer peer = new XScrollPanePeer(target);
1038         targetCreatedPeer(target, peer);
1039         return peer;
1040     }
1041 
1042     @Override
1043     public TextAreaPeer createTextArea(TextArea target) {
1044         TextAreaPeer peer = new XTextAreaPeer(target);
1045         targetCreatedPeer(target, peer);
1046         return peer;
1047     }
1048 
1049     @Override
1050     public ChoicePeer createChoice(Choice target) {
1051         XChoicePeer peer = new XChoicePeer(target);
1052         targetCreatedPeer(target, peer);
1053         return peer;
1054     }
1055 
1056     @Override
1057     public CanvasPeer createCanvas(Canvas target) {
1058         XCanvasPeer peer = (isXEmbedServerRequested() ? new XEmbedCanvasPeer(target) : new XCanvasPeer(target));
1059         targetCreatedPeer(target, peer);
1060         return peer;
1061     }
1062 
1063     @Override
1064     public PanelPeer createPanel(Panel target) {
1065         PanelPeer peer = new XPanelPeer(target);
1066         targetCreatedPeer(target, peer);
1067         return peer;
1068     }
1069 
1070     @Override
1071     public WindowPeer createWindow(Window target) {
1072         WindowPeer peer = new XWindowPeer(target);
1073         targetCreatedPeer(target, peer);
1074         return peer;
1075     }
1076 
1077     @Override
1078     public DialogPeer createDialog(Dialog target) {
1079         DialogPeer peer = new XDialogPeer(target);
1080         targetCreatedPeer(target, peer);
1081         return peer;
1082     }
1083 
1084     private static Boolean sunAwtDisableGtkFileDialogs = null;
1085 
1086     /**
1087      * Returns the value of "sun.awt.disableGtkFileDialogs" property. Default
1088      * value is {@code false}.
1089      */
1090     public synchronized static boolean getSunAwtDisableGtkFileDialogs() {
1091         if (sunAwtDisableGtkFileDialogs == null) {
1092             sunAwtDisableGtkFileDialogs = AccessController.doPrivileged(
1093                                               new GetBooleanAction("sun.awt.disableGtkFileDialogs"));
1094         }
1095         return sunAwtDisableGtkFileDialogs.booleanValue();
1096     }
1097 
1098     @Override
1099     public FileDialogPeer createFileDialog(FileDialog target) {
1100         FileDialogPeer peer = null;
1101         // The current GtkFileChooser is available from GTK+ 2.4
1102         if (!getSunAwtDisableGtkFileDialogs() && checkGtkVersion(2, 4, 0)) {
1103             peer = new GtkFileDialogPeer(target);
1104         } else {
1105             peer = new XFileDialogPeer(target);
1106         }
1107         targetCreatedPeer(target, peer);
1108         return peer;
1109     }
1110 
1111     @Override
1112     public MenuBarPeer createMenuBar(MenuBar target) {
1113         XMenuBarPeer peer = new XMenuBarPeer(target);
1114         targetCreatedPeer(target, peer);
1115         return peer;
1116     }
1117 
1118     @Override
1119     public MenuPeer createMenu(Menu target) {
1120         XMenuPeer peer = new XMenuPeer(target);
1121         //vb157120: looks like we don't need to map menu items
1122         //in new menus implementation
1123         //targetCreatedPeer(target, peer);
1124         return peer;
1125     }
1126 
1127     @Override
1128     public PopupMenuPeer createPopupMenu(PopupMenu target) {
1129         XPopupMenuPeer peer = new XPopupMenuPeer(target);
1130         targetCreatedPeer(target, peer);
1131         return peer;
1132     }
1133 
1134     @Override
1135     public synchronized MouseInfoPeer getMouseInfoPeer() {
1136         if (xPeer == null) {
1137             xPeer = new XMouseInfoPeer();
1138         }
1139         return xPeer;
1140     }
1141 
1142     public XEmbeddedFramePeer createEmbeddedFrame(XEmbeddedFrame target)
1143     {
1144         XEmbeddedFramePeer peer = new XEmbeddedFramePeer(target);
1145         targetCreatedPeer(target, peer);
1146         return peer;
1147     }
1148 
1149     XEmbedChildProxyPeer createEmbedProxy(XEmbedChildProxy target) {
1150         XEmbedChildProxyPeer peer = new XEmbedChildProxyPeer(target);
1151         targetCreatedPeer(target, peer);
1152         return peer;
1153     }
1154 
1155     @Override
1156     public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() throws HeadlessException {
1157         return XKeyboardFocusManagerPeer.getInstance();
1158     }
1159 
1160     /**
1161      * Returns a new custom cursor.
1162      */
1163     @Override
1164     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
1165       throws IndexOutOfBoundsException {
1166         return new XCustomCursor(cursor, hotSpot, name);
1167     }
1168 
1169     @Override
1170     public TrayIconPeer createTrayIcon(TrayIcon target)
1171       throws HeadlessException, AWTException
1172     {
1173         TrayIconPeer peer = new XTrayIconPeer(target);
1174         targetCreatedPeer(target, peer);
1175         return peer;
1176     }
1177 
1178     @Override
1179     public SystemTrayPeer createSystemTray(SystemTray target) throws HeadlessException {
1180         SystemTrayPeer peer = new XSystemTrayPeer(target);
1181         return peer;
1182     }
1183 
1184     @Override
1185     public boolean isTraySupported() {
1186         XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
1187         if (peer != null) {
1188             return peer.isAvailable();
1189         }
1190         return false;
1191     }
1192 
1193     @Override
1194     public DataTransferer getDataTransferer() {
1195         return XDataTransferer.getInstanceImpl();
1196     }
1197 
1198     /**
1199      * Returns the supported cursor size
1200      */
1201     @Override
1202     public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
1203         return XCustomCursor.getBestCursorSize(
1204                                                java.lang.Math.max(1,preferredWidth), java.lang.Math.max(1,preferredHeight));
1205     }
1206 
1207 
1208     @Override
1209     public int getMaximumCursorColors() {
1210         return 2;  // Black and white.
1211     }
1212 
1213     @Override
1214     public Map<TextAttribute, ?> mapInputMethodHighlight( InputMethodHighlight highlight) {
1215         return XInputMethod.mapInputMethodHighlight(highlight);
1216     }
1217     @Override
1218     public boolean getLockingKeyState(int key) {
1219         if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
1220                key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
1221             throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
1222         }
1223         awtLock();
1224         try {
1225             return getModifierState( key );
1226         } finally {
1227             awtUnlock();
1228         }
1229     }
1230 
1231     @Override
1232     public  Clipboard getSystemClipboard() {
1233         SecurityManager security = System.getSecurityManager();
1234         if (security != null) {
1235             security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1236         }
1237         synchronized (this) {
1238             if (clipboard == null) {
1239                 clipboard = new XClipboard("System", "CLIPBOARD");
1240             }
1241         }
1242         return clipboard;
1243     }
1244 
1245     @Override
1246     public Clipboard getSystemSelection() {
1247         SecurityManager security = System.getSecurityManager();
1248         if (security != null) {
1249             security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1250         }
1251         synchronized (this) {
1252             if (selection == null) {
1253                 selection = new XClipboard("Selection", "PRIMARY");
1254             }
1255         }
1256         return selection;
1257     }
1258 
1259     @Override
1260     public void beep() {
1261         awtLock();
1262         try {
1263             XlibWrapper.XBell(getDisplay(), 0);
1264             XlibWrapper.XFlush(getDisplay());
1265         } finally {
1266             awtUnlock();
1267         }
1268     }
1269 
1270     @Override
1271     public PrintJob getPrintJob(final Frame frame, final String doctitle,
1272                                 final Properties props) {
1273 
1274         if (frame == null) {
1275             throw new NullPointerException("frame must not be null");
1276         }
1277 
1278         PrintJob2D printJob = new PrintJob2D(frame, doctitle, props);
1279 
1280         if (printJob.printDialog() == false) {
1281             printJob = null;
1282         }
1283         return printJob;
1284     }
1285 
1286     @Override
1287     public PrintJob getPrintJob(final Frame frame, final String doctitle,
1288                 final JobAttributes jobAttributes,
1289                 final PageAttributes pageAttributes)
1290     {
1291         if (frame == null) {
1292             throw new NullPointerException("frame must not be null");
1293         }
1294 
1295         PrintJob2D printJob = new PrintJob2D(frame, doctitle,
1296                                              jobAttributes, pageAttributes);
1297 
1298         if (printJob.printDialog() == false) {
1299             printJob = null;
1300         }
1301 
1302         return printJob;
1303     }
1304 
1305     static void XSync() {
1306         awtLock();
1307         try {
1308             XlibWrapper.XSync(getDisplay(),0);
1309         } finally {
1310             awtUnlock();
1311         }
1312     }
1313 
1314     @Override
1315     public int getScreenResolution() {
1316         long display = getDisplay();
1317         awtLock();
1318         try {
1319             return (int) ((XlibWrapper.DisplayWidth(display,
1320                 XlibWrapper.DefaultScreen(display)) * 25.4) /
1321                     XlibWrapper.DisplayWidthMM(display,
1322                 XlibWrapper.DefaultScreen(display)));
1323         } finally {
1324             awtUnlock();
1325         }
1326     }
1327 
1328     static native long getDefaultXColormap();
1329     static native long getDefaultScreenData();
1330 
1331     static ColorModel screenmodel;
1332 
1333     static ColorModel getStaticColorModel() {
1334         if (screenmodel == null) {
1335             screenmodel = config.getColorModel ();
1336         }
1337         return screenmodel;
1338     }
1339 
1340     @Override
1341     public ColorModel getColorModel() {
1342         return getStaticColorModel();
1343     }
1344 
1345     /**
1346      * Returns a new input method adapter descriptor for native input methods.
1347      */
1348     @Override
1349     public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
1350         return new XInputMethodDescriptor();
1351     }
1352 
1353     /**
1354      * Returns whether enableInputMethods should be set to true for peered
1355      * TextComponent instances on this platform. True by default.
1356      */
1357     @Override
1358     public boolean enableInputMethodsForTextComponent() {
1359         return true;
1360     }
1361 
1362     static int getMultiClickTime() {
1363         if (awt_multiclick_time == 0) {
1364             initializeMultiClickTime();
1365         }
1366         return awt_multiclick_time;
1367     }
1368     static void initializeMultiClickTime() {


1380                            a second, so we need to multiply by 100 to convert to
1381                            milliseconds */
1382                         awt_multiclick_time = (int)Long.parseLong(multiclick_time_query) * 100;
1383                     } else {
1384                         awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1385                     }
1386                 }
1387             } catch (NumberFormatException nf) {
1388                 awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1389             } catch (NullPointerException npe) {
1390                 awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1391             }
1392         } finally {
1393             awtUnlock();
1394         }
1395         if (awt_multiclick_time == 0) {
1396             awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
1397         }
1398     }
1399 
1400     @Override
1401     public boolean isFrameStateSupported(int state)
1402       throws HeadlessException
1403     {
1404         if (state == Frame.NORMAL || state == Frame.ICONIFIED) {
1405             return true;
1406         } else {
1407             return XWM.getWM().supportsExtendedState(state);
1408         }
1409     }
1410 
1411     static void dumpPeers() {
1412         if (log.isLoggable(PlatformLogger.Level.FINE)) {
1413             log.fine("Mapped windows:");
1414             winMap.forEach((k, v) -> {
1415                 log.fine(k + "->" + v);
1416                 if (v instanceof XComponentPeer) {
1417                     Component target = (Component)((XComponentPeer)v).getTarget();
1418                     log.fine("\ttarget: " + target);
1419                 }
1420             });


1423 
1424             log.fine("Mapped special peers:");
1425             specialPeerMap.forEach((k, v) -> {
1426                 log.fine(k + "->" + v);
1427             });
1428 
1429             log.fine("Mapped dispatchers:");
1430             winToDispatcher.forEach((k, v) -> {
1431                 log.fine(k + "->" + v);
1432             });
1433         }
1434     }
1435 
1436     /* Protected with awt_lock. */
1437     private static boolean initialized;
1438     private static boolean timeStampUpdated;
1439     private static long timeStamp;
1440 
1441     private static final XEventDispatcher timeFetcher =
1442     new XEventDispatcher() {
1443             @Override
1444             public void dispatchEvent(XEvent ev) {
1445                 switch (ev.get_type()) {
1446                   case XConstants.PropertyNotify:
1447                       XPropertyEvent xpe = ev.get_xproperty();
1448 
1449                       awtLock();
1450                       try {
1451                           timeStamp = xpe.get_time();
1452                           timeStampUpdated = true;
1453                           awtLockNotifyAll();
1454                       } finally {
1455                           awtUnlock();
1456                       }
1457 
1458                       break;
1459                 }
1460             }
1461         };
1462 
1463     private static XAtom _XA_JAVA_TIME_PROPERTY_ATOM;


1492                     finally {
1493                         event.dispose();
1494                     }
1495                 }
1496                 else {
1497                     while (!timeStampUpdated) {
1498                         awtLockWait();
1499                     }
1500                 }
1501             } catch (InterruptedException ie) {
1502             // Note: the returned timeStamp can be incorrect in this case.
1503                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
1504                     log.fine("Catched exception, timeStamp may not be correct (ie = " + ie + ")");
1505                 }
1506             }
1507         } finally {
1508             awtUnlock();
1509         }
1510         return timeStamp;
1511     }
1512     @Override
1513     protected void initializeDesktopProperties() {
1514         desktopProperties.put("DnD.Autoscroll.initialDelay",
1515                               Integer.valueOf(50));
1516         desktopProperties.put("DnD.Autoscroll.interval",
1517                               Integer.valueOf(50));
1518         desktopProperties.put("DnD.Autoscroll.cursorHysteresis",
1519                               Integer.valueOf(5));
1520         desktopProperties.put("Shell.shellFolderManager",
1521                               "sun.awt.shell.ShellFolderManager");
1522         // Don't want to call getMultiClickTime() if we are headless
1523         if (!GraphicsEnvironment.isHeadless()) {
1524             desktopProperties.put("awt.multiClickInterval",
1525                                   Integer.valueOf(getMultiClickTime()));
1526             desktopProperties.put("awt.mouse.numButtons",
1527                                   Integer.valueOf(getNumberOfButtons()));
1528         }
1529     }
1530 
1531     /**
1532      * This method runs through the XPointer and XExtendedPointer array.


1551                     numberOfButtons -= 2;
1552                 } else if (numberOfButtons == 4 || numberOfButtons ==5){
1553                     numberOfButtons = 3;
1554                 }
1555             }
1556             //Assume don't have to re-query the number again and again.
1557             return numberOfButtons;
1558         } finally {
1559             awtUnlock();
1560         }
1561     }
1562 
1563     static int getNumberOfButtonsForMask() {
1564         return Math.min(XConstants.MAX_BUTTONS, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons());
1565     }
1566 
1567     private final static String prefix  = "DnD.Cursor.";
1568     private final static String postfix = ".32x32";
1569     private static final String dndPrefix  = "DnD.";
1570 
1571     @Override
1572     protected Object lazilyLoadDesktopProperty(String name) {
1573         if (name.startsWith(prefix)) {
1574             String cursorName = name.substring(prefix.length(), name.length()) + postfix;
1575 
1576             try {
1577                 return Cursor.getSystemCustomCursor(cursorName);
1578             } catch (AWTException awte) {
1579                 throw new RuntimeException("cannot load system cursor: " + cursorName, awte);
1580             }
1581         }
1582 
1583         if (name.equals("awt.dynamicLayoutSupported")) {
1584             return  Boolean.valueOf(isDynamicLayoutSupported());
1585         }
1586 
1587         if (initXSettingsIfNeeded(name)) {
1588             return desktopProperties.get(name);
1589         }
1590 
1591         return super.lazilyLoadDesktopProperty(name);
1592     }
1593 
1594     @Override
1595     public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
1596         if (name == null) {
1597             // See JavaDoc for the Toolkit.addPropertyChangeListener() method
1598             return;
1599         }
1600         initXSettingsIfNeeded(name);
1601         super.addPropertyChangeListener(name, pcl);
1602     }
1603 
1604     /**
1605      * Initializes XAWTXSettings if a property for a given property name is provided by
1606      * XSettings and they are not initialized yet.
1607      *
1608      * @return true if the method has initialized XAWTXSettings.
1609      */
1610     private boolean initXSettingsIfNeeded(final String propName) {
1611         if (!loadedXSettings &&
1612             (propName.startsWith("gnome.") ||
1613              propName.equals(SunToolkit.DESKTOPFONTHINTS) ||
1614              propName.startsWith(dndPrefix)))


2073 
2074         long current_time_utc = System.currentTimeMillis();
2075         if (log.isLoggable(PlatformLogger.Level.FINER)) {
2076             log.finer("reset_time=" + reset_time_utc + ", current_time=" + current_time_utc
2077                       + ", server_offset=" + server_offset + ", wrap_time=" + WRAP_TIME_MILLIS);
2078         }
2079 
2080         if ((current_time_utc - reset_time_utc) > WRAP_TIME_MILLIS) {
2081             reset_time_utc = System.currentTimeMillis() - getCurrentServerTime();
2082         }
2083 
2084         if (log.isLoggable(PlatformLogger.Level.FINER)) {
2085             log.finer("result = " + (reset_time_utc + server_offset));
2086         }
2087         return reset_time_utc + server_offset;
2088     }
2089 
2090     /**
2091      * @see sun.awt.SunToolkit#needsXEmbedImpl
2092      */
2093     @Override
2094     protected boolean needsXEmbedImpl() {
2095         // XToolkit implements supports for XEmbed-client protocol and
2096         // requires the supports from the embedding host for it to work.
2097         return true;
2098     }
2099 
2100     @Override
2101     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
2102         return (modalityType == null) ||
2103                (modalityType == Dialog.ModalityType.MODELESS) ||
2104                (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
2105                (modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
2106                (modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
2107     }
2108 
2109     @Override
2110     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
2111         return (exclusionType == null) ||
2112                (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
2113                (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
2114                (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
2115     }
2116 
2117     static EventQueue getEventQueue(Object target) {
2118         AppContext appContext = targetToAppContext(target);
2119         if (appContext != null) {
2120             return (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
2121         }
2122         return null;
2123     }
2124 
2125     static void removeSourceEvents(EventQueue queue,
2126                                    Object source,
2127                                    boolean removeAllEvents) {
2128         AWTAccessor.getEventQueueAccessor()
2129             .removeSourceEvents(queue, source, removeAllEvents);
2130     }
2131 
2132     @Override
2133     public boolean isAlwaysOnTopSupported() {
2134         for (XLayerProtocol proto : XWM.getWM().getProtocols(XLayerProtocol.class)) {
2135             if (proto.supportsLayer(XLayerProtocol.LAYER_ALWAYS_ON_TOP)) {
2136                 return true;
2137             }
2138         }
2139         return false;
2140     }
2141 
2142     @Override
2143     public boolean useBufferPerWindow() {
2144         return XToolkit.getBackingStoreType() == XConstants.NotUseful;
2145     }
2146 
2147     /**
2148      * Returns one of XConstants: NotUseful, WhenMapped or Always.
2149      * If backing store is not available on at least one screen, or
2150      * java2d uses DGA(which conflicts with backing store) on at least one screen,
2151      * or the string system property "sun.awt.backingStore" is neither "Always"
2152      * nor "WhenMapped", then the method returns XConstants.NotUseful.
2153      * Otherwise, if the system property "sun.awt.backingStore" is "WhenMapped",
2154      * then the method returns XConstants.WhenMapped.
2155      * Otherwise (i.e., if the system property "sun.awt.backingStore" is "Always"),
2156      * the method returns XConstants.Always.
2157      */
2158     static int getBackingStoreType() {
2159         return backingStoreType;
2160     }
2161 
2162     private static void setBackingStoreType() {


2431         }
2432     }
2433 
2434     private static long eventNumber;
2435     public static long getEventNumber() {
2436         awtLock();
2437         try {
2438             return eventNumber;
2439         } finally {
2440             awtUnlock();
2441         }
2442     }
2443 
2444     private static XEventDispatcher oops_waiter;
2445     private static boolean oops_updated;
2446     private static boolean oops_move;
2447 
2448     /**
2449      * @inheritDoc
2450      */
2451     @Override
2452     protected boolean syncNativeQueue(final long timeout) {
2453         XBaseWindow win = XBaseWindow.getXAWTRootWindow();
2454 
2455         if (oops_waiter == null) {
2456             oops_waiter = new XEventDispatcher() {
2457                     @Override
2458                     public void dispatchEvent(XEvent e) {
2459                         if (e.get_type() == XConstants.ConfigureNotify) {
2460                             // OOPS ConfigureNotify event catched
2461                             oops_updated = true;
2462                             awtLockNotifyAll();
2463                         }
2464                     }
2465                 };
2466         }
2467 
2468         awtLock();
2469         try {
2470             addEventDispatcher(win.getWindow(), oops_waiter);
2471 
2472             oops_updated = false;
2473             long event_number = getEventNumber();
2474             // Generate OOPS ConfigureNotify event
2475             XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(), oops_move ? 0 : 1, 0);
2476             // Change win position each time to avoid system optimization
2477             oops_move = !oops_move;


2484                 try {
2485                     // Wait for OOPS ConfigureNotify event
2486                     awtLockWait(timeout);
2487                 } catch (InterruptedException e) {
2488                     throw new RuntimeException(e);
2489                 }
2490                 // This "while" is a protection from spurious
2491                 // wake-ups.  However, we shouldn't wait for too long
2492                 if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
2493                     throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
2494                 }
2495             }
2496             // Don't take into account OOPS ConfigureNotify event
2497             return getEventNumber() - event_number > 1;
2498         } finally {
2499             removeEventDispatcher(win.getWindow(), oops_waiter);
2500             eventLog.finer("Exiting syncNativeQueue");
2501             awtUnlock();
2502         }
2503     }
2504     @Override
2505     public void grab(Window w) {
2506         final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
2507         if (peer != null) {
2508             ((XWindowPeer) peer).setGrab(true);
2509         }
2510     }
2511 
2512     @Override
2513     public void ungrab(Window w) {
2514         final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
2515         if (peer != null) {
2516             ((XWindowPeer) peer).setGrab(false);
2517         }
2518     }
2519     /**
2520      * Returns if the java.awt.Desktop class is supported on the current
2521      * desktop.
2522      * <p>
2523      * The methods of java.awt.Desktop class are supported on the Gnome desktop.
2524      * Check if the running desktop is Gnome by checking the window manager.
2525      */
2526     @Override
2527     public boolean isDesktopSupported(){
2528         return XDesktopPeer.isDesktopSupported();
2529     }
2530 
2531     @Override
2532     public DesktopPeer createDesktopPeer(Desktop target){
2533         return new XDesktopPeer();
2534     }
2535 
2536     @Override
2537     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
2538         return areExtraMouseButtonsEnabled;
2539     }
2540 
2541     @Override
2542     public boolean isWindowOpacitySupported() {
2543         XNETProtocol net_protocol = XWM.getWM().getNETProtocol();
2544 
2545         if (net_protocol == null) {
2546             return false;
2547         }
2548 
2549         return net_protocol.doOpacityProtocol();
2550     }
2551 
2552     @Override
2553     public boolean isWindowShapingSupported() {
2554         return XlibUtil.isShapingSupported();
2555     }
2556