/* =========== IN_Init =========== */ void IN_Init (void) { int MajorVersion = 0, MinorVersion = 0; qboolean DGA = false; Cvar_RegisterVariable (&m_filter, NULL); Cmd_AddCommand ("force_centerview", Force_CenterView_f); if (COM_CheckParm ("-nomouse")) mouse_available = false; else mouse_available = true; mouse_grab_active = false; dga_mouse_available = false; dga_mouse_active = false; /* if (COM_CheckParm ("-nokeyb")) keyboard_available = false; else */ keyboard_available = true; keyboard_grab_active = false; dga_keyboard_available = false; dga_keyboard_active = false; if (x_disp == NULL) Sys_Error ("IN_Init: x_disp not initialised before input..."); DGA = XF86DGAQueryVersion(x_disp, &MajorVersion, &MinorVersion); if(COM_CheckParm("-nodga")) { Con_Warning ("XFree86 DGA extension disabled at command line\n"); } else if (DGA) { Con_Printf ("XFree86 DGA extension version %d.%d found\n", MajorVersion, MinorVersion); if (COM_CheckParm("-nodgamouse")) Con_Warning ("XFree86 DGA Mouse disabled at command line\n"); else dga_mouse_available = true; if (COM_CheckParm("-nodgakeyb")) Con_Warning ("XFree86 DGA Keyboard disabled at command line\n"); else dga_keyboard_available = true; } else { Con_Warning ("XFree86 DGA extension not supported\n"); } IN_GrabMouse(); // grab mouse first! IN_GrabKeyboard(); }
static void windowed_mouse_f(struct cvar_s *var) { if (var->value) { Con_DPrintf("Callback: _windowed_mouse ON\n"); if (!VID_IsFullScreen()) { IN_GrabMouse(); IN_GrabKeyboard(); } } else { Con_DPrintf("Callback: _windowed_mouse OFF\n"); if (!VID_IsFullScreen()) { IN_UngrabMouse(); IN_UngrabKeyboard(); } } }
void IN_Commands(void) { if (!mouse_available) return; // FIXME - Need this consistant, robust // If we have the mouse, but are not in the game... if (mouse_grab_active && key_dest != key_game && !VID_IsFullScreen()) { IN_UngrabMouse(); IN_UngrabKeyboard(); } // If we don't have the mouse, but we're in the game and we want it... if (!mouse_grab_active && key_dest == key_game && (_windowed_mouse.value || VID_IsFullScreen())) { IN_GrabKeyboard(); IN_GrabMouse(); IN_CenterMouse(); } }
void IN_Init(void) { #ifdef USE_XF86DGA int MajorVersion, MinorVersion; #endif keyboard_grab_active = false; mouse_grab_active = false; // FIXME - do proper detection? // - Also, look at other vid_*.c files for clues mouse_available = (COM_CheckParm("-nomouse")) ? false : true; if (x_disp == NULL) Sys_Error("x_disp not initialised before input..."); #ifdef USE_XF86DGA dga_mouse_active = false; if (!XF86DGAQueryVersion(x_disp, &MajorVersion, &MinorVersion)) { Con_Printf("Failed to detect XF86DGA Mouse\n"); in_dgamouse.value = 0; dga_available = false; } else { dga_available = true; } #endif // Need to grab the input focus at startup, just in case... // FIXME - must be viewable or get BadMatch XSetInputFocus(x_disp, x_win, RevertToParent, CurrentTime); IN_InitCvars(); if (VID_IsFullScreen()) { if (!mouse_grab_active) IN_GrabMouse(); if (!keyboard_grab_active) IN_GrabKeyboard(); } }
/* =========== IN_ProcessEvents =========== */ void IN_ProcessEvents (void) { // handle the mouse state when windowed if that's changed if (!vidmode_fullscreen) { if ( key_dest == key_game && !mouse_grab_active && vid_activewindow ) // if ( key_dest != key_console && !mouse_grab_active && vid_activewindow ) { IN_GrabMouse (); } else if ( key_dest != key_game && mouse_grab_active ) // else if ( key_dest == key_console && mouse_grab_active ) { IN_UngrabMouse (); } } // getting and handle events { XEvent x_event; static qboolean active = true; if (!x_disp) return; while (XPending(x_disp)) { XNextEvent(x_disp, &x_event); switch (x_event.type) { case KeyPress: // key pressed case KeyRelease: // key released Key_Event(XLateKey(&x_event.xkey), x_event.type == KeyPress); break; case MotionNotify: // mouse moved if (mouse_grab_active) { if (dga_mouse_active) { mouse_x += (float)x_event.xmotion.x_root; mouse_y += (float)x_event.xmotion.y_root; } else { mouse_x = (float)x_event.xmotion.x - (float)(vid.width / 2); mouse_y = (float)x_event.xmotion.y - (float)(vid.height / 2); if (mouse_x || mouse_y) // do warp { // move the mouse to the window center again XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0, vid.width / 2, vid.height / 2); } } } break; case ButtonPress: // mouse button pressed case ButtonRelease: // mouse button released switch (x_event.xbutton.button) { case 1: Key_Event (K_MOUSE1, x_event.type == ButtonPress); break; case 2: Key_Event (K_MOUSE3, x_event.type == ButtonPress); break; case 3: Key_Event (K_MOUSE2, x_event.type == ButtonPress); break; case 4: Key_Event (K_MWHEELUP, x_event.type == ButtonPress); break; case 5: Key_Event (K_MWHEELDOWN, x_event.type == ButtonPress); break; case 6: Key_Event (K_MOUSE4, x_event.type == ButtonPress); break; case 7: Key_Event (K_MOUSE5, x_event.type == ButtonPress); break; case 8: Key_Event (K_MOUSE6, x_event.type == ButtonPress); break; case 9: Key_Event (K_MOUSE7, x_event.type == ButtonPress); break; case 10: Key_Event (K_MOUSE8, x_event.type == ButtonPress); break; } break; case CreateNotify: // window created window_x = x_event.xcreatewindow.x; window_y = x_event.xcreatewindow.y; window_width = x_event.xcreatewindow.width; window_height = x_event.xcreatewindow.height; break; case ConfigureNotify: // window changed size/location window_x = x_event.xconfigure.x; window_y = x_event.xconfigure.y; window_width = x_event.xconfigure.width; window_height = x_event.xconfigure.height; // check for resize if (!vidmode_fullscreen) { if (window_width < 320) window_width = 320; if (window_height < 200) window_height = 200; vid.width = window_width; vid.height = window_height; vid.conwidth = vid.width; vid.conheight = vid.height; vid.recalc_refdef = true; // force a surface cache flush } break; case DestroyNotify: // window has been destroyed Sys_Quit (0); break; case ClientMessage: // window manager messages if ((x_event.xclient.format == 32) && ((unsigned int)x_event.xclient.data.l[0] == wm_delete_window_atom)) Sys_Quit (0); break; case MapNotify: // window restored case UnmapNotify: // window iconified/rolledup/whatever vid_hiddenwindow = (x_event.type == UnmapNotify); case FocusIn: // window is now the input focus case FocusOut: // window is no longer the input focus switch (x_event.xfocus.mode) { case NotifyNormal: case NotifyGrab: case NotifyUngrab: vid_activewindow = (x_event.type == FocusIn); break; } if(vidmode_fullscreen) { if(x_event.type == MapNotify) { // set our video mode XF86VidModeSwitchToMode(x_disp, scrnum, &game_vidmode); // move the viewport to top left XF86VidModeSetViewPort(x_disp, scrnum, 0, 0); } else if(x_event.type == UnmapNotify) { // set our video mode XF86VidModeSwitchToMode(x_disp, scrnum, &init_vidmode); } } else //if (!vidmode_fullscreen) { // enable/disable sound, set/restore gamma and grab/ungrab keyb // on focus gain/loss if (vid_activewindow && !vid_hiddenwindow && !active) { S_UnblockSound (); S_ClearBuffer (); VID_Gamma_Set (); IN_GrabKeyboard(); active = true; } else if (active) { S_BlockSound (); S_ClearBuffer (); VID_Gamma_Restore (); IN_UngrabKeyboard(); active = false; } } // fix the leftover Alt from any Alt-Tab or the like that switched us away Key_ClearStates (); break; case EnterNotify: // mouse entered window case LeaveNotify: // mouse left window vid_notifywindow = (x_event.type == EnterNotify); break; } } } }