From: Gernot Ziegler (gz++at++lysator.liu.se)
Date: 10/07/2001 04:24:57
Hej guys !
I have now played wih XGrabPointers to implement Quake-style movement, but
have by now only had partial success;
This is what I would like to have:
The mouse pointer should become invisible, stay within the confined
window, and report its movement as usual ...
--------------------------
This is my current code:
// Draw process callback
static void DrawChannel (pfChannel *chan, void *)
{
static int do_once = 1;
#if 1 /* experiments 20010923 */
Display *dpy = pfGetCurWSConnection();
pfPipeWindow *win = chan->getPWin();
pfWSWindow xwin = win->getWSWindow();
XWindowAttributes watt;
XGetWindowAttributes (dpy, xwin, &watt);
//printf("Window width: %d and height: %d\n", watt.width,
watt.height);
if (do_once)
{
XGrabPointer(dpy, xwin, True,
/*KeyPressMask | KeyReleaseMask |*/ PointerMotionMask
| PointerMotionHintMask | ButtonPressMask | ButtonReleaseMask
|
ButtonMotionMask | Button1MotionMask,
GrabModeAsync, GrabModeAsync, xwin, None,
CurrentTime);
do_once = 0;
}
#if 0
int XGrabPointer(display, grab_window, owner_events,
event_mask, pointer_mode,
keyboard_mode, confine_to, cursor, time)
Display *display;
Window grab_window;
Bool owner_events;
unsigned int event_mask;
int pointer_mode, keyboard_mode;
Window confine_to;
Cursor cursor;
Time time;
#endif
//XWarpPointer(dpy, xwin, None, 1, 1, 400, 400, 1, 1);
// usleep(100000);
#endif
chan->clear();
pfDraw ();
}
the X server accepts this, warps the pointer to the channel window, and
confines it there ... but no mouse movement is returned anymore !
Mouse movement is normally received by the following routine:
void ProcessQuakeXformerMouse(QuakeXformer *xf, pfuMouse *mouse, pfChannel
*inputChan)
{
int focus=1;
pfiInputXform *ix;
ix = xf->getCurModel();
/* Only listen to mouse if cursor is in channel and GUI doesn't
* have focus
*/
/* XXXX mouse and input handling should be separated from model update
!!! */
if (!(mouse->inWin) || pfuInGUI(mouse->xpos, mouse->ypos) ||
!pfuMouseInChan(mouse, inputChan))
focus = 0;
xf->setFocus(focus);
if (!ix)
return;
ix->setFocus(focus);
ix->setMode(PFIX_MODE_AUTO, !focus);
// if an arrow button or a mouse button was pressed: calculate the new
position based on the mouse pos
if (focus)
{
pfiInputCoord *icoord;
pfVec2 pos;
printf("xpos: %d ypos: %d\n", mouse->xpos, mouse->ypos);
pfuCalcNormalizedChanXY(&pos[0], &pos[1], inputChan, mouse->xpos,
mouse->ypos);
icoord = xf->getInputCoordPtr();
icoord->setVec(pos.vec);
printf("pos[0]: %f pos[1]: %f\n", pos[0], pos[1]);
}
if (ix->isOfType(pfiInputXformTravel::getClassType()))
ProcessQuakeTravelMouse(xf, (pfiInputXformTravel*)ix, mouse);
else
{
pfNotify(PFNFY_NOTICE, PFNFY_PRINT, "QuakeXformer - Unrecognized
type %s - 0x%x",
ix->getTypeName(), ix->getClassType());
ix->update();
}
}
--------------------------
What am I doing wrong ?
Could it be that I am not allowed to call XgrabPointer in DrawChannel, but
instead have to do it from somewhere inside these pfu-routines to let them
receive the events ? Or do I have to code X pointer event handling all on
my own ?
General confusion here ;) Thanks for your tips in advance !
Servus,
Gernot
/-----------------------------W-E-L-C-O-M-E------------------------------\
T The Austria <=> Sweden connection..... T
| E-Mail: gz++at++lysator.liu.se H
O Homepage: http://www.lysator.liu.se/~gz E
\------------------------------F-U-T-U-R-E-------------------------------/
This archive was generated by hypermail 2b29 : Sun Oct 07 2001 - 04:41:00 PDT