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.
The source code for the workaround is available here.
March 14, 2012 at 8:33 am
Gday, I’m trying to use your patch but i’m getting an error when trying to run iceweasel…
sirjohndfox@stud:~/fullscreenhack-0.2$ LD_PRELOAD=/home/sirjohndfox/fullscreenhack-0.2/libfullscreenhack.so firefox
fullscreen hack loaded…
fullscreen hack loaded…
/usr/bin/iceweasel: line 116: exec: fullscreen: not found
Any ideas?
cheers
John
March 14, 2012 at 3:02 pm
/usr/bin/iceweasel is a shell script. You should edit it so that it loads the patch when it runs the real iceweasel binary.
March 22, 2012 at 3:56 pm
Hi
I use your patch and now I can see youtube with correct resolution. Thanks your help!!!!! i was looking for a solution since much time ago
However i have another bug yet. I see fullscreen videos in same monitor although Browser was in other. you could help me with this?.
Thanks anyway
March 22, 2012 at 6:46 pm
Flash always sticks to the first monitor where you open a browser window.
March 22, 2012 at 4:02 pm
I forgot to say I don’t have this problem in youtube. it’s in the rest of webs with flash.
I’m sorry for my english.
March 27, 2012 at 3:27 am
Did not work at all for me, tests run but after install and restart it doesn’t go full screen.
All I can think of is I don’t have any npviewer in my processes, it’s been replaced by plugin-container like a month ago or more. maybe your fix works for earlier versions of ff… you can email me if you think of something. Thanks.
I use ubuntu 11.10 x64, firefox 10 x32, flash 11.1 (x32 I guess)
PS: I had to do
sudo apt-get install libc6-dev-i386
to get some dependencies like bits/predefs.h
March 29, 2012 at 10:20 pm
EDIT : Actually, it worked twice, I don’t know on what circumstances, but more importantly, youtube is blue now, red has disappeared from any video… Only youtube and only on this computer where I ran your script. I want to reverse whatever your script does, how do I do that? Thank you.
I have tested reinstalling flash but it did nothing.
March 30, 2012 at 1:05 am
To uninstall it edit /usr/lib/nspluginwrapper/noarch/npviewer and delete the marked lines near the bottom. Then delete /usr/lib/nspluginwrapper/i386/linux/libfullscreenhack.so.
May 6, 2012 at 2:06 pm
BTW, the reversed red/blue channels is a known bug in flash player which Adobe refuses to fix.
May 6, 2012 at 1:48 pm
It works perfect, this was driving me crazy, thanks!
May 11, 2012 at 11:35 am
This is perfect. You deserve a damn medal.
May 14, 2012 at 1:55 pm
I updated your source code if you’re interested.
I was having this issue and I came across your hack.
I changed it to 64bit and included code that detects if you’re using Xinerama and if you are it gets the values of the screen width and height relative to your cursor position.
It’s much more automated this way.
It’s also very easy to switch it back to 32bit if necessary.
Thanks,
~Timothy Zorn