简体   繁体   中英

Context menu does not consistently work on arch linux?

I am using arch linux and a basic cpp xlib custom window manager. However, every time I right click to open the context menu it just flickers and disappears. I cannot use it at all. I also cannot use top drop down menus (file, edit, about, ect.) on any application. Is there anything in Xlib which I have to look out for to ensure I may use the context menus normally?

This is the case in every application I have tried. Only clue I have is in brave it occasionally displays the following message:

XGetWindowAttributes failed for window [WINDOW_ID]

The following simplified example also has this issue:

int main()
{
    display = XOpenDisplay(nullptr);
    root = DefaultRootWindow(display);
    XSelectInput(display, root, SubstructureRedirectMask | SubstructureNotifyMask | StructureNotifyMask);
 
    XGrabServer(display);
    Window returned_root;
    Window returned_parent;
    Window* top_level_windows;
    unsigned int num_top_level_windows;
    XQueryTree(display, root, &returned_root, &returned_parent, &top_level_windows, &num_top_level_windows);
 
    for(unsigned int i = 0; i < num_top_level_windows; ++i)
    {
        Frame(top_level_windows[i], true);
    }
 
    XFree(top_level_windows);
    XUngrabServer(display);
 
    for(;;)
    {
        XEvent event;
        XNextEvent(display, &event);
 
        switch (event.type)
        {
        case MapRequest:
        {
            Frame(event.xmaprequest.window, false);
            XMapWindow(display, event.xmaprequest.window);
            break;
        }
        case ButtonPress:
            XRaiseWindow(display, event.xbutton.window);
            break;
        }
    }
 
    return true;
}

void Frame(Window window, bool created_before_manager)
{
    //Retrieve attributes of window to frame
    XWindowAttributes attr = {0};
    XGetWindowAttributes(display, window, &attr);
 
    //If window was created before window manager started, we should frame it only if it is visible and does not set override_redirect
    if(created_before_manager && (attr.override_redirect || attr.map_state != IsViewable))
    {
        return;
    }
 
    //Create frame
    Window frame = XCreateSimpleWindow(display, root, attr.x, attr.y, attr.width, attr.height, 5, 0xff0000, 0xffffff);
    XReparentWindow(display, window, frame, 0, 0);
    XMapWindow(display, frame);
 
    XGrabButton(display, Button1Mask, Mod1Mask, window, None, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
}

To be clear it also works with a super simple example such as:

int main()
{
    Display* display = XOpenDisplay(nullptr);
    for(;;) {}
    return true;
}

The reason I believe the window manager is at fault is because this issue only occurs after I run the window manager.

I expected this to work out of the box. I have not found any information on context menus needing special treatment. They do have the override_redirect flag set to true, so I do not frame them. I cannot find information on any other special treatment required.

It is necessary to make sure the client window has input. I had the input set to whatever was clicked (frame, title bar, or client) because it worked fine as far as normal input is concerned. However, the context menus will only work if you make sure the input is set to the client window directly.

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