Hi,

Attached is a patch which fixes an issue I have with laggy screen
updates when resizing or moving floating windows.

What the patch does is:
Limit the amount of updates when resizing or moving a floating window
to 60 times per second. This makes resizing and moving alot smoother
and by limiting it it also uses alot less resources.

Patch also available at:
http://www.codemadness.nl/downloads/patches/dwm/0001-limit-updates-per-second-for-win-move-resize.patch

Applies cleanly against latest git master
(18248ebf4b9465b837e717dcd14a5202a98248e0).

Kind regards,
Hiltjo Posthuma
From 7448503641e069417dc69ebcbd0920bb5328a0fa Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <hil...@codemadness.org>
Date: Sat, 2 Aug 2014 15:53:47 +0000
Subject: [PATCH] limit updates per second for win move/resize

Limit the amount of updates when resizing or moving a window in floating
mode to 60 times per second. This makes resizing and moving alot smoother
and by limiting it it also uses alot less resources on my machine.
---
 dwm.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/dwm.c b/dwm.c
index ffc8864..f896170 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1123,6 +1123,7 @@ movemouse(const Arg *arg) {
 	Client *c;
 	Monitor *m;
 	XEvent ev;
+	Time lasttime = 0;
 
 	if(!(c = selmon->sel))
 		return;
@@ -1145,6 +1146,10 @@ movemouse(const Arg *arg) {
 			handler[ev.type](&ev);
 			break;
 		case MotionNotify:
+			if ((ev.xmotion.time - lasttime) <= (1000 / 60))
+				continue;
+			lasttime = ev.xmotion.time;
+
 			nx = ocx + (ev.xmotion.x - x);
 			ny = ocy + (ev.xmotion.y - y);
 			if(nx >= selmon->wx && nx <= selmon->wx + selmon->ww
@@ -1264,11 +1269,11 @@ resizeclient(Client *c, int x, int y, int w, int h) {
 
 void
 resizemouse(const Arg *arg) {
-	int ocx, ocy;
-	int nw, nh;
+	int ocx, ocy, nw, nh;
 	Client *c;
 	Monitor *m;
 	XEvent ev;
+	Time lasttime = 0;
 
 	if(!(c = selmon->sel))
 		return;
@@ -1290,6 +1295,10 @@ resizemouse(const Arg *arg) {
 			handler[ev.type](&ev);
 			break;
 		case MotionNotify:
+			if ((ev.xmotion.time - lasttime) <= (1000 / 60))
+				continue;
+			lasttime = ev.xmotion.time;
+
 			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
 			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
 			if(c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
-- 
2.0.4

Reply via email to