Example #1
0
static VOID HIDD_LinuxInput_HandleMouseEvent(struct EventHandler * eh, struct pHidd_Mouse_Event *mouse_event)
{
    if ((eh->capabilities & CAP_MOUSE) && eh->mousehidd)
        HIDD_LinuxMouse_HandleEvent((OOP_Object *)eh->mousehidd, mouse_event);
}
Example #2
0
static VOID inputtask_entry(struct inputtask_params *inputparams)
{
    struct linux_staticdata *lsd;
    struct inputtask_params itp;
    UBYTE lastcode = 0xFF;
    
    struct MsgPort *kbd_port = NULL;
    struct MsgPort *mouse_port = NULL;
    
    struct mouse_state oldstate = { { 0, 0, 0 }, 0, 0 };
    struct pHidd_Mouse_Event mouse_event;
    
    HIDD *unixio = NULL;
    ULONG kbdsig, mousesig, sigs;
    /* We must copy the parameter struct because they are allocated
     on the parent's stack */
kprintf("INSIDE INPUT TASK\n");
    itp = *inputparams;
    lsd = itp.lsd;
kprintf("in inputtask: lsd = %p\n", lsd);

kprintf("CREATING UNIXIO,,, OOPBase=%p\n", OOPBase);
kprintf("now\n");
    unixio = (HIDD)New_UnixIO(OOPBase, SysBase);
kprintf("UNIXIO %p\n", unixio);
    if (NULL == unixio) {
    	goto failexit;
    }
    
    kbd_port   = CreateMsgPort();
    mouse_port = CreateMsgPort();
    
    if (NULL == kbd_port || NULL == mouse_port)
	goto failexit;
    
    Signal(itp.parent, itp.ok_signal);
    
    kbdsig	= 1L << kbd_port->mp_SigBit;
    mousesig	= 1L << mouse_port->mp_SigBit;
kprintf("SIGS: %p, %p\n", kbdsig, mousesig);
kprintf("FDS: %d, %d\n", lsd->kbdfd, lsd->mousefd);

    Hidd_UnixIO_AsyncIO(unixio, lsd->kbdfd,   vHidd_UnixIO_Terminal, kbd_port,	vHidd_UnixIO_Read, SysBase);
    Hidd_UnixIO_AsyncIO(unixio, lsd->mousefd, vHidd_UnixIO_Terminal, mouse_port,  vHidd_UnixIO_Read, SysBase);
    
    for (;;) {
	LONG err_kbd, err_mouse;
	
	//kprintf("GETTING INPUT FROM UNIXIO\n");
	/* Turn on kbd support */
//	init_kbd(lsd);
	
	
//    	ret = (int)Hidd_UnixIO_Wait( unixio, lsd->kbdfd, vHidd_UnixIO_Read, NULL, NULL);
//	cleanup_kbd(lsd);
//	kprintf("GOT INPUT FROM UNIXIO\n");
	
	sigs = Wait( kbdsig | mousesig );

	if (sigs & kbdsig) {
	
//kprintf("---------- GOT KBD INPUT --------------------\n");
 	    for (;;) {
		UBYTE code;
		size_t bytesread;
	    
	    
		bytesread = read(lsd->kbdfd, &code, 1);
		if (-1 == bytesread)  {
	    	    kprintf("!!! COULD NOT READ FROM LINUX KBD DEVICE: %s\n"
			, strerror(errno));
		    break;
		
		} else {
	    	    /* Let the kbd hidd handle it */
		    /* Key doewn ? */
		    
		    //kprintf("## code %d\n", code);
		    if (code == lastcode)
			break;
		    
	    	    // if (!(code & 0x80)) kprintf("GOT SCANCODE %d from kbd hidd\n", code);
		    if (code == 88) /* F12 */
		    {
			    kill(getpid(), SIGTERM);
		    }
		
		    /* Send code to the application */
    	    	    ObtainSemaphore(&lsd->sema);
		    if (lsd->kbdhidd) HIDD_LinuxKbd_HandleEvent(lsd->kbdhidd, code);
    	    	    ReleaseSemaphore(&lsd->sema);

		    lastcode = code;
		}
		break;

	    }	/* for (;;) */
	    free_unixio_message(kbd_port, lsd);

	    err_kbd = Hidd_UnixIO_AsyncIO(unixio, lsd->kbdfd,   vHidd_UnixIO_Terminal, kbd_port,	vHidd_UnixIO_Read, SysBase);

	} /* if (sigs & kbdsig) */
	
	if (sigs & mousesig)
	{
	    ULONG i;
	    LONG bytesread;
	    UBYTE buf[4];
	    BYTE dx = 0, dy = 0;
	    struct mouse_state newstate;
	    
	    /* Got mouse event */
	    //kprintf("------------- MOUSE EVENT ------------\n");
	    for (i = 0; i < 4; i ++) {
	    	bytesread = read(lsd->mousefd, &buf[i], 1);
		if (-1 == bytesread)
		{
		    if (errno == EAGAIN)
		    {
		    	i--;
			continue;
		    }
		    kprintf("!!! linux input task: Could not read from mouse device: %s\n", strerror(errno));
		    goto end_mouse_event;    
		}
		
		if ((buf[0] & 8) != 8) i--;
	    }
	    
	    //kprintf("%02x: %02x: %02x\n", buf[0], buf[1], buf[2]);
	    /* Get button states */
	    newstate.buts[0] = (buf[0] & 0x01) ? 1 : 0;
	    newstate.buts[1] = (buf[0] & 0x02) ? 1 : 0;
	    newstate.buts[2] = (buf[0] & 0x04) ? 1 : 0;
	    
	    if (buf[1] != 0) {
		dx = (buf[0] & 0x10) ? buf[1] - 256 : buf[1];
	    }
	    
	    if (buf[2] != 0) {
		dy = (buf[0] & 0x20) ? buf[2] - 256 : buf[2];
	    }
		
	    newstate.dx = dx;
	    newstate.dy = -dy;
	    
	    //kprintf("EVENT: STATE 1:%d, 2:%d, 3:%d, dx:%d, dy:%d\n"
	    //	, newstate.buts[0], newstate.buts[1], newstate.buts[2]
	    //	, newstate.dx, newstate.dy);
		
            ObtainSemaphore(&lsd->sema);    
    	    if (lsd->mousehidd)
	    {
    		mouse_event.x = newstate.dx;
		mouse_event.y = newstate.dy;

		if (newstate.dx || newstate.dy)
		{
	    	    mouse_event.button = vHidd_Mouse_NoButton;
		    mouse_event.type = vHidd_Mouse_Motion;

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}

		if (newstate.buts[0] != oldstate.buts[0])
		{
	    	    mouse_event.button = vHidd_Mouse_Button1;
		    mouse_event.type = newstate.buts[0] ? vHidd_Mouse_Press : vHidd_Mouse_Release;	

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}

		if (newstate.buts[1] != oldstate.buts[1])
		{
	    	    mouse_event.button = vHidd_Mouse_Button2;
		    mouse_event.type = newstate.buts[1] ? vHidd_Mouse_Press : vHidd_Mouse_Release;	

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}

		if (newstate.buts[2] != oldstate.buts[2])
		{
	    	    mouse_event.button = vHidd_Mouse_Button3;
		    mouse_event.type = newstate.buts[2] ? vHidd_Mouse_Press : vHidd_Mouse_Release;	

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}
	    }
    	    ReleaseSemaphore(&lsd->sema);
	    
    	    oldstate = newstate;
	    	    	    
end_mouse_event:
	    free_unixio_message(mouse_port, lsd);

	    err_mouse	= Hidd_UnixIO_AsyncIO(unixio, lsd->mousefd, vHidd_UnixIO_Terminal, mouse_port,  vHidd_UnixIO_Read, SysBase);

	}
    	
    } /* Forever */
    
failexit:

    if (NULL != kbd_port)
    	DeleteMsgPort(kbd_port);

    if (NULL != mouse_port)
	DeleteMsgPort(mouse_port);
	
    if (NULL != unixio)
    	OOP_DisposeObject((OOP_Object *)unixio);

    Signal(itp.parent, itp.fail_signal);
     
    return;
    
}