Esempio n. 1
0
 public static void dumpPendingDisplayConnections() {
   synchronized (globalLock) {
     System.err.println(
         "X11Util: Reusable X11 Display Connections: " + reusableDisplayList.size());
     for (int i = 0; i < reusableDisplayList.size(); i++) {
       NamedDisplay ndpy = (NamedDisplay) reusableDisplayList.get(i);
       System.err.println("X11Util: Reusable[" + i + "]: " + ndpy);
       if (null != ndpy) {
         Throwable t = ndpy.getCreationStack();
         if (null != t) {
           t.printStackTrace();
         }
       }
     }
     System.err.println(
         "X11Util: Pending X11 Display Connections (creation order): "
             + pendingDisplayList.size());
     for (int i = 0; i < pendingDisplayList.size(); i++) {
       NamedDisplay ndpy = (NamedDisplay) pendingDisplayList.get(i);
       System.err.println("X11Util: Pending[" + i + "]: " + ndpy);
       if (null != ndpy) {
         Throwable t = ndpy.getCreationStack();
         if (null != t) {
           t.printStackTrace();
         }
       }
     }
   }
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public static boolean markDisplayUncloseable(long handle) {
   NamedDisplay ndpy;
   synchronized (globalLock) {
     ndpy = (NamedDisplay) openDisplayMap.get(handle);
   }
   if (null != ndpy) {
     ndpy.setUncloseable(true);
     return true;
   }
   return false;
 }
Esempio n. 4
0
 public static void dumpOpenDisplayConnections() {
   synchronized (globalLock) {
     System.err.println("X11Util: Open X11 Display Connections: " + openDisplayList.size());
     for (int i = 0; i < openDisplayList.size(); i++) {
       NamedDisplay ndpy = openDisplayList.get(i);
       System.err.println("X11Util: Open[" + i + "]: " + ndpy);
       if (null != ndpy) {
         Throwable t = ndpy.getCreationStack();
         if (null != t) {
           t.printStackTrace();
         }
       }
     }
   }
 }
Esempio n. 5
0
  /** Returns a created or reused named display. */
  public static long openDisplay(String name) {
    long dpy = 0;
    NamedDisplay namedDpy = null;
    name = validateDisplayName(name);
    boolean reused = false;

    synchronized (globalLock) {
      for (int i = 0; i < reusableDisplayList.size(); i++) {
        if (reusableDisplayList.get(i).getName().equals(name)) {
          namedDpy = reusableDisplayList.remove(i);
          dpy = namedDpy.getHandle();
          reused = true;
          break;
        }
      }
      if (0 == dpy) {
        dpy = XOpenDisplay(name);
        if (0 == dpy) {
          throw new NativeWindowException(
              "X11Util.Display: Unable to create a display("
                  + name
                  + ") connection. Thread "
                  + Thread.currentThread().getName());
        }
        // if you like to debug and synchronize X11 commands ..
        // setSynchronizeDisplay(dpy, true);
        namedDpy = new NamedDisplay(name, dpy);
        pendingDisplayList.add(namedDpy);
      }
      namedDpy.addRef();
      openDisplayMap.put(dpy, namedDpy);
      openDisplayList.add(namedDpy);
      if (markAllDisplaysUnclosable) {
        namedDpy.setUncloseable(true);
      }
    }
    if (DEBUG) {
      System.err.println(
          "X11Util.Display: openDisplay [reuse "
              + reused
              + "] "
              + namedDpy
              + ". Thread "
              + Thread.currentThread().getName());
      // Thread.dumpStack();
    }
    return namedDpy.getHandle();
  }
Esempio n. 6
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());
      }
    }
  }