+void BlackboxWindow::endMove(void) {
+ assert(flags.moving);
+ assert(blackbox->getChangingWindow() == this);
+
+ flags.moving = False;
+ blackbox->setChangingWindow(0);
+
+ if (! screen->doOpaqueMove()) {
+ /* when drawing the rubber band, we need to make sure we only draw inside
+ * the frame... frame.changing_* contain the new coords for the window,
+ * so we need to subtract 1 from changing_w/changing_h every where we
+ * draw the rubber band (for both moving and resizing)
+ */
+ XDrawRectangle(blackbox->getXDisplay(), screen->getRootWindow(),
+ screen->getOpGC(), frame.changing.x(), frame.changing.y(),
+ frame.changing.width() - 1, frame.changing.height() - 1);
+ XUngrabServer(blackbox->getXDisplay());
+
+ configure(frame.changing.x(), frame.changing.y(),
+ frame.changing.width(), frame.changing.height());
+ } else {
+ configure(frame.rect.x(), frame.rect.y(),
+ frame.rect.width(), frame.rect.height());
+ }
+ screen->hideGeometry();
+
+ XUngrabPointer(blackbox->getXDisplay(), CurrentTime);
+
+ // if there are any left over motions from the move, drop them now
+ XSync(blackbox->getXDisplay(), false); // make sure we don't miss any
+ XEvent e;
+ while (XCheckTypedWindowEvent(blackbox->getXDisplay(), frame.window,
+ MotionNotify, &e));
+}
+
+
+void BlackboxWindow::beginResize(int x_root, int y_root, Corner dir) {
+ assert(! (flags.resizing || flags.moving));
+
+ /*
+ Only one window can be moved/resized at a time. If another window is already
+ being moved or resized, then stop it before whating to work with this one.
+ */
+ BlackboxWindow *changing = blackbox->getChangingWindow();
+ if (changing && changing != this) {
+ if (changing->flags.moving)
+ changing->endMove();
+ else // if (changing->flags.resizing)
+ changing->endResize();
+ }
+
+ resize_dir = dir;
+
+ Cursor cursor;
+ Corner anchor;
+
+ switch (resize_dir) {
+ case BottomLeft:
+ anchor = TopRight;
+ cursor = blackbox->getLowerLeftAngleCursor();
+ break;
+
+ case BottomRight:
+ anchor = TopLeft;
+ cursor = blackbox->getLowerRightAngleCursor();
+ break;
+
+ case TopLeft:
+ anchor = BottomRight;
+ cursor = blackbox->getUpperLeftAngleCursor();
+ break;
+
+ case TopRight:
+ anchor = BottomLeft;
+ cursor = blackbox->getUpperRightAngleCursor();
+ break;
+
+ default:
+ assert(false); // unhandled Corner
+ return; // unreachable, for the compiler
+ }
+
+ XGrabServer(blackbox->getXDisplay());
+ XGrabPointer(blackbox->getXDisplay(), frame.window, False,
+ PointerMotionMask | ButtonReleaseMask,
+ GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
+
+ flags.resizing = True;
+ blackbox->setChangingWindow(this);
+
+ int gw, gh;
+ frame.changing = frame.rect;
+
+ constrain(anchor, &gw, &gh);
+
+ XDrawRectangle(blackbox->getXDisplay(), screen->getRootWindow(),
+ screen->getOpGC(), frame.changing.x(), frame.changing.y(),
+ frame.changing.width() - 1, frame.changing.height() - 1);
+
+ screen->showGeometry(gw, gh);
+
+ frame.grab_x = x_root;
+ frame.grab_y = y_root;
+}
+
+
+void BlackboxWindow::doResize(int x_root, int y_root) {
+ assert(flags.resizing);
+ assert(blackbox->getChangingWindow() == this);
+
+ XDrawRectangle(blackbox->getXDisplay(), screen->getRootWindow(),
+ screen->getOpGC(), frame.changing.x(), frame.changing.y(),
+ frame.changing.width() - 1, frame.changing.height() - 1);
+
+ int gw, gh;
+ Corner anchor;
+
+ switch (resize_dir) {
+ case BottomLeft:
+ anchor = TopRight;
+ frame.changing.setSize(frame.rect.width() - (x_root - frame.grab_x),
+ frame.rect.height() + (y_root - frame.grab_y));
+ break;
+ case BottomRight:
+ anchor = TopLeft;
+ frame.changing.setSize(frame.rect.width() + (x_root - frame.grab_x),
+ frame.rect.height() + (y_root - frame.grab_y));
+ break;
+ case TopLeft:
+ anchor = BottomRight;
+ frame.changing.setSize(frame.rect.width() - (x_root - frame.grab_x),
+ frame.rect.height() - (y_root - frame.grab_y));
+ break;
+ case TopRight:
+ anchor = BottomLeft;
+ frame.changing.setSize(frame.rect.width() + (x_root - frame.grab_x),
+ frame.rect.height() - (y_root - frame.grab_y));
+ break;