Ejemplo n.º 1
0
LOCAL void rfb_focuswindow(struct rfb_Display *mod, struct rfb_Window *v)
{
	TAPTR TExecBase = TGetExecBase(mod);
	TIMSG *imsg;

	if (v == mod->rfb_FocusWindow || (v && (v->rfbw_Flags & RFBWFL_IS_POPUP)))
		return;

	if (mod->rfb_FocusWindow)
	{
		if (rfb_getimsg(mod, mod->rfb_FocusWindow, &imsg, TITYPE_FOCUS))
		{
			imsg->timsg_Code = 0;
			TPutMsg(mod->rfb_FocusWindow->rfbw_IMsgPort, TNULL, imsg);
		}
	}

	if (v)
	{
		if (rfb_getimsg(mod, v, &imsg, TITYPE_FOCUS))
		{
			imsg->timsg_Code = 1;
			TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
		}
	}

	mod->rfb_FocusWindow = v;
}
Ejemplo n.º 2
0
static TBOOL rfb_passevent(RFBDISPLAY *mod, RFBWINDOW *v, TIMSG *omsg)
{		
	TAPTR TExecBase = TGetExecBase(mod);
	TUINT type = omsg->timsg_Type;
	if (v && (v->rfbw_InputMask & type))
	{
		TIMSG *imsg;
		if (rfb_getimsg(mod, v, &imsg, omsg->timsg_Type))
		{
			TINT x = omsg->timsg_MouseX;
			TINT y = omsg->timsg_MouseY;
			mod->rfb_MouseX = x;
			mod->rfb_MouseY = y;
			imsg->timsg_Code = omsg->timsg_Code;
			imsg->timsg_Qualifier = omsg->timsg_Qualifier;
			imsg->timsg_MouseX = x - v->rfbw_WinRect[0];
			imsg->timsg_MouseY = y - v->rfbw_WinRect[1];
			imsg->timsg_ScreenMouseX = x;
			imsg->timsg_ScreenMouseY = y;
			memcpy(imsg->timsg_KeyCode, omsg->timsg_KeyCode, 8);
			TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
			return TTRUE;
		}
	}
	return TFALSE;
}
Ejemplo n.º 3
0
static TBOOL rfb_passevent(struct rfb_Display *mod, struct rfb_Window *v,
	TIMSG *omsg)
{
	TAPTR TExecBase = TGetExecBase(mod);
	TUINT type = omsg->timsg_Type;

	if (v && (v->rfbw_InputMask & type))
	{
		TIMSG *imsg;

		if (rfb_getimsg(mod, v, &imsg, omsg->timsg_Type))
		{
			/* note: screen coordinates */
			TINT x = omsg->timsg_MouseX;
			TINT y = omsg->timsg_MouseY;

			mod->rfb_MouseX = x;
			mod->rfb_MouseY = y;
			imsg->timsg_Code = omsg->timsg_Code;
			imsg->timsg_Qualifier = omsg->timsg_Qualifier;
			imsg->timsg_MouseX = x - v->rfbw_ScreenRect.r[0];
			imsg->timsg_MouseY = y - v->rfbw_ScreenRect.r[1];
			imsg->timsg_ScreenMouseX = x;
			imsg->timsg_ScreenMouseY = y;
			memcpy(imsg->timsg_KeyCode, omsg->timsg_KeyCode, 8);
			TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
			return TTRUE;
		}
	}
	return TFALSE;
}
Ejemplo n.º 4
0
static int tek_lib_exec_sendmsg(lua_State *L)
{
	struct LuaExecTask *lexec = tek_lib_exec_check(L);
	struct TExecBase *TExecBase = lexec->exec;
	const char *taskname = luaL_checkstring(L, 1);
	size_t msglen;
	const char *src = luaL_checklstring(L, 2, &msglen);
	TAPTR ref, task;
	char *msg = TAllocMsg(msglen + TEK_LIB_TASKNAME_LEN);
	if (msg == TNULL)
		luaL_error(L, "out of memory");
	task = tek_lib_exec_locktask(TExecBase, taskname, &ref);
	if (task)
	{
		memcpy(msg, src, msglen);
        strcpy(msg + msglen, lexec->taskname);
		TPutMsg(TGetUserPort(task), TNULL, msg);
		tek_lib_exec_unlocktask(TExecBase, ref);
		lua_pushboolean(L, TTRUE);
	}
	else
	{
		TFree(msg);
		lua_pushnil(L);
	}
	return 1;
}
Ejemplo n.º 5
0
static TBOOL tek_lib_exec_sendtaskport(struct TTask *task,
	const char *portname, const char *buf, size_t len)
{
	struct TExecBase *TExecBase = TGetExecBase(task);
	char atomname[256];
	TAPTR atom;
	TBOOL success = TFALSE;
	sprintf(atomname, "msgport.%s.%p", portname, task);
	atom = TLockAtom(atomname, TATOMF_SHARED | TATOMF_NAME);
	if (atom)
	{
		TAPTR imsgport = (TAPTR) TGetAtomData(atom);
		if (imsgport)
		{
			TAPTR msg = TAllocMsg0(len);
			if (msg)
			{
				memcpy(msg, buf, len);
				TPutMsg(imsgport, TNULL, msg);
				success = TTRUE;
			}
		}
		TUnlockAtom(atom, TATOMF_KEEP);
	}
	return success;
}
Ejemplo n.º 6
0
LOCAL void fb_sendimessages(WINDISPLAY *mod, TBOOL do_interval)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
	struct TNode *next, *node = mod->fbd_VisualList.tlh_Head;
	for (; (next = node->tln_Succ); node = next)
	{
		WINWINDOW *v = (WINWINDOW *) node;
		TIMSG *imsg;

		if (do_interval && (v->fbv_InputMask & TITYPE_INTERVAL) &&
			fb_getimsg(mod, v, &imsg, TITYPE_INTERVAL))
			TPutMsg(v->fbv_IMsgPort, TNULL, imsg);

		while ((imsg = (TIMSG *) TRemHead(&v->fbv_IMsgQueue)))
			TPutMsg(v->fbv_IMsgPort, TNULL, imsg);
	}
}
Ejemplo n.º 7
0
static int tek_lib_exec_child_sendmsg(lua_State *L)
{
	struct LuaExecChild *ctx = luaL_checkudata(L, 1, TEK_LIB_TASK_CLASSNAME);
	if (ctx->task)
	{
		struct TExecBase *TExecBase = ctx->exec;
		size_t len;
		const char *buf = luaL_checklstring(L, 2, &len);
		char *msg = TAllocMsg(len + TEK_LIB_TASKNAME_LEN);
		if (msg == TNULL)
			luaL_error(L, "out of memory");
		memcpy(msg, buf, len);
		strcpy(msg + len, ctx->parent->taskname);
		TPutMsg(TGetUserPort(ctx->task), TNULL, msg);
	}
	else
		luaL_error(L, "closed handle");
	return 0;
}
Ejemplo n.º 8
0
LOCAL void x11_sendimessages(struct X11Display *mod)
{
	TAPTR TExecBase = TGetExecBase(mod);
	struct TNode *next, *node = mod->x11_vlist.tlh_Head.tln_Succ;

	for (; (next = node->tln_Succ); node = next)
	{
		struct X11Window *v = (struct X11Window *) node;
		TIMSG *imsg;

		while ((imsg = (TIMSG *) TRemHead(&v->imsgqueue)))
		{
			/* only certain input message types are sent two-way */
			struct TMsgPort *rport = imsg->timsg_Type == TITYPE_REQSELECTION ?
				mod->x11_IReplyPort : TNULL;
			TPutMsg(v->imsgport, rport, imsg);
		}
	}
}
Ejemplo n.º 9
0
static TMODAPI void
fb_beginio(WINDISPLAY *mod, struct TVRequest *req)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
	TPutMsg(mod->fbd_CmdPort, req->tvr_Req.io_ReplyPort, req);
}
Ejemplo n.º 10
0
static void rfb_processevent(RFBDISPLAY *mod)
{
	TAPTR TExecBase = TGetExecBase(mod);
	TIMSG *msg;
	
	if (mod->rfb_RndIMsgPort == TNULL)
		return;

	while ((msg = TGetMsg(mod->rfb_RndIMsgPort)))
	{
		/*RFBWINDOW *v = (RFBWINDOW *) msg->timsg_Instance;*/
		TIMSG *imsg;
		
		switch (msg->timsg_Type)
		{
			case TITYPE_INTERVAL:
				TDBPRINTF(TDB_WARN,("unhandled event: INTERVAL\n"));
				break;
			case TITYPE_REFRESH:
			{
				TINT drect[4];
				drect[0] = msg->timsg_X;
				drect[1] = msg->timsg_Y;
				drect[2] = msg->timsg_X + msg->timsg_Width - 1;
				drect[3] = msg->timsg_Y + msg->timsg_Height - 1;
				rfb_damage(mod, drect, TNULL);
				break;
			}
			case TITYPE_NEWSIZE:
				TDBPRINTF(TDB_WARN,("unhandled event: NEWSIZE\n"));
				break;
				
			case TITYPE_CLOSE:
			{
				/* send to root window */
				TLock(mod->rfb_InstanceLock);
				RFBWINDOW *v = (RFBWINDOW *) TLASTNODE(&mod->rfb_VisualList);
				if (rfb_getimsg(mod, v, &imsg, TITYPE_CLOSE))
					TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
				TUnlock(mod->rfb_InstanceLock);
				break;
			}
			case TITYPE_FOCUS:
				TDBPRINTF(TDB_INFO,("unhandled event: FOCUS\n"));
				break;
			case TITYPE_MOUSEOVER:
				TDBPRINTF(TDB_INFO,("unhandled event: MOUSEOVER\n"));
				break;
				
			case TITYPE_KEYUP:
			case TITYPE_KEYDOWN:
				/* pass keyboard events to focused window, else to the
				 * hovered window (also setting the focus): */
				if (!rfb_passevent_to_focus(mod, msg))
					rfb_passevent_by_mousexy(mod, msg, TTRUE);
				break;

			case TITYPE_MOUSEMOVE:
				/* pass mouse movements to focused and hovered window: */
				if (rfb_passevent_by_mousexy(mod, msg, TFALSE) != 
					mod->rfb_FocusWindow)
					rfb_passevent_to_focus(mod, msg);
				break;
				
			case TITYPE_MOUSEBUTTON:
			{
				/* set focus on mousebutton down */
				TBOOL focus = msg->timsg_Code & (TMBCODE_LEFTDOWN | 
					TMBCODE_RIGHTDOWN | TMBCODE_MIDDLEDOWN);
				rfb_passevent_by_mousexy(mod, msg, focus);
				break;
			}
		}
		TReplyMsg(msg);
	}
}
Ejemplo n.º 11
0
static void rfb_runtask(struct TTask *task)
{
	TAPTR TExecBase = TGetExecBase(task);
	RFBDISPLAY *mod = TGetTaskData(task);
	struct TVRequest *req;
	TUINT sig;

	TTIME intt = { RAWFB_INTERVAL_MICROS };
	/* next absolute time to send interval message: */
	TTIME nextt;
	TTIME waitt, nowt;
	
	TAPTR cmdport = TGetUserPort(task);
	TUINT cmdportsignal = TGetPortSignal(cmdport);
	TUINT imsgportsignal = TGetPortSignal(mod->rfb_RndIMsgPort);
	
	TDBPRINTF(TDB_INFO,("RawFB device context running\n"));
	
	TGetSystemTime(&nowt);
	nextt = nowt;
	TAddTime(&nextt, &intt);
	
	do
	{
		/* process input messages: */
		rfb_processevent(mod);
		
		/* do draw commands: */
		while ((req = TGetMsg(cmdport)))
		{
			rfb_docmd(mod, req);
			TReplyMsg(req);
		}
		
		/* check if time interval has expired: */
		TGetSystemTime(&nowt);
		if (TCmpTime(&nowt, &nextt) > 0)
		{
			/* expired; send intervals: */
			TLock(mod->rfb_InstanceLock);
			
			struct TNode *next, *node = mod->rfb_VisualList.tlh_Head;
			for (; (next = node->tln_Succ); node = next)
			{
				RFBWINDOW *v = (RFBWINDOW *) node;
				TIMSG *imsg;
				if ((v->rfbw_InputMask & TITYPE_INTERVAL) &&
					rfb_getimsg(mod, v, &imsg, TITYPE_INTERVAL))
					TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
			}
			
			TUnlock(mod->rfb_InstanceLock);
			TAddTime(&nextt, &intt);
		}

		/* calculate new wait time: */
		waitt = nextt;
		TGetSystemTime(&nowt);
		TSubTime(&waitt, &nowt);
		
		if (waitt.tdt_Int64 <= 0 || waitt.tdt_Int64 > RAWFB_INTERVAL_MICROS)
		{
			/* something's wrong with the clock, recalculate */
			TDBPRINTF(TDB_INFO,("clock problem: %lld\n", waitt.tdt_Int64));
			nextt = nowt;
			TAddTime(&nextt, &intt);
			waitt = nextt;
			TSubTime(&waitt, &nowt);
		}
		
		sig = TWaitTime(&waitt, 
			cmdportsignal | imsgportsignal | TTASK_SIG_ABORT);
		
	} while (!(sig & TTASK_SIG_ABORT));
	
	TDBPRINTF(TDB_INFO,("RawFB device context closedown\n"));
	
	rfb_exittask(mod);
}
Ejemplo n.º 12
0
static void rfb_processevent(struct rfb_Display *mod)
{
	TAPTR TExecBase = TGetExecBase(mod);
	TIMSG *msg;

	if (mod->rfb_RndIMsgPort == TNULL)
		return;

	while ((msg = TGetMsg(mod->rfb_RndIMsgPort)))
	{
		/*struct rfb_Window *v = (struct rfb_Window *) msg->timsg_Instance; */
		TIMSG *imsg;

		switch (msg->timsg_Type)
		{
			case TITYPE_INTERVAL:
				TDBPRINTF(TDB_WARN, ("unhandled event: INTERVAL\n"));
				break;
			case TITYPE_REFRESH:
			{
				TINT drect[4];

				drect[0] = msg->timsg_X;
				drect[1] = msg->timsg_Y;
				drect[2] = msg->timsg_X + msg->timsg_Width - 1;
				drect[3] = msg->timsg_Y + msg->timsg_Height - 1;
				rfb_damage(mod, drect, TNULL);
				rfb_flush_clients(mod, TTRUE);
				break;
			}
			case TITYPE_NEWSIZE:
				if ((mod->rfb_Flags & RFBFL_BUFFER_OWNER) &&
					(mod->rfb_Flags & RFBFL_BUFFER_CAN_RESIZE))
				{
					region_free(&mod->rfb_RectPool, &mod->rfb_DirtyRegion);
					mod->rfb_Flags &= ~RFBFL_DIRTY;

					TINT neww = mod->rfb_Width = msg->timsg_Width;
					TINT newh = mod->rfb_Height = msg->timsg_Height;

					TUINT pixfmt = mod->rfb_PixBuf.tpb_Format;
					TUINT bpp = TVPIXFMT_BYTES_PER_PIXEL(pixfmt);
					TUINT bpl = bpp * neww;

					struct TVPixBuf newbuf;

					newbuf.tpb_BytesPerLine = bpl;
					newbuf.tpb_Format = mod->rfb_PixBuf.tpb_Format;
					newbuf.tpb_Data = TAlloc(mod->rfb_MemMgr, bpl * newh);
					if (newbuf.tpb_Data == TNULL)
						break;

					struct TNode *next, 
						*node = mod->rfb_VisualList.tlh_Head.tln_Succ;

					for (; (next = node->tln_Succ); node = next)
					{
						struct rfb_Window *v = (struct rfb_Window *) node;

						rfb_setrealcliprect(mod, v);

						TINT w0 = REGION_RECT_WIDTH(&v->rfbw_ScreenRect);
						TINT h0 = REGION_RECT_HEIGHT(&v->rfbw_ScreenRect);

						if ((v->rfbw_Flags & RFBWFL_FULLSCREEN))
						{
							v->rfbw_ScreenRect.r[0] = 0;
							v->rfbw_ScreenRect.r[1] = 0;
							v->rfbw_ScreenRect.r[2] = neww - 1;
							v->rfbw_ScreenRect.r[3] = newh - 1;
						}

						TINT ww = REGION_RECT_WIDTH(&v->rfbw_ScreenRect);
						TINT wh = REGION_RECT_HEIGHT(&v->rfbw_ScreenRect);

						if (v->rfbw_MinWidth > 0 && ww < v->rfbw_MinWidth)
							v->rfbw_ScreenRect.r[0] =
								v->rfbw_ScreenRect.r[2] - v->rfbw_MinWidth;
						if (v->rfbw_MinHeight > 0 && wh < v->rfbw_MinHeight)
							v->rfbw_ScreenRect.r[1] =
								v->rfbw_ScreenRect.r[3] - v->rfbw_MinHeight;

						ww = REGION_RECT_WIDTH(&v->rfbw_ScreenRect);
						wh = REGION_RECT_HEIGHT(&v->rfbw_ScreenRect);

						if (v->rfbw_Flags & RFBWFL_BACKBUFFER)
							rfb_resizewinbuffer(mod, v, w0, h0, ww, wh);
						else
							v->rfbw_PixBuf = newbuf;

						rfb_setwinrect(mod, v);

						if (ww != w0 || wh != h0)
						{
							if (rfb_getimsg(mod, v, &imsg, TITYPE_NEWSIZE))
							{
								imsg->timsg_Width = ww;
								imsg->timsg_Height = wh;
								TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
							}
						}
					}

					TFree(mod->rfb_PixBuf.tpb_Data);
					mod->rfb_PixBuf = newbuf;

					struct Rect drect;

					REGION_RECT_SET(&drect, 0, 0, neww - 1, newh - 1);
					rfb_damage(mod, drect.r, TNULL);
				}
				else
					TDBPRINTF(TDB_WARN, ("Cannot resize this framebuffer\n"));
				break;

			case TITYPE_CLOSE:
			{
				/* send to root window */
				TLock(mod->rfb_InstanceLock);
				struct rfb_Window *v =
					(struct rfb_Window *) TLASTNODE(&mod->rfb_VisualList);
				if (rfb_getimsg(mod, v, &imsg, TITYPE_CLOSE))
					TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
				TUnlock(mod->rfb_InstanceLock);
				break;
			}
			case TITYPE_FOCUS:
				TDBPRINTF(TDB_INFO, ("unhandled event: FOCUS\n"));
				break;
			case TITYPE_MOUSEOVER:
				TDBPRINTF(TDB_INFO, ("unhandled event: MOUSEOVER\n"));
				break;

			case TITYPE_KEYUP:
			case TITYPE_KEYDOWN:
				rfb_passevent_keyboard(mod, msg);
				break;

			case TITYPE_MOUSEMOVE:
				rfb_passevent_mousemove(mod, msg);
				break;

			case TITYPE_MOUSEBUTTON:
				rfb_passevent_mousebutton(mod, msg);
				break;
		}
		TReplyMsg(msg);
	}
}
Ejemplo n.º 13
0
LOCAL TBOOL rfb_damage(struct rfb_Display *mod, TINT drect[],
	struct rfb_Window *v)
{
	TAPTR TExecBase = TGetExecBase(mod);
	struct RectPool *pool = &mod->rfb_RectPool;
	struct Region A, B;

