Make Metacity compositing smoother

25 October 2008

If you’re like me, you’ll drink Coke and disrupt your sleeping cycle on a regular basis. You’ll also be frustrated that Metacity’s compositing is horribly jerky. Well, as I found out from chatting on IRC one day, Metacity’s compositor is hard-coded to run at 50fps.

Normally, your monitor’s refresh rate will be something around 75hz, so 50fps, which is less than your monitor’s refresh rate, is hardly optimal. Fortunately, you can fix it with this simple patch:

diff -ur metacity-2.22.0.orig/src/core/compositor.c metacity-2.22.0/src/core/compositor.c
--- metacity-2.22.0.orig/src/core/compositor.c	2008-03-10 08:49:15.000000000 +1100
+++ metacity-2.22.0/src/core/compositor.c	2008-10-25 11:30:13.000000000 +1100
@@ -1290,16 +1290,18 @@
   if (compositor->repaint_id > 0)
     return;

-#if 0
-  compositor->repaint_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE,
-                                            compositor_idle_cb, compositor,
-                                            NULL);
-#else
   /* Limit it to 50fps */
+  /*
   compositor->repaint_id = g_timeout_add_full (G_PRIORITY_HIGH, 20,
                                                compositor_idle_cb, compositor,
                                                NULL);
-#endif
+  */
+
+  /* Nah, let's do 75fps */
+  compositor->repaint_id = g_timeout_add_full (G_PRIORITY_HIGH, 13,
+                                               compositor_idle_cb, compositor,
+                                               NULL);
+
 }
 #endif

The timeout is changed from updating every 20 milliseconds (1000msec ÷ 50fps = 20msec), to every 13 milliseconds (1000msec ÷ 75fps ≈ 13msec), which makes it much smoother.

8 replies

Leave a reply