Add button and motion events.

This commit is contained in:
2022-12-24 06:36:20 +01:00
parent abd5989de8
commit 65b25c8be3
5 changed files with 232 additions and 49 deletions

View File

@ -16,6 +16,7 @@
// Adapted from https://www.khronos.org/opengl/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)
#include "render_context.hpp"
#include "../events.hpp"
#include <cstdio>
#include <cstring>
#include <GLES3/gl32.h>
@ -25,8 +26,7 @@ extern unsigned rk_events_mask;
Display * rk_display = nullptr;
Window rk_window = 0;
XIC rk_input_context = nullptr;
static XIM rk_input_manager = nullptr;
static Colormap rk_colormap = 0;
static GLXContext rk_context = nullptr;
static bool rk_error_occured = false;
@ -164,24 +164,13 @@ rk_window_t rk_create_context(
}
XStoreName(rk_display, rk_window, name);
rk_input_manager = XOpenIM(rk_display, nullptr, nullptr, nullptr);
if (!rk_input_manager) {
rk_printf("Failed to open input manager.");
rk_destroy_context();
return nullptr;
}
rk_input_context = XCreateIC(rk_input_manager,
XNInputStyle, XIMPreeditNone | XIMStatusNone,
XNClientWindow, rk_window,
NULL);
if (!rk_input_context) {
rk_printf("Failed to create input context.");
if (!rk_initialize_events()) {
rk_printf("Failed to initialize events.");
rk_destroy_context();
return nullptr;
}
XMapWindow(rk_display, rk_window);
XSetICFocus(rk_input_context);
char const * const glx_exts = glXQueryExtensionsString(rk_display, DefaultScreen(rk_display));
glXCreateContextAttribsARBProc const glXCreateContextAttribsARB =
@ -244,15 +233,7 @@ void rk_destroy_context() {
glXDestroyContext(rk_display, rk_context);
rk_context = nullptr;
}
if (rk_input_context) {
XUnsetICFocus(rk_input_context);
XDestroyIC(rk_input_context);
rk_input_context = nullptr;
}
if (rk_input_manager) {
XCloseIM(rk_input_manager);
rk_input_manager = nullptr;
}
rk_terminate_events();
if (rk_window) {
XDestroyWindow(rk_display, rk_window);
rk_window = 0;