	if (!region_init(pool, &A, drect))
		return TFALSE;

	TDBPRINTF(TDB_TRACE, ("incoming damage: %d %d %d %d\n",
			drect[0], drect[1], drect[2], drect[3]));

	/* traverse window stack; refresh B where A and B overlap ; A = A - B */

	struct TNode *next, *node = mod->rfb_VisualList.tlh_Head.tln_Succ;
	TBOOL success = TTRUE;
	TBOOL below = TFALSE;

	TLock(mod->rfb_InstanceLock);

	for (; success && !region_isempty(pool, &A) &&
		(next = node->tln_Succ); node = next)
	{
		struct rfb_Window *bv = (struct rfb_Window *) node;

		if (v && !below)
		{
			if (bv == v)
				below = TTRUE;
			else
				/* above: subtract current from rect to be damaged: */
				success = region_subrect(pool, &A, bv->rfbw_ScreenRect.r);
			continue;
		}

		success = TFALSE;
		if (region_init(pool, &B, bv->rfbw_ScreenRect.r))
		{
			if (region_andregion(pool, &B, &A))
			{
				region_shift(&B,
					bv->rfbw_WinRect.r[0] - bv->rfbw_ScreenRect.r[0],
					bv->rfbw_WinRect.r[1] - bv->rfbw_ScreenRect.r[1]);

				struct TNode *next, 
					*node = B.rg_Rects.rl_List.tlh_Head.tln_Succ;

				for (; (next = node->tln_Succ); node = next)
				{
					struct RectNode *r = (struct RectNode *) node;

					if (bv->rfbw_Flags & RFBWFL_BACKBUFFER)
					{
						rfb_markdirty(mod, bv, r->rn_Rect);
					}
					else if (bv->rfbw_InputMask & TITYPE_REFRESH)
					{
						TIMSG *imsg;

						if (rfb_getimsg(mod, bv, &imsg, TITYPE_REFRESH))
						{
							TDBPRINTF(TDB_TRACE, ("send refresh %d %d %d %d\n",
									r->rn_Rect[0], r->rn_Rect[1],
									r->rn_Rect[2], r->rn_Rect[3]));
							imsg->timsg_X = r->rn_Rect[0];
							imsg->timsg_Y = r->rn_Rect[1];
							imsg->timsg_Width =
								r->rn_Rect[2] - r->rn_Rect[0] + 1;
							imsg->timsg_Height =
								r->rn_Rect[3] - r->rn_Rect[1] + 1;
							imsg->timsg_X -= bv->rfbw_ScreenRect.r[0];
							imsg->timsg_Y -= bv->rfbw_ScreenRect.r[1];
							TPutMsg(bv->rfbw_IMsgPort, TNULL, imsg);
						}
					}
				}
				success = TTRUE;
			}
			region_free(pool, &B);
		}

		if (success)
			success = region_subrect(pool, &A, bv->rfbw_ScreenRect.r);
	}

