10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt; 27 28 import java.awt.AWTError; 29 import java.awt.GraphicsDevice; 30 import java.awt.Point; 31 import java.awt.Rectangle; 32 import java.net.InetAddress; 33 import java.net.NetworkInterface; 34 import java.net.SocketException; 35 import java.net.UnknownHostException; 36 37 import java.util.*; 38 39 import sun.java2d.SunGraphicsEnvironment; 40 import sun.java2d.SurfaceManagerFactory; 41 import sun.java2d.UnixSurfaceManagerFactory; 42 import sun.util.logging.PlatformLogger; 43 import sun.java2d.xr.XRSurfaceData; 44 45 /** 46 * This is an implementation of a GraphicsEnvironment object for the 47 * default local GraphicsEnvironment used by the Java Runtime Environment 48 * for X11 environments. 49 * 50 * @see GraphicsDevice 51 * @see java.awt.GraphicsConfiguration 52 */ 53 public final class X11GraphicsEnvironment extends SunGraphicsEnvironment { 54 55 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11GraphicsEnvironment"); 56 private static final PlatformLogger screenLog = PlatformLogger.getLogger("sun.awt.screen.X11GraphicsEnvironment"); 57 58 private static Boolean xinerState; 59 60 static { 61 java.security.AccessController.doPrivileged( 62 new java.security.PrivilegedAction<Object>() { 63 public Object run() { 273 } 274 } 275 return Boolean.FALSE; 276 }}); 277 return result.booleanValue(); 278 } 279 280 281 282 /** 283 * Returns face name for default font, or null if 284 * no face names are used for CompositeFontDescriptors 285 * for this platform. 286 */ 287 public String getDefaultFontFaceName() { 288 289 return null; 290 } 291 292 private static native boolean pRunningXinerama(); 293 private static native Point getXineramaCenterPoint(); 294 295 /** 296 * Override for Xinerama case: call new Solaris API for getting the correct 297 * centering point from the windowing system. 298 */ 299 public Point getCenterPoint() { 300 if (runningXinerama()) { 301 Point p = getXineramaCenterPoint(); 302 if (p != null) { 303 return p; 304 } 305 } 306 return super.getCenterPoint(); 307 } 308 309 /** 310 * Override for Xinerama case 311 */ 312 public Rectangle getMaximumWindowBounds() { 313 if (runningXinerama()) { 314 return getXineramaWindowBounds(); 315 } else { 316 return super.getMaximumWindowBounds(); 317 } 318 } 319 320 public boolean runningXinerama() { 321 if (xinerState == null) { 322 // pRunningXinerama() simply returns a global boolean variable, 323 // so there is no need to synchronize here 324 xinerState = Boolean.valueOf(pRunningXinerama()); 325 if (screenLog.isLoggable(PlatformLogger.Level.FINER)) { 326 screenLog.finer("Running Xinerama: " + xinerState); 327 } 328 } 329 return xinerState.booleanValue(); 330 } 331 332 /** 333 * Return the bounds for a centered Window on a system running in Xinerama 334 * mode. 335 * 336 * Calculations are based on the assumption of a perfectly rectangular 337 * display area (display edges line up with one another, and displays 338 * have consistent width and/or height). 339 * 340 * The bounds to return depend on the arrangement of displays and on where 341 * Windows are to be centered. There are two common situations: 342 * 343 * 1) The center point lies at the center of the combined area of all the 344 * displays. In this case, the combined area of all displays is 345 * returned. 346 * 347 * 2) The center point lies at the center of a single display. In this case 348 * the user most likely wants centered Windows to be constrained to that 349 * single display. The boundaries of the one display are returned. 350 * 351 * It is possible for the center point to be at both the center of the 352 * entire display space AND at the center of a single monitor (a square of 353 * 9 monitors, for instance). In this case, the entire display area is 354 * returned. 355 * 356 * Because the center point is arbitrarily settable by the user, it could 357 * fit neither of the cases above. The fallback case is to simply return 358 * the combined area for all screens. 359 */ 360 protected Rectangle getXineramaWindowBounds() { 361 Point center = getCenterPoint(); 362 Rectangle unionRect, tempRect; 363 GraphicsDevice[] gds = getScreenDevices(); 364 Rectangle centerMonitorRect = null; 365 int i; 366 367 // if center point is at the center of all monitors 368 // return union of all bounds 369 // 370 // MM*MM MMM M 371 // M*M * 372 // MMM M 373 374 // if center point is at center of a single monitor (but not of all 375 // monitors) 376 // return bounds of single monitor 377 // 378 // MMM MM 379 // MM* *M 380 381 // else, center is in some strange spot (such as on the border between 382 // monitors), and we should just return the union of all monitors 383 // 384 // MM MMM 385 // MM MMM 386 387 unionRect = getUsableBounds(gds[0]); 388 389 for (i = 0; i < gds.length; i++) { 390 tempRect = getUsableBounds(gds[i]); 391 if (centerMonitorRect == null && 392 // add a pixel or two for fudge-factor 393 (tempRect.width / 2) + tempRect.x > center.x - 1 && 394 (tempRect.height / 2) + tempRect.y > center.y - 1 && 395 (tempRect.width / 2) + tempRect.x < center.x + 1 && 396 (tempRect.height / 2) + tempRect.y < center.y + 1) { 397 centerMonitorRect = tempRect; 398 } 399 unionRect = unionRect.union(tempRect); 400 } 401 402 // first: check for center of all monitors (video wall) 403 // add a pixel or two for fudge-factor 404 if ((unionRect.width / 2) + unionRect.x > center.x - 1 && 405 (unionRect.height / 2) + unionRect.y > center.y - 1 && 406 (unionRect.width / 2) + unionRect.x < center.x + 1 && 407 (unionRect.height / 2) + unionRect.y < center.y + 1) { 408 409 if (screenLog.isLoggable(PlatformLogger.Level.FINER)) { 410 screenLog.finer("Video Wall: center point is at center of all displays."); 411 } 412 return unionRect; 413 } 414 415 // next, check if at center of one monitor 416 if (centerMonitorRect != null) { 417 if (screenLog.isLoggable(PlatformLogger.Level.FINER)) { 418 screenLog.finer("Center point at center of a particular " + 419 "monitor, but not of the entire virtual display."); 420 } 421 return centerMonitorRect; 422 } 423 424 // otherwise, the center is at some weird spot: return unionRect 425 if (screenLog.isLoggable(PlatformLogger.Level.FINER)) { 426 screenLog.finer("Center point is somewhere strange - return union of all bounds."); 427 } 428 return unionRect; 429 } 430 431 /** 432 * From the DisplayChangedListener interface; devices do not need 433 * to react to this event. 434 */ 435 @Override 436 public void paletteChanged() { 437 } 438 } | 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt; 27 28 import java.awt.AWTError; 29 import java.awt.GraphicsDevice; 30 import java.net.InetAddress; 31 import java.net.NetworkInterface; 32 import java.net.SocketException; 33 import java.net.UnknownHostException; 34 import java.util.Enumeration; 35 36 import sun.java2d.SunGraphicsEnvironment; 37 import sun.java2d.SurfaceManagerFactory; 38 import sun.java2d.UnixSurfaceManagerFactory; 39 import sun.java2d.xr.XRSurfaceData; 40 import sun.util.logging.PlatformLogger; 41 42 /** 43 * This is an implementation of a GraphicsEnvironment object for the 44 * default local GraphicsEnvironment used by the Java Runtime Environment 45 * for X11 environments. 46 * 47 * @see GraphicsDevice 48 * @see java.awt.GraphicsConfiguration 49 */ 50 public final class X11GraphicsEnvironment extends SunGraphicsEnvironment { 51 52 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11GraphicsEnvironment"); 53 private static final PlatformLogger screenLog = PlatformLogger.getLogger("sun.awt.screen.X11GraphicsEnvironment"); 54 55 private static Boolean xinerState; 56 57 static { 58 java.security.AccessController.doPrivileged( 59 new java.security.PrivilegedAction<Object>() { 60 public Object run() { 270 } 271 } 272 return Boolean.FALSE; 273 }}); 274 return result.booleanValue(); 275 } 276 277 278 279 /** 280 * Returns face name for default font, or null if 281 * no face names are used for CompositeFontDescriptors 282 * for this platform. 283 */ 284 public String getDefaultFontFaceName() { 285 286 return null; 287 } 288 289 private static native boolean pRunningXinerama(); 290 291 public boolean runningXinerama() { 292 if (xinerState == null) { 293 // pRunningXinerama() simply returns a global boolean variable, 294 // so there is no need to synchronize here 295 xinerState = Boolean.valueOf(pRunningXinerama()); 296 if (screenLog.isLoggable(PlatformLogger.Level.FINER)) { 297 screenLog.finer("Running Xinerama: " + xinerState); 298 } 299 } 300 return xinerState.booleanValue(); 301 } 302 303 /** 304 * From the DisplayChangedListener interface; devices do not need 305 * to react to this event. 306 */ 307 @Override 308 public void paletteChanged() { 309 } 310 } |