If you’ve ever tried to watch a Youtube video in fullscreen on a Linux multihead desktop (especially with twinview), you’ve probably seen this bug. Read on for the explanation and fix.
Above are a couple of examples. In the first case, the video is a small box in the middle of the screen. The player chrome stretches to the whole width of the display, but is vertically nearer the middle. In the second case, the video is the right size but shifted off the screen. This doesn’t happen with all Flash based video players and is dependent on the way that the applet interprets the information it gets from the Flash runtime.
If you look at the full multihead layout of my desktop it looks like this:
What happens is that Flash tells the applet the full size of the display. When the applet goes fullscreen it has to scale itself to fit the new fullscreen window. When playing video, the applet will want to maintain the aspect ratio of the video too. So it will try to fit the video to the display. So, what seems to be happening is that some applets scale the video up to the full size of the display, and then back down to the size of the fullscreen window, like this:
First, scale the video to the full display size, maintaining aspect by adding black bars at the sides:
Then, in the first example above, the result is scaled back down to fit on the primary monitor, adding black bars at the top and bottom:
In the second example the result is simply cropped to fit on the primary monitor:
If you have a different monitor layout to me you’ll probably see different but similar problems.
So how can we fix this? Flash plugin is giving the applets the size of the full area of the multihead displays. It must use some operating system specific code to find this information in the first place. If we can feed it different values when it asks for this information, we can work around the problem.
After much tracing of the Flash plugin, it turns out that it gets this data using an XGetGeometry call on the root window of the display. I used an LD_PRELOAD library to patch this call so that it returns the size of the primary monitor instead. This is enough to fix all the buggy Flash video player applets.
When using this hack I noticed that fullscreen videos played faster too. I suspect this could be because the buggy players are scaling the video up to the much larger than required size of the full display, and then back down to the monitor size, instead of directly scaling to the monitor size.
UPDATE: The source code for the workaround is available on GitHub.