	TUnlock(mod->rfb_InstanceLock);

	region_free(pool, &A);

	return success;
}
Ejemplo n.º 14
0
static void tek_lib_visual_io_task(struct TTask *task)
{
	struct TExecBase *TExecBase = TGetExecBase(task);
	struct IOData *iodata = TGetTaskData(task);
	TEKVisual *vis = iodata->vis;
	TIMSG *imsg;
	TUINT sig;
	#if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM)
	char buf[256];
	fd_set rset;
	#endif
	do
	{
		#if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM)
		FD_ZERO(&rset);
		FD_SET(iodata->fd_pipe[0], &rset);
		#endif
		#if defined(ENABLE_FILENO)
		if (iodata->fd_stdin != -1)
			FD_SET(iodata->fd_stdin, &rset);
		#endif
		#if defined(ENABLE_DGRAM)
		FD_SET(iodata->fd_dgram, &rset);
		#endif
		#if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM)
		if (select(iodata->fdmax, &rset, NULL, NULL, NULL) > 0)
		{
			int nbytes = 0;
			
			/* consume signal: */
			if (FD_ISSET(iodata->fd_pipe[0], &rset))
			{
				ioctl(iodata->fd_pipe[0], FIONREAD, &nbytes);
				if (nbytes > 0)
					if (read(iodata->fd_pipe[0], buf,
						TMIN(sizeof(buf), (size_t) nbytes)) != nbytes)
					TDBPRINTF(TDB_ERROR,("Error reading from selfpipe\n"));
			}
			
			#if defined(ENABLE_FILENO)
			/* stdin line reader: */
			if (iodata->fd_stdin >= 0 && FD_ISSET(iodata->fd_stdin, &rset))
			{
				if (ioctl(iodata->fd_stdin, FIONREAD, &nbytes) == 0)
				{
					if (nbytes == 0)
						iodata->fd_stdin = -1; /* stop processing */
					else
					{
						char *line;
						size_t len;
						visual_io_reader_addbytes(&iodata->linereader, nbytes);
						while (visual_io_readline(&iodata->linereader, &line,
							&len))
						{
							if (getusermsg(vis, &imsg, TITYPE_USER, len))
							{
								memcpy((void *) (imsg + 1), line, len);
								TPutMsg(vis->vis_IMsgPort, TNULL,
									&imsg->timsg_Node);
							}
						}
					}
				}
				else
					iodata->fd_stdin = -1; /* stop processing */
			}
			#endif
			
			#if defined(ENABLE_DGRAM)
			if (iodata->fd_dgram >= 0 && FD_ISSET(iodata->fd_dgram, &rset))
			{
				char umsg[IOMAXMSGSIZE];
				TIMSG *imsg;
				ssize_t len = recv(iodata->fd_dgram, umsg, sizeof umsg, 0);
				if (len >= 0 && getusermsg(vis, &imsg, TITYPE_USER, len))
				{
					memcpy((void *) (imsg + 1), umsg, len);
					TPutMsg(vis->vis_IMsgPort, TNULL, &imsg->timsg_Node);
				}
			}
			#endif
		}
		sig = TSetSignal(0, TTASK_SIG_ABORT | TTASK_SIG_USER);
		#else
		sig = TWait(TTASK_SIG_ABORT | TTASK_SIG_USER);
		#endif
		if (sig & TTASK_SIG_USER)
		{
			TAPTR msg, uport = TGetUserPort(TNULL);
			while ((msg = TGetMsg(uport)))
			{
				TSIZE len = TGetSize(msg);
				/* repackage into user input message */
				if (getusermsg(vis, &imsg, TITYPE_USER, len))
				{
					memcpy((void *) (imsg + 1), msg, len);
					TPutMsg(vis->vis_IMsgPort, TNULL, &imsg->timsg_Node);
				}
				TAckMsg(msg);
			}
		}
	} while (!(sig & TTASK_SIG_ABORT));
	
	tek_lib_visual_io_exit(task);
}
Ejemplo n.º 15
0
LOCAL void x11_taskfunc(struct TTask *task)
{
	TAPTR TExecBase = TGetExecBase(task);
	struct X11Display *inst = TGetTaskData(task);
	TUINT sig = 0;
	fd_set rset;
	struct TVRequest *req;
	TIMSG *imsg;
	char buf[256];
	struct timeval tv, *ptv;
	struct TMsgPort *cmdport = TGetUserPort(task);
	TUINT cmdportsignal = TGetPortSignal(cmdport);
	TUINT ireplysignal = TGetPortSignal(inst->x11_IReplyPort);
	TUINT waitsigs = cmdportsignal | ireplysignal | TTASK_SIG_ABORT;

	/* interval time: 1/50s: */
	TTIME intt = { 20000 };

	/* next absolute time to send interval message: */
	TTIME nextt;
	TTIME waitt, nowt;

	TDBPRINTF(TDB_INFO, ("Device instance running\n"));

	TGetSystemTime(&nowt);
	nextt = nowt;
	TAddTime(&nextt, &intt);

	do
	{
		if (sig & ireplysignal)
		{
			while ((imsg = TGetMsg(inst->x11_IReplyPort)))
			{
				/* returned input message */
				if (imsg->timsg_Type == TITYPE_REQSELECTION)
				{
					XSelectionEvent *reply =
						(XSelectionEvent *) imsg->timsg_Requestor;
					struct TTagItem *replytags =
						(struct TTagItem *) imsg->timsg_ReplyData;
					size_t len =
						TGetTag(replytags, TIMsgReply_UTF8SelectionLen, 0);
					TUINT8 *xdata = (TUINT8 *) TGetTag(replytags,
						TIMsgReply_UTF8Selection, TNULL);

					XChangeProperty(inst->x11_Display, reply->requestor,
						reply->property, XA_ATOM, 8, PropModeReplace,
						(unsigned char *) xdata, len);
					XSendEvent(inst->x11_Display, reply->requestor, 0,
						NoEventMask, (XEvent *) reply);
					XSync(inst->x11_Display, False);
					TFree((TAPTR) imsg->timsg_Requestor);
					TFree(xdata);
					/* reqselect roundtrip ended */
				}
				TFree(imsg);
			}
		}

		if (sig & cmdportsignal)
		{
			while (inst->x11_RequestInProgress == TNULL &&
				(req = TGetMsg(cmdport)))
			{
				x11_docmd(inst, req);
				if (inst->x11_RequestInProgress)
					break;
				TReplyMsg(req);
			}
		}

		XFlush(inst->x11_Display);

		FD_ZERO(&rset);
		FD_SET(inst->x11_fd_display, &rset);
		FD_SET(inst->x11_fd_sigpipe_read, &rset);

		TGetSystemTime(&nowt);

		if (inst->x11_NumInterval > 0 || inst->x11_RequestInProgress)
		{
			if (TCmpTime(&nowt, &nextt) >= 0)
			{
				/* expired; send interval: */
				struct TNode *next, *node = inst->x11_vlist.tlh_Head.tln_Succ;

				for (; (next = node->tln_Succ); node = next)
				{
					struct X11Window *v = (struct X11Window *) node;
					TIMSG *imsg;

					if ((v->eventmask & TITYPE_INTERVAL) &&
						x11_getimsg(inst, v, &imsg, TITYPE_INTERVAL))
						TPutMsg(v->imsgport, TNULL, imsg);
				}
				TAddTime(&nextt, &intt);
			}

			/* calculate new wait time: */
			waitt = nextt;
			TSubTime(&waitt, &nowt);
			if (waitt.tdt_Int64 <= 0 || waitt.tdt_Int64 > 20000)
			{
				nextt = nowt;
				TAddTime(&nextt, &intt);
				waitt = nextt;
				TSubTime(&waitt, &nowt);
			}
			tv.tv_sec = waitt.tdt_Int64 / 1000000;
			tv.tv_usec = waitt.tdt_Int64 % 1000000;
			ptv = &tv;
		}
		else
			ptv = NULL;

		/* wait for display, signal fd and timeout: */
		if (select(inst->x11_fd_max, &rset, NULL, NULL, ptv) > 0)
		{
			int nbytes;

			/* consume signal: */
			if (FD_ISSET(inst->x11_fd_sigpipe_read, &rset))
			{
				ioctl(inst->x11_fd_sigpipe_read, FIONREAD, &nbytes);
				if (nbytes > 0)
					if (read(inst->x11_fd_sigpipe_read, buf,
							TMIN(sizeof(buf), (size_t) nbytes)) != nbytes)
						TDBPRINTF(TDB_ERROR,
							("could not read wakeup signal\n"));
			}
		}

		/* process input messages: */
		x11_processevent(inst);

		/* send out input messages to owners: */
		x11_sendimessages(inst);

		/* get signal state: */
		sig = TSetSignal(0, waitsigs);

	}
	while (!(sig & TTASK_SIG_ABORT));

	TDBPRINTF(TDB_INFO, ("Device instance exit\n"));

	x11_exitinstance(inst);
}
Ejemplo n.º 16
0
static int tek_lib_exec_child_sigjoin(lua_State *L, TUINT sig, TBOOL sigparent,
	TBOOL do_results)
{
	struct LuaExecChild *ctx = luaL_checkudata(L, 1, TEK_LIB_TASK_CLASSNAME);
	struct TExecBase *TExecBase = ctx->exec;
	struct TTask *self = TFindTask(TNULL), *task = ctx->task;
	union TTaskRequest *req = &self->tsk_Request;
	TBOOL abort = TFALSE;
	int nres = 0;
	if (!task)
		return 0;
	
	TDBPRINTF(TDB_TRACE,("child_join sig=%d sigparent=%d\n", sig, sigparent));
	
	/* signal task */
	TSignal(task, sig);
	/* prepare destroy request */
	self->tsk_ReqCode = TTREQ_DESTROYTASK;
	req->trq_Task.trt_Task = task;
	/* send to exec */
	TPutMsg(TExecBase->texb_ExecPort, &self->tsk_SyncPort, self);
	for (;;)
	{
		/* wait for return of request or receiving abort ourselves: */
		TUINT sig = TWait(TTASK_SIG_SINGLE | TTASK_SIG_ABORT);
		if (sig & TTASK_SIG_SINGLE)
			break;
		if (sig & TTASK_SIG_ABORT)
		{
			/* forward to child task */
			TSignal(task, TTASK_SIG_ABORT);
			if (sigparent)
			{
				/* also forward to own parent task */
				struct LuaExecTask *parent = getparent(TExecBase);
				if (parent)
					TSignal(parent->task, TTASK_SIG_ABORT);
				abort = TTRUE;
			}
		}
	}
	/* take delivery of replied destroy request */
	TGetMsg(&self->tsk_SyncPort);
	/* free task */	
	TFreeTask(task);
	
	ctx->task = TNULL;
	tek_lib_exec_freectxargs(ctx);
	if (!abort && do_results)
	{
		int i;
		nres = ctx->numres + 1;
		lua_pushboolean(L, ctx->luastatus == 0);
		for (i = 0; i < ctx->numres; ++i)
			lua_pushlstring(L, ctx->results[i].arg, ctx->results[i].len);
	}
	tek_lib_exec_freeargs(TExecBase, ctx->results, ctx->numres);
	luaL_unref(L, lua_upvalueindex(1), ctx->ref);
	if (abort)
		luaL_error(L, "received abort signal");
	return nres;
}
Ejemplo n.º 17
0
LOCAL void fb_sendimsg(WINDISPLAY *mod, WINWINDOW *win, TIMSG *imsg)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
	TPutMsg(win->fbv_IMsgPort, TNULL, imsg);
}
Ejemplo n.º 18
0
static void rfb_runtask(struct TTask *task)
{
	TAPTR TExecBase = TGetExecBase(task);
	struct rfb_Display *mod = TGetTaskData(task);
	struct TVRequest *req;
	TUINT sig = 0;

	TTIME intt = { 20000 };
	/* next absolute time to send interval message: */
	TTIME nextt;
	TTIME waitt, nowt, *pwaitt;

	TAPTR cmdport = TGetUserPort(task);
	TUINT cmdportsignal = TGetPortSignal(cmdport);
	TUINT imsgportsignal = TGetPortSignal(mod->rfb_RndIMsgPort);
	TUINT waitsigs = cmdportsignal | imsgportsignal | TTASK_SIG_ABORT;

	TDBPRINTF(TDB_INFO, ("RawFB device context running\n"));

	TGetSystemTime(&nowt);
	nextt = nowt;
	TAddTime(&nextt, &intt);

	do
	{
		if (sig & cmdportsignal)
		{
			TBOOL checkrect = mod->rfb_Flags & RFBFL_PTR_VISIBLE;
			TINT arec[4];

			while ((req = TGetMsg(cmdport)))
			{
				if (checkrect)
				{
					TINT res = rfb_cmdrectaffected(mod, req, arec, TTRUE);

					if (res < 0 || (res > 0 &&
							REGION_OVERLAPRECT(mod->rfb_PtrBackBuffer.rect,
								arec)))
					{
						rfb_restoreptrbg(mod);
						checkrect = TFALSE;
					}
				}
				rfb_docmd(mod, req);
				TReplyMsg(req);
			}
		}

		if (mod->rfb_Flags & RFBFL_SHOWPTR)
			rfb_drawpointer(mod);

		/* check if time interval has expired: */
		TGetSystemTime(&nowt);

		/* do interval timers */
		if (mod->rfb_NumInterval > 0)
		{
			if (TCmpTime(&nowt, &nextt) >= 0)
			{
				/* expired; send intervals: */
				TLock(mod->rfb_InstanceLock);
				struct TNode *next, 
					*node = mod->rfb_VisualList.tlh_Head.tln_Succ;

				for (; (next = node->tln_Succ); node = next)
				{
					struct rfb_Window *v = (struct rfb_Window *) node;
					TIMSG *imsg;

					if ((v->rfbw_InputMask & TITYPE_INTERVAL) &&
						rfb_getimsg(mod, v, &imsg, TITYPE_INTERVAL))
						TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
				}
				TUnlock(mod->rfb_InstanceLock);
				TAddTime(&nextt, &intt);
			}

			/* calculate new wait time: */
			waitt = nextt;
			TSubTime(&waitt, &nowt);
			if (waitt.tdt_Int64 <= 0 || waitt.tdt_Int64 > 20000)
			{
				nextt = nowt;
				TAddTime(&nextt, &intt);
				waitt = nextt;
				TSubTime(&waitt, &nowt);
			}
			pwaitt = &waitt;
		}
		else
			pwaitt = TNULL;

#if defined(ENABLE_LINUXFB)
		rfb_linux_wait(mod, pwaitt);
		sig = TSetSignal(0, waitsigs);
#else
		sig = TWaitTime(pwaitt, waitsigs);
#endif

		if (sig & imsgportsignal)
			rfb_processevent(mod);

	} while (!(sig & TTASK_SIG_ABORT));

	TDBPRINTF(TDB_INFO, ("RawFB device context closedown\n"));

	rfb_exittask(mod);
}