static int getPointer_RealScreen (int *column, int *row) { int ok = 0; #ifdef HAVE_LIBGPM if (gpmOpenConnection()) { if (gpm_fd >= 0) { int error = 0; while (1) { fd_set mask; struct timeval timeout; Gpm_Event event; int result; FD_ZERO(&mask); FD_SET(gpm_fd, &mask); memset(&timeout, 0, sizeof(timeout)); if ((result = select(gpm_fd+1, &mask, NULL, NULL, &timeout)) == 0) break; error = 1; if (result == -1) { if (errno == EINTR) continue; logSystemError("select"); break; } if (!FD_ISSET(gpm_fd, &mask)) { logMessage(GPM_LOG_LEVEL, "GPM file descriptor not set: %d", gpm_fd); break; } if ((result = Gpm_GetEvent(&event)) == -1) { if (errno == EINTR) continue; logSystemError("Gpm_GetEvent"); break; } error = 0; if (result == 0) { gpmCloseConnection(1); break; } *column = event.x; *row = event.y; ok = 1; } if (error) gpmCloseConnection(0); } } #endif /* HAVE_LIBGPM */ return ok; }
int gpm_fd_activate(int fd) { Gpm_Event evt; /* Mouse activity? */ if (fd==gpm_fd && Gpm_GetEvent(&evt) > 0) { gpm_last_event = evt; infilter_send_pointing(PG_TRIGGER_PNTR_RELATIVE,evt.dx,evt.dy, ((evt.buttons>>2)&1) || ((evt.buttons<<2)&4) || (evt.buttons&2),gpm_cursor); return 1; }
MEVENT* gpm_get_mouse_event( MEVENT* event ) { struct Gpm_Event ev; /* Mouse event */ struct timeval timeout; struct timeval *time_addr = NULL; int flag; fd_set select_set; if (!mouse_enabled) { return NULL; } FD_ZERO (&select_set); if (gpm_fd < 0) { mouse_enabled = 0; return NULL; } else { FD_SET (gpm_fd, &select_set); } time_addr = &timeout; timeout.tv_sec = 0; timeout.tv_usec = 200; flag = select (gpm_fd + 1, &select_set, NULL, NULL, time_addr); if (flag <= 0) { return NULL; } if (gpm_fd > 0 && FD_ISSET (gpm_fd, &select_set)) { Gpm_GetEvent (&ev); Gpm_FitEvent (&ev); Gpm_DrawPointer (ev.x, ev.y, gpm_consolefd); event->id = 0; event->x = ev.x -1; event->y = ev.y -1; __gpm_to_curses(ev, event); return event; } return NULL; }
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; }
static void gpm_mouse_in(struct gpm_mouse_spec *gms) { Gpm_Event gev; struct term_event ev; struct term_event_mouse mouse; if (Gpm_GetEvent(&gev) <= 0) { clear_handlers(gms->h); return; } mouse.x = int_max(gev.x - 1, 0); mouse.y = int_max(gev.y - 1, 0); if (gev.buttons & GPM_B_LEFT) mouse.button = B_LEFT; else if (gev.buttons & GPM_B_MIDDLE) mouse.button = B_MIDDLE; else if (gev.buttons & GPM_B_RIGHT) mouse.button = B_RIGHT; else return; if (gev.type & GPM_DOWN) mouse.button |= B_DOWN; else if (gev.type & GPM_UP) mouse.button |= B_UP; else if (gev.type & GPM_DRAG) mouse.button |= B_DRAG; else return; set_mouse_term_event(&ev, mouse.x, mouse.y, mouse.button); gms->fn(gms->data, (char *) &ev, sizeof(ev)); }
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; }
int mouse_wgetch(WINDOW *win) { int key; #if defined(NCURSES_MOUSE_VERSION) /* before calling this you have to put (only the first time) a "wtimeout(dialog, WTIMEOUT_VAL);" */ do { key = dlg_getc(win); if (key == KEY_MOUSE) { MEVENT event; mseRegion *p; if (getmouse(&event) != ERR && (p = mouse_region(event.y, event.x)) != 0) { key = M_EVENT + p->code; } else { (void) beep(); key = ERR; } } } while (key == ERR); #elif defined(HAVE_LIBGPM) fd_set selSet; int flag, result; int fd = STDIN_FILENO; static Gpm_Event ev; key = 0; if (!gpm_flag || gpm_fd <= -1) return dlg_getc(win); if (gpm_morekeys) return (*gpm_handler) (&ev, gpm_data); gpm_hflag = 0; while (1) { if (gpm_visiblepointer) GPM_DRAWPOINTER(&ev); do { FD_ZERO(&selSet); FD_SET(fd, &selSet); FD_SET(gpm_fd, &selSet); gpm_timeout.tv_usec = WTIMEOUT_VAL * 10000; gpm_timeout.tv_sec = 0; flag = select(5, &selSet, (fd_set *) 0, (fd_set *) 0, &gpm_timeout); /* fprintf(stderr, "X"); */ } while (!flag); if (FD_ISSET(fd, &selSet)) return dlg_getc(win); if (flag == -1) continue; if (Gpm_GetEvent(&ev) && gpm_handler && (result = (*gpm_handler) (&ev, gpm_data))) { gpm_hflag = 1; return result; } } #else /* before calling this you have to put (only the first time) a "wtimeout(dialog, WTIMEOUT_VAL);" */ do { key = dlg_getc(win); } while (key == ERR); #endif return key; }
int vrpn_Mouse::get_report() { #if defined(linux) && defined(VRPN_USE_GPM_MOUSE) fd_set readset; FD_ZERO( &readset ); FD_SET( gpm_fd, &readset ); struct timeval timeout = { 0, 0 }; select( gpm_fd+1, &readset, NULL, NULL, &timeout ); if( ! FD_ISSET( gpm_fd, &readset ) ) return 0; Gpm_Event evt; if( Gpm_GetEvent( &evt ) <= 0 ) return 0; if( evt.type & GPM_UP ) { if( evt.buttons & GPM_B_LEFT ) buttons[0] = 0; if( evt.buttons & GPM_B_MIDDLE ) buttons[1] = 0; if( evt.buttons & GPM_B_RIGHT ) buttons[2] = 0; } else { buttons[0] = (evt.buttons & GPM_B_LEFT) ? 1 : 0; buttons[1] = (evt.buttons & GPM_B_MIDDLE) ? 1 : 0; buttons[2] = (evt.buttons & GPM_B_RIGHT) ? 1 : 0; } channel[0] = (vrpn_float64) evt.dx / gpm_mx; channel[1] = (vrpn_float64) evt.dy / gpm_my; return 1; #elif defined(_WIN32) const unsigned LEFT_MOUSE_BUTTON = 0x01; const unsigned RIGHT_MOUSE_BUTTON = 0x02; const unsigned MIDDLE_MOUSE_BUTTON = 0x04; // Find out if the mouse buttons are pressed. if (0x80000 & GetKeyState(LEFT_MOUSE_BUTTON)) { vrpn_Button::buttons[0] = 1; } else { vrpn_Button::buttons[0] = 0; } if (0x80000 & GetKeyState(MIDDLE_MOUSE_BUTTON)) { vrpn_Button::buttons[1] = 1; } else { vrpn_Button::buttons[1] = 0; } if (0x80000 & GetKeyState(RIGHT_MOUSE_BUTTON)) { vrpn_Button::buttons[2] = 1; } else { vrpn_Button::buttons[2] = 0; } // Find the position of the cursor in X,Y with range 0..1 across the screen POINT curPos; GetCursorPos(&curPos); vrpn_Analog::channel[0] = (vrpn_float64)(curPos.x - GetSystemMetrics(SM_XVIRTUALSCREEN)) / GetSystemMetrics(SM_CXVIRTUALSCREEN); vrpn_Analog::channel[1] = (vrpn_float64)(curPos.y - GetSystemMetrics(SM_YVIRTUALSCREEN)) / GetSystemMetrics(SM_CYVIRTUALSCREEN); vrpn_gettimeofday( ×tamp, NULL ); report_changes(); return 1; #else return 0; #endif }
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; }
static int slang_getchar(aa_context * c1, int wait) { int c; volatile int flag = 0; #ifdef GPM_MOUSEDRIVER static Gpm_Event ev; #endif struct timeval tv; fd_set readfds; if (wait) { setjmp(buf); iswaiting = 1; } else iswaiting = 0; if (__resized_slang == 2) { iswaiting = 0; __resized_slang = 1; return (AA_RESIZE); } /*non-gpm way */ if (!wait) { #ifdef GPM_MOUSEDRIVER if (gpm_fd == -1) { #endif if (!SLang_input_pending(0)) return AA_NONE; #ifdef GPM_MOUSEDRIVER } else { GPM_DRAWPOINTER(&ev); tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO(&readfds); if (gpm_fd != -2) FD_SET(gpm_fd, &readfds); FD_SET(STDIN_FILENO, &readfds); if (!(flag = select( ((gpm_fd == -2)?STDIN_FILENO:gpm_fd) + 1, &readfds, NULL, NULL, &tv))) return AA_NONE; } #endif } #ifdef GPM_MOUSEDRIVER if (gpm_fd != -1) { GPM_DRAWPOINTER(&ev); while (!flag) { FD_ZERO(&readfds); if (gpm_fd != -2) FD_SET(gpm_fd, &readfds); FD_SET(STDIN_FILENO, &readfds); tv.tv_sec = 60; flag = select( ((gpm_fd == -2)?STDIN_FILENO:gpm_fd) + 1, &readfds, NULL, NULL, &tv); } if (flag == -1) { printf("error!\n"); return (AA_NONE); } if ((gpm_fd > -1) && (FD_ISSET(gpm_fd, &readfds))) { if (Gpm_GetEvent(&ev) && gpm_handler && ((*gpm_handler) (&ev, gpm_data))) { gpm_hflag = 1; return AA_MOUSE; } } } if (gpm_fd == -2) c = Gpm_Getchar(); else #endif c = SLkp_getkey(); iswaiting = 0; if (__resized_slang == 2) { __resized_slang = 1; return (AA_RESIZE); } if (c == 27) return (AA_ESC); if (c > 0 && c < 128 && c != 127) return (c); switch (c) { case SL_KEY_ERR: return (AA_NONE); case SL_KEY_LEFT: return (AA_LEFT); case SL_KEY_RIGHT: return (AA_RIGHT); case SL_KEY_UP: return (AA_UP); case SL_KEY_DOWN: return (AA_DOWN); case SL_KEY_BACKSPACE: case 127: return (AA_BACKSPACE); } return (AA_UNKNOWN); }
static int linux_getchar(aa_context * c1, int wait) { #ifdef GPM_MOUSEDRIVER static Gpm_Event e; #endif int c; int key; struct timeval tv; do { fd_set readfds; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO(&readfds); FD_SET(tty_fd, &readfds); #ifdef GPM_MOUSEDRIVER if (gpm_visiblepointer) GPM_DRAWPOINTER(&e); if (__curses_usegpm) { FD_SET(gpm_fd, &readfds); } #endif #ifdef GPM_MOUSEDRIVER select((__curses_usegpm ? gpm_fd : 0) + 1, &readfds, NULL, NULL, wait ? NULL : &tv); if (__curses_usegpm && FD_ISSET(gpm_fd, &readfds)) { if (Gpm_GetEvent(&e) == 1) { __gpm_user_handler(&e, NULL); return AA_MOUSE; } } #else select(tty_fd, &readfds, NULL, NULL, wait ? NULL : &tv); #endif c = scan_keyboard(); if (c != -1) { switch (c) { case ESCAPE_KEY: key = AA_ESC; break; case ENTER_KEY: key = 13; break; case BACKSPACE: key = AA_BACKSPACE; break; case CURSOR_LEFT: key = AA_LEFT; break; case CURSOR_RIGHT: key = AA_RIGHT; break; case CURSOR_UP: key = AA_UP; break; case CURSOR_DOWN: key = AA_DOWN; break; case CURSORBLOCK_LEFT: key = AA_LEFT; break; case CURSORBLOCK_RIGHT: key = AA_RIGHT; break; case CURSORBLOCK_UP: key = AA_UP; break; case CURSORBLOCK_DOWN: key = AA_DOWN; break; default: key = keymap_trans(c) & 255; } if (!key_down[c]) key |= AA_RELEASE; return key; } else key = AA_NONE; } while (wait); return AA_NONE; }