Skip to content

Commit ad7eb3a

Browse files
committed
Position popup menu shown from keyboard correctly in wxGTK
Don't always show it at (-1, -1) and avoid GTK errors like Gdk-CRITICAL **: gdk_window_get_device_position_double: assertion 'gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD' failed See wxWidgets#24522. (cherry picked from commit 95d1413)
1 parent aaa58fb commit ad7eb3a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ wxGTK:
300300
- Make GTKSuppressDiagnostics(), broken since 3.2.1, work again (#24432).
301301
- Fix wxTE_PROCESS_ENTER in wxGTK comboboxes with autocomplete (#24394).
302302
- Fix -Wdeprecated-copy-dtor warnings in the headers with gcc 14 (#24502).
303+
- Position popup menu shown from keyboard correctly (#24522).
303304

304305
wxMSW:
305306

src/gtk/window.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6114,7 +6114,20 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
61146114
event = (GdkEvent*)&eventTmp;
61156115
}
61166116
if (x == -1 && y == -1)
6117-
gdk_window_get_device_position(window, device, &x, &y, NULL);
6117+
{
6118+
if (gdk_device_get_source(device) == GDK_SOURCE_KEYBOARD)
6119+
{
6120+
// We can't get the position from this device in this case, as
6121+
// gdk_window_get_device_position() would just fail with a
6122+
// "critical" error, so use the global mouse position instead:
6123+
// it should be what we want anyhow.
6124+
wxGetMousePosition(&x, &y);
6125+
}
6126+
else
6127+
{
6128+
gdk_window_get_device_position(window, device, &x, &y, NULL);
6129+
}
6130+
}
61186131

61196132
const GdkRectangle rect = { x, y, 1, 1 };
61206133
gtk_menu_popup_at_rect(GTK_MENU(menu->m_menu),

0 commit comments

Comments
 (0)