You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
“y” argument to moveWindow() being ignored? #16343
Operating System / Platform => macOS Catalina 10.15.2
Compiler => Xcode / clang / c++
Detailed description
(I must be doing something wrong. This seems too obvious to be a real bug.)
Running a version of OpenCV 4.1.2, recently installed (via homebrew) on macOS Catalina 10.15.2, I tried to show several images in individual windows. I wanted to offset the windows along a diagonal:
int window_counter = 0;
int window_position = 0;
for (int i = 0; i < 4; i++)
{
std::string window_name = "TexSyn" + std::to_string(window_counter++);
cv::namedWindow(window_name);
cv::moveWindow(window_name, window_position, window_position);
window_position += 30;
cv::imshow(window_name, opencv_image);
}
cv::waitKey(0);
The windows appear. They are offset in “x” but not in “y”:
y = [[window screen] frame].size.height - y; ? Maybe this explains why all the windows are anchored to the top (I think that's what I see in your screenshot).
What do you think? I don't do iOS so why that special handling exists for the y direction is beyond me.🤷
@alalek@cwreynolds I'm tempted to take that line out but there must be a story why that special handling exists. Seems like lot of debug string comments are also left out in that file, maybe someone forgot to remove debug lines and this special y-direction handling was for debug? 🤷
Thanks. Before I saw your note I was thinking the same thing. There is very little that goes on in that Cocoa-specific function besides flipping the y coordinate. I know next to nothing about the macOS native windowing system. When I web searched I saw that the origin is normally in the lower left, but that sometimes may be “flipped” due to coordinate transforms. Which comes down to: “increasing y is up, unless it is down.”
I was considering trying it without that line, but having installed OpenCV via homebrew I would first have to clone the repo and get set up to build. If someone can try that easier than me I would be just as happy.
Update: I am mistaken. In my repro screenshot above, things are not working correctly. As you can see, first window (1) is supposed to be at 100, 100. But it is clearly not at 100, 100. More like 0, 100.
It seems that y coordinates given to moveWindow may be off by like 100.
(Sorry if this is just spectator noise, but I am baffled by how this symptom got even weirder after @saskatchewancatch’s experiment. In his screen shot, the vertical position difference between window 1 and 2 is less than between window 2 and 3. I’d be tempted to guess that the windows are moved to the given position, but with the Y shifted up about 128 pixels, then clipped at the top of the screen.)
@vpisarev: One more observation, then I promise I will shut up. I ran @saskatchewancatch’s test case, then overlaid a green diagonal line. It passes very close the the lower-left corner of windows 2 and 3. Window 1 is displaced down to keep it on the screen.
It looks like the x, y arguments to moveWindow() are being applied to the lower left corner of the window.
The doc is ambiguous on this detail, but I assumed the x, y arguments to moveWindow() should refer to the upper-left corner of the window
@cwreynolds Interesting observation. Though it's interesting that the moveWindow implementation is calling setFrameTopLeftPoint which supposedly sets the window position using the top left part of the window as the anchor.
I think another part of the problem is that the moveWindow function is relying on the resolution of the whole screen to figure out where to set the top-left of the window. This is a problem because it does not account for the fact that the MacOs menu bar takes up some space at the top. Thus, if Cocoa functions to set the top-left of the window are called to set position to (0, 0), the window will get placed not at (0, 0), but just right under the menu bar.
The workaround to this would be to get the visibleFrame property of the screen instead of just the frame, as is done currently in moveWindow. visibleFrame will return the position/size of the screen area that is not occupied by the menu bar.
Dear @cwreynolds, @saskatchewancatch, thank you for the help! This discussion and the advice to use "visibleFrame" property worked out well. Also, I had to postpone the actual repositioning of newly created windows until the very first imshow.
Activity
alalek commentedon Jan 14, 2020
Which GUI backend is used? (check
getBuildInformation())There is corresponding code for these backends:
cwreynolds commentedon Jan 14, 2020
Thanks for looking at this. Down below it says GUI: Cocoa: YES:
saskatchewancatch commentedon Jan 15, 2020
I think there may be a clue here: window_cocoa.mm Line 290 in the Cocoa handling of
moveWindowy = [[window screen] frame].size.height - y;? Maybe this explains why all the windows are anchored to the top (I think that's what I see in your screenshot).What do you think? I don't do iOS so why that special handling exists for the y direction is beyond me.🤷
@alalek @cwreynolds I'm tempted to take that line out but there must be a story why that special handling exists. Seems like lot of debug string comments are also left out in that file, maybe someone forgot to remove debug lines and this special y-direction handling was for debug? 🤷
cwreynolds commentedon Jan 15, 2020
@saskatchewancatch @alalek
Thanks. Before I saw your note I was thinking the same thing. There is very little that goes on in that Cocoa-specific function besides flipping the y coordinate. I know next to nothing about the macOS native windowing system. When I web searched I saw that the origin is normally in the lower left, but that sometimes may be “flipped” due to coordinate transforms. Which comes down to: “increasing y is up, unless it is down.”
I was considering trying it without that line, but having installed OpenCV via
homebrewI would first have to clone the repo and get set up to build. If someone can try that easier than me I would be just as happy.saskatchewancatch commentedon Feb 3, 2020
@vpisarev I see you've taken this issue. I tried something last week, maybe this will help your debug efforts.
When I use OP's repro code, I am able to repro the issue. But when I try my own, the behaviour is as expected. This will produce 3 cascaded windows:
But OP's code will repro the issue as shown in his screenshot.
My MacBook Pro SSD is busted and I left the issue last week.
Perhaps this finding is helpful to you.
saskatchewancatch commentedon Feb 3, 2020
Update: I am mistaken. In my repro screenshot above, things are not working correctly. As you can see, first window (1) is supposed to be at 100, 100. But it is clearly not at 100, 100. More like 0, 100.
It seems that y coordinates given to moveWindow may be off by like 100.
cwreynolds commentedon Feb 3, 2020
(Sorry if this is just spectator noise, but I am baffled by how this symptom got even weirder after @saskatchewancatch’s experiment. In his screen shot, the vertical position difference between window 1 and 2 is less than between window 2 and 3. I’d be tempted to guess that the windows are moved to the given position, but with the Y shifted up about 128 pixels, then clipped at the top of the screen.)
cwreynolds commentedon Feb 5, 2020
@vpisarev: One more observation, then I promise I will shut up. I ran @saskatchewancatch’s test case, then overlaid a green diagonal line. It passes very close the the lower-left corner of windows 2 and 3. Window 1 is displaced down to keep it on the screen.
It looks like the x, y arguments to moveWindow() are being applied to the lower left corner of the window.
The doc is ambiguous on this detail, but I assumed the x, y arguments to moveWindow() should refer to the upper-left corner of the window
saskatchewancatch commentedon Feb 6, 2020
@cwreynolds Interesting observation. Though it's interesting that the
moveWindowimplementation is calling setFrameTopLeftPoint which supposedly sets the window position using the top left part of the window as the anchor.I think another part of the problem is that the
moveWindowfunction is relying on the resolution of the whole screen to figure out where to set the top-left of the window. This is a problem because it does not account for the fact that the MacOs menu bar takes up some space at the top. Thus, if Cocoa functions to set the top-left of the window are called to set position to (0, 0), the window will get placed not at (0, 0), but just right under the menu bar.The workaround to this would be to get the
visibleFrameproperty of the screen instead of just the frame, as is done currently inmoveWindow.visibleFramewill return the position/size of the screen area that is not occupied by the menu bar.fixed cv::moveWindow() on mac (issue opencv#16343). Thanks to @cwreyn…
vpisarev commentedon Feb 14, 2020
Dear @cwreynolds, @saskatchewancatch, thank you for the help! This discussion and the advice to use "visibleFrame" property worked out well. Also, I had to postpone the actual repositioning of newly created windows until the very first imshow.
cwreynolds commentedon Feb 15, 2020
Great! Thank you for the fix @vpisarev
Merge pull request opencv#16588 from vpisarev:fix_macos_move_window
Merge pull request opencv#16588 from vpisarev:fix_macos_move_window