rem: static int move;
add: static int move = 0; static Time lastButtonReleasedEvent = 0;
context: handleTextFieldActionEvents(XEvent *event, void *data){    TextField *tPtr = (TextField*)data;    static int move;        CHECK_CLASS(data, WC_TextField);    switch (event->type) {     case KeyPress:        if (tPtr->flags.enabled && tPtr->flags.focused) {            handleTextFieldKeyPress(tPtr, event);	    XGrabPointer(WMScreenDisplay(W_VIEW(tPtr)->screen),			 W_VIEW(tPtr)->window, False, 			 PointerMotionMask|ButtonPressMask|ButtonReleaseMask,			 GrabModeAsync, GrabModeAsync, None, 			 W_VIEW(tPtr)->screen->invisibleCursor,			 CurrentTime);	    tPtr->flags.pointerGrabbed = 1;	}        break;     case MotionNotify:		if (tPtr->flags.pointerGrabbed) {	    tPtr->flags.pointerGrabbed = 0;	    XUngrabPointer(WMScreenDisplay(W_VIEW(tPtr)->screen), CurrentTime);	}        if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) {	    if (tPtr->viewPosition < tPtr->textLen && event->xmotion.x >                tPtr->usableWidth) {		if (WMWidthOfString(tPtr->font,				    &(tPtr->text[tPtr->viewPosition]),				    tPtr->cursorPosition-tPtr->viewPosition)                    > tPtr->usableWidth) {		    tPtr->viewPosition++;		}	    } else if (tPtr->viewPosition > 0 && event->xmotion.x < 0) {		paintCursor(tPtr);		tPtr->viewPosition--;	    }	    if (!tPtr->selection.count) {		tPtr->selection.position = tPtr->cursorPosition;	    }	    	    tPtr->cursorPosition = 		pointToCursorPosition(tPtr, event->xmotion.x);	    	    tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;	    	    /*	     printf("notify %d %d\n",event->xmotion.x,tPtr->usableWidth);	     */	    	    paintCursor(tPtr);	    paintTextField(tPtr);	}        if (move) {            XSetSelectionOwner(tPtr->view->screen->display,                       XA_PRIMARY, tPtr->view->window,  event->xmotion.time);            {                WMNotification *notif = WMCreateNotification("_lostOwnership",                        NULL,tPtr);                WMPostNotification(notif);                WMReleaseNotification(notif);            }        }	break;     case ButtonPress:	if (tPtr->flags.pointerGrabbed) {	    tPtr->flags.pointerGrabbed = 0;	    XUngrabPointer(WMScreenDisplay(W_VIEW(tPtr)->screen), CurrentTime);	    break;	}        move = 1;        switch (tPtr->flags.alignment) {            int textWidth;         case WARight:            textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);            if (tPtr->flags.enabled && !tPtr->flags.focused) {                WMSetFocusToWidget(tPtr);            } else if (tPtr->flags.focused) {                tPtr->selection.count = 0;            }            if(textWidth < tPtr->usableWidth){                tPtr->cursorPosition = pointToCursorPosition(tPtr, 				     event->xbutton.x - tPtr->usableWidth                                     + textWidth);            }            else tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);            /*            tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                tPtr->cursorPosition += tPtr->usableWidth - textWidth;            }            tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                                     */            paintTextField(tPtr);            break;                 case WALeft:            if (tPtr->flags.enabled && !tPtr->flags.focused) {                WMSetFocusToWidget(tPtr);                tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                paintTextField(tPtr);            } else if (tPtr->flags.focused) {                tPtr->cursorPosition = pointToCursorPosition(tPtr,                                      event->xbutton.x);                tPtr->selection.count = 0;                paintTextField(tPtr);            }            if (event->xbutton.button == Button2 && tPtr->flags.enabled) {                char *text;                text = W_GetTextSelection(tPtr->view->screen, XA_PRIMARY);                                if (!text) {                text = W_GetTextSelection(tPtr->view->screen,                              tPtr->view->screen->clipboardAtom);                }                if (!text) {		    text = W_GetTextSelection(tPtr->view->screen, 					      XA_CUT_BUFFER0);                }                if (text) {		    WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);		    XFree(text);                    NOTIFY(tPtr, didChange, WMTextDidChangeNotification,                           (void*)WMInsertTextEvent);                }            }            break;        }	break;     case ButtonRelease:	if (tPtr->flags.pointerGrabbed) {	    tPtr->flags.pointerGrabbed = 0;	    XUngrabPointer(WMScreenDisplay(W_VIEW(tPtr)->screen), CurrentTime);	}        move = 0;        break;    }}