Support DPI scaling in wxUIActionSimulator when using GTK+ 3

Scale the coordinates passed to MouseMove() by the GTK scaling factor to
ensure that the mouse clicks are really delivered to the correct windows,
without this change wxUIActionSimulator was unusable on systems using high DPI
(i.e. GDK_SCALE of 2).

Per-monitor DPI scaling is still not supported however.
This commit is contained in:
Vadim Zeitlin 2016-05-23 02:36:28 +02:00
parent 38c8a10b79
commit 594d916dcb

View File

@ -27,6 +27,11 @@
#include "wx/unix/utilsx11.h"
#ifdef __WXGTK3__
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#endif
// Normally we fall back on "plain X" implementation if XTest is not available,
// but it's useless to do it when using GTK+ 3 as it's not going to work with
// it anyhow because GTK+ 3 needs XInput2 events and not the "classic" ones we
@ -239,6 +244,27 @@ bool wxUIActionSimulatorXTestImpl::DoX11Button(int xbutton, bool isDown)
bool wxUIActionSimulatorXTestImpl::DoX11MouseMove(long x, long y)
{
#ifdef __WXGTK3__
// We need to take into account the scaling factor as the input coordinates
// are in GTK logical "application pixels", while we need the physical
// "device pixels" for the X call below, so scale them if we have the
// required support at both compile- and run-time.
#if GTK_CHECK_VERSION(3,10,0)
if ( gtk_check_version(3, 10, 0) == NULL )
{
if ( GdkScreen* const screen = gdk_screen_get_default() )
{
// For multi-monitor support we would need to determine to which
// monitor the point (x, y) belongs, for now just use the scale
// factor of the main one.
gint const scale = gdk_screen_get_monitor_scale_factor(screen, 0);
x *= scale;
y *= scale;
}
}
#endif // GTK+ 3.10+
#endif // __WXGTK3__
return XTestFakeMotionEvent(m_display, -1, x, y, 0) != 0;
}