< prev index next >

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

Print this page




  91     /**
  92      * True when the x settings have been loaded.
  93      */
  94     private boolean loadedXSettings;
  95 
  96     /**
  97     * XSETTINGS for the default screen.
  98      * <p>
  99      */
 100     private XSettings xs;
 101 
 102     private FontConfigManager fcManager = new FontConfigManager();
 103 
 104     static int arrowCursor;
 105     static TreeMap<Long, XBaseWindow> winMap = new TreeMap<>();
 106     static HashMap<Object, Object> specialPeerMap = new HashMap<>();
 107     static HashMap<Long, Collection<XEventDispatcher>> winToDispatcher = new HashMap<>();
 108     static UIDefaults uidefaults;
 109     static final X11GraphicsEnvironment localEnv;
 110     private static final X11GraphicsDevice device;
 111     private static final X11GraphicsConfig config;
 112     private static final long display;
 113     static int awt_multiclick_time;
 114     static boolean securityWarningEnabled;
 115 
 116     private static volatile int screenWidth = -1, screenHeight = -1; // Dimensions of default screen





 117     static long awt_defaultFg; // Pixel
 118     private static XMouseInfoPeer xPeer;
 119 
 120     static {
 121         initSecurityWarning();
 122         if (GraphicsEnvironment.isHeadless()) {
 123             localEnv = null;
 124             device = null;
 125             config = null;
 126             display = 0;
 127         } else {
 128             localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
 129                 .getLocalGraphicsEnvironment();
 130             device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();
 131             config = (X11GraphicsConfig) device.getDefaultConfiguration();
 132             display = device.getDisplay();
 133             setupModifierMap();
 134             initIDs();
 135             setBackingStoreType();
 136         }
 137     }
 138 
 139     /*
 140      * Return (potentially) platform specific display timeout for the
 141      * tray icon
 142      */
 143     static native long getTrayIconDisplayTimeout();
 144 
 145     private static native void initIDs();
 146     static native void waitForEvents(long nextTaskTime);
 147     static Thread toolkitThread;
 148     static boolean isToolkitThread() {
 149         return Thread.currentThread() == toolkitThread;
 150     }
 151 


 661                 }
 662             };
 663 
 664     static {
 665         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 666         if (ge instanceof SunGraphicsEnvironment) {
 667             ((SunGraphicsEnvironment) ge).addDisplayChangedListener(
 668                     displayChangedHandler);
 669         }
 670     }
 671 
 672     private static void initScreenSize() {
 673         if (screenWidth == -1 || screenHeight == -1) {
 674             awtLock();
 675             try {
 676                 XWindowAttributes pattr = new XWindowAttributes();
 677                 try {
 678                     XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
 679                                                      XToolkit.getDefaultRootWindow(),
 680                                                      pattr.pData);
 681                     screenWidth  = config.scaleDown(pattr.get_width());
 682                     screenHeight = config.scaleDown(pattr.get_height());
 683                 } finally {
 684                     pattr.dispose();
 685                 }
 686             } finally {
 687                 awtUnlock();
 688             }
 689         }
 690     }
 691 
 692     static int getDefaultScreenWidth() {
 693         initScreenSize();
 694         return screenWidth;
 695     }
 696 
 697     static int getDefaultScreenHeight() {
 698         initScreenSize();
 699         return screenHeight;
 700     }
 701 
 702     @Override
 703     protected int getScreenWidth() {
 704         return getDefaultScreenWidth();
 705     }
 706 
 707     @Override
 708     protected int getScreenHeight() {
 709         return getDefaultScreenHeight();
 710     }
 711 
 712     private static Rectangle getWorkArea(long root, int scale)
 713     {
 714         XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
 715 
 716         long native_ptr = Native.allocateLongArray(4);
 717         try
 718         {
 719             boolean workareaPresent = XA_NET_WORKAREA.getAtomData(root,
 720                 XAtom.XA_CARDINAL, native_ptr, 4);
 721             if (workareaPresent)
 722             {
 723                 int rootX = (int)Native.getLong(native_ptr, 0);
 724                 int rootY = (int)Native.getLong(native_ptr, 1);
 725                 int rootWidth = (int)Native.getLong(native_ptr, 2);
 726                 int rootHeight = (int)Native.getLong(native_ptr, 3);
 727 
 728                 return new Rectangle(scaleDown(rootX, scale),
 729                                      scaleDown(rootY, scale),
 730                                      scaleDown(rootWidth, scale),
 731                                      scaleDown(rootHeight, scale));


1356         }
1357     }
1358 
1359     @Override
1360     public int getScreenResolution() {
1361         long display = getDisplay();
1362         awtLock();
1363         try {
1364             return (int) ((XlibWrapper.DisplayWidth(display,
1365                 XlibWrapper.DefaultScreen(display)) * 25.4) /
1366                     XlibWrapper.DisplayWidthMM(display,
1367                 XlibWrapper.DefaultScreen(display)));
1368         } finally {
1369             awtUnlock();
1370         }
1371     }
1372 
1373     static native long getDefaultXColormap();
1374     static native long getDefaultScreenData();
1375 
1376     static ColorModel screenmodel;
1377 
1378     static ColorModel getStaticColorModel() {
1379         if (screenmodel == null) {
1380             screenmodel = config.getColorModel ();
1381         }
1382         return screenmodel;
1383     }
1384 
1385     @Override
1386     public ColorModel getColorModel() {
1387         return getStaticColorModel();
1388     }
1389 
1390     /**
1391      * Returns a new input method adapter descriptor for native input methods.
1392      */
1393     @Override
1394     public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
1395         return new XInputMethodDescriptor();
1396     }
1397 
1398     /**
1399      * Returns whether enableInputMethods should be set to true for peered
1400      * TextComponent instances on this platform. True by default.
1401      */
1402     @Override
1403     public boolean enableInputMethodsForTextComponent() {
1404         return true;
1405     }
1406 
1407     static int getMultiClickTime() {
1408         if (awt_multiclick_time == 0) {
1409             initializeMultiClickTime();




  91     /**
  92      * True when the x settings have been loaded.
  93      */
  94     private boolean loadedXSettings;
  95 
  96     /**
  97     * XSETTINGS for the default screen.
  98      * <p>
  99      */
 100     private XSettings xs;
 101 
 102     private FontConfigManager fcManager = new FontConfigManager();
 103 
 104     static int arrowCursor;
 105     static TreeMap<Long, XBaseWindow> winMap = new TreeMap<>();
 106     static HashMap<Object, Object> specialPeerMap = new HashMap<>();
 107     static HashMap<Long, Collection<XEventDispatcher>> winToDispatcher = new HashMap<>();
 108     static UIDefaults uidefaults;
 109     static final X11GraphicsEnvironment localEnv;
 110     private static final X11GraphicsDevice device;

 111     private static final long display;
 112     static int awt_multiclick_time;
 113     static boolean securityWarningEnabled;
 114 
 115     /**
 116      * Dimensions of default virtual screen in pixels. These values are used to
 117      * limit the maximum size of the window.
 118      */
 119     private static volatile int screenWidth = -1, screenHeight = -1;
 120 
 121     static long awt_defaultFg; // Pixel
 122     private static XMouseInfoPeer xPeer;
 123 
 124     static {
 125         initSecurityWarning();
 126         if (GraphicsEnvironment.isHeadless()) {
 127             localEnv = null;
 128             device = null;

 129             display = 0;
 130         } else {
 131             localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
 132                 .getLocalGraphicsEnvironment();
 133             device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();

 134             display = device.getDisplay();
 135             setupModifierMap();
 136             initIDs();
 137             setBackingStoreType();
 138         }
 139     }
 140 
 141     /*
 142      * Return (potentially) platform specific display timeout for the
 143      * tray icon
 144      */
 145     static native long getTrayIconDisplayTimeout();
 146 
 147     private static native void initIDs();
 148     static native void waitForEvents(long nextTaskTime);
 149     static Thread toolkitThread;
 150     static boolean isToolkitThread() {
 151         return Thread.currentThread() == toolkitThread;
 152     }
 153 


 663                 }
 664             };
 665 
 666     static {
 667         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 668         if (ge instanceof SunGraphicsEnvironment) {
 669             ((SunGraphicsEnvironment) ge).addDisplayChangedListener(
 670                     displayChangedHandler);
 671         }
 672     }
 673 
 674     private static void initScreenSize() {
 675         if (screenWidth == -1 || screenHeight == -1) {
 676             awtLock();
 677             try {
 678                 XWindowAttributes pattr = new XWindowAttributes();
 679                 try {
 680                     XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
 681                                                      XToolkit.getDefaultRootWindow(),
 682                                                      pattr.pData);
 683                     screenWidth  = pattr.get_width();
 684                     screenHeight = pattr.get_height();
 685                 } finally {
 686                     pattr.dispose();
 687                 }
 688             } finally {
 689                 awtUnlock();
 690             }
 691         }
 692     }
 693 
 694     static int getDefaultScreenWidth() {
 695         initScreenSize();
 696         return screenWidth;
 697     }
 698 
 699     static int getDefaultScreenHeight() {
 700         initScreenSize();
 701         return screenHeight;
 702     }
 703 










 704     private static Rectangle getWorkArea(long root, int scale)
 705     {
 706         XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
 707 
 708         long native_ptr = Native.allocateLongArray(4);
 709         try
 710         {
 711             boolean workareaPresent = XA_NET_WORKAREA.getAtomData(root,
 712                 XAtom.XA_CARDINAL, native_ptr, 4);
 713             if (workareaPresent)
 714             {
 715                 int rootX = (int)Native.getLong(native_ptr, 0);
 716                 int rootY = (int)Native.getLong(native_ptr, 1);
 717                 int rootWidth = (int)Native.getLong(native_ptr, 2);
 718                 int rootHeight = (int)Native.getLong(native_ptr, 3);
 719 
 720                 return new Rectangle(scaleDown(rootX, scale),
 721                                      scaleDown(rootY, scale),
 722                                      scaleDown(rootWidth, scale),
 723                                      scaleDown(rootHeight, scale));


1348         }
1349     }
1350 
1351     @Override
1352     public int getScreenResolution() {
1353         long display = getDisplay();
1354         awtLock();
1355         try {
1356             return (int) ((XlibWrapper.DisplayWidth(display,
1357                 XlibWrapper.DefaultScreen(display)) * 25.4) /
1358                     XlibWrapper.DisplayWidthMM(display,
1359                 XlibWrapper.DefaultScreen(display)));
1360         } finally {
1361             awtUnlock();
1362         }
1363     }
1364 
1365     static native long getDefaultXColormap();
1366     static native long getDefaultScreenData();
1367 














1368     /**
1369      * Returns a new input method adapter descriptor for native input methods.
1370      */
1371     @Override
1372     public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
1373         return new XInputMethodDescriptor();
1374     }
1375 
1376     /**
1377      * Returns whether enableInputMethods should be set to true for peered
1378      * TextComponent instances on this platform. True by default.
1379      */
1380     @Override
1381     public boolean enableInputMethodsForTextComponent() {
1382         return true;
1383     }
1384 
1385     static int getMultiClickTime() {
1386         if (awt_multiclick_time == 0) {
1387             initializeMultiClickTime();


< prev index next >