From aee73b628ecfe98b800ae7f653f6b19655b78b58 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Fri, 16 May 2025 08:55:26 +0200 Subject: Add a function to ope the display --- src/main/ui/x11/ui.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/main/ui/x11/ui.c') diff --git a/src/main/ui/x11/ui.c b/src/main/ui/x11/ui.c index 9018250..5199eea 100644 --- a/src/main/ui/x11/ui.c +++ b/src/main/ui/x11/ui.c @@ -22,6 +22,7 @@ #include #include #include +#include "../../util.h" static Display *display; static Window window; @@ -29,21 +30,28 @@ static GLXContext gl_context; void cleanup(void); -void -ui_init() +static Display * +ui_open_display(void) { - display = XOpenDisplay(NULL); + Display *display = XOpenDisplay(NULL); if (!display) { - fprintf(stderr, "Error: Can't open X11 display\n"); + log_error("Can't open X11 display"); exit(1); } + return display; +} + +void +ui_init() +{ + display = ui_open_display(); + int screen = DefaultScreen(display); Window root = RootWindow(display, screen); GLint attribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; XVisualInfo *vi = glXChooseVisual(display, screen, attribs); - if (!vi) { fprintf(stderr, "Error: No compatible Visual found\n"); exit(1); -- cgit v1.2.3