+ } else if (ev->xany.type == ButtonPress &&
+ ev->xbutton.button == Button1) {
+ cberg->button_down_p = True;
+ cberg->mouse_x = ev->xbutton.x;
+ cberg->mouse_y = ev->xbutton.y;
+ cberg->motion_state = MOTION_MANUAL;
+ cberg->paused.tv_sec = 0;
+ } else if (ev->xany.type == ButtonRelease &&
+ ev->xbutton.button == Button1) {
+ cberg->button_down_p = False;
+ cberg->motion_state = MOTION_AUTO;
+ /* After mouse-up, don't go back into auto-motion mode for a second, so
+ that repeated click-and-drag gestures don't fight with auto-motion. */
+ gettimeofday(&cberg->paused, NULL);
+ } else if (ev->xany.type == MotionNotify &&
+ cberg->button_down_p) {
+ int dx = ev->xmotion.x - cberg->mouse_x;
+ int dy = ev->xmotion.y - cberg->mouse_y;
+ cberg->mouse_x = ev->xmotion.x;
+ cberg->mouse_y = ev->xmotion.y;
+ cberg->motion_state = MOTION_MANUAL;
+
+ /* Take the larger dimension, since motion_state doesn't scale */
+ if (dx > 0 && dx > dy) dy = 0;
+ if (dx < 0 && dx < dy) dy = 0;
+ if (dy > 0 && dy > dx) dx = 0;
+ if (dy < 0 && dy < dx) dx = 0;
+
+ {
+ int rot = current_device_rotation();
+ int swap;
+ while (rot <= -180) rot += 360;
+ while (rot > 180) rot -= 360;
+ if (rot > 135 || rot < -135) /* 180 */
+ dx = -dx, dy = -dy;
+ else if (rot > 45) /* 90 */
+ swap = dx, dx = -dy, dy = swap;
+ else if (rot < -45) /* 270 */
+ swap = dx, dx = dy, dy = -swap;
+ }
+
+ if (dx > 0) cberg->motion_state |= MOTION_LEFT;
+ else if (dx < 0) cberg->motion_state |= MOTION_RIGHT;
+ else if (dy > 0) cberg->motion_state |= MOTION_FORW;
+ else if (dy < 0) cberg->motion_state |= MOTION_BACK;