Class OSDesktopWindow


  • @Immutable
    public class OSDesktopWindow
    extends java.lang.Object
    This class encapsulates information about a window on the operating system's GUI desktop
    • Constructor Summary

      Constructors 
      Constructor Description
      OSDesktopWindow​(long windowId, java.lang.String title, java.lang.String command, java.awt.Rectangle locAndSize, long owningProcessId, int order, boolean visible)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getCommand()
      Gets the command name (possibly the full file path) of the window's executable program, if known.
      java.awt.Rectangle getLocAndSize()
      Gets a Rectangle representing the window's location and size.
      int getOrder()
      Makes a best effort to get the order in which this window appears on the desktop.
      long getOwningProcessId()
      Gets the process ID of the process which owns this window, if known.
      java.lang.String getTitle()
      Gets the Window title, if any.
      long getWindowId()
      Gets the operating system's handle, window ID, or other unique identifier for this window.
      boolean isVisible()
      Makes a best effort to report whether the window is visible to the user.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • windowId

        private final long windowId
      • title

        private final java.lang.String title
      • command

        private final java.lang.String command
      • locAndSize

        private final java.awt.Rectangle locAndSize
      • owningProcessId

        private final long owningProcessId
      • order

        private final int order
      • visible

        private final boolean visible
    • Constructor Detail

      • OSDesktopWindow

        public OSDesktopWindow​(long windowId,
                               java.lang.String title,
                               java.lang.String command,
                               java.awt.Rectangle locAndSize,
                               long owningProcessId,
                               int order,
                               boolean visible)
    • Method Detail

      • getWindowId

        public long getWindowId()
        Gets the operating system's handle, window ID, or other unique identifier for this window.

        On Winodws, this can be converted to a WinDef.HWND using new HWND(new Pointer(windowId)). On macOS, this is the Core Graphics Window ID. On Unix-like systems, this is the X11 Window ID.

        Returns:
        the windowId
      • getTitle

        public java.lang.String getTitle()
        Gets the Window title, if any.
        Returns:
        the title, which may be an empty string if the window has no title.
      • getCommand

        public java.lang.String getCommand()
        Gets the command name (possibly the full file path) of the window's executable program, if known.
        Returns:
        the command
      • getLocAndSize

        public java.awt.Rectangle getLocAndSize()
        Gets a Rectangle representing the window's location and size.
        Returns:
        the location and size
      • getOwningProcessId

        public long getOwningProcessId()
        Gets the process ID of the process which owns this window, if known.
        Returns:
        the owningProcessId
      • getOrder

        public int getOrder()
        Makes a best effort to get the order in which this window appears on the desktop. Higher values are more in the foreground.

        On Windows, this represents the Z Order of the window, and is not guaranteed to be atomic, as it could be impacted by race conditions.

        On macOS this is the window layer. Note that multiple windows may share the same layer.

        On X11 this represents the stacking order of the windows.

        Returns:
        a best effort identification of the window's Z order relative to other windows
      • isVisible

        public boolean isVisible()
        Makes a best effort to report whether the window is visible to the user. A "visible" window may be completely transparent.
        Returns:
        true if the window is visible to users or if visibility can not be determined, false otherwise.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object