graphics/nxmu, include/nuttx/nx/nxmu.h, libs/libnx: Add new server->client callback to notify the window client of server events. Remove the old 'blocked' callback and just make it one case of an 'event' callback.

This commit is contained in:
Gregory Nutt 2019-03-25 13:00:13 -06:00
parent 0fab8d014a
commit f5e8dc60f4
5 changed files with 72 additions and 41 deletions

View File

@ -138,20 +138,22 @@ static inline void nxmu_shutdown(FAR struct nxmu_state_s *fe)
}
/****************************************************************************
* Name: nxmu_blocked
* Name: nxmu_event
****************************************************************************/
static inline void nxmu_blocked(FAR struct nxbe_window_s *wnd, FAR void *arg)
static inline void nxmu_event(FAR struct nxbe_window_s *wnd,
enum nx_event_e event, FAR void *arg)
{
struct nxclimsg_blocked_s outmsg;
struct nxclimsg_event_s outmsg;
int ret;
outmsg.msgid = NX_CLIMSG_BLOCKED;
outmsg.msgid = NX_CLIMSG_EVENT;
outmsg.wnd = wnd;
outmsg.arg = arg;
outmsg.event = event;
ret = nxmu_sendclient(wnd->conn, &outmsg,
sizeof(struct nxclimsg_blocked_s));
sizeof(struct nxclimsg_event_s));
if (ret < 0)
{
gerr("ERROR: nxmu_sendclient failed: %d\n", ret);
@ -363,7 +365,7 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev)
case NX_SVRMSG_BLOCKED: /* Block messsages to a window */
{
FAR struct nxsvrmsg_blocked_s *blocked = (FAR struct nxsvrmsg_blocked_s *)buffer;
nxmu_blocked(blocked->wnd, blocked->arg);
nxmu_event(blocked->wnd, NXEVENT_BLOCKED, blocked->arg);
}
break;

View File

@ -96,6 +96,14 @@ typedef FAR void *NXWINDOW;
/* NX server callbacks ******************************************************/
/* Event callbacks */
enum nx_event_e
{
NXEVENT_BLOCKED = 0, /* Window messages are blocked */
NXEVENT_SYCNCHED, /* Synchronization handshake */
};
/* These define callbacks that must be provided to nx_openwindow. These
* callbacks will be invoked as part of the processing performed by
* nx_eventhandler()
@ -199,33 +207,51 @@ struct nx_callback_s
#endif
/**************************************************************************
* Name: blocked
* Name: event
*
* Description:
* This callback is the response from nx_block (or nxtk_block). Those
* blocking interfaces are used to assure that no further messages are
* directed to the window. Receipt of the blocked callback signifies
* that (1) there are no further pending callbacks and (2) that the
* window is now 'defunct' and will receive no further callbacks.
* This callback is used to communicate server events to the window
* listener.
*
* This callback supports coordinated destruction of a window. In
* the multi-user mode, the client window logic must stay intact until
* all of the queued callbacks are processed. Then the window may be
* safely closed. Closing the window prior with pending callbacks can
* lead to bad behavior when the callback is executed.
* NXEVENT_BLOCKED - Window messages are blocked.
*
* This callback is the response from nx_block (or nxtk_block). Those
* blocking interfaces are used to assure that no further messages are
* directed to the window. Receipt of the blocked callback signifies
* that (1) there are no further pending callbacks and (2) that the
* window is now 'defunct' and will receive no further callbacks.
*
* This callback supports coordinated destruction of a window. In
* the multi-user mode, the client window logic must stay intact until
* all of the queued callbacks are processed. Then the window may be
* safely closed. Closing the window prior with pending callbacks can
* lead to bad behavior when the callback is executed.
*
* NXEVENT_SYCNCHED - Synchronization handshake
*
* This completes the handshake started by nx_synch(). nx_synch()
* sends a syncrhonization messages to the NX server which responds
* with this event. The sleeping client is awakened and continues
* graphics processing, completing the handshake.
*
* Due to the highly asynchronous nature of client-server
* communications, nx_synch() is sometimes necessary to assure that
* the client and server are fully synchronized.
*
* Input Parameters:
* hwnd - Window handle of the blocked window
* arg1 - User provided argument (see nx_openwindow, nx_requestbkgd,
* nxtk_openwindow, or nxtk_opentoolbar)
* arg2 - User provided argument (see nx_block or nxtk_block)
* hwnd - Window handle of the blocked window
* event - The server event
* arg1 - User provided argument (see nx_openwindow, nx_requestbkgd,
* nxtk_openwindow, or nxtk_opentoolbar)
* arg2 - User provided argument (see nx_block or nxtk_block)
*
* Returned Value:
* None
*
**************************************************************************/
void (*blocked)(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2);
void (*event)(NXWINDOW hwnd, enum nx_event_e event, FAR void *arg1,
FAR void *arg2);
};
/****************************************************************************

View File

@ -130,7 +130,7 @@ enum nxmsg_e
NX_CLIMSG_NEWPOSITION, /* New window size/position */
NX_CLIMSG_MOUSEIN, /* New mouse positional data available for window */
NX_CLIMSG_KBDIN, /* New keypad input available for window */
NX_CLIMSG_BLOCKED, /* The window is blocked */
NX_CLIMSG_EVENT, /* Server->client event */
/* Client-to-Server Messages **********************************************/
@ -229,15 +229,14 @@ struct nxclimsg_kbdin_s
};
#endif
/* This message confirms that that all queued window messages have been
* flushed and that the all further window messages are blocked.
*/
/* This message provides server event notifications to the client. */
struct nxclimsg_blocked_s
struct nxclimsg_event_s
{
uint32_t msgid; /* NX_CLIMSG_BLOCKED */
FAR struct nxbe_window_s *wnd; /* The window that is blocked */
FAR void *arg; /* User argument */
enum nx_event_e event; /* Server event */
};
/* Client-to-Server Message Structures **************************************/

