diff --git a/ChangeLog b/ChangeLog index 72fab8a711..c53f9c891e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3635,4 +3635,10 @@ * Config.mk: Defined DELIM to be either / or \, depending upon CONFIG_WINDOWS_NATIVE. This will allow me to eliminate a lot of conditional logic elsewhere. + * nuttx/graphics: One a mouse button is pressed, continue to report all + mouse button events to the first window that received the the initial + button down event, even if the mouse attempts to dray outside the + window. From Petteri Aimonen. + * nuttx/graphics/nxmu/nx_block.c: One more fixe to the NX block message + logic from Petteri Aimonen. diff --git a/graphics/nxmu/nx_block.c b/graphics/nxmu/nx_block.c index 3a051f9d7d..7b198613c6 100644 --- a/graphics/nxmu/nx_block.c +++ b/graphics/nxmu/nx_block.c @@ -140,7 +140,7 @@ int nx_block(NXWINDOW hwnd, FAR void *arg) * that it will not be blocked. */ - ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxbe_window_s)); + ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxsvrmsg_blocked_s)); } return ret; diff --git a/graphics/nxmu/nxmu_mouse.c b/graphics/nxmu/nxmu_mouse.c index 3ebe062d29..93441cc01f 100644 --- a/graphics/nxmu/nxmu_mouse.c +++ b/graphics/nxmu/nxmu_mouse.c @@ -61,9 +61,10 @@ * Private Data ****************************************************************************/ -static struct nxgl_point_s g_mpos; -static struct nxgl_point_s g_mrange; -static uint8_t g_mbutton; +static struct nxgl_point_s g_mpos; +static struct nxgl_point_s g_mrange; +static uint8_t g_mbutton; +static struct nxbe_window_s *g_mwnd; /**************************************************************************** * Public Data @@ -154,6 +155,7 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe, struct nxbe_window_s *wnd; nxgl_coord_t x = pos->x; nxgl_coord_t y = pos->y; + uint8_t oldbuttons; int ret; /* Clip x and y to within the bounding rectangle */ @@ -182,20 +184,36 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe, { /* Update the mouse value */ - g_mpos.x = x; - g_mpos.y = y; - g_mbutton = buttons; + oldbuttons = g_mbutton; + g_mpos.x = x; + g_mpos.y = y; + g_mbutton = buttons; - /* Pick the window to receive the mouse event. Start with - * the top window and go down. Stop with the first window - * that gets the mouse report + /* If a button is already down, regard this as part of a mouse drag + * event. Pass all the following events to the window where the drag + * started in. + */ + + if (oldbuttons && g_mwnd && g_mwnd->cb->mousein) + { + struct nxclimsg_mousein_s outmsg; + outmsg.msgid = NX_CLIMSG_MOUSEIN; + outmsg.wnd = g_mwnd; + outmsg.buttons = g_mbutton; + nxgl_vectsubtract(&outmsg.pos, &g_mpos, &g_mwnd->bounds.pt1); + + return nxmu_sendclient(g_mwnd->conn, &outmsg, sizeof(struct nxclimsg_mousein_s)); + } + + /* Pick the window to receive the mouse event. Start with the top + * window and go down. Stop with the first window that gets the mouse + * report */ for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) { - /* The background window normally has no callback structure - * (unless a client has taken control of the background via - * nx_requestbkgd()). + /* The background window normally has no callback structure (unless + * a client has taken control of the background via nx_requestbkgd()). */ if (wnd->cb) @@ -207,6 +225,8 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe, } } } + + g_mwnd = wnd; } return OK; diff --git a/graphics/nxsu/nx_mousein.c b/graphics/nxsu/nx_mousein.c index bee4a22650..5b268358bf 100644 --- a/graphics/nxsu/nx_mousein.c +++ b/graphics/nxsu/nx_mousein.c @@ -62,9 +62,10 @@ * Private Data ****************************************************************************/ -static struct nxgl_point_s g_mpos; -static struct nxgl_point_s g_mrange; -static uint8_t g_mbutton; +static struct nxgl_point_s g_mpos; +static struct nxgl_point_s g_mrange; +static uint8_t g_mbutton; +static struct nxbe_window_s *g_mwnd; /**************************************************************************** * Public Data @@ -148,6 +149,7 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) { FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle; struct nxbe_window_s *wnd; + uint8_t oldbuttons; int ret; /* Clip x and y to within the bounding rectangle */ @@ -176,13 +178,27 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) { /* Update the mouse value */ + oldbuttons = g_mbutton; g_mpos.x = x; g_mpos.y = y; g_mbutton = buttons; - /* Pick the window to receive the mouse event. Start with - * the top window and go down. Step with the first window - * that gets the mouse report + /* If a button is already down, regard this as part of a mouse drag + * event. Pass all the following events to the window where the drag + * started in. + */ + + if (oldbuttons && g_mwnd && g_mwnd->cb->mousein) + { + struct nxgl_point_s relpos; + nxgl_vectsubtract(&relpos, &g_mpos, &g_mwnd->bounds.pt1); + g_mwnd->cb->mousein((NXWINDOW)g_mwnd, &relpos, g_mbutton, g_mwnd->arg); + return OK; + } + + /* Pick the window to receive the mouse event. Start with the top + * window and go down. Step with the first window that gets the mouse + * report */ for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) @@ -193,6 +209,8 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) break; } } + + g_mwnd = wnd; } return OK; } diff --git a/graphics/nxtk/nxtk_events.c b/graphics/nxtk/nxtk_events.c index aaec16b5af..facf921762 100644 --- a/graphics/nxtk/nxtk_events.c +++ b/graphics/nxtk/nxtk_events.c @@ -261,9 +261,20 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, nxgl_vectoradd(&abspos, pos, &fwnd->wnd.bounds.pt1); + /* In order to deliver mouse release events to the same window where the + * mouse down event happened, we store the initial mouse down location. + */ + + if (fwnd->mbutton == 0 && buttons != 0) + { + fwnd->mpos = abspos; + } + + fwnd->mbutton = buttons; + /* Is the mouse position inside of the client window region? */ - if (fwnd->fwcb->mousein && nxgl_rectinside(&fwnd->fwrect, &abspos)) + if (fwnd->fwcb->mousein && nxgl_rectinside(&fwnd->fwrect, &fwnd->mpos)) { nxgl_vectsubtract(&relpos, &abspos, &fwnd->fwrect.pt1); fwnd->fwcb->mousein((NXTKWINDOW)fwnd, &relpos, buttons, fwnd->fwarg); @@ -271,7 +282,7 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, /* If the mouse position inside the toobar region? */ - else if (fwnd->tbcb->mousein && nxgl_rectinside(&fwnd->tbrect, &abspos)) + else if (fwnd->tbcb->mousein && nxgl_rectinside(&fwnd->tbrect, &fwnd->mpos)) { nxgl_vectsubtract(&relpos, &abspos, &fwnd->tbrect.pt1); fwnd->tbcb->mousein((NXTKWINDOW)fwnd, &relpos, buttons, fwnd->tbarg); diff --git a/graphics/nxtk/nxtk_internal.h b/graphics/nxtk/nxtk_internal.h index 87a098845a..3a31215d83 100644 --- a/graphics/nxtk/nxtk_internal.h +++ b/graphics/nxtk/nxtk_internal.h @@ -72,6 +72,11 @@ struct nxtk_framedwindow_s struct nxgl_rect_s fwrect; FAR const struct nx_callback_s *fwcb; FAR void *fwarg; + + /* Initial mouse down location */ + + uint8_t mbutton; + struct nxgl_point_s mpos; }; /****************************************************************************