Skip to content

Commit 85b7a11

Browse files
committed
draw only a rectangle when moving/resizing
this keeps resources low, ie when using the wm through an shh X-forworded session on low bandwidth, it is costly to redraw the whole window contents on resize/move. drawing just a rectangle to represent the new position/size of the window, addresses this issue.
1 parent eb3820f commit 85b7a11

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

monsterwm.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,17 +764,39 @@ void mousemotion(const Arg *arg) {
764764

765765
if (!d->curr->isfloat && !d->curr->istrans) { d->curr->isfloat = True; tile(d); focus(d->curr, d); }
766766

767+
/* init rectangle properties */
768+
XGCValues gv = { .function = GXinvert, .subwindow_mode = IncludeInferiors, .line_width = BORDER_WIDTH };
769+
GC gc = XCreateGC(dis, root, GCFunction|GCSubwindowMode|GCLineWidth, &gv);
770+
771+
/* draw rectangle */
772+
if (arg->i == MOVE) XDrawRectangle(dis, root, gc, xw = wa.x, yh = wa.y, wa.width, wa.height);
773+
else XDrawRectangle(dis, root, gc, wa.x, wa.y, xw = wa.width, yh = wa.height);
774+
767775
do {
768776
XMaskEvent(dis, BUTTONMASK|PointerMotionMask|SubstructureRedirectMask, &ev);
769777
if (ev.type == MotionNotify) {
778+
/* clear rectangle from prev position */
779+
if (arg->i == MOVE) XDrawRectangle(dis, root, gc, xw, yh, wa.width, wa.height);
780+
else if (arg->i == RESIZE) XDrawRectangle(dis, root, gc, wa.x, wa.y, xw, yh);
781+
770782
xw = (arg->i == MOVE ? wa.x:wa.width) + ev.xmotion.x - rx;
771783
yh = (arg->i == MOVE ? wa.y:wa.height) + ev.xmotion.y - ry;
772-
if (arg->i == RESIZE) XResizeWindow(dis, d->curr->win,
773-
xw > MINWSZ ? xw:wa.width, yh > MINWSZ ? yh:wa.height);
774-
else if (arg->i == MOVE) XMoveWindow(dis, d->curr->win, xw, yh);
784+
785+
/* draw rectangle in new position */
786+
if (arg->i == MOVE) XDrawRectangle(dis, root, gc, xw, yh, wa.width, wa.height);
787+
else if (arg->i == RESIZE) XDrawRectangle(dis, root, gc, wa.x, wa.y, xw, yh);
775788
} else if (ev.type == ConfigureRequest || ev.type == MapRequest) events[ev.type](&ev);
776789
} while (ev.type != ButtonRelease);
777790

791+
/* clear rectangle from last position */
792+
if (arg->i == MOVE) XDrawRectangle(dis, root, gc, xw, yh, wa.width, wa.height);
793+
else if (arg->i == RESIZE) XDrawRectangle(dis, root, gc, wa.x, wa.y, xw, yh);
794+
795+
/* actually move/resize the window to the new position/size */
796+
if (arg->i == RESIZE) XResizeWindow(dis, d->curr->win,
797+
xw > MINWSZ ? xw:wa.width, yh > MINWSZ ? yh:wa.height);
798+
else if (arg->i == MOVE) XMoveWindow(dis, d->curr->win, xw, yh);
799+
778800
XUngrabPointer(dis, CurrentTime);
779801
}
780802

0 commit comments

Comments
 (0)