Having troubles using XkbKeycodeToKeysym

Mibi88 mbcontact50 at gmail.com
Wed May 1 09:39:13 UTC 2024


Hello,

I hope that I'm asking on the right place for help, if not, where should 
I ask for help about XLib?

I'm writing a program that uses opengl, glx and xlib. Everything works 
fine, I can get the mouse position, the mouse button press events etc. 
But when I try to get Symcodes from keycodes, my program just segfaults. 
I checked the arguments I'm passing multiple times, I tried using 
XKeycodeToKeysym...

I tested it on another computer, and I had the same issue.

I'm getting the event like this:

if(XPending(window->display)){

XNextEvent(window->display, &window->event);

if(window->event.type== KeymapNotify){

XRefreshKeyboardMapping(&(window->event.xmapping));

}

return1;

}

return0;

I'm getting the keysyms as following:

KeySymkeysym;

keysym = XkbKeycodeToKeysym(window->display, window->event.xkey.keycode, 0,

window->event.xkey.state);

That's how I create my window:

GLintvisual_attributes[] = {

GLX_RGBA,

GLX_DEPTH_SIZE,

8,

GLX_DOUBLEBUFFER,

None /* Always ends with None */

};

window->display= XOpenDisplay(NULL);

if(window->display== NULL){

puts("[MibiEngine] Failed to connect to the X server!");

return1;

}

window->root= DefaultRootWindow(window->display);

window->visual_info= glXChooseVisual(window->display, 0,

visual_attributes);

if(!window->visual_info){

puts("[MibiEngine] No visual found!");

return2;

}

window->color_map= XCreateColormap(window->display, window->root,

window->visual_info->visual, AllocNone);

window->set_window_attributes.colormap= window->color_map;

window->set_window_attributes.event_mask= MW_EVENT_MASKS;

window->window= XCreateWindow(window->display, window->root, 0, 0, width,

height, 0, window->visual_info->depth,

InputOutput, window->visual_info->visual,

CWColormap | CWEventMask,

&window->set_window_attributes);

XSelectInput(window->display, window->window, MW_EVENT_MASKS);

/* Make the window appear */

XMapWindow(window->display, window->window);

/* Set the text in the title bar */

XStoreName(window->display, window->window, title);

/* Create the OpenGL context */

window->glx_context= glXCreateContext(window->display, window->visual_info,

NULL, GL_TRUE);

glXMakeCurrent(window->display, window->window, window->glx_context);

window->wm_delete= XInternAtom(window->display, "WM_DELETE_WINDOW", True);

XSetWMProtocols(window->display, window->window, &window->wm_delete, 1);

The window struct I'm using everywhere is defined as following:

typedefstruct{

Display*display;

Windowroot;

XVisualInfo*visual_info;

Colormapcolor_map;

XSetWindowAttributesset_window_attributes;

Windowwindow;

GLXContextglx_context;

XWindowAttributeswindow_attributes;

XEventevent;

Atomwm_delete;

XIMxim;

XICxic;

longmask;

} MWWindow;

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.x.org/archives/xorg/attachments/20240501/612daa2a/attachment.htm>


More information about the xorg mailing list