Beispiel #1
0
void UXViewport::ReleaseInputs()
{
	guard(UXViewport::ReleaseInputs);

	// Restore DGA mode.
	if (UseDGA)
	{
		UseDGA = false;
		XF86DGADirectVideo(XDisplay, DefaultScreen(XDisplay), 0);
	}

	// Restore acceleration.
	XChangePointerControl(XDisplay, True, True, MouseAccel_N, MouseAccel_D, MouseThreshold);
	
	// Restore pointer and keyboard.
	XUngrabPointer( XDisplay, CurrentTime );
	XUngrabKeyboard( XDisplay, CurrentTime );

	// Restore cursor.
	XUndefineCursor( XDisplay, XWindow );

	// Restore Keyboard AutoRepeat
	if(	RestoreAutoRepeat )
	{
		RestoreAutoRepeat = false;
		XAutoRepeatOn( XDisplay );
	}

	unguard;
}
Beispiel #2
0
static void switch_to_best_mode (void)
{
    Screen *scr = ScreenOfDisplay (display, screen);
    int w = WidthOfScreen (scr);
    int h = HeightOfScreen (scr);
    int d = DefaultDepthOfScreen (scr);
#ifdef USE_VIDMODE_EXTENSION
    int i, best;
    if (vidmodeavail) {
	best = 0;
	for (i = 1; i < vidmodecount; i++) {
	    if (allmodes[i]->hdisplay >= current_width
		&& allmodes[i]->vdisplay >= current_height
		&& allmodes[i]->hdisplay <= allmodes[best]->hdisplay
		&& allmodes[i]->vdisplay <= allmodes[best]->vdisplay)
		best = i;
	}
	write_log ("entering DGA mode: %dx%d (%d, %d)\n",
		allmodes[best]->hdisplay, allmodes[best]->vdisplay,
		current_width, current_height);
	XF86VidModeSwitchToMode (display, screen, allmodes[best]);
	XF86VidModeSetViewPort (display, screen, 0, 0);
    }
#endif
    XMoveWindow (display, mywin, 0, 0);
    XWarpPointer (display, None, rootwin, 0, 0, 0, 0, 0, 0);
    XF86DGADirectVideo (display, screen, XF86DGADirectGraphics | XF86DGADirectMouse | XF86DGADirectKeyb);
    XF86DGASetViewPort (display, screen, 0, 0);
    memset (fb_addr, 0, (w * h) * (d / 8));
}
Beispiel #3
0
void S9xGraphicsMode ()
{
	if (is_graphics)
		return;

	XSelectInput (ourdisp, inputwin, KeyPressMask | KeyReleaseMask);
	XSetInputFocus (ourdisp, inputwin, RevertToNone, CurrentTime);
	XGrabKeyboard (ourdisp, inputwin, True, GrabModeAsync, GrabModeAsync,
	               CurrentTime);
	XGrabPointer (ourdisp, inputwin, True, 0,
	              GrabModeAsync, GrabModeAsync, inputwin, None, CurrentTime);

	XFlush(ourdisp);

	XAutoRepeatOff (ourdisp);

#ifdef USE_XF86VIDMODE
	if (orig_mode != mod320x240) {
		XF86VidModeSwitchToMode (ourdisp,ourscreen, mod320x240);
	}
	XFlush (ourdisp);
	XF86VidModeSetViewPort (ourdisp, ourscreen, 0, 0);
	XFlush (ourdisp);
#endif

	XF86DGADirectVideo (ourdisp, ourscreen, XF86DGADirectGraphics);
	memset ((void *) ourvideo.vidMemBegin, 0, ourvideo.width * 240 *
	        ourvideo.screendepth);
	is_graphics = TRUE;
	XFlush (ourdisp);
}
Beispiel #4
0
static void 
sighup(int foo) 
{
	//reg_IO->vidDesktopStartAddr = vidpage0offset;
	XF86DGADirectVideo(display,0,0);
	exit(0);
}
Beispiel #5
0
static void uninstall_grabs( void )
{
	assert( x11display.dpy && x11display.win );

	if( mouse_active )
	{
		if( dgamouse )
		{
			dgamouse = qfalse;
			XF86DGADirectVideo( x11display.dpy, x11display.scr, 0 );
		}

		XUngrabPointer( x11display.dpy, CurrentTime );
		XUndefineCursor( x11display.dpy, x11display.win ); // inviso cursor

		mouse_active = qfalse;
		mx = my = 0;
	}

	XUngrabKeyboard( x11display.dpy, CurrentTime );

	x11display.ic = 0;

	input_active = qfalse;
}
Beispiel #6
0
static void
IN_ActivateDGAMouse(void)
{
    if (dga_available && !dga_mouse_active) {
	XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), XF86DGADirectMouse);
	dga_mouse_active = true;
    }
}
Beispiel #7
0
/*
===========
IN_ActivateDGAMouse
===========
*/
static void IN_ActivateDGAMouse (void)
{
	int DGAflags;

	if (dga_mouse_available && !dga_mouse_active)
	{
		DGAflags = XF86DGADirectMouse;
		if (dga_keyboard_active)
		{
			XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0);
			DGAflags |= XF86DGADirectKeyb;
		}

		XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), DGAflags);
		dga_mouse_active = true;
	}
}
Beispiel #8
0
/*
===========
IN_DeactivateDGAKeyboard
===========
*/
static void IN_DeactivateDGAKeyboard (void)
{
	int DGAflags;

	if (dga_keyboard_available && dga_keyboard_active)
	{
		DGAflags = 0;
		if (dga_mouse_active)
		{
			XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0);
			DGAflags |= XF86DGADirectMouse;
		}

		XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), DGAflags);
		dga_keyboard_active = false;
	}
}
Beispiel #9
0
static void
IN_DeactivateDGAMouse(void)
{
    if (dga_available && dga_mouse_active) {
	XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0);
	dga_mouse_active = false;
	IN_CenterMouse();	// maybe set mouse_x = 0 and mouse_y = 0?
    }
}
static void install_grabs(void)
{
  // inviso cursor
  XWarpPointer(dpy, None, win,
               0, 0, 0, 0,
               glConfig.vidWidth / 2, glConfig.vidHeight / 2);
  XSync(dpy, False);

  XDefineCursor(dpy, win, CreateNullCursor(dpy, win));

  XGrabPointer(dpy, win, // bk010108 - do this earlier?
               False,
               MOUSE_MASK,
               GrabModeAsync, GrabModeAsync,
               win,
               None,
               CurrentTime);

  XGetPointerControl(dpy, &mouse_accel_numerator, &mouse_accel_denominator,
                     &mouse_threshold);

  XChangePointerControl(dpy, True, True, 1, 1, 0);

  XSync(dpy, False);

  mouseResetTime = Sys_Milliseconds ();

#ifdef HAVE_XF86DGA
  if (in_dgamouse->value)
  {
    int MajorVersion, MinorVersion;

    if (!XF86DGAQueryVersion(dpy, &MajorVersion, &MinorVersion))
    {
      // unable to query, probalby not supported, force the setting to 0
      ri.Printf( PRINT_ALL, "Failed to detect XF86DGA Mouse\n" );
      ri.Cvar_Set( "in_dgamouse", "0" );
    } else
    {
      XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectMouse);
      XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
    }
  } else
