hopefully better input grabbing state tracking

This commit is contained in:
Bill Currie 2003-03-07 22:30:15 +00:00
parent c731afa957
commit a8c989969d
3 changed files with 48 additions and 61 deletions

View file

@ -59,7 +59,6 @@ void X11_CloseDisplay (void);
void X11_CreateNullCursor (void);
void X11_CreateWindow (int, int);
void X11_ForceViewPort (void);
void X11_Grabber(qboolean);
void X11_Init_Cvars (void);
void X11_OpenDisplay (void);
void X11_ProcessEvent (void);

View file

@ -507,61 +507,6 @@ X11_RestoreVidMode (void)
#endif
}
static void
X11_GrabKeyboard (qboolean yes)
{
static qboolean is_grabbed = false;
if (yes) {
if (!is_grabbed) {
if (XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabSuccess) {
is_grabbed = true;
XSetInputFocus (x_disp, x_win, RevertToPointerRoot,
CurrentTime);
}
}
} else {
XUngrabKeyboard (x_disp, CurrentTime);
is_grabbed = false;
}
}
static void
X11_GrabMouse (qboolean yes)
{
static qboolean is_grabbed = false;
if (yes) {
if (!is_grabbed) {
if (XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None,
CurrentTime) == GrabSuccess) {
is_grabbed = true;
}
}
return;
}
XUngrabPointer (x_disp, CurrentTime);
is_grabbed = false;
XWarpPointer (x_disp, x_win, x_win, 0, 0, 0, 0, vid.width / 2,
vid.height / 2);
}
void
X11_Grabber (qboolean grab)
{
if (!vid_context_created) {
Con_Printf ("No video context to grab to!\n");
return;
}
X11_GrabMouse (grab);
X11_GrabKeyboard (grab);
XSync (x_disp, false);
}
void
X11_SetCaption (const char *text)
{

View file

@ -553,6 +553,31 @@ event_motion (XEvent *event)
}
}
static void
grab_error (int code, const char *device)
{
const char *reason;
switch (code) {
case AlreadyGrabbed:
reason = "already grabbed";
break;
case GrabNotViewable:
reason = "grab not viewable";
break;
case GrabFrozen:
reason = "grab frozen";
break;
case GrabInvalidTime:
reason = "grab invalid time";
break;
default:
reason = "unknown reason";
break;
}
Con_Printf ("failed to grab %s: %s", device, reason);
}
void
IN_LL_Grab_Input (int grab)
{
@ -567,12 +592,30 @@ IN_LL_Grab_Input (int grab)
if ((input_grabbed && grab) || (!input_grabbed && !grab))
return;
input_grabbed = grab;
X11_Grabber (grab);
if (in_dga->int_val) {
if (grab)
if (grab) {
int ret;
ret = XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
if (ret != GrabSuccess) {
grab_error (ret, "mouse");
return;
}
ret = XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
CurrentTime);
if (ret != GrabSuccess) {
XUngrabPointer (x_disp, CurrentTime);
grab_error (ret, "keyboard");
return;
}
input_grabbed = 1;
if (in_dga)
dga_on ();
else
} else {
XUngrabPointer (x_disp, CurrentTime);
XUngrabKeyboard (x_disp, CurrentTime);
input_grabbed = 0;
if (in_dga)
dga_off ();
}
}