< prev index next >

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

Print this page




  24  */
  25 package sun.awt.X11;
  26 
  27 import java.awt.*;
  28 
  29 import java.awt.event.ComponentEvent;
  30 import java.awt.event.InvocationEvent;
  31 import java.awt.event.WindowEvent;
  32 
  33 import sun.awt.IconInfo;
  34 import sun.util.logging.PlatformLogger;
  35 
  36 import sun.awt.AWTAccessor;
  37 import sun.awt.SunToolkit;
  38 
  39 abstract class XDecoratedPeer extends XWindowPeer {
  40     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XDecoratedPeer");
  41     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XDecoratedPeer");
  42     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XDecoratedPeer");
  43     private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XDecoratedPeer");

  44 
  45     // Set to true when we get the first ConfigureNotify after being
  46     // reparented - indicates that WM has adopted the top-level.
  47     boolean configure_seen;
  48     boolean insets_corrected;
  49 
  50     XIconWindow iconWindow;
  51     WindowDimensions dimensions;
  52     XContentWindow content;
  53     Insets currentInsets;
  54     XFocusProxyWindow focusProxy;
  55 
  56     XDecoratedPeer(Window target) {
  57         super(target);
  58     }
  59 
  60     XDecoratedPeer(XCreateWindowParams params) {
  61         super(params);
  62     }
  63 


 249     private static Insets difference(Insets i1, Insets i2) {
 250         return new Insets(i1.top-i2.top, i1.left - i2.left, i1.bottom-i2.bottom, i1.right-i2.right);
 251     }
 252 
 253     private static boolean isNull(Insets i) {
 254         return (i == null) || ((i.left | i.top | i.right | i.bottom) == 0);
 255     }
 256 
 257     private static Insets copy(Insets i) {
 258         return new Insets(i.top, i.left, i.bottom, i.right);
 259     }
 260 
 261     // insets which we get from WM (e.g from _NET_FRAME_EXTENTS)
 262     private Insets wm_set_insets;
 263 
 264     private Insets getWMSetInsets(XAtom changedAtom) {
 265         if (isEmbedded()) {
 266             return null;
 267         }
 268 
 269         if (wm_set_insets != null) {
 270             return wm_set_insets;
 271         }
 272 
 273         if (changedAtom == null) {
 274             wm_set_insets = XWM.getInsetsFromExtents(getWindow());
 275         } else {
 276             wm_set_insets = XWM.getInsetsFromProp(getWindow(), changedAtom);
 277         }
 278 
 279         if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
 280             insLog.finer("FRAME_EXTENTS: {0}", wm_set_insets);
 281         }
 282 
 283         if (wm_set_insets != null) {
 284             wm_set_insets = copy(wm_set_insets);
 285         }
 286         return wm_set_insets;
 287     }
 288 
 289     private void resetWMSetInsets() {


 328                 insets_corrected = false;
 329 
 330                 /*
 331                  * We can be repareted to root for two reasons:
 332                  *   . setVisible(false)
 333                  *   . WM exited
 334                  */
 335                 if (isVisible()) { /* WM exited */
 336                     /* Work around 4775545 */
 337                     XWM.getWM().unshadeKludge(this);
 338                     insLog.fine("- WM exited");
 339                 } else {
 340                     insLog.fine(" - reparent due to hide");
 341                 }
 342             } else { /* reparented to WM frame, figure out our insets */
 343                 setReparented(true);
 344                 insets_corrected = false;
 345 
 346                 // Check if we have insets provided by the WM
 347                 Insets correctWM = getWMSetInsets(null);
 348                 if (correctWM != null) {





 349                     if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
 350                         insLog.finer("wm-provided insets {0}", correctWM);
 351                     }
 352                     // If these insets are equal to our current insets - no actions are necessary
 353                     Insets dimInsets = dimensions.getInsets();
 354                     if (correctWM.equals(dimInsets)) {
 355                         insLog.finer("Insets are the same as estimated - no additional reshapes necessary");
 356                         no_reparent_artifacts = true;
 357                         insets_corrected = true;
 358                         applyGuessedInsets();
 359                         return;
 360                     }
 361                 } else {
 362                     correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());
 363 
 364                     if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
 365                         if (correctWM != null) {
 366                             insLog.finer("correctWM {0}", correctWM);
 367                         } else {
 368                             insLog.finer("correctWM insets are not available, waiting for configureNotify");
 369                         }
 370                     }
 371                 }
 372 
 373                 if (correctWM != null) {
 374                     handleCorrectInsets(correctWM);


 375                 }
 376             }
 377         } finally {
 378             XToolkit.awtUnlock();
 379         }
 380     }
 381 
 382     protected void handleCorrectInsets(Insets correctWM) {
 383         XToolkit.awtLock();
 384         try {
 385             /*
 386              * Ok, now see if we need adjust window size because
 387              * initial insets were wrong (most likely they were).
 388              */
 389             Insets correction = difference(correctWM, currentInsets);
 390             if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
 391                 insLog.finest("Corrention {0}", correction);
 392             }
 393             if (!isNull(correction)) {
 394                 currentInsets = copy(correctWM);




  24  */
  25 package sun.awt.X11;
  26 
  27 import java.awt.*;
  28 
  29 import java.awt.event.ComponentEvent;
  30 import java.awt.event.InvocationEvent;
  31 import java.awt.event.WindowEvent;
  32 
  33 import sun.awt.IconInfo;
  34 import sun.util.logging.PlatformLogger;
  35 
  36 import sun.awt.AWTAccessor;
  37 import sun.awt.SunToolkit;
  38 
  39 abstract class XDecoratedPeer extends XWindowPeer {
  40     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XDecoratedPeer");
  41     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XDecoratedPeer");
  42     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XDecoratedPeer");
  43     private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XDecoratedPeer");
  44     private static final int MAX_INSET_ATTEMPT = 100;
  45 
  46     // Set to true when we get the first ConfigureNotify after being
  47     // reparented - indicates that WM has adopted the top-level.
  48     boolean configure_seen;
  49     boolean insets_corrected;
  50 
  51     XIconWindow iconWindow;
  52     WindowDimensions dimensions;
  53     XContentWindow content;
  54     Insets currentInsets;
  55     XFocusProxyWindow focusProxy;
  56 
  57     XDecoratedPeer(Window target) {
  58         super(target);
  59     }
  60 
  61     XDecoratedPeer(XCreateWindowParams params) {
  62         super(params);
  63     }
  64 


 250     private static Insets difference(Insets i1, Insets i2) {
 251         return new Insets(i1.top-i2.top, i1.left - i2.left, i1.bottom-i2.bottom, i1.right-i2.right);
 252     }
 253 
 254     private static boolean isNull(Insets i) {
 255         return (i == null) || ((i.left | i.top | i.right | i.bottom) == 0);
 256     }
 257 
 258     private static Insets copy(Insets i) {
 259         return new Insets(i.top, i.left, i.bottom, i.right);
 260     }
 261 
 262     // insets which we get from WM (e.g from _NET_FRAME_EXTENTS)
 263     private Insets wm_set_insets;
 264 
 265     private Insets getWMSetInsets(XAtom changedAtom) {
 266         if (isEmbedded()) {
 267             return null;
 268         }
 269 
 270         if (!isNull(wm_set_insets)) {
 271             return wm_set_insets;
 272         }
 273 
 274         if (changedAtom == null) {
 275             wm_set_insets = XWM.getInsetsFromExtents(getWindow());
 276         } else {
 277             wm_set_insets = XWM.getInsetsFromProp(getWindow(), changedAtom);
 278         }
 279 
 280         if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
 281             insLog.finer("FRAME_EXTENTS: {0}", wm_set_insets);
 282         }
 283 
 284         if (wm_set_insets != null) {
 285             wm_set_insets = copy(wm_set_insets);
 286         }
 287         return wm_set_insets;
 288     }
 289 
 290     private void resetWMSetInsets() {


 329                 insets_corrected = false;
 330 
 331                 /*
 332                  * We can be repareted to root for two reasons:
 333                  *   . setVisible(false)
 334                  *   . WM exited
 335                  */
 336                 if (isVisible()) { /* WM exited */
 337                     /* Work around 4775545 */
 338                     XWM.getWM().unshadeKludge(this);
 339                     insLog.fine("- WM exited");
 340                 } else {
 341                     insLog.fine(" - reparent due to hide");
 342                 }
 343             } else { /* reparented to WM frame, figure out our insets */
 344                 setReparented(true);
 345                 insets_corrected = false;
 346 
 347                 // Check if we have insets provided by the WM
 348                 Insets correctWM = getWMSetInsets(null);
 349                 int maxAttempts = MAX_INSET_ATTEMPT;
 350                 while (maxAttempts--> 0 && isNull(correctWM)) {
 351                     Thread.yield();
 352                     correctWM = getWMSetInsets(null);
 353                 }
 354                 if (!isNull(correctWM)) {
 355                     if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
 356                         insLog.finer("wm-provided insets {0}", correctWM);
 357                     }
 358                     // If these insets are equal to our current insets - no actions are necessary
 359                     Insets dimInsets = dimensions.getInsets();
 360                     if (correctWM.equals(dimInsets)) {
 361                         insLog.finer("Insets are the same as estimated - no additional reshapes necessary");
 362                         no_reparent_artifacts = true;
 363                         insets_corrected = true;
 364                         applyGuessedInsets();
 365                         return;
 366                     }
 367                 } else {
 368                     correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());
 369 
 370                     if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
 371                         if (correctWM != null) {
 372                             insLog.finer("correctWM {0}", correctWM);
 373                         } else {
 374                             insLog.finer("correctWM insets are not available, waiting for configureNotify");
 375                         }
 376                     }
 377                 }
 378 
 379                 if (!isNull(correctWM)) {
 380                     handleCorrectInsets(correctWM);
 381                 } else {
 382                     insets_corrected = false;
 383                 }
 384             }
 385         } finally {
 386             XToolkit.awtUnlock();
 387         }
 388     }
 389 
 390     protected void handleCorrectInsets(Insets correctWM) {
 391         XToolkit.awtLock();
 392         try {
 393             /*
 394              * Ok, now see if we need adjust window size because
 395              * initial insets were wrong (most likely they were).
 396              */
 397             Insets correction = difference(correctWM, currentInsets);
 398             if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
 399                 insLog.finest("Corrention {0}", correction);
 400             }
 401             if (!isNull(correction)) {
 402                 currentInsets = copy(correctWM);


< prev index next >