#endif /* HAVE_XF86DGA */
  {
    mwx = glConfig.vidWidth / 2;
    mwy = glConfig.vidHeight / 2;
    mx = my = 0;
  }

  XGrabKeyboard(dpy, win,
                False,
                GrabModeAsync, GrabModeAsync,
                CurrentTime);

  XSync(dpy, False);
}
Beispiel #11
0
static void leave_dga_mode (void)
{
    XF86DGADirectVideo (display, screen, 0);
    XUngrabPointer (display, CurrentTime);
    XUngrabKeyboard (display, CurrentTime);
#ifdef USE_VIDMODE_EXTENSION
    if (vidmodeavail)
	XF86VidModeSwitchToMode (display, screen, allmodes[0]);
#endif
}
Beispiel #12
0
static void Sys_XInstallGrabs( void ) {
	assert( dpy );

	XWarpPointer( dpy, None, win,
				 0, 0, 0, 0,
				 glConfig.vidWidth / 2, glConfig.vidHeight / 2 );

	XSync( dpy, False );

	XDefineCursor( dpy, win, Sys_XCreateNullCursor( dpy, win ) );

	XGrabPointer( dpy, win,
				 False,
				 MOUSE_MASK,
				 GrabModeAsync, GrabModeAsync,
				 win,
				 None,
				 CurrentTime );

	XGetPointerControl( dpy, &mouse_accel_numerator, &mouse_accel_denominator,
					   &mouse_threshold );

	XChangePointerControl( dpy, True, True, 1, 1, 0 );

	XSync( dpy, False );

	mouse_reset_time = Sys_Milliseconds ();

	if ( in_dgamouse.GetBool() && !dga_found ) {
		common->Printf("XF86DGA not available, forcing DGA mouse off\n");
		in_dgamouse.SetBool( false );
	}

	if ( in_dgamouse.GetBool() ) {
#if defined( ID_ENABLE_DGA )
		XF86DGADirectVideo( dpy, DefaultScreen( dpy ), XF86DGADirectMouse );
		XWarpPointer( dpy, None, win, 0, 0, 0, 0, 0, 0 );
#endif
	} else {
		mwx = glConfig.vidWidth / 2;
		mwy = glConfig.vidHeight / 2;
		mx = my = 0;
	}

	XGrabKeyboard( dpy, win,
				  False,
				  GrabModeAsync, GrabModeAsync,
				  CurrentTime );

	XSync( dpy, False );

	mouse_active = true;
}
Beispiel #13
0
static void uninstall_grabs(void)
{
    input_grabbed = false;

#ifdef USE_DGA
    XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0);
    dgamouse = false;
#endif

    XUngrabPointer(x_disp, CurrentTime);
    XUngrabKeyboard(x_disp, CurrentTime);

    // show cursor again
    XUndefineCursor(x_disp, x_win);

}
Beispiel #14
0
static void uninit(void)
{

#ifdef HAVE_DGA2
    XDGADevice *dgadevice;
#endif

    if (!vo_config_count)
        return;

    if (vo_dga_is_running)
    {
        vo_dga_is_running = 0;
        mp_msg(MSGT_VO, MSGL_V, "vo_dga: in uninit\n");
        if (vo_grabpointer)
            XUngrabPointer(mDisplay, CurrentTime);
        XUngrabKeyboard(mDisplay, CurrentTime);
#ifdef HAVE_DGA2
        XDGACloseFramebuffer(mDisplay, mScreen);
        dgadevice = XDGASetMode(mDisplay, mScreen, 0);
        if (dgadevice != NULL)
        {
            XFree(dgadevice);
        }
#else
        XF86DGADirectVideo(mDisplay, mScreen, 0);
        // first disable DirectVideo and then switch mode back!     
#ifdef HAVE_XF86VM
        if (vo_dga_vidmodes != NULL)
        {
            int screen;

            screen = XDefaultScreen(mDisplay);
            mp_msg(MSGT_VO, MSGL_V,
                   "vo_dga: VidModeExt: Switching back..\n");
            // seems some graphics adaptors need this more than once ...
            XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]);
            XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]);
            XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]);
            XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]);
            XFree(vo_dga_vidmodes);
        }
