diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mgl.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -12,15 +12,17 @@ static mgl_context context; static int init_count = 0; static XErrorHandler prev_xerror = NULL; static XIOErrorHandler prev_xioerror = NULL; +static bool connected_to_x_server = false; -static int ignore_xerror(Display *display, XErrorEvent *ee) { +static int mgl_x_error_handler(Display *display, XErrorEvent *ee) { (void)display; (void)ee; return 0; } -static int ignore_xioerror(Display *display) { +static int mgl_x_io_error_handler(Display *display) { (void)display; + connected_to_x_server = false; return 0; } @@ -64,9 +66,10 @@ int mgl_init(void) { mgl_deinit(); return -1; } + connected_to_x_server = true; - prev_xerror = XSetErrorHandler(ignore_xerror); - prev_xioerror = XSetIOErrorHandler(ignore_xioerror); + prev_xerror = XSetErrorHandler(mgl_x_error_handler); + prev_xioerror = XSetIOErrorHandler(mgl_x_io_error_handler); if(!xrender_is_supported(context.connection, &context.render_event_base, &context.render_error_base)) { fprintf(stderr, "mgl error: x11 render extension is not supported by your X server\n"); @@ -102,6 +105,7 @@ void mgl_deinit(void) { if(context.connection) { XCloseDisplay(context.connection); context.connection = NULL; + connected_to_x_server = false; /* GLX needs to be unloaded after closing the display on nvidia because @@ -136,3 +140,14 @@ mgl_context* mgl_get_context(void) { #endif return &context; } + +bool mgl_is_connected_to_display_server(void) { + return connected_to_x_server; +} + +void mgl_ping_display_server(void) { + if(context.connection) { + XNoOp(context.connection); + XFlush(context.connection); + } +} |