< prev index next >

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

Print this page




  85     {
  86         long root;
  87 
  88         XToolkit.awtLock();
  89         try
  90         {
  91             root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
  92                                           screenNumber);
  93         }
  94         finally
  95         {
  96             XToolkit.awtUnlock();
  97         }
  98 
  99         return root == rootCandidate;
 100     }
 101 
 102     /**
 103      * Returns the bounds of the given window, in absolute coordinates
 104      */
 105     static Rectangle getWindowGeometry(long window)
 106     {
 107         XToolkit.awtLock();
 108         try
 109         {
 110             int res = XlibWrapper.XGetGeometry(XToolkit.getDisplay(),
 111                                                window,
 112                                                XlibWrapper.larg1, // root_return
 113                                                XlibWrapper.larg2, // x_return
 114                                                XlibWrapper.larg3, // y_return
 115                                                XlibWrapper.larg4, // width_return
 116                                                XlibWrapper.larg5, // height_return
 117                                                XlibWrapper.larg6, // border_width_return
 118                                                XlibWrapper.larg7); // depth_return
 119             if (res == 0)
 120             {
 121                 return null;
 122             }
 123 
 124             int x = Native.getInt(XlibWrapper.larg2);
 125             int y = Native.getInt(XlibWrapper.larg3);
 126             long width = Native.getUInt(XlibWrapper.larg4);
 127             long height = Native.getUInt(XlibWrapper.larg5);
 128 
 129             return new Rectangle(x, y, (int)width, (int)height);


 130         }
 131         finally
 132         {
 133             XToolkit.awtUnlock();
 134         }
 135     }
 136 
 137     /**
 138      * Translates the given point from one window to another. Returns
 139      * null if the translation is failed
 140      */
 141     static Point translateCoordinates(long src, long dst, Point p)
 142     {
 143         Point translated = null;
 144 
 145         XToolkit.awtLock();
 146         try
 147         {
 148             XTranslateCoordinates xtc =
 149                 new XTranslateCoordinates(src, dst, p.x, p.y);
 150             try
 151             {
 152                 int status = xtc.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 153                 if ((status != 0) &&
 154                     ((XErrorHandlerUtil.saved_error == null) ||
 155                     (XErrorHandlerUtil.saved_error.get_error_code() == XConstants.Success)))
 156                 {
 157                     translated = new Point(xtc.get_dest_x(), xtc.get_dest_y());

 158                 }
 159             }
 160             finally
 161             {
 162                 xtc.dispose();
 163             }
 164         }
 165         finally
 166         {
 167             XToolkit.awtUnlock();
 168         }
 169 
 170         return translated;
 171     }
 172 
 173     /**
 174      * Translates the given rectangle from one window to another.
 175      * Returns null if the translation is failed
 176      */
 177     static Rectangle translateCoordinates(long src, long dst, Rectangle r)

 178     {
 179         Point translatedLoc = translateCoordinates(src, dst, r.getLocation());


 180         if (translatedLoc == null)
 181         {
 182             return null;
 183         }
 184         else
 185         {
 186             return new Rectangle(translatedLoc, r.getSize());
 187         }
 188     }
 189 
 190     /**
 191      * Returns the parent for the given window
 192      */
 193     static long getParentWindow(long window)
 194     {
 195         XToolkit.awtLock();
 196         try
 197         {
 198             XBaseWindow bw = XToolkit.windowToXWindow(window);
 199             if (bw != null)


 388                             XToolkit.getDisplay(),
 389                             XlibWrapper.larg1,
 390                             XlibWrapper.larg2);
 391             } finally {
 392                 XToolkit.awtUnlock();
 393             }
 394         }
 395 
 396         return isShapingSupported.booleanValue();
 397     }
 398 
 399     static int getButtonMask(int button) {
 400         // Button indices start with 1. The first bit in the button mask is the 8th.
 401         // The state mask does not support button indicies > 5, so we need to
 402         // cut there.
 403         if (button <= 0 || button > XConstants.MAX_BUTTONS) {
 404             return 0;
 405         } else {
 406             return 1 << (7 + button);
 407         }




 408     }
 409 }


  85     {
  86         long root;
  87 
  88         XToolkit.awtLock();
  89         try
  90         {
  91             root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
  92                                           screenNumber);
  93         }
  94         finally
  95         {
  96             XToolkit.awtUnlock();
  97         }
  98 
  99         return root == rootCandidate;
 100     }
 101 
 102     /**
 103      * Returns the bounds of the given window, in absolute coordinates
 104      */
 105     static Rectangle getWindowGeometry(long window, int scale)
 106     {
 107         XToolkit.awtLock();
 108         try
 109         {
 110             int res = XlibWrapper.XGetGeometry(XToolkit.getDisplay(),
 111                                                window,
 112                                                XlibWrapper.larg1, // root_return
 113                                                XlibWrapper.larg2, // x_return
 114                                                XlibWrapper.larg3, // y_return
 115                                                XlibWrapper.larg4, // width_return
 116                                                XlibWrapper.larg5, // height_return
 117                                                XlibWrapper.larg6, // border_width_return
 118                                                XlibWrapper.larg7); // depth_return
 119             if (res == 0)
 120             {
 121                 return null;
 122             }
 123 
 124             int x = Native.getInt(XlibWrapper.larg2);
 125             int y = Native.getInt(XlibWrapper.larg3);
 126             long width = Native.getUInt(XlibWrapper.larg4);
 127             long height = Native.getUInt(XlibWrapper.larg5);
 128 
 129             return new Rectangle(scaleDown(x, scale), scaleDown(y, scale),
 130                                  scaleDown((int) width, scale),
 131                                  scaleDown((int) height, scale));
 132         }
 133         finally
 134         {
 135             XToolkit.awtUnlock();
 136         }
 137     }
 138 
 139     /**
 140      * Translates the given point from one window to another. Returns
 141      * null if the translation is failed
 142      */
 143     static Point translateCoordinates(long src, long dst, Point p, int scale)
 144     {
 145         Point translated = null;
 146 
 147         XToolkit.awtLock();
 148         try
 149         {
 150             XTranslateCoordinates xtc =
 151                 new XTranslateCoordinates(src, dst, p.x * scale, p.y * scale);
 152             try
 153             {
 154                 int status = xtc.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 155                 if ((status != 0) &&
 156                     ((XErrorHandlerUtil.saved_error == null) ||
 157                     (XErrorHandlerUtil.saved_error.get_error_code() == XConstants.Success)))
 158                 {
 159                     translated = new Point(scaleDown(xtc.get_dest_x(), scale),
 160                                            scaleDown(xtc.get_dest_y(), scale));
 161                 }
 162             }
 163             finally
 164             {
 165                 xtc.dispose();
 166             }
 167         }
 168         finally
 169         {
 170             XToolkit.awtUnlock();
 171         }
 172 
 173         return translated;
 174     }
 175 
 176     /**
 177      * Translates the given rectangle from one window to another.
 178      * Returns null if the translation is failed
 179      */
 180     static Rectangle translateCoordinates(long src, long dst, Rectangle r,
 181                                           int scale)
 182     {
 183         Point translatedLoc = translateCoordinates(src, dst, r.getLocation(),
 184                                                    scale);
 185 
 186         if (translatedLoc == null)
 187         {
 188             return null;
 189         }
 190         else
 191         {
 192             return new Rectangle(translatedLoc, r.getSize());
 193         }
 194     }
 195 
 196     /**
 197      * Returns the parent for the given window
 198      */
 199     static long getParentWindow(long window)
 200     {
 201         XToolkit.awtLock();
 202         try
 203         {
 204             XBaseWindow bw = XToolkit.windowToXWindow(window);
 205             if (bw != null)


 394                             XToolkit.getDisplay(),
 395                             XlibWrapper.larg1,
 396                             XlibWrapper.larg2);
 397             } finally {
 398                 XToolkit.awtUnlock();
 399             }
 400         }
 401 
 402         return isShapingSupported.booleanValue();
 403     }
 404 
 405     static int getButtonMask(int button) {
 406         // Button indices start with 1. The first bit in the button mask is the 8th.
 407         // The state mask does not support button indicies > 5, so we need to
 408         // cut there.
 409         if (button <= 0 || button > XConstants.MAX_BUTTONS) {
 410             return 0;
 411         } else {
 412             return 1 << (7 + button);
 413         }
 414     }
 415 
 416     static int scaleDown(int x, int scale) {
 417         return x / scale;
 418     }
 419 }
< prev index next >