#endif
#endif
    }
    vo_x11_uninit();
}
static void
XF86cleanup(int sig)
{
    ScrPtr sp;
    int i;
    static char beenhere = 0;

    if (beenhere)
	_exit(3);
    beenhere = 1;

    for (i = 0; i < numScrs; i++) {
	sp = scrList[i];
	XF86DGADirectVideo(sp->display, sp->screen, 0);
	XSync(sp->display, False);
    }
    _exit(3);
}
Beispiel #16
0
static void uninstall_grabs( void ) {
	if ( dgamouse ) {
		dgamouse = qfalse;
		XF86DGADirectVideo( dpy, DefaultScreen( dpy ), 0 );
	}

	XChangePointerControl( dpy, qtrue, qtrue, mouse_accel_numerator,
						   mouse_accel_denominator, mouse_threshold );

	XUngrabPointer( dpy, CurrentTime );
	XUngrabKeyboard( dpy, CurrentTime );

	XWarpPointer( dpy, None, win,
				  0, 0, 0, 0,
				  glConfig.vidWidth / 2, glConfig.vidHeight / 2 );

	// inviso cursor
	XUndefineCursor( dpy, win );
}
Beispiel #17
0
static void install_grabs(void)
{
// inviso cursor
	XDefineCursor(dpy, win, CreateNullCursor(dpy, win));

	XGrabPointer(dpy, win,
				 False,
				 MOUSE_MASK,
				 GrabModeAsync, GrabModeAsync,
				 win,
				 None,
				 CurrentTime);

	XGetPointerControl(dpy, &mouse_accel_numerator, &mouse_accel_denominator,
		&mouse_threshold);

	XChangePointerControl(dpy, qtrue, qtrue, 2, 1, 0);

	if (in_dgamouse->value) {
		int MajorVersion, MinorVersion;

		if (!XF86DGAQueryVersion(dpy, &MajorVersion, &MinorVersion)) { 
			// unable to query, probalby not supported
			ri.Printf( PRINT_ALL, "Failed to detect XF86DGA Mouse\n" );
			ri.Cvar_Set( "in_dgamouse", "0" );
		} else {
			dgamouse = qtrue;
			XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectMouse);
			XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
		}
	} else {
		XWarpPointer(dpy, None, win,
					 0, 0, 0, 0,
					 glConfig.vidWidth / 2, glConfig.vidHeight / 2);
	}

	XGrabKeyboard(dpy, win,
				  False,
				  GrabModeAsync, GrabModeAsync,
				  CurrentTime);

//	XSync(dpy, True);
}
Beispiel #18
0
void I_ShutdownGraphics(void)
{
  fprintf(stderr, "I_ShutdownGraphics : ");

  // Free internal structures
  if (pixelvals != NULL) free(pixelvals);
  I_EndImageTranslation();

#ifdef HAVE_LIBXXF86DGA
  if (doDga) {
     XF86DGADirectVideo(X_display, X_screen, 0);
  }
  else
#endif

#ifdef HAVE_LIBXEXT
  if (doShm) {
    // Detach from X server
    if (!XShmDetach(X_display, &X_shminfo))
      I_Error("XShmDetach() failed in I_ShutdownGraphics()");
    else
      fprintf(stderr, "Released XShm shared memory.\n\r");

    // Release shared memory.
    shmdt(X_shminfo.shmaddr);
    shmctl(X_shminfo.shmid, IPC_RMID, 0);
    
    // Paranoia.
    image->data = NULL;
  } else
#endif
  {
    if (multiply != 1) {
      free(image->data);
    }
    image->data = NULL; // Prevent server trying to free image data
    XDestroyImage(image);
    fprintf(stderr, "Released XImage memory\n");
  }
  XDestroyWindow(X_display, X_mainWindow);
  XCloseDisplay(X_display);
  X_display = NULL;
}
Beispiel #19
0
static void uninstall_grabs(void)
{
	if (dgamouse) {
		dgamouse = qfalse;
		XF86DGADirectVideo(dpy, DefaultScreen(dpy), 0);
	}

	XChangePointerControl(dpy, qtrue, qtrue, mouse_accel_numerator, 
		mouse_accel_denominator, mouse_threshold);

	XUngrabPointer(dpy, CurrentTime);
	XUngrabKeyboard(dpy, CurrentTime);

// inviso cursor
	XUndefineCursor(dpy, win);

//	XAutoRepeatOn(dpy);

//	XSync(dpy, True);
}
Beispiel #20
0
static void uninstall_grabs( void ) {
	if ( in_dgamouse->value ) {
		if ( com_developer->value ) {
			ri.Printf( PRINT_ALL, "DGA Mouse - Disabling DGA DirectVideo\n" );
		}
		XF86DGADirectVideo( dpy, DefaultScreen( dpy ), 0 );
	}

	XChangePointerControl( dpy, qtrue, qtrue, mouse_accel_numerator,
						   mouse_accel_denominator, mouse_threshold );

	XUngrabPointer( dpy, CurrentTime );
	XUngrabKeyboard( dpy, CurrentTime );

	XWarpPointer( dpy, None, win,
				  0, 0, 0, 0,
				  glConfig.vidWidth / 2, glConfig.vidHeight / 2 );

	// inviso cursor
	XUndefineCursor( dpy, win );
}
Beispiel #21
0
void Sys_XUninstallGrabs(void) {
	assert( dpy );

#if defined( ID_ENABLE_DGA )
	if ( in_dgamouse.GetBool() ) {
		common->DPrintf( "DGA Mouse - Disabling DGA DirectVideo\n" );
		XF86DGADirectVideo( dpy, DefaultScreen( dpy ), 0 );
	}
#endif

	XChangePointerControl( dpy, true, true, mouse_accel_numerator,
						  mouse_accel_denominator, mouse_threshold );

	XUngrabPointer( dpy, CurrentTime );
	XUngrabKeyboard( dpy, CurrentTime );

	XWarpPointer( dpy, None, win,
				 0, 0, 0, 0,
				 glConfig.vidWidth / 2, glConfig.vidHeight / 2);

	XUndefineCursor( dpy, win );

	mouse_active = false;
}
Beispiel #22
0
void S9xTextMode ()
{
	if (!is_graphics)
		return;

	if (ourdisp == NULL)
		return;


	XF86DGADirectVideo (ourdisp, ourscreen, 0);
#ifdef USE_XF86VIDMODE
	if (orig_mode != mod320x240) {
		XF86VidModeSwitchToMode (ourdisp, ourscreen, orig_mode);
	}
#endif
	XAutoRepeatOn (ourdisp);

	XUngrabKeyboard (ourdisp, CurrentTime);
	XUngrabPointer (ourdisp, CurrentTime);
	XSelectInput (ourdisp, inputwin, 0);
	XSync (ourdisp, True);

	is_graphics = FALSE;
}
Beispiel #23
0
static void install_grabs(void)
{
    int MajorVersion, MinorVersion;

    input_grabbed = true;

    // don't show mouse cursor icon
    XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));

    XGrabPointer(x_disp, x_win,
                 True,
                 0,
                 GrabModeAsync, GrabModeAsync,
                 x_win,
                 None,
                 CurrentTime);

#ifdef USE_DGA
    if (!COM_CheckParm("-nodga") &&
            XF86DGAQueryVersion(x_disp, &MajorVersion, &MinorVersion)) {
        // let us hope XF86DGADirectMouse will work
        XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), XF86DGADirectMouse);
        dgamouse = true;
        XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0, 0, 0); // oldman: this should be here really
    }
    else
