0

I am using arch linux and a basic cpp custom window manager. However, every time I right click to open the context menu it just flickers and dissapears. 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 menu 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]

Searching for the error brought some chromium specific results, but nothing to apply to linux generally. Any clue on how to resolve or even debug this is appriciated!

The following simplified example exhibits 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 ConfigureRequest:
            OnConfigureRequest(event.xconfigurerequest);
            break;
        case ButtonPress:
            XRaiseWindow(display, event.xbutton.window);
            break;
        }
    }
 
    return true;
}
 
void OnConfigureRequest(const XConfigureRequestEvent& event)
{
    XWindowChanges changes;
    changes.x = event.x;
    changes.y = event.y;
    changes.width = event.width;
    changes.height = event.height;
    changes.border_width = event.border_width;
    changes.sibling = event.above;
    changes.stack_mode = event.detail;
 
    if(frame_list.count(event.window))
    {
        const Window frame = event.window;
        XConfigureWindow(display, frame, event.value_mask, &changes);
    }
 
    //Grant request
    XConfigureWindow(display, event.window, event.value_mask, &changes);
}
 
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);
}

The issue is also found in 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.

5
  • "a basic cpp custom window manager" – You'll probably have to provide the source before anyone will have any chance of providing meaningful answers.
    – xiota
    Nov 15, 2022 at 11:45
  • Yes, sorry, but we can't help you debug your own program whose code we cannot see. You could try posting on Stack Overflow and showing the code used to launch the menus, but as it stands, this is just too vague to be answerable.
    – terdon
    Nov 15, 2022 at 11:49
  • @terdon and xiota thank you for the tips! I left the code out because there is nothing particular in it. I have amended the code into the question as a github repo. Only two files are necessary; both mentioned in the amendment.
    – Eshy
    Nov 15, 2022 at 15:19
  • OK, but don't expect people to go and read an entire software project to understand and debug it. If you cannot make this more (much, much more) focused I don't think anyone here will be able to help you. I would suggest you try and find the actual part in the code used to handle the menu and then ask about it on Stack Overflow and not here.
    – terdon
    Nov 15, 2022 at 15:26
  • @terdon understood, I'll simplify and post this on stack overflow.
    – Eshy
    Nov 15, 2022 at 15:32

1 Answer 1

0

Answer from the stack overflow version of this question:

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .