code: @Nullable
    public static XDesktop getCurrentDesktop(XComponentContext xContext) {
      try {
        if (xContext == null) {
          return null;
        }
        XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
                xContext.getServiceManager());
        if (xMCF == null) {
          return null;
        }
        Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
        if (desktop == null) {
          return null;
        }
        return UnoRuntime.queryInterface(XDesktop.class, desktop);
      } catch (Throwable t) {
        MessageHandler.printException(t);     // all Exceptions thrown by UnoRuntime.queryInterface are caught
        return null;           // Return null as method failed
      }
    }
docs: Returns the current XDesktop
  Returns null if it fails