--- src/key.c +++ src/key.c @@ -247,8 +247,17 @@ define_sequences (key_define_t *kd) } #ifdef HAVE_TEXTMODE_X11_SUPPORT +#include + static Display *x11_display; static Window x11_window; + +static jmp_buf jmp_no_x; + +int x11_IOError(Display *d) +{ + longjmp(jmp_no_x, 1); +} #endif /* HAVE_TEXTMODE_X11_SUPPORT */ /* This has to be called before slang_init or whatever routine @@ -290,9 +299,19 @@ void init_key (void) #endif /* __QNX__ */ #ifdef HAVE_TEXTMODE_X11_SUPPORT - x11_display = XOpenDisplay (0); - if (x11_display) + XSetIOErrorHandler(x11_IOError); + if (setjmp(jmp_no_x)) { + x11_display = NULL; + fprintf (stderr, "Error: X connection broken\n"); + } + else { + x11_display = XOpenDisplay (0); + } + + if (x11_display) { + XSetIOErrorHandler(NULL); x11_window = DefaultRootWindow (x11_display); + } #endif /* HAVE_TEXTMODE_X11_SUPPORT */ }