예제 #1
0
파일: os2pm.c 프로젝트: OS2World/LIB-libfly
void fly_init (int x0, int y0, int rows, int cols, char *font)
{
    TID       tid;
    int       rc;
    ULONG     reset;

    tiled1 = _tmalloc (tiled_size);
    if (tiled1 == NULL) fly_error ("cannot allocate tiled memory\n");
    us1_16 = _tmalloc (sizeof(USHORT));
    us2_16 = _tmalloc (sizeof(USHORT));
    pci = _tmalloc (sizeof(VIOCURSORINFO));

    rc = DosCreateMutexSem (NULL, &mtx_Queue, 0, FALSE);
    debug_tools ("rc = %d after DosCreateMutexSem\n", rc);

    rc = DosCreateMutexSem (NULL, &mtx_Video, 0, FALSE);
    debug_tools ("rc = %d after DosCreateMutexSem\n", rc);

    rc = DosCreateEventSem (NULL, &hev_NewMessage, 0, FALSE);
    debug_tools ("rc = %d after DosCreateEventSem\n", rc);

    rc = DosCreateEventSem (NULL, &hev_VideoReady, 0, FALSE);
    debug_tools ("rc = %d after DosCreateEventSem\n", rc);
    
    grab_video ();
    if (rows != -1 && cols != -1)
        video_init (rows, cols);
    else
        video_init (25, 80);
    release_video ();

    DosResetEventSem (hev_VideoReady, &reset);
    rc = DosCreateThread (&tid, interface_thread, 0, 0, 32786);
    debug_tools ("rc = %d after DosCreateThread\n", rc);

    DosWaitEventSem (hev_VideoReady, SEM_INDEFINITE_WAIT);
    fl_opt.initialized = TRUE;
    DosSleep (300);

    if (font != NULL)
        fly_set_font (font);

    //debug_tools ("rows = %d, cols = %d in fly_init\n", rows, cols);
    if (rows != -1 && cols != -1)
        video_set_window_size (rows, cols);
    
    debug_tools ("x0 = %d, y0 = %d in fly_init\n", x0, y0);
    if (x0 >= 0 && y0 >= 0)
        video_set_window_pos (x0, y0);
}
예제 #2
0
void os2KbdMonitorThread(void* arg)
{
	struct KeyPacket packet;
	APIRET rc;
	USHORT length,print_flag;
	ULONG queueParam;
	HMONITOR hKbdMonitor;
	MONIN monInbuf;
	MONOUT monOutbuf;
	char queueName[128];

#if 0
	monInbuf=(MONIN *)_tmalloc(2*sizeof(MONIN));
	if (monInbuf==NULL) {
		xf86Msg(X_ERROR,
			"Could not allocate memory in kbd monitor thread!\n");
		exit(1);
	}
	monOutbuf=(MONOUT *) &monInbuf[1];
#endif

	monInbuf.cb=sizeof(MONIN);
	monOutbuf.cb=sizeof(MONOUT);

	rc = DosMonOpen("KBD$",&hKbdMonitor);
	xf86Msg(X_INFO,"Opened kbd monitor, rc=%d\n",rc);
 	rc = DosMonReg(hKbdMonitor,
		       (PBYTE)&monInbuf,(PBYTE)&monOutbuf,(USHORT)2,(USHORT)-1);
	xf86Msg(X_INFO,"Kbd monitor registered, rc=%d\n",rc);
	if (rc) {
		DosMonClose(hKbdMonitor);
		exit(1);
	}

	/* create a queue */
	sprintf(queueName,"\\QUEUES\\XF86KBD\\%d",getpid());
	rc = DosCreateQueue(&hKbdQueue,0L,queueName);
	xf86Msg(X_INFO,"Kbd Queue created, rc=%d\n",rc);
	(void)DosPurgeQueue(hKbdQueue);

	while (1) {
		length = sizeof(packet);
		rc = DosMonRead((PBYTE)&monInbuf,0,(PBYTE)&packet,&length);
		if (rc)	{
			xf86Msg(X_ERROR,
				"DosMonRead returned bad RC! rc=%d\n",rc);
			DosMonClose(hKbdMonitor);
			exit(1);
		}
		queueParam = packet.mnflags+(packet.ddflags<<16);
		if (packet.mnflags&0x7F00)
			DosWriteQueue(hKbdQueue,queueParam,0L,NULL,0L);
			/*xf86Msg(X_INFO,"Wrote a char to queue, rc=%d\n",rc); */
		print_flag = packet.ddflags & 0x1F;

		/*xf86Msg(X_INFO,"Kbd Monitor: Key press %d, scan code %d, ddflags %d\n",
			  packet.mnflags&0x8000,(packet.mnflags&0x7F00)>>8,packet.ddflags); 
		*/

		/* This line will swallow print-screen keypresses */
		if (print_flag == 0x13 || print_flag == 0x14 || 
		    print_flag == 0x15 || print_flag == 0x16)
			rc = 0;
		else
			rc = DosMonWrite((PBYTE)&monOutbuf,(PBYTE)&packet,length); 
		if (rc) {
			xf86Msg(X_ERROR,
				"DosMonWrite returned bad RC! rc=%d\n",rc);
			DosMonClose(hKbdMonitor);
			exit(1);
		}
	}

	DosCloseQueue(hKbdQueue);
	DosMonClose(hKbdMonitor);
}