#endif
        XWarpPointer(x_disp, None, x_win,
                     0, 0, 0, 0,
                     vid.width / 2, vid.height / 2);

    XGrabKeyboard(x_disp, x_win,
                  False,
                  GrabModeAsync, GrabModeAsync,
                  CurrentTime);
}
Beispiel #24
0
static void install_grabs( void )
{
	int res;
	int fevent;

	assert( x11display.dpy && x11display.win );

	if( !x11display.features.wmStateFullscreen )
	{
		res = XGrabKeyboard( x11display.dpy, x11display.win, False, GrabModeAsync, GrabModeAsync, CurrentTime );
		if( res != GrabSuccess )
		{
			Com_Printf( "Warning: XGrabKeyboard failed\n" );
			return;
		}
	}

	XDefineCursor( x11display.dpy, x11display.win, CreateNullCursor( x11display.dpy, x11display.win ) );

	res = XGrabPointer( x11display.dpy, x11display.win, True, 0, GrabModeAsync, GrabModeAsync, x11display.win, None, CurrentTime );
	if( res != GrabSuccess )
	{
		// TODO: Find a solution to Pointer Grabs at focus changes, which sometimes result
		// in Grabbing Errors. Like switches from Windowed/Fullscreen to Hidden State.
		//Com_Printf( "Warning: XGrabPointer failed\n" );
		XUngrabKeyboard( x11display.dpy, CurrentTime );
		XUndefineCursor( x11display.dpy, x11display.win );
		return;
	}

	if( in_dgamouse->integer )
	{
		int MajorVersion, MinorVersion;

		if( XF86DGAQueryVersion( x11display.dpy, &MajorVersion, &MinorVersion ) )
		{
			XF86DGADirectVideo( x11display.dpy, x11display.scr, XF86DGADirectMouse );
			XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0,
				x11display.win_width/2, x11display.win_height/2 );
			dgamouse = qtrue;
		}
		else
		{
			// unable to query, probalby not supported
			Com_Printf( "Failed to detect XF86DGA Mouse\n" );
			Cvar_Set( "in_dgamouse", "0" );
			dgamouse = qfalse;
		}
	}
	else
	{
		XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0,
			x11display.win_width/2, x11display.win_height/2 );
	}

	ignore_one = qtrue; // first mouse update after install_grabs is ignored
	mx = my = 0;
	mouse_active = qtrue;

	in_dgamouse->modified = qfalse;

	input_active = qtrue;

	// init X Input method, needed by Xutf8LookupString
	x11display.im = XOpenIM( x11display.dpy, NULL, NULL, NULL );
	x11display.ic = XCreateIC( x11display.im,
		XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
		XNClientWindow, x11display.win,
		NULL );
	if ( x11display.ic )
	{
		XGetICValues( x11display.ic, XNFilterEvents, &fevent, NULL );
		XSelectInput( x11display.dpy, x11display.win, fevent | x11display.wa.event_mask );
	}
}
Beispiel #25
0
static void 
restore(void) 
{
	//reg_IO->vidDesktopStartAddr = vidpage0offset;
	XF86DGADirectVideo(display,0,0);
}
Beispiel #26
0
void I_InitGraphics(void)
{
  const char*	displayname = NULL;
  int		n;
  int		pnum;
  int		x=0;
  int		y=0;
  
  {  
    static int		firsttime=1;
    
    if (!firsttime) {
      return;
    }
    firsttime = 0;
  }

  { // Check for screen enlargement
    char str[3] = { '-', 0, 0 };

    for (n=1; n<4; n++) {
      str[1] = n + '0';
      if (M_CheckParm(str)) multiply = n;
    }
  }
  
  X_width = SCREENWIDTH * multiply;
  X_height = SCREENHEIGHT * multiply;
  
  // check for command-line geometry
  if ( (pnum=M_CheckParm("-geom")) ? 1 : (pnum=M_CheckParm("-geometry"))) 
   if (pnum+1 < myargc) { // check parm given
    // warning: char format, different type arg
    char	xsign=' ';
    char	ysign=' ';
    const char* pg = myargv[pnum+1];
    
    pg += strcspn(pg, "+-");
    
    // warning: char format, different type arg 3,5
    n = sscanf(pg, "%c%d%c%d", &xsign, &x, &ysign, &y);
    
    if (n==2)
      x = y = 0;
    else if (n==4) {
      if (xsign == '-')
	x = -x;
      if (ysign == '-')
	y = -y;
    } else
      fprintf(stderr, "I_InitGraphics: bad -geom offsets \"%s\"\n", pg);
  }
  
  // check for command-line display name
  if ( (pnum=M_CheckParm("-disp")) ) // suggest parentheses around assignment
    displayname = myargv[pnum+1];
  // CPhipps - support more standard -display param
  if ( (pnum=M_CheckParm("-display")) ) // ditto
    displayname = myargv[pnum+1];
  // CPhipps - and -displayname as for xterm
  if ( (pnum=M_CheckParm("-displayname")) ) // ditto
    displayname = myargv[pnum+1];

  // open the display
  if (!(X_display = XOpenDisplay(displayname))) {
    if (displayname)
      I_Error("Could not open display [%s]", displayname);
    else
      I_Error("Could not open display (DISPLAY=[%s])", getenv("DISPLAY"));
  }

  // use the default visual 
  X_screen = DefaultScreen(X_display);

  X_deletewin = XInternAtom(X_display, "WM_DELETE_WINDOW", False);

  // check for the MITSHM extension
  // even if it's available, make sure it's a local connection
  lprintf(LO_INFO,"I_InitGraphics:");

#ifdef HAVE_LIBXXF86DGA
  if ((doDga = (M_CheckParm("-dga") && XF86DGAQueryExtension(X_display, &n, &n)) )) {
    lprintf(LO_INFO,"I_InitGraphics: found DGA extension\n");
    if (M_CheckParm("-noaccel") || (X_opt & 1)) doDga = false;
    else lprintf(LO_INFO, "(using DGA)");
  }
  else 
#endif
#ifdef HAVE_LIBXEXT
  if ((doShm = XShmQueryExtension(X_display))) {

    if (!displayname) displayname = getenv("DISPLAY");
    
    if (displayname) {
      // CPhipps - don't modify the original string, please.
      //         - oops my code here was totally wrong
      // I have no idea exactly what should go here.

      if (M_CheckParm("-noaccel") || (X_opt & 1)) doShm = false;
      else lprintf(LO_INFO, "(using MITShm)");
    }
  }
  else 
#endif 
    if (devparm) 
      fprintf(stderr, "No MITShm extension in server");

  if (devparm)
    fputc('\n', stderr);

  if ((X_visual = I_FindMode(X_screen)) == NULL) 
    I_Error("Unsupported visual");
  
  // create the colormap
  X_cmap = XCreateColormap(X_display, RootWindow(X_display, X_screen), 
			   X_visual, true_color ? AllocNone : AllocAll);

#ifdef HAVE_LIBXXF86DGA
  /* setup for DGA */
  if(doDga) {
     char *fb;
     X_mainWindow=RootWindow(X_display, X_screen);
     XF86DGAGetViewPortSize(X_display, X_screen, &DGA_width, &DGA_height);
     XF86DGAGetVideo(X_display, X_screen, &fb,
		     &DGA_real_width, &DGA_pagelen, &DGA_memlen);

     fprintf(stderr,
	     "I_InitGraphics: DGA reports %dx%d scan=%d page=%d mem=%d\n",
	     DGA_width,DGA_height,DGA_real_width,DGA_pagelen,DGA_memlen);

     out_buffer=(void*)fb;

     XF86DGADirectVideo(X_display, X_screen, XF86DGADirectGraphics);
     XF86DGASetVidPage(X_display, X_screen, 0);
     XF86DGAForkApp(X_screen);
     XSelectInput(X_display, X_mainWindow, KeyPressMask | KeyReleaseMask);
     fprintf(stderr,"DGA framebuffer @%p\n",fb);
     memset(fb,0,102400);
  }
#endif

#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif

  { // setup attributes for main window
    unsigned long	attribmask;
    XSetWindowAttributes attribs;

    attribmask = CWEventMask | CWColormap | CWBorderPixel;
    attribs.event_mask = KeyPressMask | KeyReleaseMask
#ifdef MONITOR_VISIBILITY
      | VisibilityChangeMask
#endif
      | ExposureMask;
    
    attribs.colormap = X_cmap;
    attribs.border_pixel = 0;
    
    // create the main window
    X_mainWindow = XCreateWindow( X_display,
				  RootWindow(X_display, X_screen),
				  x, y,
				  X_width, X_height,
				  0, // borderwidth
				  X_bpp, // depth
				  InputOutput, X_visual,
				  attribmask, &attribs );
  }
  
#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif

  {
    XClassHint c_hint;
    XTextProperty x_name;
    XSizeHints s_hint;
    XWMHints wm_hint;
    char lcase_buf[10], ucase_buf[10];
    char* str;

    strcpy(str = lcase_buf, lcase_lxdoom);
    XStringListToTextProperty(&str, 1, &x_name);

    s_hint.flags = PSize | PMinSize | PMaxSize;
    s_hint.min_width = s_hint.max_width = s_hint.base_width = X_width;
    s_hint.min_height = s_hint.max_height = s_hint.base_height = X_height;

    wm_hint.input = True;
    wm_hint.window_group = X_mainWindow;
    wm_hint.flags = InputHint | WindowGroupHint;

    strcpy(c_hint.res_name = lcase_buf, lcase_lxdoom);
    strcpy(c_hint.res_class = ucase_buf, ucase_lxdoom);
    
    XSetWMProtocols(X_display, X_mainWindow, &X_deletewin, 1);
    
    XSetWMProperties(X_display, X_mainWindow, &x_name, &x_name, 
		     (char**)myargv, myargc, &s_hint, &wm_hint, &c_hint);

    XFlush(X_display);
  }

#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif
  // Hide pointer while over this window
  XDefineCursor(X_display, X_mainWindow,
		I_XCreateNullCursor( X_display, X_mainWindow ) );
  
  { // create the GC
    XGCValues		xgcvalues;
    int		valuemask;
    
    valuemask = GCGraphicsExposures;
    xgcvalues.graphics_exposures = False;
    X_gc = XCreateGC(X_display, X_mainWindow, valuemask, &xgcvalues);
  }
  
#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif
  {
     // name the window
     XStoreName(X_display, X_mainWindow, "lxdoom");
  
     // map the window
     XMapWindow(X_display, X_mainWindow);
  }  

  // wait until it is OK to draw
#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif
  do {
    XNextEvent(X_display, &X_event);
  } while (!(X_event.type == Expose && !X_event.xexpose.count));

#ifdef HAVE_LIBXXF86DGA
  if(doDga) {}
  else
#endif

#ifdef HAVE_LIBXEXT
  if (doShm) {
    
    X_shmeventtype = XShmGetEventBase(X_display) + ShmCompletion;
    
    // create the image
    image = XShmCreateImage( X_display, X_visual,
			     X_bpp, ZPixmap,
			     0, &X_shminfo,
			     X_width, X_height );
    
    I_XShmGrabSharedMemory(image->bytes_per_line * image->height);
    
    if (!(out_buffer = (pval*)image->data)) {
      perror("");
      I_Error("shmat() failed in I_InitGraphics()");
    }
    
    // get the X server to attach to it
    if (!XShmAttach(X_display, &X_shminfo))
      I_Error("XShmAttach() failed in InitGraphics()");
    
    if (!expand_buffer) {
      // Render directly into MitSHM memory
      Z_Free(screens[0]);
      screens[0] = (unsigned char *) (image->data); 
    }
  } else
#endif 
  {
    if (!expand_buffer) {
      // Very efficient, render directly into image
      out_buffer = (pval*)screens[0];
    } else {
      // Will have to enlarge from rendering buffer
      //  into image buffer
      out_buffer = (pval*)malloc (X_width * X_height * BYTESPP);
    }

	{ 
/* hack to enable 15 bpp usage */
		int bpp=X_bpp;
		if(bpp==15)bpp=16;

    	image=XCreateImage( X_display, X_visual,
				X_bpp, ZPixmap,
				0, (char*)out_buffer,
				X_width, X_height,
				bpp, 0);
#ifdef NOT_NOW
    image=XCreateImage( X_display, X_visual,
			X_bpp, ZPixmap,
			0, (char*)out_buffer,
			X_width, X_height,
			X_bpp, 0);
#endif

	}
    if (!image) 
      I_Error("XCreateImage: failed to create image %dx%d %d bpp", 
	      X_width, X_height, X_bpp);
  }
  
  atexit(I_ShutdownGraphics);

  I_XInitInputs();
}
Beispiel #27
0
void UXViewport::CaptureInputs()
{
	guard(UXViewport::CaptureInputs);
	
	// Check keyboard state.
	XKeyboardState KeyState;
	XGetKeyboardControl(XDisplay, &KeyState);
	if( KeyState.global_auto_repeat == AutoRepeatModeOn )
	{
		RestoreAutoRepeat = true;
		XAutoRepeatOff( XDisplay );
	}

	// Examine root window.
	Window RootRoot;
	int r_x, r_y;
	unsigned int r_width, r_height, r_border, r_depth;
	XGetGeometry(
		XDisplay, DefaultRootWindow(XDisplay), &RootRoot,
		&r_x, &r_y, &r_width, &r_height, &r_border, &r_depth
	);

	XWarpPointer(XDisplay, None, XWindow,
		0, 0, 0, 0, r_width/2, r_height/2);

	XSync(XDisplay, False);

	//XDefineCursor(XDisplay, XWindow, GetNullCursor());

	// Capture the pointer.
	XGrabPointer(XDisplay, XWindow, False,
		ButtonPressMask | ButtonReleaseMask | 
		PointerMotionMask | ButtonMotionMask,
		GrabModeAsync, GrabModeAsync, XWindow, None, CurrentTime );

	// Control acceleration.
	XChangePointerControl(XDisplay, True, True, 2, 1, 0);

	XSync(XDisplay, False);
		
	// Query DGA capabilities.
	UXClient* C = GetOuterUXClient();
	if (C->DGAMouseEnabled)
	{
		INT VersionMajor, VersionMinor;
		if (!XF86DGAQueryVersion(XDisplay, &VersionMajor, &VersionMinor))
		{
			debugf( TEXT("XF86DGA disabled.") );
			UseDGA = false;
		} else {
			debugf( TEXT("XF86DGA enabled.") );
			UseDGA = true;
			XF86DGADirectVideo(XDisplay, DefaultScreen(XDisplay), XF86DGADirectMouse);
			XWarpPointer(XDisplay, None, XWindow, 0, 0, 0, 0, 0, 0);
		}
	} else
		UseDGA = false;

	XGrabKeyboard(XDisplay, XWindow, False, GrabModeAsync, GrabModeAsync, CurrentTime);

	XSync(XDisplay, False);

	unguard;
}
Beispiel #28
0
static int config(uint32_t width, uint32_t height,
                       uint32_t d_width, uint32_t d_height,
                       uint32_t flags, char *title, uint32_t format)
{

    int x_off, y_off;
    int wanted_width, wanted_height;

    static unsigned char *vo_dga_base;
    static int prev_width, prev_height;

#ifdef HAVE_DGA2
    // needed to change DGA video mode
    int mX = VO_DGA_INVALID_RES, mY = VO_DGA_INVALID_RES, mVBI =
        100000, mMaxY = 0, i, j = 0;
    int dga_modenum;
    XDGAMode *modeline;
    XDGADevice *dgadevice;
#else
#ifdef HAVE_XF86VM
    unsigned int vm_event, vm_error;
    unsigned int vm_ver, vm_rev;
    int i, j = 0, have_vm = 0;
    int mX = VO_DGA_INVALID_RES, mY = VO_DGA_INVALID_RES, mVBI =
        100000, mMaxY = 0, dga_modenum;
#endif
    int bank, ram;
#endif

    vo_dga_src_format = format;

    wanted_width = d_width;
    wanted_height = d_height;

    if (!wanted_height)
        wanted_height = height;
    if (!wanted_width)
        wanted_width = width;

    if (!vo_dbpp)
    {
        if ((format & IMGFMT_BGR_MASK) == IMGFMT_BGR)
        {
            vo_dga_src_mode = vd_ModeValid(format & 0xff);
        }
    } else
    {
        vo_dga_src_mode = vd_ModeValid(vo_dbpp);
    }
    vo_dga_hw_mode = SRC_MODE.vdm_hw_mode;

    if (!vo_dga_src_mode)
    {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: unsupported video format!\n");
        return 1;
    }

    vo_dga_vp_width = vo_screenwidth;
    vo_dga_vp_height = vo_screenheight;

    mp_msg(MSGT_VO, MSGL_V, "vo_dga: XServer res: %dx%d\n",
           vo_dga_vp_width, vo_dga_vp_height);

// choose a suitable mode ...

#ifdef HAVE_DGA2
// Code to change the video mode added by Michael Graffam
// [email protected]

    mp_msg(MSGT_VO, MSGL_V, "vo_dga: vo_modelines=%p, vo_modecount=%d\n",
           vo_modelines, vo_modecount);

    if (vo_modelines == NULL)
    {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: can't get modelines\n");
        return 1;
    }

    mp_msg(MSGT_VO, MSGL_INFO,
           "vo_dga: DGA 2.0 available :-) Can switch resolution AND depth!\n");
    for (i = 0; i < vo_modecount; i++)
    {
        if (vd_ModeEqual(vo_modelines[i].depth,
                         vo_modelines[i].bitsPerPixel,
                         vo_modelines[i].redMask,
                         vo_modelines[i].greenMask,
                         vo_modelines[i].blueMask, vo_dga_hw_mode))
        {

            mp_msg(MSGT_VO, MSGL_V, "maxy: %4d, depth: %2d, %4dx%4d, ",
                   vo_modelines[i].maxViewportY, vo_modelines[i].depth,
                   vo_modelines[i].imageWidth,
                   vo_modelines[i].imageHeight);
            if (check_res
                (i, wanted_width, wanted_height, vo_modelines[i].depth,
                 vo_modelines[i].viewportWidth,
                 vo_modelines[i].viewportHeight,
                 (unsigned) vo_modelines[i].verticalRefresh,
                 vo_modelines[i].maxViewportY, &mX, &mY, &mVBI, &mMaxY))
                j = i;
        }
    }
    mp_msg(MSGT_VO, MSGL_INFO,
           "vo_dga: Selected hardware mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d.\n",
           mX, mY, mVBI, HW_MODE.vdm_depth, HW_MODE.vdm_bitspp);
    mp_msg(MSGT_VO, MSGL_INFO,
           "vo_dga: Video parameters by codec: %3d x %3d, depth %2d, bitspp %2d.\n",
           width, height, SRC_MODE.vdm_depth, SRC_MODE.vdm_bitspp);
    vo_dga_vp_width = mX;
    vo_dga_vp_height = mY;

    if ((flags & VOFLAG_SWSCALE) || (flags & VOFLAG_FULLSCREEN))
    {                           /* -zoom or -fs */
        scale_dstW = (d_width + 7) & ~7;
        scale_dstH = d_height;
        scale_srcW = width;
        scale_srcH = height;
        aspect_save_screenres(mX, mY);
        aspect_save_orig(scale_srcW, scale_srcH);
        aspect_save_prescale(scale_dstW, scale_dstH);
        if (flags & VOFLAG_FULLSCREEN)       /* -fs */
            aspect(&scale_dstW, &scale_dstH, A_ZOOM);
        else if (flags & VOFLAG_SWSCALE)  /* -fs */
            aspect(&scale_dstW, &scale_dstH, A_NOZOOM);
        mp_msg(MSGT_VO, MSGL_INFO,
               "vo_dga: Aspect corrected size for SwScaler: %4d x %4d.\n",
               scale_dstW, scale_dstH);
        /* XXX this is a hack, but I'm lazy ;-) :: atmos */
        width = scale_dstW;
        height = scale_dstH;
    }

    vo_dga_width = vo_modelines[j].bytesPerScanline / HW_MODE.vdm_bytespp;
    dga_modenum = vo_modelines[j].num;
    modeline = vo_modelines + j;

#else

#ifdef HAVE_XF86VM

    mp_msg(MSGT_VO, MSGL_INFO,
           "vo_dga: DGA 1.0 compatibility code: Using XF86VidMode for mode switching!\n");

    if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error))
    {
        XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev);
        mp_msg(MSGT_VO, MSGL_INFO,
               "vo_dga: XF86VidMode Extension v%i.%i\n", vm_ver, vm_rev);
        have_vm = 1;
    } else
    {
        mp_msg(MSGT_VO, MSGL_ERR,
               "vo_dga: XF86VidMode Extension not available.\n");
    }

