mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
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:
@@ -171,8 +171,7 @@ extern int up_x11eventloop(void);
|
|||||||
/* up_eventloop.c ***********************************************************/
|
/* up_eventloop.c ***********************************************************/
|
||||||
|
|
||||||
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
|
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
|
||||||
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);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* up_tapdev.c ************************************************************/
|
/* 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;
|
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
|
||||||
bool pendown; /* true: pen is down */
|
bool pendown; /* true: pen is down */
|
||||||
@@ -815,40 +815,3 @@ int up_tcenter(int x, int y, int buttons)
|
|||||||
return OK;
|
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
|
* 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);
|
extern int up_tcleave(int x, int y, int buttons);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -82,94 +82,48 @@ volatile int g_evloopactive;
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_x11eventloop
|
* Name: up_buttonmap
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
static int up_buttonmap(int state)
|
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,
|
return ((state & Button1Mask) != 0) ? 1 : 0;
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_x11eventloop
|
* Name: up_x11eventthread
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
static void *up_x11eventthread(void *arg)
|
static void *up_x11eventthread(void *arg)
|
||||||
{
|
{
|
||||||
|
Window window;
|
||||||
XEvent event;
|
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,
|
(void)XAllowEvents(g_display, AsyncBoth, CurrentTime);
|
||||||
EnterWindowMask|LeaveWindowMask,
|
|
||||||
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
|
||||||
if (ret != GrabSuccess)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed grap pointer\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enable motion and button events.
|
/* Grab mouse button 1, enabling mouse-related events */
|
||||||
* EnterWindowMask|LeaveWindowMask - When mouse enters or leaves window
|
|
||||||
* ButtonMotionMask - When mouse moves with any button pressed
|
window = DefaultRootWindow(g_display);
|
||||||
* ButtonPress|ButtonRelease - When button is pressed or released
|
(void)XGrabButton(g_display, Button1, AnyModifier, window, 1,
|
||||||
|
ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
|
||||||
|
GrabModeAsync, GrabModeAsync, None, None);
|
||||||
|
|
||||||
|
/* Then loop until we are commanded to stop (when g_evloopactive becomes zero),
|
||||||
|
* waiting for events and processing events as they are received.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
XSelectInput(g_display, g_window,
|
while ( g_evloopactive)
|
||||||
EnterWindowMask|LeaveWindowMask|ButtonMotionMask|
|
|
||||||
ButtonPressMask|ButtonReleaseMask);
|
|
||||||
|
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
while (g_evloopactive)
|
|
||||||
{
|
{
|
||||||
XNextEvent(g_display, &event);
|
XNextEvent(g_display, &event);
|
||||||
switch (event.type)
|
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 */
|
case MotionNotify : /* Enabled by ButtonMotionMask */
|
||||||
{
|
{
|
||||||
up_tcenter(event.xmotion.x, event.xmotion.y,
|
up_buttonevent(event.xmotion.x, event.xmotion.y,
|
||||||
up_buttonmap(event.xmotion.state));
|
up_buttonmap(event.xmotion.state));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -177,7 +131,7 @@ static void *up_x11eventthread(void *arg)
|
|||||||
case ButtonPress : /* Enabled by ButtonPressMask */
|
case ButtonPress : /* Enabled by ButtonPressMask */
|
||||||
case ButtonRelease : /* Enabled by ButtonReleaseMask */
|
case ButtonRelease : /* Enabled by ButtonReleaseMask */
|
||||||
{
|
{
|
||||||
up_tcenter(event.xbutton.x, event.xbutton.y,
|
up_buttonevent(event.xbutton.x, event.xbutton.y,
|
||||||
up_buttonmap(event.xbutton.state));
|
up_buttonmap(event.xbutton.state));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -186,6 +140,8 @@ static void *up_x11eventthread(void *arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XUngrabButton(g_display, Button1, AnyModifier, window);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,13 +70,13 @@
|
|||||||
/* Also used in up_x11eventloop */
|
/* Also used in up_x11eventloop */
|
||||||
|
|
||||||
Display *g_display;
|
Display *g_display;
|
||||||
Window g_window;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Variables
|
* Private Variables
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int g_screen;
|
static int g_screen;
|
||||||
|
static Window g_window;
|
||||||
static GC g_gc;
|
static GC g_gc;
|
||||||
#ifndef CONFIG_SIM_X11NOSHM
|
#ifndef CONFIG_SIM_X11NOSHM
|
||||||
static XShmSegmentInfo g_xshminfo;
|
static XShmSegmentInfo g_xshminfo;
|
||||||
@@ -127,9 +127,12 @@ static inline int up_x11createframe(void)
|
|||||||
&hints, NULL, NULL);
|
&hints, NULL, NULL);
|
||||||
|
|
||||||
XMapWindow(g_display, g_window);
|
XMapWindow(g_display, g_window);
|
||||||
|
|
||||||
|
/* Select window input events */
|
||||||
|
|
||||||
XSelectInput(g_display, g_window,
|
XSelectInput(g_display, g_window,
|
||||||
ButtonPressMask | ButtonReleaseMask |
|
ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask);
|
||||||
ButtonMotionMask | KeyPressMask | ExposureMask);
|
|
||||||
gcval.graphics_exposures = 0;
|
gcval.graphics_exposures = 0;
|
||||||
g_gc = XCreateGC(g_display, g_window, GCGraphicsExposures, &gcval);
|
g_gc = XCreateGC(g_display, g_window, GCGraphicsExposures, &gcval);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user