简体   繁体   中英

How to remove window decorations with XCB?

I am trying to do the same thing as in this question .

So far, I am learned about xcb_change_property function from official documentation .

But still the following code does not gives any results.

xcb_connection_t *c = xcb_connect ( NULL, NULL );

/* get the first screen */
xcb_screen_t *screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;

xcb_window_t win = xcb_generate_id ( c );

xcb_create_window ( c,                             /* Connection          */
                    XCB_COPY_FROM_PARENT,          /* depth (same as root)*/
                    win,                           /* window Id           */
                    screen->root,                  /* parent window       */
                    0, 0,                          /* x, y                */
                    system::getCore()->screen.width(), /* width */
                    system::getCore()->screen.height(), /* height       */
                    0,                            /* border_width        */
                    XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
                    screen->root_visual,           /* visual              */
                    0,
                    NULL );                     /* masks*/


xcb_intern_atom_cookie_t cookie = xcb_intern_atom ( c, 0, strlen ( "_MOTIF_WM_HINTS" ), "_MOTIF_WM_HINTS" );
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply ( c, cookie, NULL );

xcb_change_property ( c,
                     XCB_PROP_MODE_REPLACE,
                     win,
                     (*reply).atom,
                     XCB_ATOM_INTEGER,
                     32,
                     0,
                     0 );

xcb_map_window ( c, win );
xcb_flush ( c );

What am I doing wrong?

The key is to use (*reply).atom, twice, instead of the XCB_ATOM_INTEGER:

Code that works for me:

xcb_intern_atom_cookie_t cookie3 = xcb_intern_atom(connection, 0, strlen ( "_MOTIF_WM_HINTS" ), "_MOTIF_WM_HINTS" );
xcb_intern_atom_reply_t *reply3 = xcb_intern_atom_reply ( connection, cookie3, NULL );

// motif hints
typedef struct MotifHints
{
    uint32_t   flags;
    uint32_t   functions;
    uint32_t   decorations;
    int32_t    input_mode;
    uint32_t   status;
};

MotifHints hints;

hints.flags = 2;
hints.functions = 0;
hints.decorations = 0;
hints.input_mode = 0;
hints.status = 0;

xcb_change_property ( connection,
    XCB_PROP_MODE_REPLACE,
    window,
    reply3->atom,
    reply3->atom,  // THIS is essential
    32,  // format of property
    5,   // length of data (5x32 bit) , followed by pointer to data
    &hints ); // is this is a motif hints struct

free(reply3);

A look at the SFML source helps too, file WindowImplX11.cpp .

Your question doesn't really explain very well what you are looking to do. Your comment explaining the actual goal, however, does. If I understand correctly, you want to create an application that works something like the Compiz "Annotate" plugin. I cannot say with 100% certainty, but without some other extensions I do not believe this is possible. You really need a composite extension to do this well, but without it you can simulate the effect in a few ways...

(1) You could basically grab a screenshot and draw on that, and maybe even update the background periodically by hiding the entire thing and retaking the screenshot. Anything close to real time updates would probably not look very smooth.

(2) You could listen to all mouse movement and/or keyboard events and create a lot of small windows all over the screen. You'd probably get to a point where it wouldn't let you create more windows and it probably wouldn't be too pretty.

(3) You could use the "shape" extension which allows you to make oddly shaped windows and try to create a window from what would essentially be an alpha mask to overlay over the other windows. I'm not sure what all you can do with that extension as I have never used it. You may be limited to simple polygons.

There are surely other solutions, and some combination of these could obviously work. Clearly your best solution, if composite is available, is to use that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM