Multi-user graphics front-end

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1325 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2008-11-28 14:42:52 +00:00
parent 604c94dce8
commit 43d77227a0
27 changed files with 4082 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
############################################################################
# graphics/nxmu/Make.defs
#
# Copyright (C) 2008 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
NX_ASRCS =
NXAPI_CSRCS = nx_bitmap.c nx_connect.c nx_disconnect.c nx_eventhandler.c \
nx_fill.c nx_filltrapezoid.c nx_getposition.c nx_kbdchin.c \
nx_kbdin.c nx_lower.c nx_mousein.c nx_move.c nx_openwindow.c \
nx_raise.c nx_setsize.c nx_setbgcolor.c nx_setposition.c
NXMU_CSRCS = nxmu_server.c nxmu_openwindow.c nxmu_reportposition.c nxmu_kbdin.c \
nxmu_mouse.c nxmu_redrawreq.c nxmu_semtake.c
NX_CSRCS = $(NXAPI_CSRCS) $(NXMU_CSRCS)
+137
View File
@@ -0,0 +1,137 @@
/****************************************************************************
* graphics/nxmu/nx_bitmap.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxbe.h"
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_bitmap
*
* Description:
* Copy a rectangular region of a larger image into the rectangle in the
* specified window.
*
* Input Parameters:
* hwnd - The window that will receive the bitmap image
* dest - Describes the rectangular region on the display that will receive the
* the bit map.
* src - The start of the source image.
* origin - The origin of the upper, left-most corner of the full bitmap.
* Both dest and origin are in window coordinates, however, origin
* may lie outside of the display.
* stride - The width of the full source image in pixels.
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest,
FAR const void *src[CONFIG_NX_NPLANES],
FAR const struct nxgl_point_s *origin, unsigned int stride)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_bitmap_s outmsg;
int ret;
int i;
#ifdef CONFIG_DEBUG
if (!wnd || !wnd->conn || !dest || !src || !origin)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Format the bitmap command */
outmsg.msgid = NX_SVRMSG_BITMAP;
outmsg.wnd = wnd;
outmsg.stride = stride;
for (i = 0; i < CONFIG_NX_NPLANES; i++)
{
outmsg.src[i] = src[i];
}
outmsg.origin.x = origin->x;
outmsg.origin.y = origin->y;
nxgl_rectcopy(&outmsg.dest, dest);
/* Forward the fill command to the server */
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_bitmap_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+107
View File
@@ -0,0 +1,107 @@
/****************************************************************************
* graphics/nxmu/nx_closewindow.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdlib.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_closewindow
*
* Description:
* Destroy a window created by nx_openwindow.
*
* Input Parameters:
* wnd - The window to be destroyed
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_closewindow(NXWINDOW hwnd)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_closewindow_s outmsg;
int ret;
/* Request destruction of the window by the serer */
outmsg.msgid = NX_SVRMSG_CLOSEWINDOW;
outmsg.wnd = wnd;
ret = mq_send(conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_closewindow_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+220
View File
@@ -0,0 +1,220 @@
/****************************************************************************
* graphics/nxmu/nx_connect.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <mqueue.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/* Each client is assigned a unique ID using the g_nxcid counter. That
* counter increments as each new counter is created and is* protected for
* thread safefy with g_nxlibsem. Note that these are the only global values
* in the NX implementation. This is because the client ID must be unique
* even across all server instances.
*
* NOTE: that client ID 0 is reserved for the server(s) themselves
*/
static sem_t g_nxlibsem = { 1 };
static uint32 g_nxcid = 1;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_connectinstance
*
* Description:
* Open a connection from a client to the NX server. One one client
* connection is normally needed per thread as each connection can host
* multiple windows.
*
* NOTE that multiple instances of the NX server may run at the same time,
* each with different message queue names.
*
* Input Parameters:
* svrmqname - The name for the server incoming message queue
* cb - Callbacks used to process received NX server messages
*
* Return:
* Success: A non-NULL handle used with subsequent NX accesses
* Failure: NULL is returned and errno is set appropriately
*
****************************************************************************/
NXHANDLE nx_connectionstance(FAR const char *svrmqname,
FAR const struct nx_callback_s *cb)
{
FAR struct nxfe_conn_s *conn;
struct nxsvrmsg_s msg;
char climqname[NX_CLIENT_MXNAMELEN];
struct mq_attr attr;
int ret;
/* Sanity checking */
#ifdef CONFIG_DEBUG
if (!svrmqname || !cb)
{
errno = EINVAL;
return NULL;
}
#endif
/* Allocate the NX client structure */
conn = (FAR struct nxfe_conn_s *)zalloc(sizeof(struct nxfe_conn_s));
if (!conn)
{
errno = ENOMEM;
goto errout;
}
/* Save the callback vtable */
conn->cb = cb;
/* Create the client MQ name */
nxmu_semtake(&g_nxlibsem);
conn->cid = g_nxcid++;
nxmu_semgive(&g_nxlibsem);
sprintf(climqname, NX_CLIENT_MQNAMEFMT, conn->cid);
/* Open the client MQ for reading */
attr.mq_maxmsg = CONFIG_NX_MXCLIENTMSGS;
attr.mq_msgsize = NX_MXCLIMSGLEN;
attr.mq_flags = 0;
#ifdef CONFIG_NX_BLOCKING
conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT, 0666, &attr);
#else
conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT|O_NONBLOCK, 0666, &attr);
#endif
if (conn->crdmq)
{
gdbg("mq_open(%s) failed: %d\n", climqname, errno);
goto errout_with_conn;
}
/* Open the server MQ for writing */
attr.mq_maxmsg = CONFIG_NX_MXSERVERMSGS;
attr.mq_msgsize = NX_MXSVRMSGLEN;
attr.mq_flags = 0;
conn->cwrmq = mq_open(svrmqname, O_WRONLY|O_CREAT, 0666, &attr);
if (conn->cwrmq)
{
gdbg("mq_open(%s) failed: %d\n", svrmqname, errno);
goto errout_with_rmq;
}
/* Inform the server that this client exists */
msg.msgid = NX_SVRMSG_CONNECT;
msg.conn = conn;
ret = mq_send(conn->cwrmq, &msg, sizeof(struct nxsvrmsg_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
goto errout_with_wmq;
}
/* Now read until we get a response to this message. The server will
* respond with either (1) NX_CLIMSG_CONNECTED, in which case the state
* will change to NX_CLISTATE_CONNECTED, or (2) NX_CLIMSG_DISCONNECTED
* in which case, nx_message will fail with errno = EHOSTDOWN.
*/
do
{
ret = nx_eventhandler((NXHANDLE)conn);
if (ret < 0)
{
gdbg("nx_message failed: %d\n", errno);
goto errout_with_wmq;
}
}
while (conn->state != NX_CLISTATE_CONNECTED);
return (NXHANDLE)conn;
errout_with_wmq:
mq_close(conn->cwrmq);
errout_with_rmq:
mq_close(conn->crdmq);
errout_with_conn:
free(conn);
errout:
return NULL;
}
+109
View File
@@ -0,0 +1,109 @@
/****************************************************************************
* graphics/nxmu/nx_disconnect.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <mqueue.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_disconnect
*
* Description:
* Disconnect a client from the NX server and/or free resources reserved
* by nx_connect/nx_connectinstance.
*
* Input Parameters:
* handle - the handle returned by nx_connect
*
* Return:
* OK on success; ERROR on failure with the errno set appropriately.
* NOTE that handle will no long be valid upon return.
*
****************************************************************************/
void nx_disconnect(NXHANDLE handle)
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
struct nxsvrmsg_s msg;
int ret;
/* Inform the server that this client no longer exists */
msg.msgid = NX_SVRMSG_CONNECT;
msg.conn = conn;
ret = mq_send(conn->cwrmq, &msg, sizeof(struct nxsvrmsg_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
/* We will finish the teardown upon receipt of the DISCONNECTED message */
}
+224
View File
@@ -0,0 +1,224 @@
/****************************************************************************
* graphics/nxmu/nx_eventhandler.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdlib.h>
#include <mqueue.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nx_connected
*
* Description:
* The server has completed the connection and is ready.
*
****************************************************************************/
static inline void nx_connected(FAR struct nxfe_conn_s *conn)
{
DEBUGASSERT(conn->state == NX_CLISTATE_NOTCONNECTED);
conn->state = NX_CLISTATE_CONNECTED;
}
/****************************************************************************
* Name: nx_disconnected
****************************************************************************/
static inline void nx_disconnected(FAR struct nxfe_conn_s *conn)
{
/* Close the server and client MQs */
(void)mq_close(conn->cwrmq);
(void)mq_close(conn->crdmq);
/* And free the client structure */
free(conn);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_eventhandler
*
* Description:
* The client code must call this function periodically to process
* incoming messages from the server.
*
* Input Parameters:
* handle - the handle returned by nx_connect
*
* Return:
* >0: The length of the message received in msgbuffer
* 0: No message was received
* <0: An error occurred and errno has been set appropriately
*
* Of particular interest, it will return errno == EHOSTDOWN when the
* server is disconnected. After that event, the handle can not longer
* be used.
*
****************************************************************************/
int nx_eventhandler(NXHANDLE handle)
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
struct nxsvrmsg_s *msg;
ubyte buffer[NX_MXCLIMSGLEN];
int nbytes;
/* Get the next message from our incoming message queue */
do
{
nbytes = mq_receive(conn->crdmq, buffer, NX_MXCLIMSGLEN, 0);
if (nbytes < 0)
{
/* EINTR is not an error. The wait was interrupted by a signal and
* we just need to try reading again.
*/
if (errno != EINTR)
{
if (errno == EAGAIN)
{
/* EAGAIN is not an error. It occurs because the MQ is opened with
* O_NONBLOCK and there is no message available now.
*/
return OK;
}
else
{
gdbg("mq_receive failed: %d\n", errno);
return ERROR;
}
}
}
}
while (nbytes < 0);
DEBUGASSERT(nbytes >= sizeof(struct nxclimsg_s));
/* Dispatch the message appropriately */
msg = (struct nxsvrmsg_s *)buffer;
switch (msg->msgid)
{
case NX_SVRMSG_CONNECT:
nx_connected(conn);
break;
case NX_SVRMSG_DISCONNECT:
nx_disconnected(conn);
errno = EHOSTDOWN;
return ERROR;
case NX_CLIMSG_REDRAW:
if (conn->cb->redraw)
{
FAR struct nxclimsg_redraw_s *redraw = (FAR struct nxclimsg_redraw_s *)buffer;
conn->cb->redraw((NXWINDOW)redraw->wnd, &redraw->rect, redraw->more);
}
break;
case NX_CLIMSG_NEWPOSITION:
if (conn->cb->position)
{
FAR struct nxclimsg_newposition_s *postn = (FAR struct nxclimsg_newposition_s *)buffer;
conn->cb->position((NXWINDOW)postn->wnd, &postn->size, &postn->pos);
}
break;
#ifdef CONFIG_NX_KBD
case NX_CLIMSG_MOUSEIN:
if (conn->cb->mousein)
{
FAR struct nxclimsg_mousein_s *mouse = (FAR struct nxclimsg_mousein_s *)buffer;
conn->cb->mousein((NXWINDOW)mouse->wnd, &mouse->pos, mouse->buttons);
}
break;
#endif
#ifdef CONFIG_NX_KBD
case NX_CLIMSG_KBDIN:
if (conn->cb->kbdin)
{
FAR struct nxclimsg_kbdin_s *kbd = (FAR struct nxclimsg_kbdin_s *)buffer;
conn->cb->kbdin((NXWINDOW)kbd->wnd, kbd->nch, kbd->ch);
}
break;
#endif
default:
gdbg("Unrecogized message opcode: %d\n", (FAR struct nxsvrmsg_s *)buffer->msgid);
break;
}
return OK;
}
+127
View File
@@ -0,0 +1,127 @@
/****************************************************************************
* graphics/nxmu/nx_fill.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <mqueue.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_fill
*
* Description:
* Fill the specified rectangle in the window with the specified color
*
* Input Parameters:
* hwnd - The window handle
* rect - The location to be filled
* color - The color to use in the fill
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_fill(NXWINDOW hwnd, FAR struct nxgl_rect_s *rect,
nxgl_mxpixel_t color[CONFIG_NX_NPLANES])
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_fill_s outmsg;
int ret;
int i;
#ifdef CONFIG_DEBUG
if (!wnd || !wnd->conn || !rect || !color)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Format the fill command */
outmsg.msgid = NX_SVRMSG_FILL;
outmsg.wnd = wnd;
nxgl_rectcopy(&outmsg.rect, rect);
for (i = 0; i < CONFIG_NX_NPLANES; i++)
{
outmsg.color[i] = color[i];
}
/* Forward the fill command to the server */
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_fill_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+128
View File
@@ -0,0 +1,128 @@
/****************************************************************************
* graphics/nxmu/nx_filltrapezoid.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <mqueue.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_filltrapezoid
*
* Description:
* Fill the specified trapezoidal region in the window with the specified color
*
* Input Parameters:
* hwnd - The window handle
* trap - The trapezoidal region to be filled
* color - The color to use in the fill
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_filltrapezoid(NXWINDOW hwnd, FAR struct nxgl_trapezoid_s *trap,
nxgl_mxpixel_t color[CONFIG_NX_NPLANES])
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_filltrapezoid_s outmsg;
int ret;
int i;
#ifdef CONFIG_DEBUG
if (!wnd || !wnd->conn || !trap || !color)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Format the fill command */
outmsg.msgid = NX_SVRMSG_FILLTRAP;
outmsg.wnd = wnd;
nxgl_trapcopy(&outmsg.trap, trap);
for (i = 0; i < CONFIG_NX_NPLANES; i++)
{
outmsg.color[i] = color[i];
}
/* Forward the fill command to the server */
ret = mq_send(wnd->conn->cwrmq, &outmsg,
sizeof(struct nxsvrmsg_filltrapezoid_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+123
View File
@@ -0,0 +1,123 @@
/****************************************************************************
* graphics/nxmu/nx_getposition.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_getposition
*
* Description:
* Request the position and size information for the selected window. The
* values will be return asynchronously through the client callback function
* pointer.
*
* Input Parameters:
* hwnd - The window handle
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_getposition(NXWINDOW hwnd)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_getposition_s outmsg;
int ret;
#ifdef CONFIG_DEBUG
if (!wnd)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Request the size/position info.
*
* It is tempting to just take the positional information from the window
* structure that we have in our hands now. However, we need to run this through
* the server to keep things serialized. There might, for example, be a pending
* size/position change and, in that case, this function would return the
* wrong info.
*/
outmsg.msgid = NX_SVRMSG_GETPOSITION;
outmsg.wnd = wnd;
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_getposition_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
return ERROR;
}
return OK;
}
+105
View File
@@ -0,0 +1,105 @@
/****************************************************************************
* graphics/nxmu/nx_kbdchin.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
#ifdef CONFIG_NX_KBD
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_kbdchin
*
* Description:
* Used by a thread or interrupt handler that manages some kind of keypad
* hardware to report text information to the NX server. That text
* data will be routed by the NX server to the appropriate window client.
*
****************************************************************************/
int nx_kbdchin(NXHANDLE handle, ubyte ch)
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
struct nxsvrmsg_kbdin_s outmsg;
int ret;
/* Inform the server of the new keypad data */
outmsg.msgid = NX_SVRMSG_KBDIN;
outmsg.nch = 1;
outmsg.ch[0] = ch;
ret = mq_send(conn->c_cwrmq, &outmsg, sizeof(struct nxsvrmsg_kbdin_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
#endif /* CONFIG_NX_KBD */
+125
View File
@@ -0,0 +1,125 @@
/****************************************************************************
* graphics/nxmu/nx_kbdin.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
#ifdef CONFIG_NX_KBD
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_kbdin
*
* Description:
* Used by a thread or interrupt handler that manages some kind of keypad
* hardware to report text information to the NX server. That text
* data will be routed by the NX server to the appropriate window client.
*
****************************************************************************/
int int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch)
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
FAR struct nxsvrmsg_kbdin_s *outmsg;
int size;
int ret;
int i;
/* Allocate a bigger message to account for the variable amount of character
* data.
*/
size = sizeof(struct nxsvrmsg_kbdin_s) + nch - 1;
outmsg = (FAR struct nxsvrmsg_kbdin_s *)malloc(size);
if (!outmsg)
{
errno = ENOMEM;
return ERROR;
}
/* Inform the server of the new keypad data */
outsg->msgid = NX_SVRMSG_KBDIN;
outmsg->nch = nch;
for (i = 0; i < nch; i+)
{
outmsg->ch[i] = ch[i];
}
ret = mq_send(conn->c_cwrmq, outmsg, size, NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
free(outmsg);
return ret;
}
#endif /* CONFIG_NX_KBD */
+105
View File
@@ -0,0 +1,105 @@
/****************************************************************************
* graphics/nxmu/nx_lower.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_raise
*
* Description:
* Lower the specified window to the bottom of the display.
*
* Input parameters:
* hwnd - the window to be lowered
*
* Returned value:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_lower(NXWINDOW hwnd)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_lower_s outmsg;
int ret;
/* Send the RAISE message */
outmsg.msgid = NX_SVRMSG_LOWER;
outmsg.wnd = wnd;
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_lower_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+106
View File
@@ -0,0 +1,106 @@
/****************************************************************************
* graphics/nxmu/nx_mousein.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
#ifdef CONFIG_NX_MOUSE
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_mousein
*
* Description:
* Used by a thread or interrupt handler that manages some kind of pointing
* hardware to report new positional data to the NX server. That positional
* data will be routed by the NX server to the appropriate window client.
*
****************************************************************************/
int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, ubyte buttons)
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
struct nxsvrmsg_mousein_s outmsg;
int ret;
/* Inform the server that this client no longer exists */
msg.msgid = NX_SVRMSG_MOUSEIN;
msg.pt.x = x;
msg.pt.y = y;
msg.buttons = buttons;
ret = mq_send(conn->c_cwrmq, &outmsg, sizeof(struct nxsvrmsg_mousein_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
#endif /* CONFIG_NX_MOUSE */
+121
View File
@@ -0,0 +1,121 @@
/****************************************************************************
* graphics/nxmu/nx_move.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_move
*
* Description:
* Move a rectangular region within the window
*
* Input Parameters:
* hwnd - The window within which the move is to be done
* rect - Describes the rectangular region to move
* offset - The offset to move the region
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_move(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
FAR const struct nxgl_point_s *offset)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_move_s outmsg;
int ret;
#ifdef CONFIG_DEBUG
if (!wnd || !wnd->conn)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Format the fill command */
outmsg.msgid = NX_SVRMSG_FILL;
outmsg.wnd = wnd;
outmsg.offset.x = offset->x;
outmsg.offset.y = offset->y;
nxgl_rectcopy(&outmsg.rect, rect);
/* Forward the fill command to the server */
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_move_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+127
View File
@@ -0,0 +1,127 @@
/****************************************************************************
* graphics/nxmu/nx_openwindow.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdlib.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_openwindow
*
* Description:
* Create a new window.
*
* Input Parameters:
* handle - The handle returned by nx_connect
* wnd - Location to return the handle of the new window
*
* Return:
* Success: A non-NULL handle used with subsequent NX accesses
* Failure: NULL is returned and errno is set appropriately
*
****************************************************************************/
NXWINDOW nx_openwindow(NXHANDLE handle)
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
FAR struct nxbe_window_s *wnd;
struct nxsvrmsg_openwindow_s outmsg;
int ret;
/* Pre-allocate the window structure */
wnd = (FAR struct nxbe_window_s *)zalloc(sizeof(struct nxbe_window_s));
if (!wnd)
{
errno = ENOMEM;
return NULL;
}
/* Request initialization the new window from the server */
outmsg.msgid = NX_SVRMSG_OPENWINDOW;
outmsg.conn = conn;
outmsg.wnd = wnd;
ret = mq_send(conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_openwindow_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
free(wnd);
return NULL;
}
/* Return the uninitialized window reference. Since the server
* serializes all operations, we can be assured that the window will
* be initialized before the first operation on the window.
*/
return (NXWINDOW)wnd;
}
+105
View File
@@ -0,0 +1,105 @@
/****************************************************************************
* graphics/nxmu/nx_raise.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_raise
*
* Description:
* Bring the specified window to the top of the display.
*
* Input parameters:
* hwnd - the window to be raised
*
* Returned value:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_raise(NXWINDOW hwnd)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_raise_s outmsg;
int ret;
/* Send the RAISE message */
outmsg.msgid = NX_SVRMSG_RAISE;
outmsg.wnd = wnd;
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_raise_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+121
View File
@@ -0,0 +1,121 @@
/****************************************************************************
* graphics/nxmu/nx_setbgcolor.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_setbgcolor
*
* Description:
* Set the color of the background
*
* Input Parameters:
* handle - The connection handle
* color - The color to use in the background
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_setbgcolor(NXHANDLE handle,
nxgl_mxpixel_t color[CONFIG_NX_NPLANES])
{
FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
struct nxsvrmsg_setbgcolor_s outmsg;
int ret;
int i;
#ifdef CONFIG_DEBUG
if (!conn)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Format the fill command */
outmsg.msgid = NX_SVRMSG_SETBGCOLOR;
for (i = 0; i < CONFIG_NX_NPLANES; i++)
{
outmsg.color[i] = color[i];
}
/* Forward the fill command to the server */
ret = mq_send(conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_setbgcolor_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
return ret;
}
+117
View File
@@ -0,0 +1,117 @@
/****************************************************************************
* graphics/nxmu/nx_setposition.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_setposition
*
* Description:
* Set the position and size for the selected window
*
* Input Parameters:
* hwnd - The window handle
* pos - The new position of the window
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_setposition(NXWINDOW hwnd, FAR struct nxgl_point_s *pos)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_setposition_s outmsg;
int ret;
#ifdef CONFIG_DEBUG
if (!wnd || !pos)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Inform the server of the changed position */
outmsg.msgid = NX_SVRMSG_SETPOSITION;
outmsg.wnd = wnd;
outmsg.pos.x = pos->x;
outmsg.pos.y = pos->y;
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_setposition_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
return ERROR;
}
return OK;
}
+116
View File
@@ -0,0 +1,116 @@
/****************************************************************************
* graphics/nxmu/nx_setsize.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_setsize`
*
* Description:
* Set the size of the selected window
*
* Input Parameters:
* hwnd - The window handle
* size - The new size of the window.
*
* Return:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_rect_s *size)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_setsize_s outmsg;
int ret;
#ifdef CONFIG_DEBUG
if (!wnd || !size)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Then inform the server of the changed position */
outmsg.msgid = NX_SVRMSG_SETSIZE;
outmsg.wnd = wnd;
nxgl_rectcopy(&outmsg.size, size);
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_setsize_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
return ERROR;
}
return OK;
}
File diff suppressed because it is too large Load Diff
+122
View File
@@ -0,0 +1,122 @@
/****************************************************************************
* graphics/nxmu/nxmu_kbdin.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
#ifdef CONFIG_NX_KBD
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxmu_kbdin
*
* Descripton:
* New keyboard data has been received from the thread or interrupt
* handler that manages some kind of keyboard/keypad hardware. Route that
* positional data to the appropriate window client.
*
****************************************************************************/
void nxmu_kbdin(FAR struct nxs_server_s *svr, ubyte nch, ubyte *ch)
{
struct nxbe_window_s *wnd;
FAR struct nxclimgs_kbdin_s *outmsg;
int size;
int ret;
int i;
/* Allocate a bigger message to account for the variable amount of
* character data.
*/
size = sizeof(struct nxclimgs_kbdin_s) + nch - 1;
outmsg = (FAR struct nxclimgs_kbdin_s *)malloc(size);
if (outmsg)
{
/* Give the keypad input only to the top child */
outsg->msgid = NX_SVRMSG_KBDIN;
outmsg->wnd = svr->topwnd;
outmsg->nch = nch;
for (i = 0; i < nch; i+)
{
outmsg->ch[i] = ch[i];
}
ret = mq_send(svr->topwnd->conn->swrmq, outmsg, size, NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
free(outmsg);
}
}
#endif /* CONFIG_NX_KBD */
+178
View File
@@ -0,0 +1,178 @@
/****************************************************************************
* graphics/nxmu/nxmu__mouse.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
#ifdef CONFIG_NX_MOUSE
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static struct nxgl_point_s g_mpos;
static struct nxgl_rect_s g_mrange;
static struct g_mbutton;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxmu_mouseinit
*
* Description:
* Initialize with the mouse in the center of the display
*
****************************************************************************/
void nxmu_mouseinit(int x, int y)
{
g_mrange.x = x;
g_mrange.y = y;
g_mpos.x = x / 2;
g_mpos.y = y / 2;
g_mbutton = 0;
}
/****************************************************************************
* Name: nxmu_mousereport
*
* Description:
* Report mouse position info to the specified window
*
****************************************************************************/
void nxmu_mousereport(struct nxbe_window_s *wnd)
{
struct nxclimsg_mousein_s outmsg;
int ret;
outmsg.msgid = NX_CLIMSG_MOUSEIN;
outmsg.wnd = wnd;
outmsg.pos.x = g_mpos.x;
outmsg.pos.y = g_mpos.y;
outmsg.buttons = g_mbutton;
ret = mq_send(wnd->conn->swrmq, outmsg, sizeof(struct nxclimsg_mousein_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
}
/****************************************************************************
* Name: nxmu_mousein
*
* Description:
* New positional data has been received from the thread or interrupt
* handler that manages some kind of pointing hardware. Route that
* positional data to the appropriate window client.
*
****************************************************************************/
void nxmu_mousein(FAR struct nxfe_state_s *fe,
FAR const struct nxgl_point_s *pos, int button)
{
struct nxbe_window_s *wnd;
x_coord_t x = pos->x;
x_coord_t y = pos->y;
/* Clip x and y to within the bounding rectangle */
if (x < 0)
{
x = 0;
}
else if (x >= g_mbound.x)
{
x = g_mbound.x - 1;
}
if (y < 0)
{
y = 0;
}
else if (y >= g_mbound.y)
{
y = g_mbound.y - 1;
}
/* Look any change in values */
if (x != g_mpos.x || y != g_mpos.y || button != g_mbutton)
{
/* Update the mouse value */
g_mpos.x = x;
g_mpos.y = y;
b_mbutton = button;
/* Pick the window to receive the mouse event */
for (wnd = fe->be.topwnd; wnd; wnd = wnd->below)
{
nxmu_mousereport(wnd);
}
}
}
#endif /* CONFIG_NX_MOUSE */
+113
View File
@@ -0,0 +1,113 @@
/****************************************************************************
* graphics/nxmu/nxmu_openwindow.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxmu_openwindow
*
* Description:
* Create a new window.
*
* Input Parameters:
* conn - The client containing connection information [IN]
* be - The server state structure [IN]
* wnd - The pre-allocated window structure to be ininitilized [IN/OUT]
*
* Return:
* None
*
****************************************************************************/
void nxsmu_openwindow(FAR struct nxfe_conn_s *conn,
FAR struct nxbe_state_s *be,
FAR struct nxbe_window_s *wnd)
{
/* The window structure was allocated in nx_openwindow and all fields have
* been set to zero (except sem... see below). We need only initialize the
* the non zero fields and insert the new window.
*/
wnd->be = be;
wnd->conn = conn;
/* Now, insert the new window at the top on the display. topwind is
* never NULL (it may point only at the background window, however)
*/
wnd->above = NULL;
wnd->below = be->topwnd;
be->topwnd->above = wnd;
be->topwnd = wnd;
/* Provide the initial mouse settings */
#ifdef CONFIG_NX_MOUSE
nxmu_mousereport(wnd);
#endif
}
+98
View File
@@ -0,0 +1,98 @@
/****************************************************************************
* graphics/nxmu/nxmu_redrawreq.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxfe_redrawreq
*
* Descripton:
* Request the client that has this window to redraw the rectangular region.
*
****************************************************************************/
void nxfe_redrawreq(FAR struct nxbe_window_s *wnd, FAR const struct nxgl_rect_s *rect)
{
struct nxclimsg_redraw_s outmsg;
int ret;
outmsg.msgid = NX_CLIMSG_REDRAW;
outmsg.wnd = wnd;
outmsg.more = FALSE;
nxgl_rectoffset(&outmsg.rect, rect, -wnd->origin.x, -wnd->origin.y);
ret = mq_send(wnd->conn->swrmq, &outmsg, sizeof(struct nxclimsg_redraw_s), NX_CLIMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
}
+104
View File
@@ -0,0 +1,104 @@
/****************************************************************************
* graphics/nxmu/nxmu_reportposition.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxfe_reportposition
*
* Descripton:
* Report the new size/position of the window.
*
****************************************************************************/
void nxfe_reportposition(FAR struct nxbe_window_s *wnd)
{
FAR struct nxclimsg_newposition_s outmsg;
int ret;
/* Send the size/position info */
outmsg.msgid = NX_CLIMSG_NEWPOSITION;
outmsg.wnd = wnd;
outmsg.pos.x = wnd->origin.x;
outmsg.pos.y = wnd->origin.y;
/* Convert the frame rectangle to a window-relative rectangle */
nxgl_rectoffset(&outmsg.size, &wnd->bounds, -wnd->origin.x, -wnd->origin.y);
/* And provide this to the client */
ret = mq_send(wnd->conn->swrmq, &outmsg, sizeof(struct nxclimsg_newposition_s), NX_SVRMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
}
+88
View File
@@ -0,0 +1,88 @@
/****************************************************************************
* graphics/nxmu/nxmu_semtake.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxmu_semtake
****************************************************************************/
void nxmu_semtake(sem_t *sem)
{
while (sem_wait(sem) != 0)
{
/* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/
ASSERT(errno == EINTR);
}
}
+499
View File
@@ -0,0 +1,499 @@
/****************************************************************************
* graphics/nxmu/nxmu_server.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <semaphore.h>
#include <mqueue.h>
#include <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/fb.h>
#include <nuttx/nx.h>
#include "nxfe.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
#define NX_NCOLORS 256
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxmu_disconnect
****************************************************************************/
static inline void nxmu_disconnect(FAR struct nxfe_conn_s *conn)
{
struct nxclimsg_s outmsg;
int ret;
/* Send the handshake message back to the client */
outmsg.msgid = NX_CLIMSG_DISCONNECTED;
ret = mq_send(conn->swrmq, &outmsg, sizeof(struct nxclimsg_s), NX_CLIMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
/* Close the outgoing client message queue */
(void)mq_close(conn->swrmq);
}
/****************************************************************************
* Name: nxmu_connect
****************************************************************************/
static inline void nxmu_connect(FAR struct nxfe_conn_s *conn)
{
char mqname[NX_CLIENT_MXNAMELEN];
struct nxclimsg_s outmsg;
int ret;
/* Create the client MQ name */
sprintf(mqname, NX_CLIENT_MQNAMEFMT, conn->cid);
/* Open the client MQ -- this should have already been created by the client */
outmsg.msgid = NX_CLIMSG_CONNECTED;
conn->swrmq = mq_open(mqname, O_WRONLY);
if (conn->swrmq)
{
gdbg("mq_open(%s) failed: %d\n", mqname, errno);
outmsg.msgid = NX_CLIMSG_DISCONNECTED;
}
/* Send the handshake message back to the client */
ret = mq_send(conn->cwrmq, &outmsg, sizeof(struct nxclimsg_s), NX_CLIMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
}
/****************************************************************************
* Name: nxmu_release
****************************************************************************/
static int nxmu_release(FAR struct nxfe_state_s *fe)
{
FAR struct nxbe_window_s *wnd;
struct nxclimsg_s outmsg;
int ret;
/* Don't want windows to close while we do this */
for (wnd = fe->be.topwnd; wnd; wnd = wnd->below)
{
outmsg.msgid = NX_CLIMSG_DISCONNECTED;
ret = mq_send(wnd->conn->swrmq, &outmsg, sizeof(struct nxclimsg_s), NX_CLIMSG_PRIO);
if (ret < 0)
{
gdbg("mq_send failed: %d\n", errno);
}
}
return OK;
}
/****************************************************************************
* Name: nxmu_shutdown
****************************************************************************/
static inline void nxmu_shutdown(FAR struct nxfe_state_s *fe)
{
FAR struct nxbe_window_s *wnd;
/* Inform all of the clients in the window list that the server is
* exit-ting. Notes: (1) that the following loop will probably attempt to
* disconnect clients multiple times because one client may have multiple
* windows: The first disconnect will fail; subsequent will return errors
* that are ignored. (2) The final window to be disconnected will be the
* background window, thus close all of the servers message queues.
*/
for (wnd = fe->be.topwnd; wnd; wnd = wnd->below)
{
(void)nxmu_disconnect(wnd->conn);
}
}
/****************************************************************************
* Name: nxmu_setup
****************************************************************************/
static inline int nxmu_setup(FAR const char *mqname,
FAR struct fb_vtable_s *fb,
FAR struct nxfe_state_s *fe)
{
struct mq_attr attr;
int ret;
memset(fe, 0, sizeof(struct nxfe_state_s));
/* Configure the framebuffer device */
ret = nxbe_fbconfigure(fb, &fe->be);
if (ret < 0)
{
gdbg("nxs_fbconfigure failed: %d\n", -ret);
errno = -ret;
return ERROR;
}
#if CONFIG_FB_CMAP
ret = nxbe_colormap(fb);
if (ret < 0)
{
gdbg("nx_colormap failed: %d\n", -ret);
errno = -ret;
return ERROR;
}
#endif
/* Initialize the non-NULL elements of the server connection structure.
* Oddly, this strcture represents the connection between the server and
* itself.
*
* Open the incoming server MQ. The server receives messages on the
* background window's incoming message queue.
*/
attr.mq_maxmsg = CONFIG_NX_MXSERVERMSGS;
attr.mq_msgsize = NX_MXSVRMSGLEN;
attr.mq_flags = 0;
fe->conn.crdmq = mq_open(mqname, O_RDONLY|O_CREAT, 0666, &attr);
if (fe->conn.crdmq)
{
gdbg("mq_open(%s) failed: %d\n", mqname, errno);
return ERROR; /* mq_open sets errno */
}
/* NOTE that the outgoing client MQ (cwrmq) is not initialized. The
* background window never initiates messages.
*/
/* Open the outgoing server MQ. This is used to send messages to the
* background window which will, of course, be received and handled by
* the server message loop.
*/
/* Open the server MQ for writing (same attributes) */
fe->conn.cwrmq = mq_open(mqname, O_WRONLY);
if (fe->conn.cwrmq)
{
gdbg("mq_open(%s) failed: %d\n", mqname, errno);
mq_close(fe->conn.crdmq);
return ERROR; /* mq_open sets errno */
}
/* The server is now "connected" to itself via the background window */
fe->conn.state = NX_CLISTATE_CONNECTED;
/* Initialize the non-NULL elements of the background window */
fe->be.bkgd.conn = &fe->conn;
fe->be.bkgd.be = (FAR struct nxbe_state_s*)fe;
fe->be.bkgd.bounds.pt2.x = fe->be.vinfo.xres;
fe->be.bkgd.bounds.pt2.y = fe->be.vinfo.yres;
/* Complete initialization of the server state structure. The
* window list contains only one element: The background window
* with nothing else above or below it
*/
fe->be.topwnd = &fe->be.bkgd;
/* Initialize the mouse position */
#ifdef CONFIG_NX_MOUSE
nxmu_mouseinit(fe->be.vinfo.xres, fe->be.vinfo.yres);
#endif
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nx_runinstance
*
* Description:
* This is the server entry point. It does not return; the calling thread
* is dedicated to supporting NX server.
*
* NOTE that multiple instances of the NX server may run at the same time,
* each with different callback and message queue names.
*
* Input Parameters:
* mqname - The name for the server incoming message queue
* fb - Vtable "object" of the framebuffer "driver" to use
*
* Return:
* This function usually does not return. If it does return, it will
* return ERROR and errno will be set appropriately.
*
****************************************************************************/
int nx_runinstance(FAR const char *mqname, FAR struct fb_vtable_s *fb)
{
struct nxfe_state_s fe;
FAR struct nxsvrmsg_s *msg;
ubyte buffer[NX_MXSVRMSGLEN];
int nbytes;
int ret;
/* Initialization *********************************************************/
/* Sanity checking */
#ifdef CONFIG_DEBUG
if (!mqname || !fb)
{
errno = EINVAL;
return ERROR;
}
#endif
/* Initialize and configure the server */
ret = nxmu_setup(mqname, fb, &fe);
if (ret < 0)
{
return ret; /* nxmu_setup sets errno */
}
/* Produce the initial, background display */
nxbe_redraw(&fe.be, &fe.be.bkgd, &fe.be.bkgd.bounds);
/* Message Loop ***********************************************************/
/* Then loop forever processing incoming messages */
for (;;)
{
/* Receive the next server message */
nbytes = mq_receive(fe.conn.crdmq, buffer, NX_MXSVRMSGLEN, 0);
if (nbytes < 0)
{
if (errno != EINTR)
{
gdbg("mq_receive failed: %d\n", errno);
goto errout; /* mq_receive sets errno */
}
continue;
}
/* Dispatch the message appropriately */
DEBUGASSERT(nbytes >= sizeof(struct nxsvrmsg_s));
msg = (FAR struct nxsvrmsg_s *)buffer;
gvdbg("Received opcode=%d nbytes=%d\n", msg->msgid, nbytes);
switch (msg->msgid)
{
/* Messages sent from clients to the NX server *********************/
case NX_SVRMSG_CONNECT: /* Establish connection with new NX server client */
{
FAR struct nxsvrmsg_s *connmsg = (FAR struct nxsvrmsg_s *)buffer;
nxmu_connect(connmsg->conn);
}
break;
case NX_SVRMSG_DISCONNECT: /* Tear down connection with terminating client */
{
FAR struct nxsvrmsg_s *disconnmsg = (FAR struct nxsvrmsg_s *)buffer;
nxmu_disconnect(disconnmsg->conn);
}
break;
case NX_SVRMSG_OPENWINDOW: /* Create a new window */
{
FAR struct nxsvrmsg_openwindow_s *openmsg = (FAR struct nxsvrmsg_openwindow_s *)buffer;
nxmu_openwindow(openmsg->conn, &fe.be, openmsg->wnd);
}
break;
case NX_SVRMSG_CLOSEWINDOW: /* Close an existing window */
{
FAR struct nxsvrmsg_closewindow_s *closemsg = (FAR struct nxsvrmsg_closewindow_s *)buffer;
nxbe_closewindow(closemsg->wnd);
}
break;
case NX_SVRMSG_SETPOSITION: /* Change window position */
{
FAR struct nxsvrmsg_setposition_s *setposmsg = (FAR struct nxsvrmsg_setposition_s *)buffer;
nxbe_setposition(setposmsg->wnd, &setposmsg->pos);
}
break;
case NX_SVRMSG_SETSIZE: /* Change window size */
{
FAR struct nxsvrmsg_setsize_s *setsizemsg = (FAR struct nxsvrmsg_setsize_s *)buffer;
nxbe_setsize(setsizemsg->wnd, &setsizemsg->size);
}
break;
case NX_SVRMSG_GETPOSITION: /* Get the window size/position */
{
FAR struct nxsvrmsg_getposition_s *getposmsg = (FAR struct nxsvrmsg_getposition_s *)buffer;
nxfe_reportposition(getposmsg->wnd);
}
break;
case NX_SVRMSG_RAISE: /* Move the window to the top of the display */
{
FAR struct nxsvrmsg_raise_s *raisemsg = (FAR struct nxsvrmsg_raise_s *)buffer;
nxbe_raise(raisemsg->wnd);
}
break;
case NX_SVRMSG_LOWER: /* Lower the window to the bottom of the display */
{
FAR struct nxsvrmsg_lower_s *lowermsg = (FAR struct nxsvrmsg_lower_s *)buffer;
nxbe_raise(lowermsg->wnd);
}
break;
case NX_SVRMSG_FILL: /* Fill a rectangular region in the window with a color */
{
FAR struct nxsvrmsg_fill_s *fillmsg = (FAR struct nxsvrmsg_fill_s *)buffer;
nxbe_fill(fillmsg->wnd, &fillmsg->rect, fillmsg->color);
}
break;
case NX_SVRMSG_FILLTRAP: /* Fill a trapezoidal region in the window with a color */
{
FAR struct nxsvrmsg_filltrapezoid_s *trapmsg = (FAR struct nxsvrmsg_filltrapezoid_s *)buffer;
nxbe_filltrapezoid(trapmsg->wnd, &trapmsg->trap, trapmsg->color);
}
break;
case NX_SVRMSG_MOVE: /* Move a rectangular region within the window */
{
FAR struct nxsvrmsg_move_s *movemsg = (FAR struct nxsvrmsg_move_s *)buffer;
nxbe_move(movemsg->wnd, &movemsg->rect, &movemsg->offset);
}
break;
case NX_SVRMSG_BITMAP: /* Copy a rectangular bitmap into the window */
{
FAR struct nxsvrmsg_bitmap_s *bmpmsg = (FAR struct nxsvrmsg_bitmap_s *)buffer;
nxbe_bitmap(bmpmsg->wnd, &bmpmsg->dest, bmpmsg->src, &bmpmsg->origin, bmpmsg->stride);
}
break;
case NX_SVRMSG_SETBGCOLOR: /* Set the color of the background */
{
FAR struct nxsvrmsg_setbgcolor_s *bgcolormsg = (FAR struct nxsvrmsg_setbgcolor_s *)buffer;
nxbe_fill(&fe.be.bkgd, &fe.be.bkgd.bounds, bgcolormsg->color);
}
break;
#ifdef CONFIG_NX_MOUSE
case NX_SVRMSG_MOUSEIN: /* New mouse report from mouse client */
{
FAR struct nxsvrmsg_mousein_s *mousemsg = (FAR struct nxsvrmsg_mousein_s *)buffer;
nxmu_mousein(&fe.be, &mousemsg->pt, mousemsg->buttons);
}
break;
#endif
#ifdef CONFIG_NX_KBD
case NX_SVRMSG_KBDIN: /* New keyboard report from keyboard client */
{
FAR struct nxsvrmsg_kbdin_s *kbdmsg = (FAR struct nxsvrmsg_kbdin_s *)buffer;
nxmu_kbdin(&fe.be, kbdmsg->nch, kbdmsg->ch);
}
break;
#endif
/* Messages sent to the backgound window ***************************/
case NX_CLIMSG_REDRAW: /* Re-draw the background window */
nxbe_redraw(&fe.be, &fe.be.bkgd, &fe.be.bkgd.bounds);
break;
case NX_CLIMSG_MOUSEIN: /* Ignored */
case NX_CLIMSG_KBDIN:
break;
case NX_CLIMSG_CONNECTED: /* Shouldn't happen */
case NX_CLIMSG_DISCONNECTED:
default:
gdbg("Unrecognized command: %d\n", msg->msgid);
break;
}
}
errout:
nxmu_shutdown(&fe);
return OK;
}