Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clipboard workaround for Google Chrome bugs
See #343 for details. Thank you to @EsterLoken for catching and reporting, and @wqweto for additional follow-up. tl;dr: this fixes Copy+Paste into Google Chrome. By manually marking CF_DIB as available at Cut/Copy-time, PD can reliably receive notifications for copy+paste when old-style CF_DIB format is requested. This is an ancient Windows bug going back to at least Windows 7 (possibly earlier? idk), but the bug was useful because you could "force" apps to choose between bitmaps/DDBs (which every app supports all the way back to Win 3.1) or DIBv5 (which any Win 98+ app should support, as it fixes DIB issues by e.g. making alpha-handling and color-management explicit). I have never before encountered an app that didn't support either DDBs or DIBv5, but at some point, Chrome developers apparently decided this was the way to go. I'm shocked that Google developers are this incompetent (/s obviously, Google's app behavior on Windows is perpetually incompetent) Longer explanation: from a code standpoint this change is trivial, but it has many potential implications for interop with other software, including breaking 32-bpp copy+paste ops in old software. Given Chrome's ubiquity, I think changing this is probably the least of several evils, but I'm extremely annoyed that Chrome is incapable of using modern clipboard formats, and that its clipboard interop breaks with regularity. (I've lost track of how many times I've tweaked PD's clipboard code to make Chrome happy. At least this time it involves broken pasting into Chrome instead of broken copying out of Chrome... so points for at least breaking in a novel way? uuuuuugh) Even longer explanation: Windows DIB format, like nearly everything in GDI, is inconsistent in its handling of alpha bytes. As an easy example, PrintScreen keypresses often place a 32-bpp DIB on the clipboard with random alpha bytes. Because you don't ever know if a clipboard DIB has useful or broken alpha, you must assume broken alpha and treat the data as 24-bpp only. (Heuristics can be used to try and "guess" alpha state, but like any heuristics, edge-cases are complicated and impossible to handle perfectly.) Old-school DDBs (CF_BITMAP) don't have this issue because alpha is explicitly *not* supported, and "modern" DIBv5 fixes the issue with not just explicit alpha support, but extra support for nice things like color-management. There is no reason to forcibly use CF_DIB except for software which predates Windows 98. (Or if you're a Google dev, apparently.) By reenabling old-style DIB support to make Chrome work, I must manually composite 32-bpp images against a backcolor when using DIB format. This is required to making pasting into e.g. MS Paint still viable. (MS Paint preferentially grabs DIB data over DDB data, so when placing 32-bpp DIB data on the clipboard you *must* composite first or you'll get a broken image when pasting into MS Paint. Paint will ignore a DDB copy completely if a DIB is present, alas.) This change also breaks some software that would preferentially choose DIBv5 over DIB when available (e.g. Chasys Draw, which can no longer paste 32-bpp data from PD. This is technically a problem on their end but users will only know "it worked before and now it doesn't", alas). I'm especially frustrated with Chrome because this change doesn't even allow you to paste 32-bpp data into Chrome - that still isn't possible, because they won't take DIBv5 or PNG-format data if available, no matter what you do. All it does is break interop with a bunch of legacy software, just so you can paste into Chrome *at all*. Anyway, I don't maintain an exhaustive list of clipboard format support in other apps, but I'm hoping that PNG as an interop format is more ubiquitious in 2020, which may negate some of the worst issues of this change. (For example, the last time I changed PD's clipboard mechanism, this fix didn't work because pasting into Paint.NET was downgraded to 24-bpp data only. Two years later, however, I can revert this because Paint.NET added PNG clipboard support in 2019, and it will preferentially use PNG data over the DIB data PD is now forced to place on the clipboard.) Anyway, I've been interrupted by my toddler roughly 1000x while trying to explain this issue, so I've probably repeated myself many times over. Sorry! I'm just frustrated with Google for what feels like the billionth time, and being forced to enable a Win-95-era clipboard format just to appease Chrome makes me very unhappy.
- Loading branch information