@@ -33,7 +33,7 @@ namespace py = pybind11;
3333using namespace pybind11 ::literals;
3434
3535static bool
36- mpl_display_is_valid (void )
36+ mpl_xdisplay_is_valid (void )
3737{
3838#ifdef __linux__
3939 void * libX11;
@@ -57,6 +57,19 @@ mpl_display_is_valid(void)
5757 return true ;
5858 }
5959 }
60+ return false ;
61+ #else
62+ return true ;
63+ #endif
64+ }
65+
66+ static bool
67+ mpl_display_is_valid (void )
68+ {
69+ #ifdef __linux__
70+ if (mpl_xdisplay_is_valid ()) {
71+ return true ;
72+ }
6073 void * libwayland_client;
6174 if (getenv (" WAYLAND_DISPLAY" )
6275 && (libwayland_client = dlopen (" libwayland-client.so.0" , RTLD_LAZY))) {
@@ -194,6 +207,16 @@ PYBIND11_MODULE(_c_internal_utils, m)
194207 succeeds, or $WAYLAND_DISPLAY is set and wl_display_connect(NULL)
195208 succeeds.
196209
210+ On other platforms, always returns True.)""" );
211+ m.def (
212+ " xdisplay_is_valid" , &mpl_xdisplay_is_valid,
213+ R"""( --
214+ Check whether the current X11 display is valid.
215+
216+ On Linux, returns True if either $DISPLAY is set and XOpenDisplay(NULL)
217+ succeeds. Use this function if you need to specifically check for X11
218+ only (e.g., for Tkinter).
219+
197220 On other platforms, always returns True.)""" );
198221 m.def (
199222 " Win32_GetCurrentProcessExplicitAppUserModelID" ,
0 commit comments