From nobody Mon Nov 25 09:40:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716792278681918.4069271125702; Sun, 26 May 2024 23:44:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBU4w-0005KN-Ae; Mon, 27 May 2024 02:43:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBU3d-0003c8-8h; Mon, 27 May 2024 02:42:12 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBU3b-0007Qa-M7; Mon, 27 May 2024 02:42:08 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 5A9C16A3FD; Mon, 27 May 2024 09:41:31 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id A740AD83F5; Mon, 27 May 2024 09:40:57 +0300 (MSK) Received: (nullmailer pid 50304 invoked by uid 1000); Mon, 27 May 2024 06:40:56 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, hikalium , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Tokarev Subject: [Stable-7.2.12 15/19] ui/gtk: Fix mouse/motion event scaling issue with GTK display backend Date: Mon, 27 May 2024 09:40:46 +0300 Message-Id: <20240527064056.50205-15-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1716792282312100008 From: hikalium Remove gtk_widget_get_scale_factor() usage from the calculation of the motion events in the GTK backend to make it work correctly on environments that have `gtk_widget_get_scale_factor() !=3D 1`. This scale factor usage had been introduced in the commit f14aab420c and at that time the window size was used for calculating the things and it was working correctly. However, in the commit 2f31663ed4 the logic switched to use the widget size instead of window size and because of the change the usage of scale factor becomes invalid (since widgets use `vc->gfx.scale_{x, y}` for scaling). Tested on Crostini on ChromeOS (15823.51.0) with an external display. Fixes: 2f31663ed4 ("ui/gtk: use widget size for cursor motion event") Fixes: f14aab420c ("ui: fix incorrect pointer position on highdpi with gtk") (f14aab420c is 95c9059e66 in stable-7.2) Signed-off-by: hikalium Acked-by: Marc-Andr=C3=A9 Lureau Message-Id: <20240512111435.30121-3-hikalium@hikalium.com> (cherry picked from commit 37e91415018db3656b46cdea8f9e4d47b3ff130d) Signed-off-by: Michael Tokarev diff --git a/ui/gtk.c b/ui/gtk.c index 283c41a1a1..8d740fae83 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -871,7 +871,7 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkE= ventMotion *motion, int x, y; int mx, my; int fbh, fbw; - int ww, wh, ws; + int ww, wh; =20 if (!vc->gfx.ds) { return TRUE; @@ -879,11 +879,15 @@ static gboolean gd_motion_event(GtkWidget *widget, Gd= kEventMotion *motion, =20 fbw =3D surface_width(vc->gfx.ds) * vc->gfx.scale_x; fbh =3D surface_height(vc->gfx.ds) * vc->gfx.scale_y; - ww =3D gtk_widget_get_allocated_width(widget); wh =3D gtk_widget_get_allocated_height(widget); - ws =3D gtk_widget_get_scale_factor(widget); =20 + /* + * `widget` may not have the same size with the frame buffer. + * In such cases, some paddings are needed around the `vc`. + * To achieve that, `vc` will be displayed at (mx, my) + * so that it is displayed at the center of the widget. + */ mx =3D my =3D 0; if (ww > fbw) { mx =3D (ww - fbw) / 2; @@ -892,8 +896,12 @@ static gboolean gd_motion_event(GtkWidget *widget, Gdk= EventMotion *motion, my =3D (wh - fbh) / 2; } =20 - x =3D (motion->x - mx) / vc->gfx.scale_x * ws; - y =3D (motion->y - my) / vc->gfx.scale_y * ws; + /* + * `motion` is reported in `widget` coordinates + * so translating it to the coordinates in `vc`. + */ + x =3D (motion->x - mx) / vc->gfx.scale_x; + y =3D (motion->y - my) / vc->gfx.scale_y; =20 if (qemu_input_is_absolute()) { if (x < 0 || y < 0 || --=20 2.39.2