PSA because every couple years I run into programmers who don't understand this:
WINDOW COORDINATES CAN BE NEGATIVE AND VALID ON WINDOWS
PSA because every couple years I run into programmers who don't understand this:
WINDOW COORDINATES CAN BE NEGATIVE AND VALID ON WINDOWS
set up a computer with two monitors, make the one on the right be the primary.
(0,0) is at the top-left of the primary monitor, the right one. So the coordinates of windows on the left monitor will be negative.
I keep running into software written by people who don't understand this.
SetCursor-type APIs that won't accept negative numbers
programs that save their position between runs, but don't accept negative numbers (so if you close and reopen it on the left monitor, it moves to the right monitor)
screen capture APIs that can't capture windows on the left screen because they're "invalid"
@Ronflaix Yeah, I believe that was how they got minimized on Windows 95, which could break in windows 98 because you could now have multiple monitors and make that coordinate visible
@foone Wasn't there some weird Win32 event/method that put them faaaar away in the top-left negative quadrant to hide the windows without hiding them or did I hallucinate that?
Pillow's ImageGrab is so subtly broken that it's frankly amazing.
Besides the weird DPI problems I'm having, it lets you write code that will work if you run it on a system without a left-of-primary monitor, and break if it does
Here's some code:
x,y,w,h=win32gui.GetClientRect(hwnd)
x,y=win32gui.ClientToScreen(hwnd, (x,y))
rect=(x,y,x+w,y+h)
im=ImageGrab.grab(rect,all_screens=True)
This gets the size of a window, figures out where on the screens it is, converts that to a PIL style rectangle, then tells PIL to screenshot it.
And this should work fine.
BUT if you have a monitor left of your active one, it turns out this will screenshot entirely the wrong place.
It's because Pillow doesn't screenshot just the area you select, it screenshots all the screens as one big image, and then crops that.
meaning it uses X-style "top-left monitor has (0,0) in the top-left" coordinates, even on windows WHICH DOESN'T USE THAT COORDINATE SYSTEM
Windows has only been Like This for 27 years, I'm amazed how often this causes bugs.
@Ronflaix not sure.
@foone Amazing. Did they ever fix it or are we that close from seeing windows just moving around because we've got big ass-screens now?
actually I may be wrong about Pillow doing this, I just got it to work and I'm not 100% way. I think I'm seeing the DPI fuck it up
076萌SNS is a social network, courtesy of 076. It runs on GNU social, version 2.0.2-beta0, available under the GNU Affero General Public License.
All 076萌SNS content and data are available under the Creative Commons Attribution 3.0 license.