/****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_mouse.c,v 1.129 2011/09/17 21:52:30 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.134 2012/01/21 19:21:29 KO.Myung-Hun Exp $")
#include <tic.h>
#endif
#endif /* use_SYSMOUSE */
+#if USE_KLIBC_MOUSE
+#include <sys/socket.h>
+#define pipe(handles) socketpair(AF_LOCAL, SOCK_STREAM, 0, handles)
+#define DosWrite(hfile, pbuffer, cbwrite, pcbactual) \
+ write(hfile, pbuffer, cbwrite)
+#define DosExit(action, result ) /* do nothing */
+#define DosCreateThread(ptid, pfn, param, flag, cbStack) \
+ (*(ptid) = _beginthread(pfn, NULL, cbStack, \
+ (void *)param), (*(ptid) == -1))
+#endif
+
#define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
#define MASK_RELEASE(x) (mmask_t) NCURSES_MOUSE_MASK(x, 001)
#define INVALID_EVENT -1
#define NORMAL_EVENT 0
+#define ValidEvent(ep) ((ep)->id != INVALID_EVENT)
+#define Invalidate(ep) (ep)->id = INVALID_EVENT
+
#if USE_GPM_SUPPORT
#ifndef LIBGPM_SONAME
}
static void
+#if USE_KLIBC_MOUSE
+mouse_server(void *param)
+#else
mouse_server(unsigned long param)
+#endif
{
SCREEN *sp = (SCREEN *) param;
unsigned short fWait = MOU_WAIT;
sp->_mouse_eventp = FirstEV(sp);
for (i = 0; i < EV_MAX; i++)
- sp->_mouse_events[i].id = INVALID_EVENT;
+ Invalidate(sp->_mouse_events + i);
initialize_mousetype(sp);
}
static void
-mouse_activate(SCREEN *sp, bool on)
+mouse_activate(SCREEN *sp, int on)
{
if (!on && !sp->_mouse_initialized)
return;
*/
ep = eventp;
for (n = runcount; n < EV_MAX; n++) {
- ep->id = INVALID_EVENT;
+ Invalidate(ep);
ep = NEXT(ep);
}
#define MASK_CHANGED(x) (!(ep->bstate & MASK_PRESS(x)) \
== !(next->bstate & MASK_RELEASE(x)))
- if (ep->id != INVALID_EVENT && next->id != INVALID_EVENT
+ if (ValidEvent(ep) && ValidEvent(next)
&& ep->x == next->x && ep->y == next->y
&& (ep->bstate & BUTTON_PRESSED)
&& (!(next->bstate & BUTTON_PRESSED))) {
merge = TRUE;
}
}
- if (merge)
- ep->id = INVALID_EVENT;
+ if (merge) {
+ Invalidate(ep);
+ }
}
}
}
/* Compact valid events */
- if (ep->id == INVALID_EVENT) {
+ if (!ValidEvent(ep)) {
if ((first_valid != NULL) && (first_invalid == NULL)) {
first_invalid = ep;
}
first_valid = ep;
} else if (first_invalid != NULL) {
*first_invalid = *ep;
- ep->id = INVALID_EVENT;
+ Invalidate(ep);
first_invalid = NEXT(first_invalid);
}
}
if (next == eventp) {
/* Will end the loop, but check event type and compact before */
- endLoop = true;
+ endLoop = TRUE;
+ } else if (!ValidEvent(next)) {
+ continue;
} else {
/* merge click events forward */
if ((ep->bstate & BUTTON_CLICKED)
merge = TRUE;
}
}
- if (merge)
- ep->id = INVALID_EVENT;
+ if (merge) {
+ Invalidate(ep);
+ }
}
/* merge double-click events forward */
merge = TRUE;
}
}
- if (merge)
- ep->id = INVALID_EVENT;
+ if (merge) {
+ Invalidate(ep);
+ }
}
}
/* Discard event if it does not match event mask */
- if (!(ep->bstate & sp->_mouse_mask)) {
- ep->id = INVALID_EVENT;
+ if (!(ep->bstate & sp->_mouse_mask2)) {
+ Invalidate(ep);
}
/* Compact valid events */
- if (ep->id == INVALID_EVENT) {
+ if (!ValidEvent(ep)) {
if (ep == first_valid) {
first_valid = next;
} else if (first_invalid == NULL) {
}
} else if (first_invalid != NULL) {
*first_invalid = *ep;
- ep->id = INVALID_EVENT;
+ Invalidate(ep);
first_invalid = NEXT(first_invalid);
}
_nc_unlock_global(tracef);
}
for (ep = first_valid; ep != first_invalid; ep = NEXT(ep)) {
- if (ep->id != INVALID_EVENT)
+ if (ValidEvent(ep))
TR(MY_TRACE,
("_nc_mouse_parse: returning composite mouse event %s at slot %ld",
_nc_tracemouse(sp, ep),
#endif /* TRACE */
/* after all this, do we have a valid event? */
- return (PREV(first_invalid)->id != INVALID_EVENT);
+ return ValidEvent(PREV(first_invalid));
}
static void
* _nc_mouse_parse was not called, e.g., when _nc_mouse_inline returns
* false).
*/
- while ((prev->id != INVALID_EVENT) && (!(prev->bstate & SP_PARM->_mouse_mask))) {
- prev->id = INVALID_EVENT;
+ while (ValidEvent(prev) && (!(prev->bstate & SP_PARM->_mouse_mask2))) {
+ Invalidate(prev);
prev = PREV(prev);
}
- if (prev->id != INVALID_EVENT) {
+ if (ValidEvent(prev)) {
/* copy the event we find there */
*aevent = *prev;
_nc_tracemouse(SP_PARM, prev),
(long) IndexEV(SP_PARM, prev)));
- prev->id = INVALID_EVENT; /* so the queue slot becomes free */
+ Invalidate(prev); /* so the queue slot becomes free */
SP_PARM->_mouse_eventp = prev;
result = OK;
} else {
/* Reset the provided event */
aevent->bstate = 0;
- aevent->id = INVALID_EVENT;
+ Invalidate(aevent);
aevent->x = 0;
aevent->y = 0;
aevent->z = 0;
/* set the mouse event mask */
{
mmask_t result = 0;
+ int b;
T((T_CALLED("mousemask(%p,%#lx,%p)"),
(void *) SP_PARM,
mouse_activate(SP_PARM, (bool) (result != 0));
SP_PARM->_mouse_mask = result;
+ SP_PARM->_mouse_mask2 = result;
+
+ /*
+ * Make a mask corresponding to the states we will need to
+ * retain (temporarily) while building up the state that the
+ * user asked for.
+ */
+ for (b = 1; b <= MAX_BUTTONS; ++b) {
+ if (SP_PARM->_mouse_mask2 & MASK_TRIPLE_CLICK(b))
+ SP_PARM->_mouse_mask2 |= MASK_DOUBLE_CLICK(b);
+ if (SP_PARM->_mouse_mask2 & MASK_DOUBLE_CLICK(b))
+ SP_PARM->_mouse_mask2 |= MASK_CLICK(b);
+ if (SP_PARM->_mouse_mask2 & MASK_CLICK(b))
+ SP_PARM->_mouse_mask2 |= (MASK_PRESS(b) |
+ MASK_RELEASE(b));
+ }
}
}
}