bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

windows move and subwindows coordinates


From: Pavel Stehule
Subject: windows move and subwindows coordinates
Date: Tue, 25 Feb 2020 13:50:04 +0100

Hi

in ncurses_st_menu I have to use one ugly hack. I would to know if it is known bug or not.

I use a windows (panels) and subwindow. Sometimes I had to detect if mouse was pressed inside subwindow. I use a function wenclose(subwindow, y, x). But for this function I have to do correction  of y, x when parent windows (of subwindow) was moved.

my code:

add_correction(menu->draw_area, &y, &x);
if (wenclose(menu->draw_area, y, x))  { ... }


/*
 * The coordinates of subwin are not "correctly" refreshed, when
 * parent panel is moved. Maybe it is bug in ncurses, maybe not.
 * The new coordinates are calculated from parent and offset to parent
 * and difference between new and old coordinates is applyed on
 * x, y points.
 */
static void
add_correction(WINDOW *s, int *y, int *x)
{
    WINDOW *p = wgetparent(s);
    /*
     * Note: function is_subwin is unknown on some
     * older ncurses implementations. Don't use it.
     */
    if (p)
    {
        int py, px, sy, sx, oy, ox;
        int fix_y, fix_x;

        getbegyx(p, py, px);
        getbegyx(s, sy, sx);
        getparyx(s, oy, ox);

        fix_y = sy - (py + oy);
        fix_x = sx - (px + ox);

        *y += fix_y;
        *x += fix_x;
    }
}

This code looks very strange, but it is working, across all used ncurses libraries.

Is it known behave?

Original code https://github.com/okbob/ncurses-st-menu/blob/master/src/st_menu.c

Regards

Pavel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]