code: def _display_is_valid():
      # Adapted from matplotilb _c_internal_utils.py
      if sys.platform != "linux":
          return True
      if os.getenv("DISPLAY"):  # if it's not there, don't bother
          libX11 = cdll.LoadLibrary("libX11.so.6")
          libX11.XOpenDisplay.restype = c_void_p
          libX11.XOpenDisplay.argtypes = [c_char_p]
          display = libX11.XOpenDisplay(None)
          if display is not None:
              libX11.XCloseDisplay.argtypes = [c_void_p]
              libX11.XCloseDisplay(display)
              return True
      # not found, try Wayland
      if os.getenv("WAYLAND_DISPLAY"):
          libwayland = cdll.LoadLibrary("libwayland-client.so.0")
          if libwayland is not None:
              if all(
                  hasattr(libwayland, f"wl_display_{kind}connect")
                  for kind in ("", "dis")
              ):
                  libwayland.wl_display_connect.restype = c_void_p
                  libwayland.wl_display_connect.argtypes = [c_char_p]
                  display = libwayland.wl_display_connect(None)
                  if display:
                      libwayland.wl_display_disconnect.argtypes = [
                          c_void_p
                      ]
                      libwayland.wl_display_disconnect(display)
                      return True
      return False
  
imports: import collections.abc
  import functools
  import os
  import platform
  import signal
  import sys
  from colorsys import rgb_to_hls
  from contextlib import contextmanager
  from ctypes import c_char_p, c_void_p, cdll
  from pathlib import Path
  import numpy
  from ...fixes import _compare_version
  from ...utils import _check_qt_version, _validate_type, logger, warn
  from ..utils import _get_cmap
label_desc: Use image node_id 7 for calling a global function with example usage: _display_is_valid() and returns: False, True, True, True