Skip to content

Commit

Permalink
gtk4: Incorporate scale factor into pointer events
Browse files Browse the repository at this point in the history
`GtkGestureClick` and `GtkEventControllerMotion` provide `x` and `y`
in widget allocation coordinates.

We must multiply them by the widget's scale factor when creating
point events for WebKit.

(cherry picked from commit db13ac3)
  • Loading branch information
obyknovenius authored and aperezdc committed Feb 26, 2024
1 parent 3a40944 commit 0ec604c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions platform/gtk4/cog-platform-gtk4.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,14 @@ on_click_pressed(GtkGestureClick* gesture, int n_press, double x,
double y, gpointer user_data)
{
struct platform_window* win = user_data;
int scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(win->gl_drawing_area));

gtk_widget_grab_focus(win->gl_drawing_area);

struct wpe_input_pointer_event wpe_event = {
.type = wpe_input_pointer_event_type_button,
.x = (int)x,
.y = (int)y,
.x = (int) (x * scale_factor),
.y = (int) (y * scale_factor),
.modifiers = wpe_input_pointer_modifier_button1,
.button = 1,
.state = 1,
Expand All @@ -291,10 +293,12 @@ on_click_released(GtkGestureClick* gesture, int n_press, double x,
double y, gpointer user_data)
{
struct platform_window* win = user_data;
int scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(win->gl_drawing_area));

struct wpe_input_pointer_event wpe_event = {
.type = wpe_input_pointer_event_type_button,
.x = (int)x,
.y = (int)y,
.x = (int) (x * scale_factor),
.y = (int) (y * scale_factor),
.modifiers = wpe_input_pointer_modifier_button1,
.button = 1,
.state = 0,
Expand All @@ -309,10 +313,12 @@ on_motion(GtkEventControllerMotion* controller, double x, double y,
gpointer user_data)
{
struct platform_window* win = user_data;
int scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(win->gl_drawing_area));

struct wpe_input_pointer_event wpe_event = {
.type = wpe_input_pointer_event_type_motion,
.x = (int)x,
.y = (int)y,
.x = (int) (x * scale_factor),
.y = (int) (y * scale_factor),
};
wpe_view_backend_dispatch_pointer_event(
wpe_view_backend_exportable_fdo_get_view_backend(win->exportable),
Expand Down

0 comments on commit 0ec604c

Please sign in to comment.