//wait for user to release mouse key
void ImouseWait(void)
{
#ifdef GGI
 struct timeval forever={FOREVER,0};  //one hour is like forever, for most CPUs
 ggiEventPoll(ggiVis, emPointer, &forever);
#else
 int dummy;
 while (ImouseRead(&dummy,&dummy))
  usleep(10000); //don't let it eat all CPU time...
#endif
}
Exemple #2
0
void
IN_SendKeyEvents (void)
{
	/* Get events from LibGGI */
	if (ggivis) {
		struct timeval t = { 0, 0 };

		if (ggiEventPoll (ggivis, emAll, &t)) {
			int         i = ggiEventsQueued (ggivis, emAll);

			while (i--)
				GetEvent ();
		}
	}
}
Exemple #3
0
static void check_events(void)
{
    struct timeval  tv = {0, 0};
    ggi_event       event;
    ggi_event_mask  mask;

    if ((mask = ggiEventPoll(ggi_conf.vis, emAll, &tv))) {
        if (ggiEventRead(ggi_conf.vis, &event, emAll) != 0) {
            mp_dbg(MSGT_VO, MSGL_DBG3,
                   "type: %4x, origin: %4x, "
                   "sym: %4x, label: %4x, button=%4x\n",
                   event.any.origin, event.any.type, event.key.sym,
                   event.key.label, event.key.button);

            switch (event.any.type) {
            case evKeyPress:
                switch (event.key.sym) {
                case GIIK_PAsterisk:    /* PStar */
                case GIIUC_Asterisk:
                    mplayer_put_key('*');
                    break;
                case GIIK_PSlash:
                case GIIUC_Slash:
                    mplayer_put_key('/');
                    break;
                case GIIK_PPlus:
                case GIIUC_Plus:
                    mplayer_put_key('+');
                    break;
                case GIIK_PMinus:
                case GIIUC_Minus:
                    mplayer_put_key('-');
                    break;
                case GIIUC_o:
                case GIIUC_O:
                    mplayer_put_key('o');
                    break;
                case GIIUC_g:
                case GIIUC_G:
                    mplayer_put_key('g');
                    break;
                case GIIUC_z:
                case GIIUC_Z:
                    mplayer_put_key('z');
                    break;
                case GIIUC_x:
                case GIIUC_X:
                    mplayer_put_key('x');
                    break;
                case GIIUC_m:
                case GIIUC_M:
                    mplayer_put_key('m');
                    break;
                case GIIUC_d:
                case GIIUC_D:
                    mplayer_put_key('d');
                    break;
                case GIIUC_q:
                case GIIUC_Q:
                    mplayer_put_key('q');
                    break;
                case GIIUC_h:
                case GIIUC_H:
                    mplayer_put_key('h');
                    break;
                case GIIUC_l:
                case GIIUC_L:
                    mplayer_put_key('l');
                    break;
                case GIIUC_Space:
                case GIIUC_p:
                case GIIUC_P:
                    mplayer_put_key('p');
                    break;
                case GIIK_Up:
                    mplayer_put_key(KEY_UP);
                    break;
                case GIIK_Down:
                    mplayer_put_key(KEY_DOWN);
                    break;
                case GIIK_Left:
                    mplayer_put_key(KEY_LEFT);
                    break;
                case GIIK_Right:
                    mplayer_put_key(KEY_RIGHT);
                    break;
                case GIIK_PageUp:
                    mplayer_put_key(KEY_PAGE_UP);
                    break;
                case GIIK_PageDown:
                    mplayer_put_key(KEY_PAGE_DOWN);
                    break;
                default:
                    break;
                }   /* switch */

                break;
            }   /* switch */
        }   /* if */
    }   /* if */
    return;
}
void GGI_PumpEvents(_THIS)
{
	struct timeval *tvp, tv = { 0, 0 };
	ggi_event ev;

	tvp = &tv;
	
	
	while (ggiEventPoll(VIS, emAll, tvp))
	{
		int queueevent_mouse = 0, queueevent_kbd = 0;
		static int buttons = 0;
		static int mouse_x = 0, mouse_y = 0, mouse_z = 0;
		int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0;
		int pressed_mouse, pressed_kbd;
		SDL_keysym keysym;
		
		posted = 0;


		ggiEventRead(VIS, &ev, emAll);
		
		switch (ev.any.type)
		{
			case evPtrRelative:
			x = ev.pmove.x;
			y = ev.pmove.y;
			z = ev.pmove.wheel;
			posted += SDL_PrivateMouseMotion(0, 1, x, y);
			break;
			case evPtrAbsolute:
			if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel)
			{
				x = ev.pmove.x - mouse_x;
				y = ev.pmove.y - mouse_y;
				z = ev.pmove.wheel - mouse_z;
				mouse_x = ev.pmove.x;
				mouse_y = ev.pmove.y;
				mouse_z = ev.pmove.wheel;
				posted += SDL_PrivateMouseMotion(0, 1, x, y);
			} 
			break;
			case evPtrButtonPress:
			posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0);
			break;
			case evPtrButtonRelease:
			posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0);
			break;
			case evKeyPress:
			case evKeyRepeat:
			posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evKeyRelease:
			posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evCommand:
			fprintf(stderr, "Command event %x recieved\n", ev.cmd.code);
			break;
 			default:
			fprintf(stderr, "Unhandled event type %d\n", ev.any.type);
			break;
		}
	}

}
void GGI_PumpEvents(_THIS)
{
	struct timeval *tvp, tv = { 0, 0 };
	ggi_event ev;

	tvp = &tv;
	
/*	ggiFlush(VIS); */
	
	while (ggiEventPoll(VIS, emAll, tvp))
/*	while (ggiEventPoll(VIS, (emKeyboard | emPointer | emCommand), tvp)) */
	{
		int queueevent_mouse = 0, queueevent_kbd = 0;
		static int buttons = 0;
		static int mouse_x = 0, mouse_y = 0, mouse_z = 0;
		int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0;
		int pressed_mouse, pressed_kbd;
		SDL_keysym keysym;
		
		posted = 0;

		/* FIXME: We do not actually want all events, only
		 * mouse and keyboard events.  Having to handle all
                 * events will slow things down.  */

		ggiEventRead(VIS, &ev, emAll);
/*		ggiEventRead(VIS, &ev, (emKeyboard | emPointer | emCommand)); */
		
		switch (ev.any.type)
		{
			case evPtrRelative:
			x = ev.pmove.x;
			y = ev.pmove.y;
			z = ev.pmove.wheel;
			posted += SDL_PrivateMouseMotion(0, 1, x, y);
			break;
			case evPtrAbsolute:
			if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel)
			{
				x = ev.pmove.x - mouse_x;
				y = ev.pmove.y - mouse_y;
				z = ev.pmove.wheel - mouse_z;
				mouse_x = ev.pmove.x;
				mouse_y = ev.pmove.y;
				mouse_z = ev.pmove.wheel;
				posted += SDL_PrivateMouseMotion(0, 1, x, y);
			} 
			break;
			case evPtrButtonPress:
			posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0);
			break;
			case evPtrButtonRelease:
			posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0);
			break;
			case evKeyPress:
			case evKeyRepeat:
			posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evKeyRelease:
			posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evCommand:
			fprintf(stderr, "Command event %x recieved\n", ev.cmd.code);
			break;
 			default:
			fprintf(stderr, "Unhandled event type %d\n", ev.any.type);
			break;
		}
	}

}
Exemple #6
0
int main(int argc, char *argv[])
{
	struct timeval cur_time;
	struct timeval flush_time;

	/* initialize */

	if (handle_args(argc, argv) < 0) {
		return 1;
	}

	/* open visual */

	if (ggiInit() < 0) {
		fprintf(stderr, "teleserver: Error initializing GGI.\n");
		return 1;
	}

	if (tserver_init(&serv, display_num) < 0) {
		ggiExit();
		return 3;
	}

	ggCurTime(&flush_time);

	printf("TeleServer Ready.\n");
	fflush(stdout);


	/* main loop */

	for (quit=0; !quit; ) {
		struct timeval tv;

		int millies;

		busy=0;

		/* check for incoming connections */

		if (tserver_check(&serv)) {
			handle_connection();
			busy++;
		}

		/* check for user input */

		tv.tv_sec = tv.tv_usec = 0;

		if (mode_up && (ggiEventPoll(vis, emAll, &tv) != 0)) {
			handle_event();
			busy++;
		}

		/* check for client commands */

		if (user) {
			check_command(user);
		}

		if (! busy) {
			ggUSleep(TSERVER_SLEEP_TIME * 1000);
		}

		ggCurTime(&cur_time);


		millies = (cur_time.tv_sec  - flush_time.tv_sec)  * 1000 +
		          (cur_time.tv_usec - flush_time.tv_usec) / 1000;

		if (millies >= TSERVER_FLUSH_TIME) {
			if (mode_up) {
				ggiFlush(vis);
			}
			flush_time = cur_time;
		}
	}

	/* shut down */
	tserver_exit(&serv);

	ggiExit();

	return 0;
}
Exemple #7
0
int do_menu(struct menu * m , int selected)
{

/* select a menu item by either a number or with arrow keys */

	int i;

	int evmask;
	ggi_event ev;
	struct timeval t={0,0};
	int oldselection = selected;

	draw_window(&m->w);

	if (m->toptext != NULL) {
		ggiSetGCForeground(m->w.vis,
			   ggiMapColor(m->w.vis,&m->toptextcolor));
		/* FIXME*/
		ggiPuts(m->w.vis, m->w.xorigin+m->toptextx,
			m->w.yorigin+m->toptexty, m->toptext);
	}

	if (m->bottomtext != NULL){
		ggiSetGCForeground(m->w.vis,
				   ggiMapColor(m->w.vis,&m->bottomtextcolor));
		/* FIXME*/
		ggiPuts(m->w.vis, m->w.xorigin+m->bottomtextx,
			m->w.yorigin+m->bottomtexty, m->bottomtext);
	}

	for (i = 0;i<=m->lastentry;i++){
		if (i!=selected){
			ggiSetGCForeground(m->w.vis,
					   ggiMapColor(m->w.vis,&m->entrycolor));
			ggiSetGCBackground(m->w.vis,
					   ggiMapColor(m->w.vis,&m->w.backgroundcolor));
		} else {
			ggiSetGCForeground(m->w.vis,
					   ggiMapColor(m->w.vis,&m->selectedcolor));
			ggiSetGCBackground(m->w.vis,
					   ggiMapColor(m->w.vis,
						       &m->selectedbackgroundcolor));
		}
		ggiPuts( m->w.vis,
			 m->w.xorigin + m->entry[i].x,
			 m->w.yorigin + m->entry[i].y,
			 m->entry[i].text);
	}
	for (;;){
		/* if we are in asynchronous mode, we must guarantee */
		/* the user sees he's next.                          */
		ggiFlush(m->w.vis);   

		/* get a keypress */
		evmask = emKey;
		ggiEventPoll(m->w.vis, evmask, NULL);
		while (ggiEventPoll(m->w.vis, evmask,&t)){
			do {
				ggiEventRead(m->w.vis,&ev, evmask);
			} while (!((1<<ev.any.type)&evmask));
			switch(ev.any.type){
			case evKeyPress:
			case evKeyRepeat:
				switch(ev.key.sym){
				case '1':selected = 0;
					break;
				case '2':selected = 1;
					break;
				case '3':selected = 2;
					break;
				case '4':selected = 3;
					break;
				case '5':selected = 4;
					break;
				case '6':selected = 5;
					break;
				case '7':selected = 6;
					break;
				case '8':selected = 7;
					break;
				case '9':selected = 8;
					break;
				case GIIK_Up:
					selected--;
					break;
				case GIIK_Down:
					selected++;
					break;
				case GIIK_Enter:
					ggiFlush(m->w.vis); 
					/* just to make sure */
					return (selected);
					break; /* never get here */
				case GIIUC_Escape:
					ggiFlush(m->w.vis); 
					/* just to make sure */
					return (-1);
				default: 
/*printf("unknown sym=%4x code=%4x\n", ev.key.sym, ev.key.code);*/
					break;
				}
			default: /*printf("can't handle this event yet.\n");*/
				break;
			}
		}

		ggiSetGCForeground(m->w.vis,
				   ggiMapColor(m->w.vis,&m->entrycolor));
		ggiSetGCBackground(m->w.vis,
				   ggiMapColor(m->w.vis,&m->w.backgroundcolor));
		ggiPuts( m->w.vis,
			 m->w.xorigin+m->entry[oldselection].x,
			 m->w.yorigin+m->entry[oldselection].y,
			 m->entry[oldselection].text);
		if (selected<0) selected = 0;
		if (selected > m->lastentry) selected = m->lastentry;
		
		ggiSetGCForeground(m->w.vis,
				   ggiMapColor(m->w.vis,&m->selectedcolor));
		ggiSetGCBackground(m->w.vis,
				   ggiMapColor(m->w.vis,
					       &m->selectedbackgroundcolor));
		ggiPuts( m->w.vis,
			 m->w.xorigin + m->entry[selected].x,
			 m->w.yorigin + m->entry[selected].y,
			 m->entry[selected].text);
		oldselection = selected;
	}
}
void WaitForEvent(struct timeval *tv) //waits for user input or whatever...
{
 struct timeval forever={FOREVER,0};  //one hour is like forever, for most CPUs
 if(!tv)
  tv=&forever;
#ifdef GGI
 IfRequested_ggiFlush();
 ggiEventPoll(ggiVis, emPointer | emKey, tv);
#else //SVGALIB
/* old version of event polling:
 {
  struct timeval now={0,0};
  pthread_t keythread;
  int term_thread=0;
  fd_set readset;
  char dummy[2];

  FD_ZERO(&readset);
  FD_SET(WaitForKey_pipeline[0], &readset);
  if(select(WaitForKey_pipeline[0]+1, &readset, NULL, NULL, &now)<=0)
  {
   if(pthread_create(&keythread,NULL,WaitForKey_thread,NULL)!=0)
   {
    printf("Can't create keyboard thread!\n");
    return;
   }
   term_thread=1;

   FD_ZERO(&readset);
   FD_SET(WaitForKey_pipeline[0], &readset);
   select(WaitForKey_pipeline[0]+1, &readset, NULL, NULL, tv);
  }

  if(FD_ISSET(WaitForKey_pipeline[0],&readset))
  {
   read(WaitForKey_pipeline[0],&dummy,1);
  }
  else if(term_thread)
   write(CancelWaitForKey_pipeline[1],"!",1);
 }
*/
 {
  struct timeval now={0,0};
  pthread_t mousethread;
  int term_thread=0;
  fd_set readset;
  char dummy[2];

  FD_ZERO(&readset);
  FD_SET(WaitForMouse_pipeline[0], &readset);
  FD_SET(STDIN_FILENO, &readset);
  if(select(max(STDIN_FILENO,WaitForMouse_pipeline[0])+1, &readset, NULL, NULL, &now)<=0)
  {
   if(pthread_create(&mousethread,NULL,WaitForMouse_thread,NULL)!=0)
   {
    printf("Can't create mouse thread!\n");
    return;
   }
   term_thread=1;

   FD_ZERO(&readset);
   FD_SET(WaitForMouse_pipeline[0], &readset);
   FD_SET(STDIN_FILENO, &readset);
   select(max(STDIN_FILENO,WaitForMouse_pipeline[0])+1, &readset, NULL, NULL, tv);
  }

  if(FD_ISSET(WaitForMouse_pipeline[0],&readset))
   read(WaitForMouse_pipeline[0],&dummy,1);
  else if(term_thread)
   pthread_cancel(mousethread);
 }

#endif
}
int ImouseRead( int *xcurs, int *ycurs)
{
#ifdef GGI
 struct timeval tv={0,0};

 while (ggiEventPoll(ggiVis, emPointer, &tv) > 0)
 {
  ggi_event ev;
  int oldbutton=xg_mousebutton;

  ggiEventRead(ggiVis, &ev, emPointer);

  if (ev.any.type == evPtrButtonPress)
   xg_mousebutton = ev.pbutton.button;

  if (ev.any.type == evPtrButtonRelease)
   xg_mousebutton = 0;

  if (ev.any.type == evPtrRelative)
  {
   *xcurs += ev.pmove.x;
   *ycurs += ev.pmove.y;
  }

  if (ev.any.type == evPtrAbsolute)
  {
   *xcurs = ev.pmove.x;
   *ycurs = ev.pmove.y;
  }
  if(*xcurs<xg_mouserange_xmin)
   *xcurs=xg_mouserange_xmin;
  if(*xcurs>xg_mouserange_xmax)
   *xcurs=xg_mouserange_xmax;
  if(*ycurs<xg_mouserange_ymin)
   *ycurs=xg_mouserange_ymin;
  if(*ycurs>xg_mouserange_ymax)
   *ycurs=xg_mouserange_ymax;

  if(xg_mousebutton!=oldbutton) //otherwise we would catch mouse release event on slow PCs...
   return xg_mousebutton;
 }//loop
 return xg_mousebutton;

#else
 if(MouseWasUpdatedInThread || mouse_update())
 {
  MouseWasUpdatedInThread=0;
  xg_mousebutton=mouse_getbutton();
  *xcurs=mouse_getx();
  *ycurs=mouse_gety();
//  if(button!=0)
//   printf("[mouse=%d]",button);

  switch(xg_mousebutton) //?? SVGAlib mouse events ....
  {
   case 4:
   xg_mousebutton=1;
   break;
   case 1:
   xg_mousebutton=2;
   break;
   case 2:
   xg_mousebutton=4; //?
   break;
  }
 }
 return xg_mousebutton;
#endif
}
int bioskey(int cmd)
{
#ifdef GGI
 struct timeval tv={0,0};

 if(cmd==2)
  return modifiers;

 if (ggiEventPoll(ggiVis, emKey, &tv) > 0)
 {
  if(cmd==1)
   return 1;
  else
  {
   ggi_event ev;

   ggiEventRead(ggiVis, &ev, emKey);

   modifiers=ev.key.modifiers;

   if (ev.any.type == evKeyPress || ev.any.type == evKeyRepeat)
   {
    return ev.key.sym;
   }//endif
  }
 }

 return 0;
#else
 fd_set readset;
 struct timeval t={0,0};
 unsigned char	buf[6];

 if(buffered!=0)
 {
  if(cmd==1)
   return 1;
  else
  {
   int ret=buffered;
   buffered=0;
   return ret;
  }
 }

 FD_ZERO(&readset);
 FD_SET(0, &readset);

 if (select(STDIN_FILENO+1, &readset, NULL, NULL, &t) <= 0)
 {
  return 0;
 }

 if(cmd==1)
  return 1;

 read(STDIN_FILENO, buf, 1);

 if ( buf[0] != 27 /* escape */)
 {
  return (int) buf[0];
 }

/* Wait a bit, to see if the character following escape was '['
*  which signals an ANSI key.
*/

 if (select(STDIN_FILENO+1, &readset, NULL, NULL, &t) <= 0)
 {
  usleep(10000l);  /* wait 1/100th of a second */
 }

if (select(STDIN_FILENO+1, &readset, NULL, NULL, &t) <= 0)
{
/* Timed out : must have been plain escape key */
 return (int)buf[0];
}

 read(STDIN_FILENO, buf+1, 1);

 if (buf[1] != '[')
 {
  /* Nope, not an ANSI key sequence */
  buffered=(int)buf[1];
  return (int)buf[0];
 }

/* handle the ANSI key sequences */

 read(STDIN_FILENO, buf+2, 1);

 buf[3] = buf[4] = buf[5] = 0;

 if (isdigit(buf[2]) || (buf[2] == '['))
 {
  read(STDIN_FILENO, buf+3, 1);
 }

 if (isdigit(buf[3]))
 {
  read(STDIN_FILENO, buf+4, 1);
 }

#define CMP_KEY(S,K) if (strcmp(buf+2, (S)) == 0) {return (int)(K);}

	CMP_KEY("A", UPARROW);	  CMP_KEY("B", DOWNARROW);
	CMP_KEY("C", RIGHTARROW); CMP_KEY("D", LEFTARROW);

	CMP_KEY("1~", HOMEKEY);   CMP_KEY("4~", ENDKEY);
	CMP_KEY("2~", INSERT); CMP_KEY("3~", DELETEKEY);
	CMP_KEY("5~", PAGEUP); CMP_KEY("6~", PAGEDOWN);

	CMP_KEY("[A",  F1); CMP_KEY("[B",  F2);
	CMP_KEY("[C",  F3); CMP_KEY("[D",  F4);
	CMP_KEY("[E",  F5); CMP_KEY("17~", F6);
	CMP_KEY("18~", F7); CMP_KEY("19~", F8);
	CMP_KEY("20~", F9); CMP_KEY("21~", F10);
	CMP_KEY("23~", F11); CMP_KEY("24~", F12);

#undef CMP_KEY

 printf("Unrecognized ANSI sequence: %s\n",buf+2);
 return 0;
#endif
}