Al's Website

Just another WordPress site

Workaround for Flash on Linux Multihead Desktops

| 41 Comments

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.

41 Comments

  1. 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

    • /usr/bin/iceweasel is a shell script. You should edit it so that it loads the patch when it runs the real iceweasel binary.

      • Hello all

        Complete noob here, but I think i’m going to make a valid point. I have downloaded the files in the archive….

        No where do I stick em, where does the libfullscreenhack.so file come from?
        Do I need to use a process to install the files?

        The read me file is great for the purposes of sales, but it does not explain to a noob, exactly what to do. So as i’m having this issue with flash, could someone please tell me how I impliment this patch. Lets call it a “complete” idiots guide :D

        Thanks all in advance

  2. 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

  3. 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.

  4. 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

    • 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.

      • 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.

      • BTW, the reversed red/blue channels is a known bug in flash player which Adobe refuses to fix.

  5. It works perfect, this was driving me crazy, thanks! :)

  6. This is perfect. You deserve a damn medal.

  7. 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

  8. how might i force it to the SECOND monitor?

  9. OMFG. This is wonderful. I think I’m in love with you now.

  10. I have added a fix for xinerama queries, which caused some flash players to still use the wrong screen dimensions, despite youtube working flawlessly with the hack.

    with the xinerama query fix all flashplayers tested work for me now, from blip.tv to porn sites.

    Pastebinned it here:
    http://pastebin.com/76vecbSp

    Cheers!

  11. Pingback: Flash-Videos im Fullscreen auf Dual-Monitor-Systemen | Linux und Ich

  12. Has anyone gotten this working with chrome on amd64 arch?

    I use gentoo, preload the hack (which says it was preloaded) but it does not change anything, videos are still buggy…

    The tester works though.

    Any help?

  13. dude, you’re fucking awesome!

    i hated this bug, and i’m just was about to “waste” my time to track down this stuff myself…

    however googling out your “cheap” solution blows my mind :D

    LD_PRELOAD!!! dude, wow…i have no words…

    it’s as brilliant as simple :)

    you simply RULE!

  14. This does not presently seem to work with the Flash 11.3.31.213 bundled with chrome 22.0.1201.0 dev

    Works perfectly with 11.2.202.236 I have with chromium and 11.0.1.60 in firefox though.

  15. I’m getting `cannot find -lXrandr` when I try to make… any idea which package I should install to get it? I’ve installed an X11-proto-randr-dev package with no joy, and I have no idea how to find this package (no C experience).

  16. Thanks! Good job!

  17. I’ve loaded this for firefox using the simpleinstall and it doesn’t change anything..

    • simpleinstall isn’t part of my code.

    • My code is outdated, and Al pulled the important fixes I made into his code. Use his.
      he doesn’t support simpleinstall nor should he. However, simpleinstall should work but you have to launch firefox with:
      LD_PRELOAD=”/usr/lib/libfullscreenhack.so” firefox
      or (64bit)
      LD_PRELOAD=”/usr/lib64/libfullscreenhack.so” firefox

      I suggest you just use Al’s repo, not mine. :D

  18. It seems, at least for my computer, that the changes to the NVidia drivers regarding xrandr support (as in enabling it) starting from version 302.07 both made your nice and my hacky fix impotent. xinerama is not queried at all anymore, unless I override “Status XRRQueryVersion (Display *dpy, int *major_version_return, int *minor_version_return)” and have it return a failure status, then xinerama gets queried again and the flash players on blip, cinemassacre, etc are getting the right dimensions again. This grotesque fix works for me for the time being, but a proper one would obviously be better. Sadly, I lack experience and finesse, if it hadn’t been for the source you provided I wouldn’t even have known where to begin. Well, cheers!

  19. hi,

    Iv been searching for a fix for this exact problem but unfortunately i need the fix for windows !

    any suggestions anyone :)

  20. You are a god among men. After long nights of attempting to fix this issue, your workaround fixed it!

    Tip for chrome users, if you disabled pepperflash like me in chrome://settings, instead tell chrome to use libfshack-npapi.so

  21. I got it working for firefox, but it seg faults under chrome. I have fedora x86_64, but my chrome is 32 bit. I compiled with -m32 to build the so. Any ideas?

    [vanw@kyoto fullscreenhack]$ env LD_PRELOAD=$(pwd)/libfshack-ppapi.so /opt/google/chrome/google-chrome
    ERROR: ld.so: object ‘/tmp/fullscreenhack/libfshack-ppapi.so’ from LD_PRELOAD cannot be preloaded: ignored.
    ERROR: ld.so: object ‘/tmp/fullscreenhack/libfshack-ppapi.so’ from LD_PRELOAD cannot be preloaded: ignored.
    ERROR: ld.so: object ‘/tmp/fullscreenhack/libfshack-ppapi.so’ from LD_PRELOAD cannot be preloaded: ignored.
    ERROR: ld.so: object ‘/tmp/fullscreenhack/libfshack-ppapi.so’ from LD_PRELOAD cannot be preloaded: ignored.
    fullscreen hack loaded… running under flash = 1
    fullscreen hack loaded… running under flash = 1
    fullscreen hack loaded… running under flash = 1
    Segmentation fault (core dumped)

  22. UPDATE: I installed the 64-bit chrome and it works now. Thanks for the great hack.

  23. where are the install instuctions

  24. is this suppose to open a new instance of firefox

  25. 64-bit Firefox, 64-bit OS, Flash 11.2 r202. God damn flawless, man. This had been bugging me for ages.

  26. how very clever! it works perfectly on my x86_64 Arch system with two different-sized monitors

  27. Could some one write up how to do all this from start to finish?

    Thanks

  28. Wow, this actually worked! I must admit I wasn’t expecting it to after many hours trying various solutions!
    Confirm this works in latest Ubuntu 14.04 :)

  29. Running Eos luna. Hade to create the usr/lib64 directory manualy to install with “sudo make firefox”.
    Worked beautifully.

Leave a Reply

Required fields are marked *.