rem: if (ev.xmotion.y_root - ofs_y < 0) { y = 0; } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE > scr->scr_height) { y = scr->scr_height - ICON_SIZE; } else { y = ev.xmotion.y_root - ofs_y; }
add: x = ev.xmotion.x_root - ofs_x; y = ev.xmotion.y_root - ofs_y; wScreenKeepInside(scr, &x, &y, ICON_SIZE, ICON_SIZE);
context: handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event){    WScreen *scr = dock->screen_ptr;    int ofs_x=event->xbutton.x, ofs_y=event->xbutton.y;    int x, y;    XEvent ev;    int grabbed = 0, swapped = 0, done;    Pixmap ghost = None;    int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */#ifdef DEBUG    puts("moving dock");#endif    if (XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask		     |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,		     GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {	wwarning("pointer grab failed for dock move");    }    y = 0;    for (x=0; x<dock->max_icons; x++) {        if (dock->icon_array[x]!=NULL &&            dock->icon_array[x]->yindex > y)            y = dock->icon_array[x]->yindex;    }    y++;    XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE*y);    done = 0;    while (!done) {	WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask		    |ButtonMotionMask|ExposureMask, &ev);	switch (ev.type) {	 case Expose:	    WMHandleEvent(&ev);	    break;	 case MotionNotify:	    if (!grabbed) {		if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD		    || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {		    XChangeActivePointerGrab(dpy, ButtonMotionMask					    |ButtonReleaseMask|ButtonPressMask,					     wCursor[WCUR_MOVE], CurrentTime);		    grabbed=1;		}		break;	    }            if (dock->type == WM_CLIP) {                if (ev.xmotion.x_root - ofs_x < 0) {                    x = 0;                } else if (ev.xmotion.x_root - ofs_x + ICON_SIZE >                           scr->scr_width) {                    x = scr->scr_width - ICON_SIZE;                } else {                    x = ev.xmotion.x_root - ofs_x;                }                if (ev.xmotion.y_root - ofs_y < 0) {                    y = 0;                } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >                           scr->scr_height) {                    y = scr->scr_height - ICON_SIZE;                } else {                    y = ev.xmotion.y_root - ofs_y;                }                moveDock(dock, x, y);            } else {            /* move vertically if pointer is inside the dock*/	    if ((dock->on_right_side &&		 ev.xmotion.x_root >= dock->x_pos - ICON_SIZE)		|| (!dock->on_right_side &&		    ev.xmotion.x_root <= dock->x_pos + ICON_SIZE*2)) {		if (ev.xmotion.y_root - ofs_y < 0) {		    y = 0;		} else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >			   scr->scr_height) {		    y = scr->scr_height - ICON_SIZE;		} else {		    y = ev.xmotion.y_root - ofs_y;		}                moveDock(dock, dock->x_pos, y);	    }	    /* move horizontally to change sides */	    x = ev.xmotion.x_root - ofs_x;	    if (!dock->on_right_side) {		/* is on left */		if (ev.xmotion.x_root > dock->x_pos + ICON_SIZE*2) {		    XMoveWindow(dpy, scr->dock_shadow, scr->scr_width-ICON_SIZE				      -DOCK_EXTRA_SPACE-1, dock->y_pos);                    if (superfluous && ghost==None) {                        ghost = MakeGhostDock(dock, dock->x_pos,                                              scr->scr_width-ICON_SIZE                                              -DOCK_EXTRA_SPACE-1,                                              dock->y_pos);                        XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,                                                   ghost);                        XClearWindow(dpy, scr->dock_shadow);                    }		    XMapRaised(dpy, scr->dock_shadow);		    swapped = 1;		} else {                    if (superfluous && ghost!=None) {			XFreePixmap(dpy, ghost);			ghost = None;		    }		    XUnmapWindow(dpy, scr->dock_shadow);		    swapped = 0;		}	    } else {		/* is on right */		if (ev.xmotion.x_root < dock->x_pos - ICON_SIZE) {		    XMoveWindow(dpy, scr->dock_shadow,				DOCK_EXTRA_SPACE, dock->y_pos);                    if (superfluous && ghost==None) {                        ghost = MakeGhostDock(dock, dock->x_pos,                                              DOCK_EXTRA_SPACE, dock->y_pos);                        XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,                                                   ghost);                        XClearWindow(dpy, scr->dock_shadow);                    }		    XMapRaised(dpy, scr->dock_shadow);		    swapped = -1;		} else {		    XUnmapWindow(dpy, scr->dock_shadow);		    swapped = 0;		    if (superfluous && ghost!=None) {			XFreePixmap(dpy, ghost);			ghost = None;		    }		}            }            }	    break;	 case ButtonPress:	    break;	 case ButtonRelease:	    if (ev.xbutton.button != event->xbutton.button)		break;	    XUngrabPointer(dpy, CurrentTime);	    XUnmapWindow(dpy, scr->dock_shadow);	    XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE);            if (dock->type == WM_DOCK) {                if (swapped!=0) {                    if (swapped>0)                        dock->on_right_side = 1;                    else                        dock->on_right_side = 0;                    swapDock(dock);                    wArrangeIcons(scr, False);                }            }	    done = 1;	    break;	}    }    if (superfluous) {	if (ghost!=None)	    XFreePixmap(dpy, ghost);	XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);    }#ifdef DEBUG    puts("End dock move");#endif}