From patchwork Tue Jun 29 13:24:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Dennis_W=C3=B6lfing?= X-Patchwork-Id: 12349861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FA4DC11F66 for ; Tue, 29 Jun 2021 13:26:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3273D61D7B for ; Tue, 29 Jun 2021 13:26:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3273D61D7B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyDlS-0004kT-9q for qemu-devel@archiver.kernel.org; Tue, 29 Jun 2021 09:26:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyDjQ-0002x5-0L for qemu-devel@nongnu.org; Tue, 29 Jun 2021 09:24:52 -0400 Received: from mout.gmx.net ([212.227.15.15]:41953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyDjN-0002wV-Mt for qemu-devel@nongnu.org; Tue, 29 Jun 2021 09:24:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1624973085; bh=jf/fnRubEY8AHqepPvhUUFcsci2Zuw6SRetbWg3+2Js=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=WVRmZAsILSjEzPBEr85u5wQivKi2uxc1WdYtTQ7vwHrijb+B1PjgvXDdCjFuMbrBw dAlSxov5leMCAXMBB4mSf+/Iq6xk3ueaGGdExEHCzIuJXZ4vCMVLMJ9QifmAVN30zg u+kEEcJY+fiInBWbgzK5hpQ9oa1s7g+2tsUrIKfs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([88.130.62.147]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MRTN9-1ld5q408sX-00NV7w; Tue, 29 Jun 2021 15:24:45 +0200 From: =?utf-8?q?Dennis_W=C3=B6lfing?= To: qemu-devel@nongnu.org Subject: [PATCH] ui/gtk: Fix relative mouse with multiple monitors Date: Tue, 29 Jun 2021 15:24:10 +0200 Message-Id: <20210629132410.286813-1-denniswoelfing@gmx.de> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:XwzDDChQ/VFiFyKMJDX45gJkotxxG+LES467Zr/lIK9cZzwdZjy j7EAbdJBB1wvQBg12RGC0UNJ8jK0GC44Hdtr/frWXDHu6rwpfNsRlNr62ahMT6eNg4+Jkjr 6XCAssJGlgfqwvIfGZawb6/YGT1cE4IbTJDZIFLVXceBvMImBQhoj29nc5jdJMv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zdomDrjqNoEBfG4VaCDC5difVBff081zaX67n0ZSrEkOenocSt9t CIQeTrTBEYfjsjSvH4tjcBkkXz3u1oYQ1gs1xs5AG+xTi1/R/Zm9ZhORF5hIbuSavkoMX6vyR LbHABXjNf2JxtmInNrE7XW5WUWQZWnNE3qp1d5M5vx57iyS/WYUn9ENMQ== Received-SPF: pass client-ip=212.227.15.15; envelope-from=denniswoelfing@gmx.de; helo=mout.gmx.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Dennis_W=C3=B6lfing?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To handle relative mouse input the event handler needs to move the mouse away from the screen edges. Failing to do so results in the mouse getting stuck at invisible walls. However the current implementation for this is broken on hosts with multiple monitors. With multiple monitors the mouse can be located outside of the current monitor which is not handled by the current code. Also the monitor itself might be located at coordinates different from (0, 0). Signed-off-by: Dennis Wölfing --- ui/gtk.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) -- 2.32.0 diff --git a/ui/gtk.c b/ui/gtk.c index 98046f577b..5258532b19 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -865,33 +865,30 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, GdkWindow *win = gtk_widget_get_window(widget); GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); GdkRectangle geometry; - int screen_width, screen_height; int x = (int)motion->x_root; int y = (int)motion->y_root; gdk_monitor_get_geometry(monitor, &geometry); - screen_width = geometry.width; - screen_height = geometry.height; /* In relative mode check to see if client pointer hit - * one of the screen edges, and if so move it back by + * one of the monitor edges, and if so move it back by * 200 pixels. This is important because the pointer * in the server doesn't correspond 1-for-1, and so * may still be only half way across the screen. Without * this warp, the server pointer would thus appear to hit * an invisible wall */ - if (x == 0) { - x += 200; + if (x <= geometry.x) { + x = geometry.x + 200; } - if (y == 0) { - y += 200; + if (y <= geometry.y) { + y = geometry.y + 200; } - if (x == (screen_width - 1)) { - x -= 200; + if (x - geometry.x >= (geometry.width - 1)) { + x = geometry.x + (geometry.width - 1) - 200; } - if (y == (screen_height - 1)) { - y -= 200; + if (y - geometry.y >= (geometry.height - 1)) { + y = geometry.y + (geometry.height - 1) - 200; } if (x != (int)motion->x_root || y != (int)motion->y_root) {