Re: `wxDialog` ignores the specified position with GTK3 (Issue #24552)

27 views
Skip to first unread message

paulcor

unread,
May 23, 2024, 12:04:37 PMMay 23
to wx-...@googlegroups.com, Subscribed

There is a logic problem in the TLW code, but I'm not sure how much it matters. For me the dialog is centered with GTK2 as well. And still centered with GTK3 even with these changes:

diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp
index 3ebd0cd052..f1c38e6b64 100644
--- a/src/gtk/toplevel.cpp
+++ b/src/gtk/toplevel.cpp
@@ -701,8 +701,6 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
             // on parent by default (this is what GtkDialog ctor does):
             gtk_window_set_type_hint(GTK_WINDOW(m_widget),
                                      GDK_WINDOW_TYPE_HINT_DIALOG);
-            gtk_window_set_position(GTK_WINDOW(m_widget),
-                                    GTK_WIN_POS_CENTER_ON_PARENT);
         }
         else
         {
@@ -792,9 +790,6 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     if (pos.IsFullySpecified())
     {
 #ifdef __WXGTK3__
-        GtkWindowPosition windowPos;
-        g_object_get(m_widget, "window-position", &windowPos, nullptr);
-        if (windowPos == GTK_WIN_POS_NONE)
             gtk_window_move(GTK_WINDOW(m_widget), m_x, m_y);
 #else
         gtk_widget_set_uposition( m_widget, m_x, m_y );

In general, the Window Manager is free to ignore any request to position a TLW. And of course with Wayland, it's guaranteed to be ignored.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24552/2127229468@github.com>

taler21

unread,
May 23, 2024, 12:04:38 PMMay 23
to wx-...@googlegroups.com, Subscribed

Description

If a wxDialog is created with a specified position, it will not be displayed at that position, but centered (on the parent window) instead.

This is a GTK3 specific issue as with GTK2 the dialog is correctly displayed at the specified position.

The cause of this issue seems to be that the dialog is first centered during creation (with both GTK2 and GTK3).

https://github.com/wxWidgets/wxWidgets/blob/3c41a6876cf8ed574122aacea81ee5014ccfa9a7/src/gtk/toplevel.cpp#L698-L706

And later it is moved to the specified position. What is always done with GTK2, but with GTK3 only under a condition that is not met due to the previous centering.

https://github.com/wxWidgets/wxWidgets/blob/3c41a6876cf8ed574122aacea81ee5014ccfa9a7/src/gtk/toplevel.cpp#L792-L802

To Reproduce:

The issue can be reproduced in the minimal sample, with the following changes.

diff --git "a/samples/minimal/minimal.cpp" "b/samples/minimal/minimal.cpp"
index 5f32257c6b..5f31b66df3 100644
--- "a/samples/minimal/minimal.cpp"
+++ "b/samples/minimal/minimal.cpp"
@@ -188,6 +188,10 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
+    wxDialog dlg( this, wxID_ANY, "Test", wxPoint(0, 0), wxSize(200, 150) );
+    dlg.ShowModal();
+    return;
+
     wxMessageBox(wxString::Format
                  (
                     "Welcome to %s!\n"
  1. Start the minimal sample.
  2. Press F1 key to show a dialog at the top left of the screen.
    With GTK2 it works as expected, but with GTK3 the dialog is not displayed at the top left of the screen, but centered on the application window.

Platform and version information

  • wxWidgets version you use: 3.2.5 and master (3c41a68)
  • wxWidgets port you use: wxGTK
  • OS and its version: Linux Mint 19
    • GTK version: 3.22.30
    • Which GDK backend is used: X11
    • Desktop environment : Cinnamon


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24552@github.com>

taler21

unread,
May 24, 2024, 1:46:15 AMMay 24
to wx-...@googlegroups.com, Subscribed

With these changes

diff --git "a/src/gtk/toplevel.cpp" "b/src/gtk/toplevel.cpp"
index 3ebd0cd052..22b0d126f6 100644
--- "a/src/gtk/toplevel.cpp"
+++ "b/src/gtk/toplevel.cpp"
@@ -792,9 +792,6 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     if (pos.IsFullySpecified())
     {
 #ifdef __WXGTK3__
-        GtkWindowPosition windowPos;
-        g_object_get(m_widget, "window-position", &windowPos, nullptr);
-        if (windowPos == GTK_WIN_POS_NONE)
             gtk_window_move(GTK_WINDOW(m_widget), m_x, m_y);
 #else
         gtk_widget_set_uposition( m_widget, m_x, m_y );

it works on:

  • Linux Mint 21 with Cinnamon desktop
  • Ubuntu 22.04 with GNOME desktop (using X11)
  • openSUSE Leap 15.5 with KDE desktop

Surely it doesn't work with Wayland. But that is another, more fundamental problem. And should not be a reason for not making it work with X11.

So please apply a fix and also backport it to 3.2. Thanks in advance!


P.S.: I don't know what system you are using, but it might not work for you because you may have "Attached Modal Dialogs" enabled. See: How to detach modal dialogs from main window


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24552/2128579550@github.com>

VZ

unread,
May 24, 2024, 1:45:09 PMMay 24
to wx-...@googlegroups.com, Subscribed

I think we could apply this, i.e. I don't think this would things worse. @paulcor Please let me know if you have any objections or prefer a different fix.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24552/2130069407@github.com>

VZ

unread,
May 25, 2024, 1:27:20 PMMay 25
to wx-...@googlegroups.com, Subscribed

Closed #24552 as completed.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/24552/issue_event/12933577032@github.com>

VZ

unread,
May 25, 2024, 1:27:20 PMMay 25
to wx-...@googlegroups.com, Subscribed

Closing as fix was applied to master and I've added it to 3.2 backports branch too. Thanks!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24552/2131368293@github.com>

Reply all
Reply to author
Forward
0 new messages