<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>I guess you declare "window" variable as a pointer to <span
        style="color:#000000;"></span><span style="color:#005032;">MWWindow</span><span
        style="color:#000000;"> structure ?<br>
      </span></p>
    <div class="moz-cite-prefix">Le 01/05/2024 à 11:39, Mibi88 a écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:98cc191b-6605-44b3-927e-9a46b007e795@gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <p>Hello,</p>
      <p>I hope that I'm asking on the right place for help, if not,
        where should I ask for help about XLib?</p>
      <p>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...</p>
      <p>I tested it on another computer, and I had the same issue.<br>
      </p>
      <p>I'm getting the event like this:</p>
      <div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
        <div
style="color:#333333;background-color:#ffffff;font-family:"Monospace";font-size:12pt;white-space:pre;"><p
        style="margin:0;"><span style="color:#000000;"></span><span
        style="color:#7f0055;font-weight:bold;">    if</span><span
        style="color:#000000;">(</span><span
        style="color:#642880;font-weight:bold;">XPending</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">)){</span></p><p style="margin:0;"><span
        style="color:#000000;">        </span><span
        style="color:#642880;font-weight:bold;">XNextEvent</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, &window-></span><span
        style="color:#0000c0;">event</span><span style="color:#000000;">);</span></p><p
        style="margin:0;"><span style="color:#000000;">        </span><span
        style="color:#7f0055;font-weight:bold;">if</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">event</span><span style="color:#000000;">.</span><span
        style="color:#0000c0;">type</span><span style="color:#000000;"> == KeymapNotify){</span></p><p
        style="margin:0;"><span style="color:#000000;">            </span><span
        style="color:#642880;font-weight:bold;">XRefreshKeyboardMapping</span><span
        style="color:#000000;">(&(window-></span><span
        style="color:#0000c0;">event</span><span style="color:#000000;">.</span><span
        style="color:#0000c0;">xmapping</span><span
        style="color:#000000;">));</span></p><p style="margin:0;"><span
        style="color:#000000;">        }</span></p><p style="margin:0;"><span
        style="color:#000000;">        </span><span
        style="color:#7f0055;font-weight:bold;">return</span><span
        style="color:#000000;"> 1;</span></p><p style="margin:0;"><span
        style="color:#000000;">    }</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span
        style="color:#7f0055;font-weight:bold;">return</span><span
        style="color:#000000;"> 0;</span></p></div>
      </div>
    </blockquote>
    Perhaps replace <span style="color:#000000;">"&window-></span><span
      style="color:#0000c0;">event" by </span><span
      style="color:#000000;">"&(window-></span><span
      style="color:#0000c0;">event)"</span>
    <blockquote type="cite"
      cite="mid:98cc191b-6605-44b3-927e-9a46b007e795@gmail.com">
      <div style="background-color:#ffffff;padding:0px 0px 0px 2px;"> </div>
      <p>I'm getting the keysyms as following:</p>
      <div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
        <div
style="color:#333333;background-color:#ffffff;font-family:"Monospace";font-size:12pt;white-space:pre;"><p
        style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#005032;">KeySym</span><span style="color:#000000;"> keysym;</span></p><p
        style="margin:0;"><span style="color:#000000;">    keysym = XkbKeycodeToKeysym(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">event</span><span style="color:#000000;">.</span><span
        style="color:#0000c0;">xkey</span><span style="color:#000000;">.</span><span
        style="color:#0000c0;">keycode</span><span
        style="color:#000000;">, 0,</span></p><p style="margin:0;"><span
        style="color:#000000;">                                window-></span><span
        style="color:#0000c0;">event</span><span style="color:#000000;">.</span><span
        style="color:#0000c0;">xkey</span><span style="color:#000000;">.</span><span
        style="color:#0000c0;">state</span><span style="color:#000000;">);</span></p></div>
      </div>
      <p>That's how I create my window:</p>
      <div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
        <div
style="color:#333333;background-color:#ffffff;font-family:"Monospace";font-size:12pt;white-space:pre;"><p
        style="margin:0;"><span style="color:#000000;">    </span><span
style="color:#000000;text-decoration:underline;text-decoration-color:#ff0000;text-decoration-style:wavy;">GLint</span><span
        style="color:#000000;"> visual_attributes[] = {</span></p><p
        style="margin:0;"><span style="color:#000000;">        GLX_RGBA,</span></p><p
        style="margin:0;"><span style="color:#000000;">        GLX_DEPTH_SIZE,</span></p><p
        style="margin:0;"><span style="color:#000000;">        8,</span></p><p
        style="margin:0;"><span style="color:#000000;">        GLX_DOUBLEBUFFER,</span></p><p
        style="margin:0;"><span style="color:#000000;">        None </span><span
        style="color:#3f7f5f;">/* Always ends with None */</span></p><p
        style="margin:0;"><span style="color:#000000;">    };</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;"> = </span><span
        style="color:#642880;font-weight:bold;">XOpenDisplay</span><span
        style="color:#000000;">(NULL);</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span
        style="color:#7f0055;font-weight:bold;">if</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;"> == NULL){</span></p><p style="margin:0;"><span
        style="color:#000000;">        </span><span
        style="color:#642880;font-weight:bold;">puts</span><span
        style="color:#000000;">(</span><span style="color:#2a00ff;">"[MibiEngine] Failed to connect to the X server!"</span><span
        style="color:#000000;">);</span></p><p style="margin:0;"><span
        style="color:#000000;">        </span><span
        style="color:#7f0055;font-weight:bold;">return</span><span
        style="color:#000000;"> 1;</span></p><p style="margin:0;"><span
        style="color:#000000;">    }</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">root</span><span style="color:#000000;"> = DefaultRootWindow(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">);</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">visual_info</span><span
        style="color:#000000;"> = </span><span
        style="color:#642880;font-weight:bold;">glXChooseVisual</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, 0,</span></p><p style="margin:0;"><span
        style="color:#000000;">                                          visual_attributes);</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#7f0055;font-weight:bold;">if</span><span
        style="color:#000000;">(!window-></span><span
        style="color:#0000c0;">visual_info</span><span
        style="color:#000000;">){</span></p><p style="margin:0;"><span
        style="color:#000000;">        </span><span
        style="color:#642880;font-weight:bold;">puts</span><span
        style="color:#000000;">(</span><span style="color:#2a00ff;">"[MibiEngine] No visual found!"</span><span
        style="color:#000000;">);</span></p><p style="margin:0;"><span
        style="color:#000000;">        </span><span
        style="color:#7f0055;font-weight:bold;">return</span><span
        style="color:#000000;"> 2;</span></p><p style="margin:0;"><span
        style="color:#000000;">    }</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">color_map</span><span
        style="color:#000000;"> = </span><span
        style="color:#642880;font-weight:bold;">XCreateColormap</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">root</span><span style="color:#000000;">,</span></p><p
        style="margin:0;"><span style="color:#000000;">                                        window-></span><span
        style="color:#0000c0;">visual_info</span><span
        style="color:#000000;">-></span><span style="color:#0000c0;">visual</span><span
        style="color:#000000;">, AllocNone);</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">set_window_attributes</span><span
        style="color:#000000;">.</span><span style="color:#0000c0;">colormap</span><span
        style="color:#000000;"> = window-></span><span
        style="color:#0000c0;">color_map</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    window-></span><span
        style="color:#0000c0;">set_window_attributes</span><span
        style="color:#000000;">.</span><span style="color:#0000c0;">event_mask</span><span
        style="color:#000000;"> = MW_EVENT_MASKS;</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">window</span><span style="color:#000000;"> = </span><span
        style="color:#642880;font-weight:bold;">XCreateWindow</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">root</span><span style="color:#000000;">, 0, 0, width,</span></p><p
        style="margin:0;"><span style="color:#000000;">                                   height, 0, window-></span><span
        style="color:#0000c0;">visual_info</span><span
        style="color:#000000;">-></span><span style="color:#0000c0;">depth</span><span
        style="color:#000000;">,</span></p><p style="margin:0;"><span
        style="color:#000000;">                                   InputOutput, window-></span><span
        style="color:#0000c0;">visual_info</span><span
        style="color:#000000;">-></span><span style="color:#0000c0;">visual</span><span
        style="color:#000000;">,</span></p><p style="margin:0;"><span
        style="color:#000000;">                                   CWColormap | CWEventMask,</span></p><p
        style="margin:0;"><span style="color:#000000;">                                   &window-></span><span
        style="color:#0000c0;">set_window_attributes</span><span
        style="color:#000000;">);</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span
        style="color:#642880;font-weight:bold;">XSelectInput</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">window</span><span style="color:#000000;">, MW_EVENT_MASKS);</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#3f7f5f;">/* Make the window appear */</span></p><p
        style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#642880;font-weight:bold;">XMapWindow</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">window</span><span style="color:#000000;">);</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#3f7f5f;">/* Set the text in the title bar */</span></p><p
        style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#642880;font-weight:bold;">XStoreName</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">window</span><span style="color:#000000;">, title);</span></p><p
        style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#3f7f5f;">/* Create the OpenGL context */</span></p><p
        style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">glx_context</span><span
        style="color:#000000;"> = </span><span
        style="color:#642880;font-weight:bold;">glXCreateContext</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">visual_info</span><span
        style="color:#000000;">,</span></p><p style="margin:0;"><span
        style="color:#000000;">                                           NULL, GL_TRUE);</span></p><p
        style="margin:0;"><span style="color:#000000;">    </span><span
        style="color:#642880;font-weight:bold;">glXMakeCurrent</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">window</span><span style="color:#000000;">, window-></span><span
        style="color:#0000c0;">glx_context</span><span
        style="color:#000000;">);</span></p><p style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    window-></span><span
        style="color:#0000c0;">wm_delete</span><span
        style="color:#000000;"> = </span><span
        style="color:#642880;font-weight:bold;">XInternAtom</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, </span><span style="color:#2a00ff;">"WM_DELETE_WINDOW"</span><span
        style="color:#000000;">, True);</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span
        style="color:#642880;font-weight:bold;">XSetWMProtocols</span><span
        style="color:#000000;">(window-></span><span
        style="color:#0000c0;">display</span><span
        style="color:#000000;">, window-></span><span
        style="color:#0000c0;">window</span><span style="color:#000000;">, &window-></span><span
        style="color:#0000c0;">wm_delete</span><span
        style="color:#000000;">, 1);</span></p></div>
      </div>
      <p>The window struct I'm using everywhere is defined as following:</p>
      <div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
        <div
