Add basic XIM support for key events.
This commit is contained in:
		@ -21,9 +21,12 @@
 | 
			
		||||
#include <GLES3/gl32.h>
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
 | 
			
		||||
extern unsigned rk_events_mask;
 | 
			
		||||
 | 
			
		||||
Display * rk_display = nullptr;
 | 
			
		||||
Window rk_window = 0;
 | 
			
		||||
extern unsigned rk_events_mask;
 | 
			
		||||
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;
 | 
			
		||||
@ -94,6 +97,8 @@ rk_window_t rk_create_context(
 | 
			
		||||
    char const * name,
 | 
			
		||||
    unsigned width,
 | 
			
		||||
    unsigned height) {
 | 
			
		||||
    XSetLocaleModifiers("");
 | 
			
		||||
 | 
			
		||||
    rk_display = XOpenDisplay(nullptr);
 | 
			
		||||
    if (!rk_display) {
 | 
			
		||||
        rk_printf("Failed to open X display.");
 | 
			
		||||
@ -151,14 +156,32 @@ rk_window_t rk_create_context(
 | 
			
		||||
    rk_window = XCreateWindow(rk_display, RootWindow(rk_display, vi->screen),
 | 
			
		||||
                                0, 0, width, height, 0, vi->depth, InputOutput, vi->visual,
 | 
			
		||||
                                CWBorderPixel | CWColormap | CWEventMask, &swa);
 | 
			
		||||
    XFree(vi);
 | 
			
		||||
    if (!rk_window) {
 | 
			
		||||
        rk_printf("Failed to create window.");
 | 
			
		||||
        rk_destroy_context();
 | 
			
		||||
        return nullptr;
 | 
			
		||||
    }
 | 
			
		||||
    XFree(vi);
 | 
			
		||||
    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.");
 | 
			
		||||
        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 =
 | 
			
		||||
@ -221,6 +244,15 @@ 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;
 | 
			
		||||
        }
 | 
			
		||||
        if (rk_window) {
 | 
			
		||||
            XDestroyWindow(rk_display, rk_window);
 | 
			
		||||
            rk_window = 0;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user