Or rather, a patch to apply over the first patch.

I noticed that setting the backlight was slow and used too much cpu if
the cpu was already in use, this loses the fancy fading (which wasn't
too fancy as I only had to doing 2 steps) and caches a small bit of
information. Seems to help some.

-- 
see shy jo
--- ../../hotkeys.old/src/xbacklight.c	2007-07-28 15:59:39.000000000 -0400
+++ xbacklight.c	2007-07-28 22:05:05.000000000 -0400
@@ -63,29 +63,31 @@
 int
 xbacklight (Display *dpy, int change)
 {
+    int     initialized = 0;
     int	    screen;
     int	    major, minor;
     int	    value = 0;
-    int	    i;
-    int	    total_time = 20;	/* ms */
-    int	    steps = 2;
 
-    if (!XRRQueryVersion (dpy, &major, &minor))
-    {
-	uError("RandR extension missing");
-	return -1;
-    }
-    if (major < 1 || (major == 1 && minor < 2))
-    {
-	uError("RandR version %d.%d too old", major, minor);
-	return -1;
-    }
-    backlight = XInternAtom (dpy, "BACKLIGHT", True);
-    if (backlight == None)
-    {
-	uError("No outputs have backlight property");
-	return -1;
+    if (! initialized) {
+	    if (!XRRQueryVersion (dpy, &major, &minor))
+	    {
+		uError("RandR extension missing");
+		return -1;
+	    }
+	    if (major < 1 || (major == 1 && minor < 2))
+	    {
+		uError("RandR version %d.%d too old", major, minor);
+		return -1;
+	    }
+	    backlight = XInternAtom (dpy, "BACKLIGHT", True);
+	    if (backlight == None)
+	    {
+		uError("No outputs have backlight property");
+		return -1;
+	    }
+	    initialized = 1;
     }
+
     for (screen = 0; screen < ScreenCount (dpy); screen++)
     {
 	Window		    root = RootWindow (dpy, screen);
@@ -97,7 +99,7 @@
 	{
 	    RROutput	output = resources->outputs[o];
 	    XRRPropertyInfo *info;
-	    double    	cur, new, step;
+	    double    	cur, new;
 	    double	min, max;
 	    double	set;
 
@@ -117,26 +119,15 @@
 			
 			if (new > max) new = max;
 			if (new < min) new = min;
-			step = (new - cur) / steps;
-			for (i = 0; i < steps && step != 0; i++)
-			{
-				if (i == steps - 1)
-				    cur = new;
-				else
-				    cur += step;
-				backlight_set (dpy, output, (long) cur);
-				XFlush (dpy);
-				usleep (total_time * 1000 / steps);
-			}
+			backlight_set (dpy, output, (long) new);
 		    }
 		    XFree (info);
 		}
 	    }
 	}
-							   
+
 	XRRFreeScreenResources (resources);
     }
-    XSync (dpy, False);
 
     return 0;
 }

Attachment: signature.asc
Description: Digital signature

Reply via email to