简体   繁体   English

如何使用XCB移除窗户装饰?

[英]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 . 到目前为止,我已经从官方文档中学到了xcb_change_property函数。

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: 关键是两次使用(* reply).atom而不是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 . 查看SFML源文件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. 如果我理解正确,则您想创建一个工作类似于Compiz“ Annotate”插件的应用程序。 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. (1)您基本上可以抓取屏幕截图并进行绘制,甚至可以通过隐藏整个内容并重新获取屏幕截图来定期更新背景。 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. (2)您可以收听所有鼠标移动和/或键盘事件,并在屏幕上创建许多小窗口。 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. (3)您可以使用“形状”扩展名,该扩展名允许您制作形状奇特的窗口,并尝试从本质上是Alpha蒙版的窗口创建窗口,以覆盖其他窗口。 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. 显然,如果可以使用复合材料,最好的解决方案就是使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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