Search code examples
resizewindowx11window-managersxcb

XCB - How to set WM_SIZE_HINTS?


I'm writing a minimalistic library for window creation in xcb. I want to be able to create a non-resizeable window. I found out, that it is possible to give hints to the window manager with:

xcb_void_cookie_t xcb_change_property (xcb_connection_t *c,       /* Connection to the X server */
                                       uint8_t          mode,     /* Property mode */
                                       xcb_window_t     window,   /* Window */
                                       xcb_atom_t       property, /* Property to change */
                                       xcb_atom_t       type,     /* Type of the property */
                                       uint8_t          format,   /* Format of the property (8, 16, 32) */
                                       uint32_t         data_len, /* Length of the data parameter */
                                       const void      *data);    /* Data */

I tried to change the WM_NORMAL_HINTS and WM_SIZE_HINTS with this function, but how do I know what data I have to put in the *data parameter? Is the type XCB_ATOM_INTEGER or something else?


Solution

  • Here is the solution:

    #include <xcb/xcb.h>
    #include <xcb/xcb_icccm.h>
    
    #define WIDTH  900
    #define HEIGHT 600
    
    int main(){
        //...
        //Connect to X Server and
        //Create a window
        //...
    
        xcb_size_hints_t hints;
    
        xcb_icccm_size_hints_set_min_size(&hints, WIDTH, HEIGHT);
        xcb_icccm_size_hints_set_max_size(&hints, WIDTH, HEIGHT);
    
        xcb_icccm_set_wm_size_hints(connection, window, XCB_ATOM_WM_NORMAL_HINTS, &hints);
        return 0;
    }