Add GTK-specific implementation of wxDisplay::GetFromWindow()

The generic implementation indirectly uses ClientToScreen(), which won't work
with Wayland, and causes debug warnings when used before window is realized.
This commit is contained in:
Paul Cornett 2019-07-25 10:35:12 -07:00
parent 79724b1710
commit b717d0c8d5

View File

@ -9,6 +9,9 @@
#include "wx/wxprec.h"
#include "wx/private/display.h"
#if wxUSE_DISPLAY
#include "wx/window.h"
#endif
#include "wx/gtk/private/wrapgtk.h"
#ifdef GDK_WINDOWING_X11
@ -67,6 +70,7 @@ public:
virtual wxDisplayImpl* CreateDisplay(unsigned n) wxOVERRIDE;
virtual unsigned GetCount() wxOVERRIDE;
virtual int GetFromPoint(const wxPoint& pt) wxOVERRIDE;
virtual int GetFromWindow(const wxWindow* win) wxOVERRIDE;
};
wxDisplayImpl* wxDisplayFactoryGTK::CreateDisplay(unsigned n)
@ -95,6 +99,26 @@ int wxDisplayFactoryGTK::GetFromPoint(const wxPoint& pt)
}
return wxNOT_FOUND;
}
int wxDisplayFactoryGTK::GetFromWindow(const wxWindow* win)
{
if (win && win->m_widget)
{
GdkDisplay* display = gtk_widget_get_display(win->m_widget);
GdkMonitor* monitor;
if (GdkWindow* window = gtk_widget_get_window(win->m_widget))
monitor = gdk_display_get_monitor_at_window(display, window);
else
monitor = gdk_display_get_primary_monitor(display);
for (unsigned i = gdk_display_get_n_monitors(display); i--;)
{
if (gdk_display_get_monitor(display, i) == monitor)
return i;
}
}
return wxNOT_FOUND;
}
#endif // wxUSE_DISPLAY
wxDisplayImplGTK::wxDisplayImplGTK(unsigned i)
@ -251,6 +275,7 @@ public:
virtual wxDisplayImpl* CreateDisplay(unsigned n) wxOVERRIDE;
virtual unsigned GetCount() wxOVERRIDE;
virtual int GetFromPoint(const wxPoint& pt) wxOVERRIDE;
virtual int GetFromWindow(const wxWindow* win) wxOVERRIDE;
};
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
@ -275,6 +300,20 @@ int wxDisplayFactoryGTK::GetFromPoint(const wxPoint& pt)
monitor = wxNOT_FOUND;
return monitor;
}
int wxDisplayFactoryGTK::GetFromWindow(const wxWindow* win)
{
int monitor = wxNOT_FOUND;
if (win && win->m_widget)
{
GdkScreen* screen = gtk_widget_get_screen(win->m_widget);
if (GdkWindow* window = gtk_widget_get_window(win->m_widget))
monitor = gdk_screen_get_monitor_at_window(screen, window);
else
monitor = gdk_screen_get_primary_monitor(screen);
}
return monitor;
}
#endif // wxUSE_DISPLAY
wxDisplayImplGTK::wxDisplayImplGTK(unsigned i)