< prev index next >

src/solaris/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


  97     private XSettings xs;
  98 
  99     private FontConfigManager fcManager = new FontConfigManager();
 100 
 101     static int arrowCursor;
 102     static TreeMap winMap = new TreeMap();
 103     static HashMap specialPeerMap = new HashMap();
 104     static HashMap winToDispatcher = new HashMap();
 105     static UIDefaults uidefaults;
 106     static final X11GraphicsEnvironment localEnv;
 107     private static final X11GraphicsDevice device;
 108     private static final X11GraphicsConfig config;
 109     private static final long display;
 110     static int awt_multiclick_time;
 111     static boolean securityWarningEnabled;
 112 
 113     private static volatile int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
 114     static long awt_defaultFg; // Pixel
 115     private static XMouseInfoPeer xPeer;
 116 






 117     static {
 118         initSecurityWarning();
 119         if (GraphicsEnvironment.isHeadless()) {
 120             localEnv = null;
 121             device = null;
 122             config = null;
 123             display = 0;
 124         } else {
 125             localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
 126                 .getLocalGraphicsEnvironment();
 127             device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();
 128             config = (X11GraphicsConfig) device.getDefaultConfiguration();
 129             display = device.getDisplay();
 130             setupModifierMap();
 131             initIDs();
 132             setBackingStoreType();
 133         }
 134     }
 135 
 136     /*


 700                 XAtom.XA_CARDINAL, native_ptr, 4);
 701             if (workareaPresent)
 702             {
 703                 int rootX = (int)Native.getLong(native_ptr, 0);
 704                 int rootY = (int)Native.getLong(native_ptr, 1);
 705                 int rootWidth = (int)Native.getLong(native_ptr, 2);
 706                 int rootHeight = (int)Native.getLong(native_ptr, 3);
 707 
 708                 return new Rectangle(rootX, rootY, rootWidth, rootHeight);
 709             }
 710         }
 711         finally
 712         {
 713             XlibWrapper.unsafe.freeMemory(native_ptr);
 714         }
 715 
 716         return null;
 717     }
 718 
 719     /*
 720      * If we're running in non-Xinerama environment and the current
 721      * window manager supports _NET protocol then the screen insets
 722      * are calculated using _NET_WM_WORKAREA property of the root
 723      * window.
 724      * Otherwise, i. e. if Xinerama is on or _NET_WM_WORKAREA is
 725      * not set, we try to calculate the insets ourselves using
 726      * getScreenInsetsManually method.













 727      */
 728     public Insets getScreenInsets(GraphicsConfiguration gc)
 729     {
 730         XNETProtocol netProto = XWM.getWM().getNETProtocol();
 731         if ((netProto == null) || !netProto.active())
 732         {
 733             return super.getScreenInsets(gc);
 734         }
 735 
 736         XToolkit.awtLock();
 737         try
 738         {
 739             X11GraphicsConfig x11gc = (X11GraphicsConfig)gc;
 740             X11GraphicsDevice x11gd = (X11GraphicsDevice)x11gc.getDevice();
 741             long root = XlibUtil.getRootWindow(x11gd.getScreen());
 742             Rectangle rootBounds = XlibUtil.getWindowGeometry(root);
 743 
 744             X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
 745                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 746             if (!x11ge.runningXinerama())
 747             {
 748                 Rectangle workArea = XToolkit.getWorkArea(root);
 749                 if (workArea != null)
 750                 {
 751                     return new Insets(workArea.y,
 752                                       workArea.x,
 753                                       rootBounds.height - workArea.height - workArea.y,
 754                                       rootBounds.width - workArea.width - workArea.x);
 755                 }
 756             }
 757 
 758             return getScreenInsetsManually(root, rootBounds, gc.getBounds());










 759         }
 760         finally
 761         {
 762             XToolkit.awtUnlock();
 763         }
 764     }
 765 












 766     /*
 767      * Manual calculation of screen insets: get all the windows with
 768      * _NET_WM_STRUT/_NET_WM_STRUT_PARTIAL hints and add these
 769      * hints' values to screen insets.
 770      *
 771      * This method should be called under XToolkit.awtLock()








 772      */
 773     private Insets getScreenInsetsManually(long root, Rectangle rootBounds, Rectangle screenBounds)
 774     {
 775         /*
 776          * During the manual calculation of screen insets we iterate
 777          * all the X windows hierarchy starting from root window. This
 778          * constant is the max level inspected in this hierarchy.
 779          * 3 is a heuristic value: I suppose any the toolbar-like
 780          * window is a child of either root or desktop window.
 781          */
 782         final int MAX_NESTED_LEVEL = 3;
 783 
 784         XAtom XA_NET_WM_STRUT = XAtom.get("_NET_WM_STRUT");
 785         XAtom XA_NET_WM_STRUT_PARTIAL = XAtom.get("_NET_WM_STRUT_PARTIAL");
 786 
 787         Insets insets = new Insets(0, 0, 0, 0);
 788 
 789         java.util.List search = new LinkedList();
 790         search.add(root);
 791         search.add(0);


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


  97     private XSettings xs;
  98 
  99     private FontConfigManager fcManager = new FontConfigManager();
 100 
 101     static int arrowCursor;
 102     static TreeMap winMap = new TreeMap();
 103     static HashMap specialPeerMap = new HashMap();
 104     static HashMap winToDispatcher = new HashMap();
 105     static UIDefaults uidefaults;
 106     static final X11GraphicsEnvironment localEnv;
 107     private static final X11GraphicsDevice device;
 108     private static final X11GraphicsConfig config;
 109     private static final long display;
 110     static int awt_multiclick_time;
 111     static boolean securityWarningEnabled;
 112 
 113     private static volatile int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
 114     static long awt_defaultFg; // Pixel
 115     private static XMouseInfoPeer xPeer;
 116 
 117     /**
 118      * Should we check "_NET_WM_STRUT/_NET_WM_STRUT_PARTIAL" during insets
 119      * calculation.
 120      */
 121     private static Boolean checkSTRUT;
 122 
 123     static {
 124         initSecurityWarning();
 125         if (GraphicsEnvironment.isHeadless()) {
 126             localEnv = null;
 127             device = null;
 128             config = null;
 129             display = 0;
 130         } else {
 131             localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
 132                 .getLocalGraphicsEnvironment();
 133             device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();
 134             config = (X11GraphicsConfig) device.getDefaultConfiguration();
 135             display = device.getDisplay();
 136             setupModifierMap();
 137             initIDs();
 138             setBackingStoreType();
 139         }
 140     }
 141 
 142     /*


 706                 XAtom.XA_CARDINAL, native_ptr, 4);
 707             if (workareaPresent)
 708             {
 709                 int rootX = (int)Native.getLong(native_ptr, 0);
 710                 int rootY = (int)Native.getLong(native_ptr, 1);
 711                 int rootWidth = (int)Native.getLong(native_ptr, 2);
 712                 int rootHeight = (int)Native.getLong(native_ptr, 3);
 713 
 714                 return new Rectangle(rootX, rootY, rootWidth, rootHeight);
 715             }
 716         }
 717         finally
 718         {
 719             XlibWrapper.unsafe.freeMemory(native_ptr);
 720         }
 721 
 722         return null;
 723     }
 724 
 725     /*
 726      * If the current window manager supports _NET protocol then the screen
 727      * insets are calculated using _NET_WORKAREA property of the root window.
 728      * <p>
 729      * Note that _NET_WORKAREA is a rectangular area and it does not work
 730      * well in the Xinerama mode.
 731      * <p>
 732      * We will trust the part of this rectangular area only if it starts at the
 733      * requested graphics configuration. Below is an example when the
 734      * _NET_WORKAREA intersects with the requested graphics configuration but
 735      * produces wrong result.
 736      *
 737      *         //<-x1,y1///////
 738      *         //            // ////////////////
 739      *         //  SCREEN1   // // SCREEN2    //
 740      *         // ********** // //     x2,y2->//
 741      *         //////////////// //            //
 742      *                          ////////////////
 743      *
 744      * When two screens overlap and the first contains a dock(*****), then
 745      * _NET_WORKAREA may start at point x1,y1 and end at point x2,y2.
 746      */
 747     public Insets getScreenInsets(GraphicsConfiguration gc)
 748     {
 749         XNETProtocol netProto = XWM.getWM().getNETProtocol();
 750         if ((netProto == null) || !netProto.active())
 751         {
 752             return super.getScreenInsets(gc);
 753         }
 754 
 755         XToolkit.awtLock();
 756         try
 757         {
 758             X11GraphicsConfig x11gc = (X11GraphicsConfig)gc;
 759             X11GraphicsDevice x11gd = (X11GraphicsDevice)x11gc.getDevice();
 760             long root = XlibUtil.getRootWindow(x11gd.getScreen());


 761             X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
 762                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 763             if (x11ge.runningXinerama() && checkSTRUT()) {
 764                 // implementation based on _NET_WM_STRUT/_NET_WM_STRUT_PARTIAL
 765                 Rectangle rootBounds = XlibUtil.getWindowGeometry(root);
 766                 Insets insets = getScreenInsetsManually(root, rootBounds,
 767                                                         gc.getBounds());
 768                 if ((insets.left | insets.top | insets.bottom | insets.right) != 0
 769                         || rootBounds == null) {
 770                     return insets;

 771                 }
 772             }
 773             Rectangle workArea = XToolkit.getWorkArea(root);
 774             Rectangle screen = gc.getBounds();
 775             if (workArea != null && screen.contains(workArea.getLocation())) {
 776                 workArea = workArea.intersection(screen);
 777                 int top = workArea.y - screen.y;
 778                 int left = workArea.x - screen.x;
 779                 int bottom = screen.height - workArea.height - top;
 780                 int right = screen.width - workArea.width - left;
 781                 return new Insets(top, left, bottom, right);
 782             }
 783             // Note that it is better to return zeros than inadequate values
 784             return new Insets(0, 0, 0, 0);
 785         }
 786         finally
 787         {
 788             XToolkit.awtUnlock();
 789         }
 790     }
 791 
 792     /**
 793      * Returns the value of "sun.awt.X11.checkSTRUT" property. Default value is
 794      * {@code false}.
 795      */
 796     private static boolean checkSTRUT() {
 797         if (checkSTRUT == null) {
 798             checkSTRUT = AccessController.doPrivileged(
 799                     new GetBooleanAction("sun.awt.X11.checkSTRUT"));
 800         }
 801         return checkSTRUT;
 802     }
 803 
 804     /*
 805      * Manual calculation of screen insets: get all the windows with
 806      * _NET_WM_STRUT/_NET_WM_STRUT_PARTIAL hints and add these
 807      * hints' values to screen insets.
 808      *
 809      * This method should be called under XToolkit.awtLock()
 810      *
 811      * This method is unused by default because of two reasons:
 812      *  - Iteration over windows may be extremely slow, and execution of
 813      *    getScreenInsets() can be x100 slower than in one monitor config.
 814      *  - _NET_WM_STRUT/_NET_WM_STRUT_PARTIAL are hints for the applications.
 815      *    WM should take into account these hints when "_NET_WORKAREA" is
 816      *    calculated, but the system panels do not necessarily contain these
 817      *    hints(Gnome 3 for example).
 818      */
 819     private Insets getScreenInsetsManually(long root, Rectangle rootBounds, Rectangle screenBounds)
 820     {
 821         /*
 822          * During the manual calculation of screen insets we iterate
 823          * all the X windows hierarchy starting from root window. This
 824          * constant is the max level inspected in this hierarchy.
 825          * 3 is a heuristic value: I suppose any the toolbar-like
 826          * window is a child of either root or desktop window.
 827          */
 828         final int MAX_NESTED_LEVEL = 3;
 829 
 830         XAtom XA_NET_WM_STRUT = XAtom.get("_NET_WM_STRUT");
 831         XAtom XA_NET_WM_STRUT_PARTIAL = XAtom.get("_NET_WM_STRUT_PARTIAL");
 832 
 833         Insets insets = new Insets(0, 0, 0, 0);
 834 
 835         java.util.List search = new LinkedList();
 836         search.add(root);
 837         search.add(0);


< prev index next >