style="color:#333333;background-color:#ffffff;font-family:"Monospace";font-size:12pt;white-space:pre;"><p
        style="margin:0;"><span style="color:#7f0055;font-weight:bold;">typedef</span><span
        style="color:#000000;"> </span><span
        style="color:#7f0055;font-weight:bold;">struct</span><span
        style="color:#000000;"> {</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">Display</span><span
        style="color:#000000;"> *</span><span style="color:#0000c0;">display</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">Window</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">root</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">XVisualInfo</span><span
        style="color:#000000;"> *</span><span style="color:#0000c0;">visual_info</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">Colormap</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">color_map</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">XSetWindowAttributes</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">set_window_attributes</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">Window</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">window</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span
style="color:#000000;text-decoration:underline;text-decoration-color:#ff0000;text-decoration-style:wavy;">GLXContext</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">glx_context</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">XWindowAttributes</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">window_attributes</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">XEvent</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">event</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">Atom</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">wm_delete</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">XIM</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">xim</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span style="color:#005032;">XIC</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">xic</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">    </span><span
        style="color:#7f0055;font-weight:bold;">long</span><span
        style="color:#000000;"> </span><span style="color:#0000c0;">mask</span><span
        style="color:#000000;">;</span></p><p style="margin:0;"><span
        style="color:#000000;">} </span><span style="color:#005032;">MWWindow</span><span
        style="color:#000000;">;</span></p></div>
      </div>
      <p>Thanks</p>
    </blockquote>
  </body>
</html>