diff --git a/include/QF/input.h b/include/QF/input.h index 054cc8bcb..2cb78571f 100644 --- a/include/QF/input.h +++ b/include/QF/input.h @@ -55,7 +55,7 @@ void IN_ModeChanged (void); void IN_HandlePause (qboolean paused); -extern struct cvar_s *_windowed_mouse; +extern struct cvar_s *in_grab; extern struct cvar_s *m_filter; extern struct cvar_s *in_freelook; extern struct cvar_s *sensitivity; @@ -68,6 +68,8 @@ void IN_LL_Init_Cvars (void); void IN_LL_Init (void); void IN_LL_Shutdown (void); void IN_LL_Commands (void); +void IN_LL_Grab_Input (void); +void IN_LL_Ungrab_Input (void); void IN_LL_SendKeyEvents (void); void IN_LL_ClearStates (void); diff --git a/include/context_x11.h b/include/context_x11.h index e9d879977..9c0f6bcba 100644 --- a/include/context_x11.h +++ b/include/context_x11.h @@ -59,6 +59,7 @@ void X11_CreateNullCursor (void); void X11_CreateWindow (int, int); void X11_ForceViewPort (void); void X11_GrabKeyboard (void); +void X11_UngrabKeyboard (void); void X11_Init_Cvars (void); void X11_OpenDisplay (void); void X11_ProcessEvent (void); diff --git a/libs/video/targets/context_x11.c b/libs/video/targets/context_x11.c index 586a7b135..aaf38e7c8 100644 --- a/libs/video/targets/context_x11.c +++ b/libs/video/targets/context_x11.c @@ -378,15 +378,15 @@ void X11_UpdateFullscreen (cvar_t *fullscreen) } if (!fullscreen->int_val) { - if (_windowed_mouse) { - _windowed_mouse->flags &= ~CVAR_ROM; + if (in_grab) { + in_grab->flags &= ~CVAR_ROM; } X11_RestoreVidMode (); } else { - if (_windowed_mouse) { - _windowed_mouse->flags &= ~CVAR_ROM; - Cvar_Set (_windowed_mouse, "1"); - _windowed_mouse->flags |= CVAR_ROM; + if (in_grab) { + in_grab->flags &= ~CVAR_ROM; + Cvar_Set (in_grab, "1"); + in_grab->flags |= CVAR_ROM; } X11_SetVidMode (scr_width, scr_height); } @@ -494,12 +494,14 @@ X11_RestoreVidMode (void) void X11_GrabKeyboard (void) { -#ifdef HAVE_VIDMODE - if (vidmode_active && vid_fullscreen->int_val) { - XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync, - CurrentTime); - } -#endif + XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync, + CurrentTime); +} + +void +X11_UngrabKeyboard (void) +{ + XUngrabKeyboard (x_disp, CurrentTime); } void diff --git a/libs/video/targets/in_common.c b/libs/video/targets/in_common.c index 13ca3972c..d69bd859b 100644 --- a/libs/video/targets/in_common.c +++ b/libs/video/targets/in_common.c @@ -56,7 +56,7 @@ #include "QF/keys.h" #include "QF/mathlib.h" -cvar_t *_windowed_mouse; +cvar_t *in_grab; cvar_t *in_amp; cvar_t *in_pre_amp; cvar_t *in_freelook; @@ -73,6 +73,23 @@ qboolean in_mouse_avail; float in_mouse_x, in_mouse_y; static float in_old_mouse_x, in_old_mouse_y; +static int input_grabbed; + +static void +in_grab_f (cvar_t *var) +{ + if (var->int_val) { + if (!input_grabbed) { + IN_LL_Grab_Input (); + input_grabbed = 1; + } + } else { + if (input_grabbed) { + IN_LL_Ungrab_Input (); + input_grabbed = 0; + } + } +} void IN_Commands (void) @@ -152,7 +169,7 @@ IN_Init_Cvars (void) { IE_Init_Cvars (); JOY_Init_Cvars (); - _windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL, + in_grab = Cvar_Get ("in_grab", "0", CVAR_ARCHIVE, in_grab_f, "With this set to 1, quake will grab the mouse from X"); in_amp = Cvar_Get ("in_amp", "1", CVAR_ARCHIVE, NULL, "global in_amp multiplier"); diff --git a/libs/video/targets/in_fbdev.c b/libs/video/targets/in_fbdev.c index 3f1c2cf02..a8b23529c 100644 --- a/libs/video/targets/in_fbdev.c +++ b/libs/video/targets/in_fbdev.c @@ -40,8 +40,6 @@ #include "QF/cvar.h" #include "QF/keys.h" -cvar_t *_windowed_mouse; - int fd_blocking (int fd, int on) { @@ -137,6 +135,16 @@ IN_LL_Commands (void) { } +void +IN_LL_Grab_Input (void) +{ +} + +void +IN_LL_Ungrab_Input (void) +{ +} + void IN_LL_ModeChanged (void) { diff --git a/libs/video/targets/in_sdl.c b/libs/video/targets/in_sdl.c index 6a416d2eb..4600b37f6 100644 --- a/libs/video/targets/in_sdl.c +++ b/libs/video/targets/in_sdl.c @@ -51,7 +51,7 @@ HWND mainwindow; #endif cvar_t *m_filter; -cvar_t *_windowed_mouse; +cvar_t *in_grab; int old_windowed_mouse; int modestate; // FIXME: just to avoid cross-comp errors - remove later @@ -822,16 +822,20 @@ IN_LL_SendKeyEvents (void) void IN_LL_Commands (void) { - if (old_windowed_mouse != _windowed_mouse->value) { - old_windowed_mouse = _windowed_mouse->value; - if (!_windowed_mouse->value) { - SDL_ShowCursor (1); - SDL_WM_GrabInput (SDL_GRAB_OFF); - } else { - SDL_WM_GrabInput (SDL_GRAB_ON); - SDL_ShowCursor (0); - } - } +} + +void +IN_LL_Grab_Input (void) +{ + SDL_WM_GrabInput (SDL_GRAB_ON); + SDL_ShowCursor (0); +} + +void +IN_LL_Ungrab_Input (void) +{ + SDL_ShowCursor (1); + SDL_WM_GrabInput (SDL_GRAB_OFF); } void @@ -842,7 +846,7 @@ IN_LL_Init (void) /* Enable UNICODE translation for keyboard input */ SDL_EnableUNICODE(1); - if (COM_CheckParm ("-nomouse") && !_windowed_mouse->value) + if (COM_CheckParm ("-nomouse") && !in_grab->value) return; in_mouse_x = in_mouse_y = 0.0; diff --git a/libs/video/targets/in_svgalib.c b/libs/video/targets/in_svgalib.c index 43a876667..b1757f565 100644 --- a/libs/video/targets/in_svgalib.c +++ b/libs/video/targets/in_svgalib.c @@ -452,6 +452,16 @@ IN_LL_Commands (void) } } +void +IN_LL_Grab_Input (void) +{ +} + +void +IN_LL_Ungrab_Input (void) +{ +} + void IN_LL_ClearStates (void) { diff --git a/libs/video/targets/in_win.c b/libs/video/targets/in_win.c index bcaeddbc5..f7209bb11 100644 --- a/libs/video/targets/in_win.c +++ b/libs/video/targets/in_win.c @@ -498,6 +498,16 @@ IN_LL_Commands (void) } } +void +IN_LL_Grab_Input (void) +{ +} + +void +IN_LL_Ungrab_Input (void) +{ +} + void IN_LL_ClearStates (void) { diff --git a/libs/video/targets/in_x11.c b/libs/video/targets/in_x11.c index 405befdf8..362579095 100644 --- a/libs/video/targets/in_x11.c +++ b/libs/video/targets/in_x11.c @@ -87,6 +87,40 @@ static int p_mouse_x, p_mouse_y; #define FOCUS_MASK (FocusChangeMask) #define INPUT_MASK (KEY_MASK | MOUSE_MASK | FOCUS_MASK) +static void +dga_on (void) +{ +#ifdef HAVE_DGA + if (dga_avail && !dga_active) { + XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), + XF86DGADirectMouse); + dga_active = true; + } +#endif +} + +static void +dga_off (void) +{ +#ifdef HAVE_DGA + if (dga_avail && dga_active) { + XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0); + dga_active = false; + } +#endif +} + +static void +in_dga_f (cvar_t *var) +{ + if (in_grab && in_grab->int_val) { + if (var->int_val) { + dga_on (); + } else { + dga_off (); + } + } +} static void XLateKey (XKeyEvent * ev, int *k, int *u) @@ -421,7 +455,7 @@ event_motion (XEvent * event) in_mouse_x += event->xmotion.x_root; in_mouse_y += event->xmotion.y_root; } else { - if (vid_fullscreen->int_val || _windowed_mouse->int_val) { + if (vid_fullscreen->int_val || in_grab->int_val) { if (!event->xmotion.send_event) { in_mouse_x += (event->xmotion.x - p_mouse_x); in_mouse_y += (event->xmotion.y - p_mouse_y); @@ -442,34 +476,25 @@ event_motion (XEvent * event) void IN_LL_Commands (void) { - static int old_windowed_mouse; - static int old_in_dga; +} - if ((old_windowed_mouse != _windowed_mouse->int_val) - || (old_in_dga != in_dga->int_val)) { - old_windowed_mouse = _windowed_mouse->int_val; - old_in_dga = in_dga->int_val; +void +IN_LL_Grab_Input (void) +{ + XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync, + GrabModeAsync, x_win, None, CurrentTime); + if (in_dga->int_val) + dga_on (); + X11_GrabKeyboard (); +} - if (_windowed_mouse->int_val) { // grab the pointer - XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync, - GrabModeAsync, x_win, None, CurrentTime); -#ifdef HAVE_DGA - if (dga_avail && in_dga->int_val && !dga_active) { - XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), - XF86DGADirectMouse); - dga_active = true; - } -#endif - } else { // ungrab the pointer -#ifdef HAVE_DGA - if (dga_avail && in_dga->int_val && dga_active) { - XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0); - dga_active = false; - } -#endif - XUngrabPointer (x_disp, CurrentTime); - } - } +void +IN_LL_Ungrab_Input (void) +{ + if (in_dga->int_val) + dga_off (); + XUngrabPointer (x_disp, CurrentTime); + X11_UngrabKeyboard (); } void @@ -528,8 +553,8 @@ IN_LL_Init (void) if (!COM_CheckParm ("-nomouse")) { dga_avail = VID_CheckDGA (x_disp, NULL, NULL, NULL); if (vid_fullscreen->int_val) { - Cvar_Set (_windowed_mouse, "1"); - _windowed_mouse->flags |= CVAR_ROM; + Cvar_Set (in_grab, "1"); + in_grab->flags |= CVAR_ROM; } X11_AddEvent (ButtonPress, &event_button); @@ -545,7 +570,7 @@ IN_LL_Init_Cvars (void) { in_snd_block= Cvar_Get ("in_snd_block", "0", CVAR_ARCHIVE, NULL, "block sound output on window focus loss"); - in_dga = Cvar_Get ("in_dga", "1", CVAR_ARCHIVE, NULL, + in_dga = Cvar_Get ("in_dga", "1", CVAR_ARCHIVE, in_dga_f, "DGA Input support"); } diff --git a/libs/video/targets/vid_glx.c b/libs/video/targets/vid_glx.c index a7a78c0e0..8b3e05e4d 100644 --- a/libs/video/targets/vid_glx.c +++ b/libs/video/targets/vid_glx.c @@ -204,8 +204,6 @@ VID_Init (unsigned char *palette) /* Invisible cursor */ X11_CreateNullCursor (); - X11_GrabKeyboard (); - XSync (x_disp, 0); ctx = glXCreateContext (x_disp, x_visinfo, NULL, True); diff --git a/libs/video/targets/vid_mgl.c b/libs/video/targets/vid_mgl.c index 5268c42b0..02cff6550 100644 --- a/libs/video/targets/vid_mgl.c +++ b/libs/video/targets/vid_mgl.c @@ -109,7 +109,7 @@ cvar_t *vid_nopageflip; cvar_t *vid_config_x; cvar_t *vid_config_y; cvar_t *vid_stretch_by_2; -cvar_t *_windowed_mouse; +cvar_t *in_grab; cvar_t *vid_fullscreen_mode; cvar_t *vid_windowed_mode; cvar_t *block_switch; @@ -1479,7 +1479,7 @@ VID_SetMode (int modenum, unsigned char *palette) // Set either the fullscreen or windowed mode if (modelist[modenum].type == MS_WINDOWED) { - if (_windowed_mouse->int_val && key_dest == key_game) { + if (in_grab->int_val && key_dest == key_game) { stat = VID_SetWindowedMode (modenum); IN_ActivateMouse (); IN_HideMouse (); @@ -1962,7 +1962,7 @@ VID_Init_Cvars () vid_stretch_by_2 = Cvar_Get ("vid_stretch_by_2", "1", CVAR_ARCHIVE, NULL, "Stretch the pixles by a two fold to acheive " "proper view"); - _windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL, + in_grab = Cvar_Get ("in_grab", "0", CVAR_ARCHIVE, NULL, "Have quake grab the mouse from X when you " "play"); vid_fullscreen_mode = Cvar_Get ("vid_fullscreen_mode", "3", CVAR_ARCHIVE, @@ -2147,7 +2147,7 @@ VID_Update (vrect_t *rects) // handle the mouse state when windowed if that's changed if (modestate == MS_WINDOWED) { - if (!_windowed_mouse->int_val) { + if (!in_grab->int_val) { if (windowed_mouse) { IN_DeactivateMouse (); IN_ShowMouse (); @@ -2471,7 +2471,7 @@ AppActivate (BOOL fActive, BOOL minimize) IN_ActivateMouse (); IN_HideMouse (); } - else if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val + else if ((modestate == MS_WINDOWED) && in_grab->int_val && key_dest == key_game) { IN_ActivateMouse (); IN_HideMouse (); @@ -2500,7 +2500,7 @@ AppActivate (BOOL fActive, BOOL minimize) IN_DeactivateMouse (); IN_ShowMouse (); - } else if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val + } else if ((modestate == MS_WINDOWED) && in_grab->int_val /* && mouseactive */ ) { IN_DeactivateMouse (); IN_ShowMouse (); @@ -2513,7 +2513,7 @@ void VID_HandlePause (qboolean pause) { #if 0 - if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val) { + if ((modestate == MS_WINDOWED) && in_grab->int_val) { if (pause) { IN_DeactivateMouse (); IN_ShowMouse (); diff --git a/libs/video/targets/vid_wgl.c b/libs/video/targets/vid_wgl.c index c4f27f9de..9d3cfc933 100644 --- a/libs/video/targets/vid_wgl.c +++ b/libs/video/targets/vid_wgl.c @@ -164,7 +164,7 @@ void GL_Init (void); //==================================== -cvar_t *_windowed_mouse; +cvar_t *in_grab; cvar_t *vid_use8bit; int window_center_x, window_center_y, window_x, window_y, window_width, @@ -379,7 +379,7 @@ VID_SetMode (int modenum, unsigned char *palette) // Set either the fullscreen or windowed mode if (modelist[modenum].type == MS_WINDOWED) { - if (_windowed_mouse->int_val && key_dest == key_game) { + if (in_grab->int_val && key_dest == key_game) { stat = VID_SetWindowedMode (modenum); IN_ActivateMouse (); IN_HideMouse (); @@ -473,7 +473,7 @@ GL_EndRendering (void) // handle the mouse state when windowed if that's changed if (modestate == MS_WINDOWED) { - if (!_windowed_mouse->int_val) { + if (!in_grab->int_val) { if (windowed_mouse) { IN_DeactivateMouse (); IN_ShowMouse (); @@ -694,7 +694,7 @@ AppActivate (BOOL fActive, BOOL minimize) gdevmode.dmPelsHeight, false); } } - else if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val + else if ((modestate == MS_WINDOWED) && in_grab->int_val && key_dest == key_game) { IN_ActivateMouse (); IN_HideMouse (); @@ -707,7 +707,7 @@ AppActivate (BOOL fActive, BOOL minimize) ChangeDisplaySettings (NULL, 0); vid_wassuspended = true; } - } else if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val) { + } else if ((modestate == MS_WINDOWED) && in_grab->int_val) { IN_DeactivateMouse (); IN_ShowMouse (); } diff --git a/libs/video/targets/vid_x11.c b/libs/video/targets/vid_x11.c index 6507705f3..e5214a68b 100644 --- a/libs/video/targets/vid_x11.c +++ b/libs/video/targets/vid_x11.c @@ -504,8 +504,6 @@ VID_Init (unsigned char *palette) x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues); } - X11_GrabKeyboard (); - // wait for first exposure event { XEvent event;