📄 srvnet.c
字号:
static voidGrGetImageInfoWrapper(void *r){ nxGetImageInfoReq *req = r; GR_IMAGE_INFO info; GrGetImageInfo(req->id, &info); GsWriteType(current_fd, GrNumGetImageInfo); GsWrite(current_fd, &info, sizeof(info));}#else /* if ! MW_FEATURE_IMAGES */#define GrDrawImageToFitWrapper GrNotImplementedWrapper#define GrFreeImageWrapper GrNotImplementedWrapper#define GrGetImageInfoWrapper GrNotImplementedWrapper#endifstatic voidGrSetScreenSaverTimeoutWrapper(void *r){ nxSetScreenSaverTimeoutReq *req = r; GrSetScreenSaverTimeout(req->timeout);}static voidGrSetSelectionOwnerWrapper(void *r){ nxSetSelectionOwnerReq *req = r; GrSetSelectionOwner(req->wid, GetReqData(req));}static voidGrGetSelectionOwnerWrapper(void *r){ GR_CHAR *typelist; GR_WINDOW_ID wid; unsigned short len; wid = GrGetSelectionOwner(&typelist); GsWriteType(current_fd, GrNumGetSelectionOwner); GsWrite(current_fd, &wid, sizeof(wid)); if(wid) { len = strlen((const char *)typelist) + 1; GsWrite(current_fd, &len, sizeof(len)); GsWrite(current_fd, typelist, len); }}static voidGrRequestClientDataWrapper(void *r){ nxRequestClientDataReq *req = r; GrRequestClientData(req->wid, req->rid, req->serial, req->mimetype);}static voidGrSendClientDataWrapper(void *r){ nxSendClientDataReq *req = r; GrSendClientData(req->wid, req->did, req->serial, req->len, GetReqVarLen(req), GetReqData(req));}static voidGrBellWrapper(void *r){ GrBell();}static voidGrSetBackgroundPixmapWrapper(void *r){ nxSetBackgroundPixmapReq *req = r; GrSetBackgroundPixmap(req->wid, req->pixmap, req->flags);}static voidGrDestroyCursorWrapper(void *r){ nxDestroyCursorReq *req = r; GrDestroyCursor(req->cursorid);}static voidGrQueryTreeWrapper(void *r){ nxQueryTreeReq *req = r; GR_WINDOW_ID parentid; GR_WINDOW_ID * children; GR_COUNT nchildren; GrQueryTree(req->windowid, &parentid, &children, &nchildren); GsWriteType(current_fd, GrNumQueryTree); GsWrite(current_fd, &parentid, sizeof(parentid)); GsWrite(current_fd, &nchildren, sizeof(nchildren)); if (nchildren) { GsWrite(current_fd, children, nchildren * sizeof(GR_WINDOW_ID)); free(children); }}#if MW_FEATURE_TIMERSstatic voidGrCreateTimerWrapper(void *r){ nxCreateTimerReq *req = r; GR_TIMER_ID timerid; timerid = GrCreateTimer(req->wid, req->period); GsWriteType(current_fd, GrNumCreateTimer); GsWrite(current_fd, &timerid, sizeof (timerid));}#else /* if ! MW_FEATURE_TIMERS */#define GrCreateTimerWrapper GrNotImplementedWrapper#endiftypedef struct image_list { void *data; int id; int size; int offset; struct image_list *next;} imagelist_t;static imagelist_t *imageListHead = 0;static imagelist_t *imageListTail = 0;static int imageListId = 0;static imagelist_t *findImageBuffer(int buffer_id){ imagelist_t *buffer = 0; for(buffer = imageListHead; buffer; buffer = buffer->next) if (buffer->id == buffer_id) break; return buffer;}static void freeImageBuffer(imagelist_t *buffer){ imagelist_t *prev = 0; imagelist_t *ptr = imageListHead; while(ptr) { if (ptr == buffer) { if (prev) prev->next = buffer->next; else imageListHead = buffer->next; if (!imageListHead) imageListTail = 0; free(buffer->data); free(buffer); return; } prev = ptr; ptr = ptr->next; } }static voidGrImageBufferAllocWrapper(void *r){ nxImageBufferAllocReq *req = r; /* Add a new buffer to the end of the list */ if (!imageListTail) { imageListHead = imageListTail = (imagelist_t *) malloc(sizeof(imagelist_t)); } else { imageListTail->next = (imagelist_t *) malloc(sizeof(imagelist_t)); imageListTail = imageListTail->next; } imageListTail->id = ++imageListId; imageListTail->data = (void *) malloc(req->size); imageListTail->size = req->size; imageListTail->offset = 0; imageListTail->next = 0; GsWriteType(current_fd,GrNumImageBufferAlloc); GsWrite(current_fd, &imageListTail->id, sizeof(int));}static voidGrImageBufferSendWrapper(void *r){ int csize; imagelist_t *buffer; nxImageBufferSendReq *req = r; buffer = findImageBuffer(req->buffer_id); if (!buffer) return; if (buffer->offset + req->size >= buffer->size) csize = buffer->size - buffer->offset; else csize = req->size; if (!csize) return; memcpy((void *) (((char *)buffer->data) + buffer->offset), GetReqData(req), csize); buffer->offset += csize;}#if MW_FEATURE_IMAGESstatic voidGrLoadImageFromBufferWrapper(void *r){ GR_IMAGE_ID id; imagelist_t *buffer; nxLoadImageFromBufferReq *req = r; buffer = findImageBuffer(req->buffer); if (!buffer) return; id = GrLoadImageFromBuffer(buffer->data, buffer->size, req->flags); GsWriteType(current_fd, GrNumLoadImageFromBuffer); GsWrite(current_fd, &id, sizeof(id)); freeImageBuffer(buffer);}static voidGrDrawImageFromBufferWrapper(void *r){ imagelist_t *buffer; nxDrawImageFromBufferReq *req = r; buffer = findImageBuffer(req->buffer); if (!buffer) return; GrDrawImageFromBuffer(req->drawid, req->gcid, req->x, req->y, req->width, req->height, buffer->data, buffer->size, req->flags); freeImageBuffer(buffer);}#else /* if ! MW_FEATURE_IMAGES */#define GrLoadImageFromBufferWrapper GrNotImplementedWrapper#define GrDrawImageFromBufferWrapper GrNotImplementedWrapper#endif#if MW_FEATURE_TIMERSstatic voidGrDestroyTimerWrapper(void *r){ nxDestroyTimerReq *req = r; GrDestroyTimer(req->timerid);}#else /* if ! MW_FEATURE_TIMERS */#define GrDestroyTimerWrapper GrNotImplementedWrapper#endifstatic voidGrSetPortraitModeWrapper(void *r){ nxSetPortraitModeReq *req = r; GrSetPortraitMode(req->portraitmode);}static voidGrQueryPointerWrapper(void *r){ GR_WINDOW_ID mwin; GR_COORD x, y; GR_BUTTON bmask; GrQueryPointer(&mwin, &x, &y, &bmask); GsWriteType(current_fd, GrNumQueryPointer); GsWrite(current_fd, &mwin, sizeof(mwin)); GsWrite(current_fd, &x, sizeof(x)); GsWrite(current_fd, &y, sizeof(y)); GsWrite(current_fd, &bmask, sizeof(bmask));}/* * This function makes the Nano-X server set up a shared memory segment * that the client can use when feeding the Nano-X server with requests. * There is a corresponding GrShmCmdsFlush function that will make the * server execute the batched commands. */#define SHMKEY_BASE 1000000#define SHMKEY_MAX 256static voidGrReqShmCmdsWrapper(void *r){#if HAVE_SHAREDMEM_SUPPORT nxReqShmCmdsReq *req = r; int key, shmid; char *tmp; if ( curclient->shm_cmds != 0 ) goto bad; for ( key=SHMKEY_BASE; key < SHMKEY_BASE+SHMKEY_MAX; key++ ) { shmid = shmget(key,req->size,IPC_CREAT|IPC_EXCL|0666); if ( shmid == -1 ) { if ( errno != EEXIST ) goto bad; } else { tmp = shmat(shmid,0,0); if ( tmp == (char *)-1 ) goto bad; curclient->shm_cmds = tmp; curclient->shm_cmds_shmid = shmid; curclient->shm_cmds_size = req->size; goto finish; } } bad: key = 0; finish: DPRINTF("Shm: Request key granted=%d\n",key); GsWrite(current_fd, &key, sizeof(key));#else /* return no shared memory support*/ int key = 0; GsWrite(current_fd, &key, sizeof(key));#endif /* HAVE_SHAREDMEM_SUPPORT*/}static void GrGetFontListWrapper(void *r){ MWFONTLIST **list; int num; int i, ttlen, mwlen; GrGetFontList(&list, &num); GsWriteType(current_fd, GrNumGetFontList); /* the number of strings comming in */ GsWrite(current_fd, &num, sizeof(int)); if(num != -1) { for(i = 0; i < num; i++) { ttlen = strlen(list[i]->ttname) + 1; mwlen = strlen(list[i]->mwname) + 1; GsWrite(current_fd, &ttlen, sizeof(int)); GsWrite(current_fd, list[i]->ttname, ttlen * sizeof(char)); GsWrite(current_fd, &mwlen, sizeof(int)); GsWrite(current_fd, list[i]->mwname, mwlen * sizeof(char)); } GrFreeFontList(&list, num); }}static voidGrNewBitmapRegionWrapper(void *r){ GR_REGION_ID region; nxNewBitmapRegionReq *req = r; region = GrNewBitmapRegion(GetReqData(req), req->width, req->height); GsWriteType(current_fd, GrNumNewBitmapRegion); GsWrite(current_fd, ®ion, sizeof(region));}static voidGrSetWindowRegionWrapper(void *r){ nxSetWindowRegionReq *req = r; GrSetWindowRegion(req->wid, req->rid, req->type);} static voidGrStretchAreaWrapper(void *r){ nxStretchAreaReq *req = r; GrStretchArea(req->drawid, req->gcid, req->dx1, req->dy1, req->dx2, req->dy2, req->srcid, req->sx1, req->sy1, req->sx2, req->sy2, req->op);}/* handle both GrGrabKey and GrUngrabKey*/static voidGrGrabKeyWrapper(void *r){ nxGrabKeyReq *req = r; if (req->type != GR_GRAB_MAX + 1) { /* GrGrabKey */ int ret = GrGrabKey(req->wid, req->key, req->type); GsWriteType(current_fd, GrNumGrabKey); GsWrite(current_fd, &ret, sizeof(ret)); } else GrUngrabKey(req->wid, req->key);}static voidGrSetTransformWrapper(void *r) { nxSetTransformReq *req = r; GR_TRANSFORM trans; if (req->mode) { trans.a = req->trans_a; trans.b = req->trans_b; trans.c = req->trans_c; trans.d = req->trans_d; trans.e = req->trans_e; trans.f = req->trans_f; trans.s = req->trans_s; GrSetTransform(&trans); } else GrSetTransform(NULL);}static voidGrCreateFontFromBufferWrapper(void *r){#if HAVE_FREETYPE_2_SUPPORT imagelist_t *buffer; nxCreateFontFromBufferReq *req = r; GR_FONT_ID result; buffer = findImageBuffer(req->buffer_id); if (!buffer) { result = 0; } else { result = GrCreateFontFromBuffer(buffer->data, buffer->size, (const char *)req->format, req->height); freeImageBuffer(buffer); } GsWriteType(current_fd, GrNumCreateFontFromBuffer); GsWrite(current_fd, &result, sizeof(result));#endif /*HAVE_FREETYPE_2_SUPPORT*/}static voidGrCopyFontWrapper(void *r){#if HAVE_FREETYPE_2_SUPPORT nxCopyFontReq *req = r; GR_FONT_ID result = GrCopyFont(req->fontid, req->height); GsWriteType(current_fd, GrNumCopyFont); GsWrite(current_fd, &result, sizeof(result));#endif /*HAVE_FREETYPE_2_SUPPORT*/}void GrShmCmdsFlushWrapper(void *r);/* * Handler functions, ordered by reqType */struct GrFunction { void (*func)(void *); GR_FUNC_NAME name;} GrFunctions[] = { /* 0 */ {GrOpenWrapper, "GrOpen"}, /* 1 */ {GrCloseWrapper, "GrClose"}, /* 2 */ {GrGetScreenInfoWrapper, "GrGetScreenInfo"}, /* 3 */ {GrNewWindowWrapper, "GrNewWindow"}, /* 4 */ {GrNewInputWindowWrapper, "GrNewInputWindow"}, /* 5 */ {GrDestroyWindowWrapper, "GrDestroyWindow"}, /* 6 */ {GrNewGCWrapper, "GrNewGC"}, /* 7 */ {GrCopyGCWrapper, "GrCopyGC"}, /* 8 */ {GrGetGCInfoWrapper, "GrGetGCInfo"}, /* 9 */ {GrDestroyGCWrapper, "GrDestroyGC"}, /* 10 */ {GrMapWindowWrapper, "GrMapWindow"}, /* 11 */ {GrUnmapWindowWrapper, "GrUnmapWindow"}, /* 12 */ {GrRaiseWindowWrapper, "GrRaiseWindow"}, /* 13 */ {GrLowerWindowWrapper, "GrLowerWindow"}, /* 14 */ {GrMoveWindowWrapper, "GrMoveWindow"}, /* 15 */ {GrResizeWindowWrapper, "GrResizeWindow"}, /* 16 */ {GrGetWindowInfoWrapper, "GrGetWindowInfo"}, /* 17 */ {GrGetFontInfoWrapper, "GrGetFontInfo"}, /* 18 */ {GrSetFocusWrapper, "GrSetFocus"}, /* 19 */ {GrSetWindowCursorWrapper, "GrSetWindowCursor"}, /* 20 */ {GrClearAreaWrapper, "GrClearAreaWrapper"}, /* 21 */ {GrSelectEventsWrapper, "GrSelectEvents"}, /* 22 */ {GrGetNextEventWrapper, "GrGetNextEvent"}, /* 23 */ {GrCheckNextEventWrapper, "GrCheckNextEvent"}, /* 24 */ {GrPeekEventWrapper, "GrPeekEvent"}, /* 25 */ {GrLineWrapper, "GrLine"}, /* 26 */ {GrPointWrapper, "GrPoint"}, /* 27 */ {GrRectWrapper, "GrRect"}, /* 28 */ {GrFillRectWrapper, "GrFillRect"}, /* 29 */ {GrPolyWrapper, "GrPoly"}, /* 30 */ {GrFillPolyWrapper, "GrFillPoly"}, /* 31 */ {GrEllipseWrapper, "GrEllipse"}, /* 32 */ {GrFillEllipseWrapper, "GrFillEllipse"}, /* 33 */ {GrSetGCForegroundWrapper, "GrSetGCForeground"}, /* 34 */ {GrSetGCBackgroundWrapper, "GrSetGCBackGround"}, /* 35 */ {GrSetGCUseBackgroundWrapper, "GrSetGCUseBackGround"}, /* 36 */ {GrSetGCModeWrapper, "GrSetGCMode"}, /* 37 */ {GrSetGCFontWrapper, "GrSetGCFont"}, /* 38 */ {GrGetGCTextSizeWrapper, "GrGetGCTextSize"}, /* 39 */ {GrReadAreaWrapper, "GrReadArea"}, /* 40 */ {GrAreaWrapper, "GrArea"}, /* 41 */ {GrBitmapWrapper, "GrBitmap"}, /* 42 */ {GrTextWrapper, "GrText"}, /* 43 */ {GrNewCursorWrapper, "GrNewCursor"}, /* 44 */ {GrMoveCursorWrapper, "GrMoveCursor"}, /* 45 */ {GrGetSystemPaletteWrapper, "GrGetSystemPalette"}, /* 46 */ {GrFindColorWrapper, "GrFindColor"}, /* 47 */ {GrReparentWindowWrapper, "GrReparentWindow"}, /* 48 */ {GrDrawImageFromFileWrapper, "GrDrawImageFromFile"}, /* 49 */ {GrLoadImageFromFileWrapper, "GrLoadImageFromFile"}, /* 50 */ {GrNewPixmapWrapper, "GrNewPixmap"}, /* 51 */ {GrCopyAreaWrapper, "GrCopyArea"}, /* 52 */ {GrSetFontSizeWrapper, "GrSetFontSize"}, /* 53 */ {GrCreateFontWrapper, "GrCreateFont"}, /* 54 */ {GrDestroyFontWrapper, "GrDestroyFont"}, /* 55 */ {GrReqShmCmdsWrapper, "GrReqShmCmds"}, /* 56 */ {GrShmCmdsFlushWrapper, "GrShmCmdsFlush"}, /* 57 */ {GrSetFontRotationWrapper, "GrSetFontRotation"}, /* 58 */ {GrSetFontAttrWrapper, "GrSetFontAttr"}, /* 59 */ {GrSetSystemPaletteWrapper, "GrSetSystemPalette"}, /* 60 */ {GrInjectEventWrapper, "GrInjectEvent"}, /* 61 */ {GrNewRegionWrapper, "GrNewRegion"}, /* 62 */ {GrDestroyRegionWrapper, "GrDestroyRegion"}, /* 63 */ {GrUnionRectWithRegionWrapper, "GrUnionRectWithRegion"}, /* 64 */ {GrUnionRegionWrapper, "GrUnionRegion"}, /* 65 */ {GrIntersectRegionWrapper, "GrIntersectRegion"},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -