From 1080111f9917e75cdb270cc9bb91b0db786e7721 Mon Sep 17 00:00:00 2001 From: Acfboy Date: Mon, 10 Aug 2026 01:10:12 +0800 Subject: [PATCH] graphics/microwindows: add NONETWORK mode for linking Nano-X apps with the server * Add CONFIG_MICROWINDOWS_NANOX_NONETWORK which builds the Nano-X client library and server in the linked-in (NONETWORK) mode, so client applications are linked directly with the server and run in the same task, requiring no network stack or socket at all * Reorganize the source lists: the drawing sources (nxdraw, nxutil, nxtransform, nxpaintnc) are shared by both modes, while the server is built from srvnet.c in the network mode and srvnonet.c in the NONETWORK mode * Use MULTITHREAD_SERVER in the network mode so that several client tasks can run at the same time in the flat build * Let the examples/nanoxterm start the server task only in the network mode (NONETWORK applications run the server inside main) Assisted-by: OpenCode:DeepSeek-V4-Flash Signed-off-by: Acfboy --- examples/nanoxterm/Makefile | 4 +++ examples/nanoxterm/nxterm.c | 4 +++ graphics/microwindows/Kconfig | 16 ++++++++++-- graphics/microwindows/Makefile | 48 +++++++++++++++++++++++++++------- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/examples/nanoxterm/Makefile b/examples/nanoxterm/Makefile index 19d45941d..0a10792e9 100644 --- a/examples/nanoxterm/Makefile +++ b/examples/nanoxterm/Makefile @@ -33,5 +33,9 @@ MODULE = $(CONFIG_EXAMPLES_NANOXTERM) MAINSRC = nxterm.c CFLAGS += -Wno-undef +ifneq ($(CONFIG_MICROWINDOWS_NANOX_NONETWORK),) +CFLAGS += -DNONETWORK=1 +endif + include $(APPDIR)/Application.mk diff --git a/examples/nanoxterm/nxterm.c b/examples/nanoxterm/nxterm.c index 636c98ff8..464150cf6 100644 --- a/examples/nanoxterm/nxterm.c +++ b/examples/nanoxterm/nxterm.c @@ -2400,7 +2400,9 @@ static void sigquit(int sig) kill(-pid, SIGHUP); } +#ifndef NONETWORK extern int nanox_server_main(int argc, char *argv[]); +#endif int main(int argc, char **argv) { @@ -2408,11 +2410,13 @@ int main(int argc, char **argv) GR_BITMAP bitmap1fg[7]; GR_BITMAP bitmap1bg[7]; +#ifndef NONETWORK /* Start the Nano-X server as a separate task; GrOpen() below retries * the connection while the server comes up. */ task_create("nanoxserver", 100, 65536, nanox_server_main, NULL); +#endif argv++; while (*argv && **argv == '-') diff --git a/graphics/microwindows/Kconfig b/graphics/microwindows/Kconfig index acff0ca9c..ff0a954e2 100644 --- a/graphics/microwindows/Kconfig +++ b/graphics/microwindows/Kconfig @@ -131,12 +131,24 @@ config MICROWINDOWS_MWIN config MICROWINDOWS_NANOX bool "Nano-X (X11 API) client/server support" default n - depends on NET_LOCAL && NET_LOCAL_STREAM + depends on MICROWINDOWS_NANOX_NONETWORK || (NET_LOCAL && NET_LOCAL_STREAM) ---help--- Build the Nano-X server core and the Nano-X client library. The Nano-X server runs as a separate task and provides the X11-like API (GrXXX calls) to client applications which - connect to it through a local stream socket. + connect to it through a local stream socket. Alternatively, + with MICROWINDOWS_NANOX_NONETWORK, the client applications + are linked directly with the server and run in the same task. + +config MICROWINDOWS_NANOX_NONETWORK + bool "Link Nano-X applications directly with the server" + default n + ---help--- + Build the Nano-X client library and server in the linked-in + (NONETWORK) mode: client applications are linked directly + with the server, so no network stack or socket is required + and the memory footprint is minimal. Only a single client + application can be active at a time. config MICROWINDOWS_NANOX_NANOWM bool "Built-in Nano-X window manager" diff --git a/graphics/microwindows/Makefile b/graphics/microwindows/Makefile index 39ead68c6..6b810362a 100644 --- a/graphics/microwindows/Makefile +++ b/graphics/microwindows/Makefile @@ -155,14 +155,10 @@ endif ifneq ($(CONFIG_MICROWINDOWS_NANOX),) -MW_NANOX_CLIENT_SRCS = microwindows/src/nanox/nxdraw.c -MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/nxutil.c -MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/nxtransform.c -MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/nxpaintnc.c -MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/client.c -MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/clientfb.c -MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/nxproto.c -MW_NANOX_CLIENT_SRCS += microwindows/src/drivers/osdep.c +MW_NANOX_DRAW_SRCS = microwindows/src/nanox/nxdraw.c +MW_NANOX_DRAW_SRCS += microwindows/src/nanox/nxutil.c +MW_NANOX_DRAW_SRCS += microwindows/src/nanox/nxtransform.c +MW_NANOX_DRAW_SRCS += microwindows/src/nanox/nxpaintnc.c MW_NANOX_WM_SRCS = microwindows/src/nanox/wmaction.c MW_NANOX_WM_SRCS += microwindows/src/nanox/wmclients.c @@ -174,15 +170,47 @@ MW_NANOX_SERVER_SRCS += microwindows/src/nanox/srvfunc.c MW_NANOX_SERVER_SRCS += microwindows/src/nanox/srvutil.c MW_NANOX_SERVER_SRCS += microwindows/src/nanox/srvevent.c MW_NANOX_SERVER_SRCS += microwindows/src/nanox/srvclip.c + +ifeq ($(CONFIG_MICROWINDOWS_NANOX_NONETWORK),y) + +# NONETWORK mode: the client application is linked directly with the +# server and runs in the same task, without a network socket. Only a +# single client can be active at a time. +CFLAGS += -DNONETWORK=1 + +ifneq ($(CONFIG_MICROWINDOWS_NANOX_NANOWM),) +CFLAGS += -DNANOWM=1 +CSRCS += $(MW_NANOX_WM_SRCS) +endif + +CSRCS += $(MW_NANOX_DRAW_SRCS) $(MW_NANOX_SERVER_SRCS) +CSRCS += microwindows/src/nanox/srvnonet.c + +else + +# Network client/server mode: each client connects to the server +# through a local stream socket. NX_PER_CLIENT_DATA enables the +# per-task client data (POSIX per-thread key) so that several client +# tasks can run at the same time in the flat build. + +MW_NANOX_CLIENT_SRCS = $(MW_NANOX_DRAW_SRCS) +MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/client.c +MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/clientfb.c +MW_NANOX_CLIENT_SRCS += microwindows/src/nanox/nxproto.c +MW_NANOX_CLIENT_SRCS += microwindows/src/drivers/osdep.c + MW_NANOX_SERVER_SRCS += microwindows/src/nanox/srvnet.c # The server main() is renamed to nanox_server_main() and invoked from # the nanoxterm example, which starts the server as a separate task. microwindows/src/nanox/srvmain.c_CFLAGS += -Dmain=nanox_server_main -CFLAGS += -DMULTITHREAD_SERVER=1 +CFLAGS += -DNX_PER_CLIENT_DATA=1 ifneq ($(CONFIG_MICROWINDOWS_NANOX_NANOWM),) CFLAGS += -DNANOWM=1 + +# Rename the server-side GrXXX symbols to SVR_GrXXX, since the server +# and the client code are linked into a single image. $(foreach src,$(MW_NANOX_WM_SRCS),$(eval $(src)_CFLAGS += -include microwindows/src/nanox/serv.h)) CSRCS += $(MW_NANOX_WM_SRCS) endif @@ -191,4 +219,6 @@ CSRCS += $(MW_NANOX_CLIENT_SRCS) $(MW_NANOX_SERVER_SRCS) endif +endif + include $(APPDIR)/Application.mk