#define GET_VREFRESH(dotclk, x, y)( (((dotclk)/(x))*1000)/(y) )

    if (have_vm)
    {
        int modecount;

        XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount,
                                   &vo_dga_vidmodes);

        if (vo_dga_vidmodes != NULL)
        {
            for (i = 0; i < modecount; i++)
            {
                if (check_res(i, wanted_width, wanted_height,
                              vo_dga_modes[vo_dga_hw_mode].vdm_depth,
                              vo_dga_vidmodes[i]->hdisplay,
                              vo_dga_vidmodes[i]->vdisplay,
                              GET_VREFRESH(vo_dga_vidmodes[i]->dotclock,
                                           vo_dga_vidmodes[i]->htotal,
                                           vo_dga_vidmodes[i]->vtotal),
                              0, &mX, &mY, &mVBI, &mMaxY))
                    j = i;
            }

            mp_msg(MSGT_VO, MSGL_INFO,
                   "vo_dga: Selected video mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d, video %3d x %3d.\n",
                   mX, mY, mVBI,
                   vo_dga_modes[vo_dga_hw_mode].vdm_depth,
                   vo_dga_modes[vo_dga_hw_mode].vdm_bitspp, width, height);
        } else
        {
            mp_msg(MSGT_VO, MSGL_INFO,
                   "vo_dga: XF86VidMode returned no screens - using current resolution.\n");
        }
        dga_modenum = j;
        vo_dga_vp_width = mX;
        vo_dga_vp_height = mY;
    }

