xmenu: my first project with xlib - Programming On Unix

Users browsing this thread: 1 Guest(s)
venam
Administrators
I gave your code a try.

It seems that all your menu location calculation rely on the position of the parent window relative to the root window and the screen geometry instead of the position of the entries themselves. Thus, you have to keep track of both x and y position and refresh the position of the parent window constantly. I don't think this is the best way to do this, you should only have to keep track of the Y cursor position that is internal to the window, not even the X.

For example, you pass to the getmenuitem function the position of the pointer on the root window instead of the position relative to within the window. Namely, ev.xbutton.x_root and ev.xbutton.y_root instead of ev.xbutton.x and ev.xbutton.y. Those are defined in man 3 XMotionEvent, in the XButtonEvent structure.

In my opinion you'll only have to rely on multiple of the item->y/geom.itemh and in the getmenuitem comparison you could simply do:

Code:
for (item = menu->list; item != NULL; item = item->next) {
    if (y >= item->y && y <= item->y + geom.itemh) {
        *menu_ret = menu;
        *item_ret = item;
        return;
    }
}

There's also an issue in allocitem in which the count doesn't seem to increment properly after the first 2 items, set in parsestdin. Adding count++ after the allocitem seems to do the trick here but it doesn't continue after the first item that has a child. I didn't dig further than that.

I hope this mini overview can help make your menu better.


Messages In This Thread
xmenu: my first project with xlib - by seninha - 14-05-2020, 06:45 PM
RE: xmenu: my first project with xlib - by z3bra - 14-05-2020, 07:32 PM
RE: xmenu: my first project with xlib - by venam - 15-05-2020, 02:47 AM
RE: xmenu: my first project with xlib - by z3bra - 15-05-2020, 06:33 AM
RE: xmenu: my first project with xlib - by movq - 15-05-2020, 09:49 AM
RE: xmenu: my first project with xlib - by venam - 15-05-2020, 03:04 PM
RE: xmenu: my first project with xlib - by venam - 19-05-2020, 12:49 AM
RE: xmenu: my first project with xlib - by opfez - 29-07-2020, 01:17 PM