diff options
Diffstat (limited to 'src/main/engine/ui/x11/ui.c')
-rw-r--r-- | src/main/engine/ui/x11/ui.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/main/engine/ui/x11/ui.c b/src/main/engine/ui/x11/ui.c index cd35edf..b1086a9 100644 --- a/src/main/engine/ui/x11/ui.c +++ b/src/main/engine/ui/x11/ui.c @@ -24,7 +24,7 @@ #include <X11/Xlib.h> #include <unistd.h> #include <time.h> -#include "../../../util.h" +#include <log.h> #include "../types.h" static Display *display; @@ -40,12 +40,23 @@ void (*on_generic_event)(int); void cleanup(void); +static Log *log = NULL; + +static void +init_log(void) +{ + if (log != NULL) return; + log = log_create("UI"); +} + static Display * ui_open_display(void) { + init_log(); + Display *display = XOpenDisplay(NULL); if (!display) { - log_error("Can't open X11 display"); + log_error(log, "Can't open X11 display"); exit(1); } @@ -55,10 +66,12 @@ ui_open_display(void) static XVisualInfo * gl_choose_visual(int screen) { + init_log(); + GLint attribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; XVisualInfo *vi = glXChooseVisual(display, screen, attribs); if (!vi) { - log_error("No compatible Visual found"); + log_error(log, "No compatible Visual found"); exit(1); } @@ -96,9 +109,11 @@ ui_set_title(const char *title) UI * ui_init(int width, int height) { + init_log(); + UI *ui = malloc(sizeof(UI)); if (ui == NULL) { - log_error("Error allocating UI"); + log_error(log, "Error allocating UI"); exit(1); } @@ -113,7 +128,7 @@ ui_init(int width, int height) gl_context = glXCreateContext(display, vi, NULL, GL_TRUE); if (!glXMakeCurrent(display, window, gl_context)) { - log_error("Error on making GLX context"); + log_error(log, "Error on making GLX context"); exit(1); } @@ -135,11 +150,13 @@ ui_on_expose(XEvent event) static void ui_on_resize(XEvent event) { + init_log(); + if (event.type != ConfigureNotify) return; if (on_resize_event != NULL) { UIEventResize *er = malloc(sizeof(UIEventResize)); if (er == NULL) { - log_error("Error allocating UIEventResize"); + log_error(log, "Error allocating UIEventResize"); exit(EXIT_FAILURE); } er->width = event.xconfigure.width; @@ -168,11 +185,13 @@ ui_get_mouse_position(Display *display, Window window, int *x, int *y) { static void ui_on_mouse_press(XEvent event) { + init_log(); + if (event.type != ButtonPress) return; if (on_mouse_press_event != NULL) { UIMouseButtonPressed *mbp = malloc(sizeof(UIMouseButtonPressed)); if (mbp == NULL) { - log_error("Error allocating UIMouseButtonPressed"); + log_error(log, "Error allocating UIMouseButtonPressed"); exit(EXIT_FAILURE); } ui_get_mouse_position(display, window, &mbp->x, &mbp->y); |