#else
    mp_msg(MSGT_VO, MSGL_INFO,
           "vo_dga: Only have DGA 1.0 extension and no XF86VidMode :-(\n");
    mp_msg(MSGT_VO, MSGL_INFO,
           "        Thus, resolution switching is NOT possible.\n");

#endif
#endif

    vo_dga_src_width = width;
    vo_dga_src_height = height;

    if (vo_dga_src_width > vo_dga_vp_width ||
        vo_dga_src_height > vo_dga_vp_height)
    {
        mp_msg(MSGT_VO, MSGL_ERR,
               "vo_dga: Sorry, video larger than viewport is not yet supported!\n");
        // ugly, do something nicer in the future ...
#ifndef HAVE_DGA2
#ifdef HAVE_XF86VM
        if (vo_dga_vidmodes)
        {
            XFree(vo_dga_vidmodes);
            vo_dga_vidmodes = NULL;
        }
#endif
#endif
        return 1;
    }

    if (vo_dga_vp_width == VO_DGA_INVALID_RES)
    {
        mp_msg(MSGT_VO, MSGL_ERR,
               "vo_dga: Something is wrong with your DGA. There doesn't seem to be a\n"
               "         single suitable mode!\n"
               "         Please file a bug report (see DOCS/HTML/en/bugreports.html)\n");
#ifndef HAVE_DGA2
#ifdef HAVE_XF86VM
        if (vo_dga_vidmodes)
        {
            XFree(vo_dga_vidmodes);
            vo_dga_vidmodes = NULL;
        }
#endif
#endif
        return 1;
    }
