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::GetSize() returns a too large size in a wxAUI program with GTK3 and Wayland #23041
Comments
It's not specific to AUI, here's a simpler diff against the diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 501caf9096..1ac8d0c54b 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -139,7 +139,7 @@ bool MyApp::OnInit()
// frame constructor
MyFrame::MyFrame(const wxString& title)
- : wxFrame(NULL, wxID_ANY, title)
+ : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600, 400))
{
// set the frame icon
SetIcon(wxICON(sample));
@@ -188,6 +188,9 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
+const wxSize s(GetSize());
+fprintf(stderr, "%d %d\n", s.x, s.y);
+return;
wxMessageBox(wxString::Format
(
"Welcome to %s!\n" The size of decorations (which seems to include a large area for a composited shadow) is getting added to the requested window size. I think we try to compensate for that, but before the first TLW is showing, we don't know how big the decorations are. |
Could we always create the (first) TLW with some minimal size and then call If not, can we make some backwards-incompatible change in 3.3 that would finally allow us to solve (all cases of) this problem? E.g. would deprecating the size parameter of |
We do something like this for X11 with the "deferred show" mechanism. It's quite horrible. I don't know if there is an equivalent to
It's very common for code to set the frame size using |
I know that it's horrible, but it was a great improvement when you implemented (or improved, I don't remember any longer) it. So if it were possible to do something similar for Wayland, it would be worth doing it, IMO.
We also need to change |
I'd like to return to this because calling diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 501caf9096..9d6600fd7e 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -175,6 +175,18 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ SetSize(654, 432);
+
+ auto showSize = [this](const char* when)
+ {
+ const wxSize s = GetSize();
+ const wxSize cs = GetClientSize();
+ wxFprintf(stderr, "%s:\tclient = (%d,%d), total = (%d,%d)\n", when, cs.x, cs.y, s.x, s.y);
+ };
+
+ showSize("Ctor");
+ CallAfter([=]() { showSize("Later"); });
}
works as expected, i.e. outputs
while this: diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 501caf9096..cc60200e05 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -139,7 +139,7 @@ bool MyApp::OnInit()
// frame constructor
MyFrame::MyFrame(const wxString& title)
- : wxFrame(NULL, wxID_ANY, title)
+ : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(654, 432))
{
// set the frame icon
SetIcon(wxICON(sample));
@@ -175,6 +175,16 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ auto showSize = [this](const char* when)
+ {
+ const wxSize s = GetSize();
+ const wxSize cs = GetClientSize();
+ wxFprintf(stderr, "%s:\tclient = (%d,%d), total = (%d,%d)\n", when, cs.x, cs.y, s.x, s.y);
+ };
+
+ showSize("Ctor");
+ CallAfter([=]() { showSize("Later"); });
}
doesn't work correctly and outputs
So it looks like we should be able to make the size specified in the ctor work too. |
I can reproduce your results, but I find that in either case, the actual size of the window is the same (I measured it with a ruler). So the size is just being reported incorrectly when |
I also can confirm that the actual size of the window doesn't correspond to the reported size by using something called "lg" (looking glass) in the GNOME Shell (I don't know of any better/less inconvenient way to check the window size under Wayland, if anybody does, please let me know). Anyhow, it would be really nice to do something about it, it's rather embarrassing that something as simple as setting the window size fails in several different creative ways. |
In particular this fixes reported size in some situations where SetSize() has been called before decoration size is known. See #23041
…3041) solve size problems of gnudatalanguage#1470 removed long labes from test_widgets
…s known Fixes initial TLW size being larger than requested See #23041
@paulcor Should both commits above be backported to 3.2? Things seem to work for me now if I call Here is the patch I used for testing: diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 501caf9096..eea0970a15 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -137,9 +137,16 @@ bool MyApp::OnInit()
// main frame
// ----------------------------------------------------------------------------
+//#define SIZE_CTOR
+
// frame constructor
MyFrame::MyFrame(const wxString& title)
+#ifdef SIZE_CTOR
+ : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600, 400))
+#else
: wxFrame(NULL, wxID_ANY, title)
+#endif
+
{
// set the frame icon
SetIcon(wxICON(sample));
@@ -175,6 +182,24 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+#ifndef SIZE_CTOR
+ SetSize(600, 400);
+#endif
+
+ auto showSize = [this](const char* when)
+ {
+ const wxSize s = GetSize();
+ const wxSize cs = GetClientSize();
+ wxFprintf(stderr, "%s:\tclient = (%d,%d), total = (%d,%d)\n", when, cs.x, cs.y, s.x, s.y);
+ };
+
+ showSize("Ctor");
+ CallAfter([=]() { showSize("Later"); });
+
+ new wxStaticText(this, wxID_ANY, "");
+ (new wxButton(this, wxID_ANY, "Show size", wxPoint(100, 100)))->
+ Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { showSize("Now"); });
}
and here is the output:
i.e. the size is always correct and With
i.e. you can't get the right size value until later (I click the button manually once the window is shown, but I guess a timer would work too), but at least it is correct eventually. |
Depends on what you mean by "wrong". That is the actual client size at that moment. It will become smaller later to keep the overall size constant. The same thing happens with X11.
They are. Most of it is space for a composited drop shadow. All done client-side by GTK, Wayland is not involved.
Again, those are the actual sizes at that moment. And again, same thing happens with X11, except the timing is a little different in this case. |
OK, thanks for the explanation, I didn't realize the "drop shadow" thing. And thanks for cherry-picking this. Could you please update Thanks again! |
Description
In a
wxAUI
program,wxWindow::GetSize()
returns an incorrect (too large) size of the program window.It's a Wayland specific problem as it works correctly with X11.
To Reproduce
It can be reproduced in the aui sample using the following changes:
The size returned by
wxWindow::GetSize()
does not correspond to the actual window size.Platform and version information
The text was updated successfully, but these errors were encountered: