Пример #1
0
void
mouse_open(void)
{
    static Gpm_Connect connectInfo;

    gpm_zerobased = gpm_visiblepointer = 1;
    connectInfo.eventMask = ~0;
    connectInfo.defaultMask = GPM_MOVE & GPM_HARD;
    connectInfo.minMod = connectInfo.maxMod = 0;
    Gpm_Open(&connectInfo, 0);
    gpm_handler = mouse_handler;
}
Пример #2
0
static int
init_mouse(int cons, int suspend)
{
	Gpm_Connect conn;

	conn.eventMask = suspend ? 0 : ~GPM_MOVE;
	conn.defaultMask = suspend ? ~0 : GPM_MOVE;
	conn.minMod = suspend ? ~0 : 0;
	conn.maxMod = suspend ? ~0 : 0;

	return Gpm_Open(&conn, cons);
}
Пример #3
0
Файл: mouse.c Проект: dborca/mc
void enable_mouse (void)
{
    if (mouse_enabled) {
	return;
    }

    switch (use_mouse_p) {
#ifdef HAVE_LIBGPM
    case MOUSE_GPM:
	{
	    int mouse_d;
	    Gpm_Connect conn;

	    conn.eventMask   = ~GPM_MOVE;
	    conn.defaultMask = GPM_MOVE;
	    conn.minMod      = 0;
	    conn.maxMod      = 0;

	    mouse_d = Gpm_Open (&conn, 0);
	    if (mouse_d == -1) {
		use_mouse_p = MOUSE_NONE;
	        return;
	    }
	    mouse_enabled = 1;
	}
	break;
#endif /* HAVE_LIBGPM */
    case MOUSE_XTERM_NORMAL_TRACKING:
	/* save old highlight mouse tracking */
	printf(ESC_STR "[?1001s");

	/* enable mouse tracking */
	printf(ESC_STR "[?1000h");

	fflush (stdout);
	mouse_enabled = 1; 
	break;
    case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
	/* save old highlight mouse tracking */
	printf(ESC_STR "[?1001s");

	/* enable mouse tracking */
	printf(ESC_STR "[?1002h");

	fflush (stdout);
	mouse_enabled = 1; 
	break;
    default:
	break;
    }
}
int gpm_enable (void) {
  int mouse_d;
  Gpm_Connect conn;

  conn.eventMask   = ~GPM_MOVE;
  conn.defaultMask = GPM_MOVE;
  conn.minMod      = 0;
  conn.maxMod      = 0;

  mouse_d = Gpm_Open (&conn, 0);
  if (mouse_d == -1) {
        return 0;
   }
  mouse_enabled = 1;
  return 1;
}
Пример #5
0
static int gpm_init(struct aa_context *context, int mode)
{
	/*conn.eventMask=~0; */
	conn.eventMask = (mode & AA_MOUSEMOVEMASK ? GPM_MOVE | GPM_DRAG : 0) | GPM_DOWN | GPM_UP;
	conn.defaultMask = 0;
	conn.maxMod = ~0;
	conn.minMod = 0;
	if (Gpm_Open(&conn, 0) == -1)
		return 0;
	if (gpm_fd < 0)
		return 0;
	__curses_usegpm = 1;
	gpm_handler = __gpm_user_handler;
	gpm_visiblepointer = 1;
	gpm_hflag = 1;
	return 1;
}
Пример #6
0
vrpn_Mouse::vrpn_Mouse( const char* name, vrpn_Connection * cxn ) :
	vrpn_Analog( name, cxn ),
	vrpn_Button_Filter( name, cxn )
{
    int i;

    // initialize the vrpn_Analog
    vrpn_Analog::num_channel = 2;
    for( i = 0; i < vrpn_Analog::num_channel; i++) {
	vrpn_Analog::channel[i] = vrpn_Analog::last[i] = 0;
    }

    // initialize the vrpn_Button_Filter
    vrpn_Button_Filter::num_buttons = 3;
    for( i = 0; i < vrpn_Button_Filter::num_buttons; i++) {
	vrpn_Button_Filter::buttons[i] = vrpn_Button_Filter::lastbuttons[i] = 0;
    }

#if defined(linux) && defined(VRPN_USE_GPM_MOUSE)
    // attempt to connect to the GPM server
    gpm_zerobased = 1;
    gpm_visiblepointer = 1;

    Gpm_Connect gc;
    gc.eventMask   = ~0;
    gc.defaultMask = GPM_MOVE | GPM_HARD;
    gc.maxMod      = 0;
    gc.minMod      = 0;

    if( Gpm_Open( &gc, 0 ) < 0 )
    {
        // either GPM server is not running, or we're trying to run
        // on an xterm.
	throw GpmOpenFailure();
    }

    set_alerts( 1 );
#elif defined(_WIN32)
    // Nothing needs to be opened under Windows; we just make direct
    // calls below to find the values.
#else
    fprintf(stderr,"vrpn_Mouse::vrpn_Mouse() Not implement on this architecture\n");
#endif
}
Пример #7
0
int main(int argc, char **argv)
{
   int            vc;                              /* argv: console number */
   Gpm_Connect    conn;                            /* connection to gpm    */
   fd_set         fds;

   /* select virtual console, 0 if not set */
   vc = (argc == 2) ? strtol(argv[1],NULL,10) : 0;

   conn.eventMask    =  GPM_MOVE; /* read only moves            */
   conn.defaultMask  = ~GPM_HARD; /* inverted GPM_HARD mask    */
   conn.minMod       =  0;
   conn.maxMod       = ~0;

   if(Gpm_Open(&conn,vc) == -1) {
      printf("Cannot connect to gpm!\n");
      return 1;
   }
   if(gpm_fd == -2) {
      printf("I must be run on the console\n");
      return 1;
   }
   

   while(1) { /* read data */
      FD_ZERO(&fds);
      FD_SET(gpm_fd, &fds);

      if (select(gpm_fd+1, &fds, 0, 0, 0) < 0 && errno == EINTR)
         continue;
      if (FD_ISSET(gpm_fd, &fds)) {
         Gpm_Event evt;
         if (Gpm_GetEvent(&evt) > 0) {
            display_data(&evt, NULL);
         } else {
            printf("Gpm_GetEvent failed\n");
         }
      }
   }

   Gpm_Close(); /* close connection */

   return 0;
}
Пример #8
0
int 
main(int argc, char** argv)
{
  Gpm_Connect conn;
  const int len = sizeof(Gpm_Connect);
  int exit_status = 0;
  conn.eventMask = (unsigned short)(-1); conn.defaultMask = 0;
  conn.minMod = 0; conn.maxMod = (unsigned short)(-1);
  
  if (0 > Gpm_Open(&conn,0)) {
    fprintf(stderr,"disable-paste: cannot open mouse connection\n");
    exit(1);
  }
  conn.vc = GPM_REQ_NOPASTE;
  conn.pid = 0;
  if (len > write(gpm_fd, &conn, len)) {
    fprintf(stderr,"disable-paste: cannot write request\n");
    exit_status = 2;
  }
  Gpm_Close();
  exit(exit_status);
}
Пример #9
0
static void _nc_mouse_init(void)
/* initialize the mouse */
{
    int i;
    static int initialized;

    if (initialized) {
	return;
    }
    initialized = TRUE;

    TR(MY_TRACE, ("_nc_mouse_init() called"));

    for (i = 0; i < EV_MAX; i++)
	events[i].id = INVALID_EVENT;

    /* we know how to recognize mouse events under xterm */
    if (key_mouse != 0
     && is_xterm(cur_term->type.term_names))
	mousetype = M_XTERM;

#if USE_GPM_SUPPORT
    else if (!strncmp(cur_term->type.term_names, "linux", 5))
    {
	/* GPM: initialize connection to gpm server */
	gpm_connect.eventMask = GPM_DOWN|GPM_UP;
	gpm_connect.defaultMask = ~gpm_connect.eventMask;
	gpm_connect.minMod = 0;
	gpm_connect.maxMod = ~0;
	if (Gpm_Open (&gpm_connect, 0) >= 0) { /* returns the file-descriptor */
	    mousetype = M_GPM;
	    SP->_mouse_fd = gpm_fd;
	}
    }
#endif

    T(("_nc_mouse_init() set mousetype to %d", mousetype));
}
Пример #10
0
static void
initialize_mousetype(void)
{
    static const char *xterm_kmous = "\033[M";

    /* Try gpm first, because gpm may be configured to run in xterm */
#if USE_GPM_SUPPORT
    /* GPM: initialize connection to gpm server */
    gpm_connect.eventMask = GPM_DOWN | GPM_UP;
    gpm_connect.defaultMask = ~(gpm_connect.eventMask | GPM_HARD);
    gpm_connect.minMod = 0;
    gpm_connect.maxMod = ~((1 << KG_SHIFT) | (1 << KG_SHIFTL) | (1 << KG_SHIFTR));
    if (Gpm_Open(&gpm_connect, 0) >= 0) {	/* returns the file-descriptor */
	mousetype = M_GPM;
	SP->_mouse_fd = gpm_fd;
	return;
    }
#endif

    /* OS/2 VIO */
#ifdef USE_EMX_MOUSE
    if (!mouse_thread
	&& strstr(cur_term->type.term_names, "xterm") == 0
	&& key_mouse) {
	int handles[2];

	if (pipe(handles) < 0) {
	    perror("mouse pipe error");
	    return;
	} else {
	    int rc;

	    if (!mouse_buttons[0]) {
		char *s = getenv("MOUSE_BUTTONS_123");

		mouse_buttons[0] = 1;
		if (s && strlen(s) >= 3) {
		    mouse_buttons[1] = s[0] - '0';
		    mouse_buttons[2] = s[1] - '0';
		    mouse_buttons[3] = s[2] - '0';
		}
	    }
	    mouse_wfd = handles[1];
	    M_FD(SP) = handles[0];
	    /* Needed? */
	    setmode(handles[0], O_BINARY);
	    setmode(handles[1], O_BINARY);
	    /* Do not use CRT functions, we may single-threaded. */
	    rc = DosCreateThread((unsigned long *) &mouse_thread,
				 mouse_server, 0, 0, 8192);
	    if (rc) {
		printf("mouse thread error %d=%#x", rc, rc);
		return;
	    } else {
		mousetype = M_XTERM;
		return;
	    }
	}
    }
#endif

    /* we know how to recognize mouse events under "xterm" */
    if (key_mouse != 0) {
	if (!strcmp(key_mouse, xterm_kmous)) {
	    mousetype = M_XTERM;
	    return;
	}
    } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
	(void) _nc_add_to_try(&(SP->_keytry), xterm_kmous, KEY_MOUSE);
	mousetype = M_XTERM;
	return;
    }
}
Пример #11
0
gint viper_kmio_gpm(MEVENT *mouse_event,guint cmd)
{
	extern guint32		viper_global_flags;
   extern int        gpm_tried;
   extern int        gpm_fd;
   struct pollfd     mio_poll;
   struct timespec   sleep_time={.tv_sec=0,.tv_nsec=5000};
   static int        mio_fd=-1;
   Gpm_Connect       gpm_connect;
   Gpm_Event         g_event;
   gint              array_sz;
   gint              i;
	int					fflags;

   if(cmd == CMD_GPM_CLOSE)
   {
      if(mio_fd > 0) Gpm_Close();
      mio_fd=-1;
      return 0;
   }

   if(mouse_event==NULL) return -1;

   /* could not connect to the GPM server.   */
   if(gpm_fd==-2 || (gpm_fd==-1 && gpm_tried==TRUE)) return -1;

   memset(&g_event,0,sizeof(g_event));

   if(mio_fd==-1)
   {
      memset(&gpm_connect,0,sizeof(gpm_connect));
      gpm_connect.defaultMask=0; /* do not propgate any GPM events            */
      gpm_connect.eventMask=GPM_MOVE | GPM_UP | GPM_DOWN | GPM_DRAG;
      gpm_connect.maxMod=~0;     /* allow all modifiers ie. CTRL, SHFT, ALT   */
      mio_fd=Gpm_Open(&gpm_connect,0);
		if(mio_fd > 0 && (viper_global_flags & VIPER_GPM_SIGIO))
		{
			fcntl(mio_fd,F_SETOWN,getpid());
   		fflags=fcntl(mio_fd,F_GETFL);
   		fcntl(mio_fd,F_SETFL,fflags | FASYNC);
		}
   }

   if(mio_fd==-1) return -1;

   memset(&mio_poll,0,sizeof(mio_poll));
   mio_poll.events=POLLIN;
   mio_poll.fd=mio_fd;

   if(poll(&mio_poll,1,1)<1) return -1;
   if(Gpm_GetEvent(&g_event)<1) return -1;

   memset(mouse_event,0,sizeof(MEVENT));
   mouse_event->bstate=g_event.modifiers;
   mouse_event->x=g_event.x-1;
   mouse_event->y=g_event.y-1;

   array_sz=sizeof(x_ncurses_state)/sizeof(x_ncurses_state[0]);

   if(!(GPM_CLICK_STRICT(g_event.type)))
   {
      for(i=0;i<array_sz;i++)
      {
         /* sift by mode... ignore COOKED table entries        */
         if(x_gpm_mode[i]==X_GPM_COOKED) continue;

         /* sift raw event... GPM_UP, GPM_DOWN, etc.           */
         if(!(g_event.type & x_gpm_event[i])) continue;

         /* sift which physical button... GPM_B_LEFT, etc.     */
         if(g_event.buttons != x_gpm_button[i]) continue;

         mouse_event->bstate |= x_ncurses_state[i];
         break;
      }
   }

   if(GPM_CLICK_STRICT(g_event.type))
   {
      for(i=0;i<array_sz;i++)
      {
         /* sift by mode... ignore RAW table entries           */
         if(x_gpm_mode[i]==X_GPM_RAW) continue;

         /* sift cooked event... GPM_SINGLE, GPM_DOUBLE, etc.  */
         if(!(g_event.type & x_gpm_event[i])) continue;

         /* sift which physical button... GPM_B_LEFT, etc.     */
         if(g_event.buttons != x_gpm_button[i]) continue;

         mouse_event->bstate=x_ncurses_state[i];
         break;
      }
   }

   if((g_event.type & GPM_DRAG) || (g_event.type & GPM_MOVE))
      mouse_event->bstate = REPORT_MOUSE_POSITION;

   if(mouse_event->bstate!=0)
   {
      while(ungetmouse(mouse_event)==ERR)
      {
         nanosleep(&sleep_time,NULL);
      }
   }

   return 0;
}
Пример #12
0
static void
init_mouse(ScreenBase * base, char **envp)
{
   char *term;

#ifndef _WIN32
   char *e;
#endif

   term = base->terminalName;

   if (base->fd < 0)
      return;

   base->mouse_top = 0;
   base->mouse_left = 0;
   base->mouse_bottom = base->Lines - 1;
   base->mouse_right = base->Columns - 1;
   base->mouse_visible = 1;
   base->mouse_auto_visible = 0;
   base->mouse_dclick_speed = 250;
   base->mouse_driver = "";

#ifdef _WIN32
   xterm_mouse = 1;
   base->mouse_present = 1;
   base->mouse_driver = "win32console";
   return;
#else

   e = get_env(envp, "XTERM_MOUSE");

   if ((e && (!strcasecmp(e, "yes") || !strcasecmp(e, "on"))) || !strncmp(term, "xterm", 5) || !strncmp(term, "rxvt", 4) || strstr(term, "xterm") || strstr(term, "rxvt"))
   {
      const char msg[] = "\033[?1001s\033[?1000h";

      xterm_mouse = 1;

      /* turn xterm mouse on */

      write(1, msg, sizeof(msg) - 1);
      base->mouse_present = 1;
      base->mouse_driver = "xterm";

      return;
   }
#endif

#ifdef HAVE_GPM_H
   {
      int r;

      memset(&conn, 0, sizeof(conn));
      conn.eventMask = GPM_MOVE | GPM_UP | GPM_DOWN | GPM_DRAG | GPM_DOUBLE;
      conn.defaultMask = 0;
      conn.minMod = 0;
      conn.maxMod = 0;
      gpm_zerobased = 1;
      r = Gpm_Open(&conn, 0);
      if (r >= 0)
      {
	 base->mouse_present = 1;
	 base->mouse_driver = "LinuxConsoleGPM";
      }
      _clip_logg(3, "Gpm_Open return %d", r);
   }
#endif
}
Пример #13
0
static void fb_gpm_in(void *nic)
{
#ifndef USE_GPM_DX
	static int lx = -1, ly = -1;
#endif
	struct event ev;
	Gpm_Event gev;
	again:
	if (Gpm_GetEvent(&gev) <= 0) {
		unhandle_fb_mouse();
		return;
	}
	/*fprintf(stderr, "%x %x %d %d %d %d\n", gev.type, gev.buttons, gev.dx, gev.dy, gev.wdx, gev.wdy);*/
#ifndef USE_GPM_DX
	if (gev.x != lx || gev.y != ly) {
		mouse_x = (gev.x - 1) * fb_xsize / fb_txt_xsize + fb_xsize / fb_txt_xsize / 2 - 1;
		mouse_y = (gev.y - 1) * fb_ysize / fb_txt_ysize + fb_ysize / fb_txt_ysize / 2 - 1;
		lx = gev.x, ly = gev.y;
	}
#else
	if (gev.dx || gev.dy) {
		if (!((int)gev.type & gpm_smooth)) {
			mouse_x += gev.dx * 8;
			mouse_y += gev.dy * 8;
		}
#ifdef GPM_HAVE_SMOOTH
		else {
			mouse_x += gev.dx;
			mouse_y += gev.dy;
		}
#endif
	}
#endif
	ev.ev = EV_MOUSE;
	if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1;
	if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1;
	if (mouse_x < 0) mouse_x = 0;
	if (mouse_y < 0) mouse_y = 0;

	if (!((int)gev.type & gpm_smooth) && (gev.dx || gev.dy)) {
		mouse_x = (mouse_x + 8) / 8 * 8 - 4;
		mouse_y = (mouse_y + 8) / 8 * 8 - 4;
		if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1;
		if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1;
		if (mouse_x < 0) mouse_x = 0;
		if (mouse_y < 0) mouse_y = 0;
	}

	ev.x = mouse_x;
	ev.y = mouse_y;
	if (gev.buttons & GPM_B_LEFT) ev.b = B_LEFT;
	else if (gev.buttons & GPM_B_MIDDLE) ev.b = B_MIDDLE;
	else if (gev.buttons & GPM_B_RIGHT) ev.b = B_RIGHT;
	else ev.b = 0;
	if ((int)gev.type & GPM_DOWN) ev.b |= B_DOWN;
	else if ((int)gev.type & GPM_UP) ev.b |= B_UP;
	else if ((int)gev.type & GPM_DRAG) ev.b |= B_DRAG;
	else ev.b |= B_MOVE;

#ifdef HAVE_WDX_WDY
	if ((ev.b & BM_ACT) == B_DRAG || (ev.b & BM_ACT) == B_MOVE) {
		if (gev.wdy < 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELDOWN;
		} else if (gev.wdy > 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELUP;
		}
#if 0
	/* it doesn't work anyway - the exps2 protocol doesn't support it and evdev support in gpm is buggy */
		else if (gev.wdx < 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELRIGHT;
		} else if (gev.wdx > 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELLEFT;
#endif
	}
#endif

#ifndef USE_GPM_DX
	if (fb_msetsize < 0) {
	} else if (fb_msetsize < 10) {
		fb_msetsize++;
	} else if ((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) {
		fb_mouse_setsize();
		fb_msetsize = -1;
	}
#endif

	if (((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) || (ev.b & BM_ACT) == B_DRAG) {
		if (can_read(fb_hgpm)) goto again;
	}

	last_mouse_buttons = (int)ev.b;
	if (!current_virtual_device) return;
	if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev.x, ev.y, (int)ev.b);
	redraw_mouse();
}

static int handle_fb_mouse(void)
{
	Gpm_Connect conn;
#ifndef USE_GPM_DX
	int gpm_ver = 0;
	struct winsize ws;
	fb_old_ws_v = 0;
#endif
	fb_hgpm = -1;
#ifndef USE_GPM_DX
	Gpm_GetLibVersion(&gpm_ver);
	fb_msetsize = -1;
	if (gpm_ver >= 11900) {
		int rs;
		EINTRLOOP(rs,ioctl(1, TIOCGWINSZ, &ws));
		if (rs != -1) {
			memcpy(&fb_old_ws, &ws, sizeof(struct winsize));
			fb_old_ws_v = 1;
			ws.ws_row *= 2;
			EINTRLOOP(rs, ioctl(1, TIOCSWINSZ, &ws));
			fb_msetsize = 0;
			memcpy(&fb_new_ws, &ws, sizeof ws);
		}
	}
	get_terminal_size(1, &fb_txt_xsize, &fb_txt_ysize);
#endif
	conn.eventMask = (unsigned short)~0U;
	conn.defaultMask = gpm_smooth;
	conn.minMod = 0;
	conn.maxMod = (unsigned short)~0U;
	if ((fb_hgpm = Gpm_Open(&conn, 0)) < 0) {
		unhandle_fb_mouse();
		return -1;
	}
	set_handlers(fb_hgpm, fb_gpm_in, (void (*)(void *))NULL, (void (*)(void *))NULL, NULL);
#ifdef SIGTSTP
	install_signal_handler(SIGTSTP, (void (*)(void *))sig_tstp, NULL, 0);
#endif
#ifdef SIGCONT
	install_signal_handler(SIGCONT, (void (*)(void *))sig_cont, NULL, 0);
#endif
#ifdef SIGTTIN
	install_signal_handler(SIGTTIN, (void (*)(void *))sig_tstp, NULL, 0);
#endif

	return 0;
}
Пример #14
0
static int
gpmOpenConnection (void) {
  switch (gpmConnectionState) {
    case  GCS_CLOSED: {
      Gpm_Connect options = {
        .eventMask = GPM_MOVE,
        .defaultMask = ~0,
        .minMod = 0,
        .maxMod = ~0
      };

      gpm_tried = 0;
      gpm_zerobased = 1;

      if (Gpm_Open(&options, -1) == -1) {
        logMessage(GPM_LOG_LEVEL, "GPM open error: %s", strerror(errno));
        asyncSetAlarmIn(NULL, 5000, gpmResetConnection, NULL);
        gpmConnectionState = GCS_FAILED;
        return 0;
      }

      logMessage(GPM_LOG_LEVEL, "GPM opened: fd=%d con=%d", gpm_fd, gpm_consolefd);
      gpmConnectionState = GCS_OPENED;
    }

    case GCS_OPENED:
      return 1;
  }

  return 0;
}

static void
gpmCloseConnection (int alreadyClosed) {
  if (gpmConnectionState == GCS_OPENED) {
    if (!alreadyClosed) Gpm_Close();
    logMessage(GPM_LOG_LEVEL, "GPM closed");
  }
  gpmConnectionState = GCS_CLOSED;
}
#endif /* HAVE_LIBGPM */

static int
routeCursor_RealScreen (int column, int row, int screen) {
  return startRouting(column, row, screen);
}

static int
highlightRegion_RealScreen (int left, int right, int top, int bottom) {
  FILE *console = getConsole();

  if (console) {
#ifdef HAVE_LIBGPM
    if (gpmOpenConnection() && (gpm_fd >= 0)) {
      if (Gpm_DrawPointer(left, top, fileno(console)) != -1) return 1;

      if (errno != EINVAL) {
        logMessage(GPM_LOG_LEVEL, "Gpm_DrawPointer error: %s", strerror(errno));
        gpmCloseConnection(0);
        return 0;
      }
    }
#endif /* HAVE_LIBGPM */
  }

  return 0;
}