Ejemplo n.º 1
0
 /**
  * Closing pending Display connections in original creation order, if {@link
  * #getMarkAllDisplaysUnclosable()} is true.
  *
  * @return number of closed Display connections
  */
 private static int closePendingDisplayConnections() {
   int num = 0;
   synchronized (globalLock) {
     if (getMarkAllDisplaysUnclosable()) {
       for (int i = 0; i < pendingDisplayList.size(); i++) {
         final NamedDisplay ndpy = (NamedDisplay) pendingDisplayList.get(i);
         if (DEBUG) {
           final boolean closeAttempted = !openDisplayMap.containsKey(ndpy.getHandle());
           System.err.println(
               "X11Util.closePendingDisplayConnections(): Closing ["
                   + i
                   + "]: "
                   + ndpy
                   + " - closeAttempted "
                   + closeAttempted);
         }
         XCloseDisplay(ndpy.getHandle());
         num++;
       }
       if (DEBUG) {
         System.err.println(
             "X11Util.closePendingDisplayConnections(): Closed "
                 + num
                 + " pending display connections");
       }
     }
   }
   return num;
 }
Ejemplo n.º 2
0
  public static void closeDisplay(long handle) {
    synchronized (globalLock) {
      final NamedDisplay namedDpy = (NamedDisplay) openDisplayMap.remove(handle);
      if (null == namedDpy) {
        X11Util.dumpPendingDisplayConnections();
        throw new RuntimeException(
            "X11Util.Display: Display(0x"
                + Long.toHexString(handle)
                + ") with given handle is not mapped. Thread "
                + Thread.currentThread().getName());
      }
      if (namedDpy.getHandle() != handle) {
        X11Util.dumpPendingDisplayConnections();
        throw new RuntimeException(
            "X11Util.Display: Display(0x"
                + Long.toHexString(handle)
                + ") Mapping error: "
                + namedDpy
                + ". Thread "
                + Thread.currentThread().getName());
      }

      namedDpy.removeRef();
      if (!openDisplayList.remove(namedDpy)) {
        throw new RuntimeException("Internal: " + namedDpy);
      }

      if (markAllDisplaysUnclosable) {
        // if set-mark 'slipped' this one .. just to be safe!
        namedDpy.setUncloseable(true);
      }
      if (!namedDpy.isUncloseable()) {
        XCloseDisplay(namedDpy.getHandle());
        pendingDisplayList.remove(namedDpy);
      } else {
        // for reuse
        X11Lib.XSync(namedDpy.getHandle(), true); // flush output buffer and discard all events
        reusableDisplayList.add(namedDpy);
      }

      if (DEBUG) {
        System.err.println(
            "X11Util.Display: Closed (real: "
                + (!namedDpy.isUncloseable())
                + ") "
                + namedDpy
                + ". Thread "
                + Thread.currentThread().getName());
      }
    }
  }