Use XGrapButton, not XGrabPointer
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4000 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
6fe938c5b2
commit
398d60ede7
@ -171,8 +171,7 @@ extern int up_x11eventloop(void);
|
||||
/* up_eventloop.c ***********************************************************/
|
||||
|
||||
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
|
||||
extern int up_tcenter(int x, int y, int buttons);
|
||||
extern int up_tcleave(int x, int y, int buttons);
|
||||
extern int up_buttonevent(int x, int y, int buttons);
|
||||
#endif
|
||||
|
||||
/* up_tapdev.c ************************************************************/
|
||||
|
@ -751,10 +751,10 @@ void sim_tcuninitialize(void)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_tcenter
|
||||
* Name: up_buttonevent
|
||||
****************************************************************************/
|
||||
|
||||
int up_tcenter(int x, int y, int buttons)
|
||||
int up_buttonevent(int x, int y, int buttons)
|
||||
{
|
||||
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
|
||||
bool pendown; /* true: pen is down */
|
||||
@ -815,40 +815,3 @@ int up_tcenter(int x, int y, int buttons)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_tcleave
|
||||
****************************************************************************/
|
||||
|
||||
int up_tcleave(int x, int y, int buttons)
|
||||
{
|
||||
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
|
||||
|
||||
ivdbg("x=%d y=%d buttons=%02x\n", x, y, buttons);
|
||||
ivdbg("contact=%d nwaiters=%d\n", priv->sample.contact, priv->nwaiters);
|
||||
|
||||
/* Treat leaving the window as penup */
|
||||
|
||||
/* Ignore the pen up if the pen was already up (CONTACT_NONE == pen up and
|
||||
* already reported. CONTACT_UP == pen up, but not reported)
|
||||
*/
|
||||
|
||||
if (priv->sample.contact != CONTACT_NONE)
|
||||
{
|
||||
priv->sample.contact = CONTACT_UP;
|
||||
|
||||
/* Is there a thread waiting for the touchpad event? If so, awaken it! */
|
||||
|
||||
if (priv->nwaiters > 0)
|
||||
{
|
||||
/* Indicate the availability of new sample data for this ID */
|
||||
|
||||
priv->sample.id = priv->id;
|
||||
priv->penchange = true;
|
||||
|
||||
/* Notify any waiters that new touchscreen data is available */
|
||||
|
||||
up_notify(priv);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
extern int up_tcenter(int x, int y, int buttons);
|
||||
extern int up_buttonevent(int x, int y, int buttons);
|
||||
extern int up_tcleave(int x, int y, int buttons);
|
||||
|
||||
/****************************************************************************
|
||||
@ -82,103 +82,57 @@ volatile int g_evloopactive;
|
||||
***************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11eventloop
|
||||
* Name: up_buttonmap
|
||||
***************************************************************************/
|
||||
|
||||
static int up_buttonmap(int state)
|
||||
{
|
||||
int ret = 0;
|
||||
/* Remove any X11 dependencies. Just maps Button1Mask to bit 0. */
|
||||
|
||||
/* Remove any X11 dependencies. Possible bit settings include: Button1Mask,
|
||||
* Button2Mask, Button3Mask, Button4Mask, Button5Mask, ShiftMask, LockMask,
|
||||
* ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask. I assume
|
||||
* that for a mouse device Button1Mask, Button2Mask, and Button3Mask are
|
||||
* sufficient.
|
||||
*/
|
||||
|
||||
if ((state & Button1Mask) != 0)
|
||||
{
|
||||
ret |= 1;
|
||||
}
|
||||
|
||||
if ((state & Button2Mask) != 0)
|
||||
{
|
||||
ret |= 2;
|
||||
}
|
||||
|
||||
if ((state & Button3Mask) != 0)
|
||||
{
|
||||
ret |= 4;
|
||||
}
|
||||
return ret;
|
||||
return ((state & Button1Mask) != 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11eventloop
|
||||
* Name: up_x11eventthread
|
||||
***************************************************************************/
|
||||
|
||||
static void *up_x11eventthread(void *arg)
|
||||
{
|
||||
Window window;
|
||||
XEvent event;
|
||||
int ret;
|
||||
|
||||
/* Grab the pointer (mouse), enabling mouse enter/leave events */
|
||||
/* Release queued events on the display */
|
||||
|
||||
ret = XGrabPointer(g_display, g_window, 0,
|
||||
EnterWindowMask|LeaveWindowMask,
|
||||
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
||||
if (ret != GrabSuccess)
|
||||
{
|
||||
fprintf(stderr, "Failed grap pointer\n");
|
||||
return NULL;
|
||||
}
|
||||
(void)XAllowEvents(g_display, AsyncBoth, CurrentTime);
|
||||
|
||||
/* Enable motion and button events.
|
||||
* EnterWindowMask|LeaveWindowMask - When mouse enters or leaves window
|
||||
* ButtonMotionMask - When mouse moves with any button pressed
|
||||
* ButtonPress|ButtonRelease - When button is pressed or released
|
||||
*/
|
||||
/* Grab mouse button 1, enabling mouse-related events */
|
||||
|
||||
XSelectInput(g_display, g_window,
|
||||
EnterWindowMask|LeaveWindowMask|ButtonMotionMask|
|
||||
ButtonPressMask|ButtonReleaseMask);
|
||||
window = DefaultRootWindow(g_display);
|
||||
(void)XGrabButton(g_display, Button1, AnyModifier, window, 1,
|
||||
ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
|
||||
GrabModeAsync, GrabModeAsync, None, None);
|
||||
|
||||
/* Then loop forever, waiting for events and processing events as they are
|
||||
* received. NOTE: It seems to be fatal if you attempt to fprintf from
|
||||
* within the following loop.
|
||||
/* Then loop until we are commanded to stop (when g_evloopactive becomes zero),
|
||||
* waiting for events and processing events as they are received.
|
||||
*/
|
||||
|
||||
while (g_evloopactive)
|
||||
while ( g_evloopactive)
|
||||
{
|
||||
XNextEvent(g_display, &event);
|
||||
switch (event.type)
|
||||
{
|
||||
case EnterNotify: /* Enabled by EnterWindowMask */
|
||||
{
|
||||
up_tcenter(event.xcrossing.x, event.xcrossing.y,
|
||||
up_buttonmap(event.xcrossing.state));
|
||||
}
|
||||
break;
|
||||
|
||||
case LeaveNotify : /* Enabled by LeaveWindowMask */
|
||||
{
|
||||
up_tcleave(event.xcrossing.x, event.xcrossing.y,
|
||||
up_buttonmap(event.xcrossing.state));
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionNotify : /* Enabled by ButtonMotionMask */
|
||||
{
|
||||
up_tcenter(event.xmotion.x, event.xmotion.y,
|
||||
up_buttonmap(event.xmotion.state));
|
||||
up_buttonevent(event.xmotion.x, event.xmotion.y,
|
||||
up_buttonmap(event.xmotion.state));
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress : /* Enabled by ButtonPressMask */
|
||||
case ButtonRelease : /* Enabled by ButtonReleaseMask */
|
||||
{
|
||||
up_tcenter(event.xbutton.x, event.xbutton.y,
|
||||
up_buttonmap(event.xbutton.state));
|
||||
up_buttonevent(event.xbutton.x, event.xbutton.y,
|
||||
up_buttonmap(event.xbutton.state));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -186,6 +140,8 @@ static void *up_x11eventthread(void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XUngrabButton(g_display, Button1, AnyModifier, window);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -70,13 +70,13 @@
|
||||
/* Also used in up_x11eventloop */
|
||||
|
||||
Display *g_display;
|
||||
Window g_window;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
static int g_screen;
|
||||
static Window g_window;
|
||||
static GC g_gc;
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
static XShmSegmentInfo g_xshminfo;
|
||||
@ -127,9 +127,12 @@ static inline int up_x11createframe(void)
|
||||
&hints, NULL, NULL);
|
||||
|
||||
XMapWindow(g_display, g_window);
|
||||
|
||||
/* Select window input events */
|
||||
|
||||
XSelectInput(g_display, g_window,
|
||||
ButtonPressMask | ButtonReleaseMask |
|
||||
ButtonMotionMask | KeyPressMask | ExposureMask);
|
||||
ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask);
|
||||
|
||||
gcval.graphics_exposures = 0;
|
||||
g_gc = XCreateGC(g_display, g_window, GCGraphicsExposures, &gcval);
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user