View File

@ -1,7 +1,8 @@
/****************************************************************************
* libs/libnx/nxmu/nx_eventhandler.c
*
* Copyright (C) 2008-2009, 2011-2013, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009, 2011-2013, 2017, 2019 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -229,14 +230,14 @@ int nx_eventhandler(NXHANDLE handle)
break;
#endif
case NX_CLIMSG_BLOCKED:
case NX_CLIMSG_EVENT:
{
FAR struct nxclimsg_blocked_s *blocked = (FAR struct nxclimsg_blocked_s *)buffer;
wnd = blocked->wnd;
FAR struct nxclimsg_event_s *event = (FAR struct nxclimsg_event_s *)buffer;
wnd = event->wnd;
DEBUGASSERT(wnd);
if (wnd->cb->blocked)
if (wnd->cb->event)
{
wnd->cb->blocked((NXWINDOW)wnd, wnd->arg, blocked->arg);
wnd->cb->event((NXWINDOW)wnd, event->event, wnd->arg, event->arg);
}
}
break;

View File

@ -1,7 +1,8 @@
/****************************************************************************
* libs/libnx/nxtk/nxtk_events.c
*
* Copyright (C) 2008-2009, 2012, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009, 2012, 2017, 2019 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -68,7 +69,8 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
static void nxtk_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch,
FAR void *arg);
#endif
static void nxtk_blocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2);
static void nxtk_event(NXWINDOW hwnd, enum nx_event_e event,
FAR void *arg1, FAR void *arg2);
/****************************************************************************
* Public Data
@ -84,7 +86,7 @@ const struct nx_callback_s g_nxtkcb =
#ifdef CONFIG_NX_KBD
, nxtk_kbdin /* kbdin */
#endif
, nxtk_blocked /* blocked */
, nxtk_event /* event */
};
/****************************************************************************
@ -290,18 +292,19 @@ static void nxtk_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch,
#endif
/****************************************************************************
* Name: nxtk_blocked
* Name: nxtk_event
****************************************************************************/
static void nxtk_blocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2)
static void nxtk_event(NXWINDOW hwnd, enum nx_event_e event,
FAR void *arg1, FAR void *arg2)
{
FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hwnd;
/* Only the client window gets keyboard input */
/* Forward the event to the window client */
if (fwnd->fwcb->blocked)
if (fwnd->fwcb->event != NULL)
{
fwnd->fwcb->blocked((NXTKWINDOW)fwnd, fwnd->fwarg, arg2);
fwnd->fwcb->event((NXTKWINDOW)fwnd, event, fwnd->fwarg, arg2);
}
}