// now let's start the DGA thing 

    if (!vo_config_count || width != prev_width || height != prev_height)
    {
#ifdef HAVE_DGA2

        if (!XDGAOpenFramebuffer(mDisplay, mScreen))
        {
            mp_msg(MSGT_VO, MSGL_ERR,
                   "vo_dga: Framebuffer mapping failed!!!\n");
            return 1;
        }

        dgadevice = XDGASetMode(mDisplay, mScreen, dga_modenum);
        XDGASync(mDisplay, mScreen);

        vo_dga_base = dgadevice->data;
        XFree(dgadevice);

        XDGASetViewport(mDisplay, mScreen, 0, 0, XDGAFlipRetrace);

#else

#ifdef HAVE_XF86VM
        if (have_vm)
        {
            XF86VidModeLockModeSwitch(mDisplay, mScreen, 0);
            // Two calls are needed to switch modes on my ATI Rage 128. Why?
            // for riva128 one call is enough!
            XF86VidModeSwitchToMode(mDisplay, mScreen,
                                    vo_dga_vidmodes[dga_modenum]);
            XF86VidModeSwitchToMode(mDisplay, mScreen,
                                    vo_dga_vidmodes[dga_modenum]);
        }
#endif

        XF86DGAGetViewPortSize(mDisplay, mScreen,
                               &vo_dga_vp_width, &vo_dga_vp_height);

        XF86DGAGetVideo(mDisplay, mScreen,
                        (char **) &vo_dga_base, &vo_dga_width, &bank,
                        &ram);

        XF86DGADirectVideo(mDisplay, mScreen,
                           XF86DGADirectGraphics | XF86DGADirectMouse |
                           XF86DGADirectKeyb);

        XF86DGASetViewPort(mDisplay, mScreen, 0, 0);

#endif
    }
    // do some more checkings here ...

    mp_msg(MSGT_VO, MSGL_V,
           "vo_dga: bytes/line: %d, screen res: %dx%d, depth: %d, base: %p, bpp: %d\n",
           vo_dga_width, vo_dga_vp_width, vo_dga_vp_height,
           HW_MODE.vdm_bytespp, vo_dga_base, HW_MODE.vdm_bitspp);

    x_off = (vo_dga_vp_width - vo_dga_src_width) >> 1;
    y_off = (vo_dga_vp_height - vo_dga_src_height) >> 1;

    vo_dga_bytes_per_line = vo_dga_src_width * HW_MODE.vdm_bytespp;
    vo_dga_lines = vo_dga_src_height;

    vo_dga_src_offset = 0;
    vo_dga_vp_offset =
        (y_off * vo_dga_width + x_off) * HW_MODE.vdm_bytespp;

    vo_dga_vp_skip = (vo_dga_width - vo_dga_src_width) * HW_MODE.vdm_bytespp;   // todo

    mp_msg(MSGT_VO, MSGL_V, "vo_dga: vp_off=%d, vp_skip=%d, bpl=%d\n",
           vo_dga_vp_offset, vo_dga_vp_skip, vo_dga_bytes_per_line);


    XGrabKeyboard(mDisplay, DefaultRootWindow(mDisplay), True,
                  GrabModeAsync, GrabModeAsync, CurrentTime);
    if (vo_grabpointer)
        XGrabPointer(mDisplay, DefaultRootWindow(mDisplay), True,
                     ButtonPressMask, GrabModeAsync, GrabModeAsync,
                     None, None, CurrentTime);

    if (!vo_config_count || width != prev_width || height != prev_height)
    {
        init_video_buffers(vo_dga_base,
                           vo_dga_vp_height,
                           vo_dga_width * HW_MODE.vdm_bytespp,
#ifdef HAVE_DGA2
                           modeline->maxViewportY,
#else
                           vo_dga_vp_height,
#endif
                           vo_doublebuffering);
        prev_width = width;
        prev_height = height;
    }

    mp_msg(MSGT_VO, MSGL_V, "vo_dga: Using %d frame buffer%s.\n",
           vo_dga_nr_video_buffers,
           vo_dga_nr_video_buffers == 1 ? "" : "s");

    vo_dga_is_running = 1;
    return 0;
}
Beispiel #29
0
void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
{
	static int originalmouseparms_num;
	static int originalmouseparms_denom;
	static int originalmouseparms_threshold;
	static qboolean restore_spi;

#ifdef USEDGA
	qboolean usedgamouse;
#endif

	if (!vidx11_display || !win)
		return;

	if (relative)
		fullscreengrab = true;

	if (!mouse_avail)
		fullscreengrab = relative = hidecursor = false;

#ifdef USEDGA
	usedgamouse = relative && vid_dgamouse.integer;
	if (!vid_x11_dgasupported)
		usedgamouse = false;
	if (fullscreengrab && vid_usingmouse && (vid_usingdgamouse != usedgamouse))
		VID_SetMouse(false, false, false); // ungrab first!
#endif

	if (vid_usingmousegrab != fullscreengrab)
	{
		vid_usingmousegrab = fullscreengrab;
		cl_ignoremousemoves = 2;
		if (fullscreengrab)
		{
			XGrabPointer(vidx11_display, win,  True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
			if (vid_grabkeyboard.integer || vid_isoverrideredirect)
				XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
		}
		else
		{
			XUngrabPointer(vidx11_display, CurrentTime);
			XUngrabKeyboard(vidx11_display, CurrentTime);
		}
	}

	if (relative)
	{
		if (!vid_usingmouse)
		{
			XWindowAttributes attribs_1;
			XSetWindowAttributes attribs_2;

			XGetWindowAttributes(vidx11_display, win, &attribs_1);
			attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
			XChangeWindowAttributes(vidx11_display, win, CWEventMask, &attribs_2);

#ifdef USEDGA
			vid_usingdgamouse = usedgamouse;
			if (usedgamouse)
			{
				XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), XF86DGADirectMouse);
				XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
			}
			else
#endif
				XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);

// COMMANDLINEOPTION: X11 Input: -noforcemparms disables setting of mouse parameters (not used with DGA, windows only)
#ifdef USEDGA
			if (!COM_CheckParm ("-noforcemparms") && !usedgamouse)
#else
			if (!COM_CheckParm ("-noforcemparms"))
#endif
			{
				XGetPointerControl(vidx11_display, &originalmouseparms_num, &originalmouseparms_denom, &originalmouseparms_threshold);
				XChangePointerControl (vidx11_display, true, false, 1, 1, -1); // TODO maybe change threshold here, or remove this comment
				restore_spi = true;
			}
			else
				restore_spi = false;

			cl_ignoremousemoves = 2;
			vid_usingmouse = true;
		}
	}
	else
	{
		if (vid_usingmouse)
		{
#ifdef USEDGA
			if (vid_usingdgamouse)
				XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), 0);
			vid_usingdgamouse = false;
#endif
			cl_ignoremousemoves = 2;

			if (restore_spi)
				XChangePointerControl (vidx11_display, true, true, originalmouseparms_num, originalmouseparms_denom, originalmouseparms_threshold);
			restore_spi = false;

			vid_usingmouse = false;
		}
	}

	if (vid_usinghidecursor != hidecursor)
	{
		vid_usinghidecursor = hidecursor;
		if (hidecursor)
			XDefineCursor(vidx11_display, win, CreateNullCursor(vidx11_display, win));
		else
			XUndefineCursor(vidx11_display, win);
	}
}