Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxFrame constructor position is not handled correctly for one of my MacOS screens #22614

Closed
whalley opened this issue Jul 8, 2022 · 7 comments
Assignees
Labels
macOS Specific to Cocoa macOS port

Comments

@whalley
Copy link

whalley commented Jul 8, 2022

Describe the bug
Cannot open window correctly on MacOS setup with multiple monitors.

Expected vs observed behaviour
I have an application that restores the application to the previously saved x,y and w,h settings. It saves position on exit and restores on startup.

It restores correctly on two screens but when a restore is attempted on another screen it does not restore at the correct point.

If I force a re-positon after the wxFrame is created it will go to the correct location.

See: moneymanagerex/moneymanagerex#4791 (this also documents an odd behaviour with toolbar margins that you can ignore)

To Reproduce
I have three screens, one on laptop and two external with locations and dimensions below reported by

this->GetPosition(&value_x, &value_y);
this->GetSize(&value_w, &value_h);

screen 0: x:0, y:25, w:1680, h:969
screen 1: x:-918, y:-1415, w:3440, h:1415
screen 2: x:-3478, y:-1415, w:2560, h:1415

If I edit the samples/aui demo and change to below:

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return false;

    wxFrame* frame = new MyFrame(NULL,
                                 wxID_ANY,
                                 "wxAUI Sample Application",
                                 wxPoint(-3090, -940),
                                 wxWindow::FromDIP(wxSize(800, 600), NULL));
    wxLogDebug("frame position: %d, %d", frame->GetPosition().x, frame->GetPosition().y);
    frame->SetPosition(wxPoint(-3090, -940));
    wxLogDebug("frame position: %d, %d", frame->GetPosition().x, frame->GetPosition().y);
    frame->Show();

    return true;
}

The output is:

01:04:41: Debug: frame position: 270, -108
01:04:41: Debug: frame position: -3090, -940

As can be seen the initial wxFrame is not positioned correctly.

Platform and version information

  • wxWidgets version you use: v3.2.0-rc1
  • wxWidgets port you use: wxOSX
  • MacOS: 12.4
@whalley whalley changed the title wxFrame constructor position is not handled correct for one of my MacOS screens wxFrame constructor position is not handled correctly for one of my MacOS screens Jul 8, 2022
@vadz vadz added the macOS Specific to Cocoa macOS port label Aug 5, 2022
@vadz
Copy link
Contributor

vadz commented Aug 5, 2022

Sorry, I have no idea what to do about this, I don't even have a multi-monitor Mac system to check this with. Could you please check what happens inside wxNonOwnedWindowCocoaImpl::Create(), i.e. what do we pass to initWithContentRect:styleMask:backing:defer: there?

@csomor It seems a bit weird to me that the code for setting the initial frame position (in the function above) is different from the code used to set it later in wxNonOwnedWindowCocoaImpl::MoveWindow(), perhaps we should also use setFrame:display: here in Create()?

@csomor
Copy link
Contributor

csomor commented Aug 5, 2022

for creating we are using a preferred initializer, if the problem really is isolated in this method, then indeed we should call a setFrame immediately afterwards, but I'm looking at the behavior with negative offsets on a single screen with the minimal sample, perhaps this already shows some trace ...

@csomor
Copy link
Contributor

csomor commented Aug 5, 2022

ok for reproducing it, you can also use the minimal sample (adding a pos parameter for wxFrame creation) and let it run on a single screen machine, same result, I'll investigate

@csomor csomor self-assigned this Aug 5, 2022
@csomor csomor closed this as completed in 5c5d5f5 Aug 5, 2022
@csomor
Copy link
Contributor

csomor commented Aug 5, 2022

@whalley could you please test whether this really fixes things for you as well ... thanks

@vadz
Copy link
Contributor

vadz commented Aug 5, 2022

I was wondering if we should be using initWithContentRect:styleMask:backing:defer:screen: instead of just initWithContentRect:styleMask:backing:defer: for the windows not on the main screen, but if it doesn't work even for a single screen case, this really looks like the only thing to do.

I'm reopening this as I think it should be backported to 3.2 too, shouldn't it?

@vadz vadz reopened this Aug 5, 2022
@vadz vadz added the backport-3.2 Fix applied to master but still has to be backported to stable 3.2 label Aug 5, 2022
@csomor
Copy link
Contributor

csomor commented Aug 5, 2022

Yes, I don't think we should switch, as it doesn't even work in my case, and yes, we shoud backport, sorry for closing it from the commit message.

@whalley
Copy link
Author

whalley commented Aug 5, 2022

@whalley could you please test whether this really fixes things for you as well ... thanks

Just tested, and yes this fixes my issue. Thanks

vadz pushed a commit to vadz/wxWidgets that referenced this issue Aug 18, 2022
for non-main screen coordinates, initWithContentRect is not working as
expected, introducing workaround

See wxWidgets#22614.

(cherry picked from commit 5c5d5f5)
@vadz vadz closed this as completed Aug 19, 2022
@vadz vadz removed the backport-3.2 Fix applied to master but still has to be backported to stable 3.2 label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macOS Specific to Cocoa macOS port
Projects
None yet
Development

No branches or pull requests

3 participants