From nobody Sat May 4 18:04:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528488193051256.33644189733866; Fri, 8 Jun 2018 13:03:13 -0700 (PDT) Received: from localhost ([::1]:37952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRNbH-0006jS-EG for importer@patchew.org; Fri, 08 Jun 2018 16:03:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRNaH-0006Rw-L4 for qemu-devel@nongnu.org; Fri, 08 Jun 2018 16:02:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRNaE-0004hj-Hs for qemu-devel@nongnu.org; Fri, 08 Jun 2018 16:02:05 -0400 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:33660) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRNaE-0004hZ-CV for qemu-devel@nongnu.org; Fri, 08 Jun 2018 16:02:02 -0400 Received: by mail-it0-x244.google.com with SMTP id k17-v6so5917471ita.0 for ; Fri, 08 Jun 2018 13:02:02 -0700 (PDT) Received: from localhost.localdomain ([69.14.184.20]) by smtp.gmail.com with ESMTPSA id z68-v6sm1053365ioz.79.2018.06.08.13.01.59 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 08 Jun 2018 13:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lwbGoUB4rlNVUbLBqkfjOoh9e/CzHlN+GQk12cR9BKo=; b=Y2PAaet060Er1RmNc664trYMZppe9B7iEnu230eTTRiAsfPnUQnFsLNXQhByx4Xadc vjTVr8C66R5CC7Mc232SczglOqinGoi0+e0729xK5GZ6nHLCGDro4vXJOSHqzWCXQYMm TX3HVn5EnR/qgHysm/M/oEhLwM/1zoewCZ5oaRX/OkaR/xXIic3dSbEtuW8mn6uBoXzu /wm3WyhSD/gVDmfyQ8vaPYQPE8P+KE3CsMLS0glM1GdTrabn9mRMdcp8rGDzaWIjOhj7 VfB0AEzlZRq4GEsdVjIHMDb/bMzsKtehJZmZUnmyGbrWRxUy7lCyj8en9okpksr5xXji cjgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lwbGoUB4rlNVUbLBqkfjOoh9e/CzHlN+GQk12cR9BKo=; b=nR906epIbkWXkfzQIIqq7WYV7wEC7tjRjMywy9dXd5KjDliV1TyN6rtefchohnvsz0 /3l4Ve1866CygiQ4ekY3gmSSnux5NiWNq6j18vqrzJNTFpiTblSE5I18iz4nc1RsBYcH pK7+ilAejQ3MtMMjZ7u0OAAvVF0vO8GyxmppjnlNgqHk84WCinL/UQlHKsgVTFKaoT3r 2jq0LqPeBjMumiqkxmAG8T9miR+CntuqBJFY1/O/7qDOO6Gl7WPLfh0yCiFXq6QryMtj u/KAagOZcicBHm6pKYl7E//HQs/blrG/TBnbcPGPSap21Y/UNRZbv74QV5SP8igRxFXq Rxdw== X-Gm-Message-State: APt69E1iCYeykQeI9dcQbJHmklz87aq/nIDR5YPan7JSYvG3Q+OnWBZB bGmosueU2tQ3/vHjuaN4xXZIDg== X-Google-Smtp-Source: ADUXVKI/eMNG0kgUtEFkfRyZxMzwHrAClQ1qyiOS+Dop7W/79I6tG0/3f9k19J+IF5SZOF8x/cSb2A== X-Received: by 2002:a24:5a11:: with SMTP id v17-v6mr3190530ita.40.1528488121283; Fri, 08 Jun 2018 13:02:01 -0700 (PDT) From: John Arbuckle To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 8 Jun 2018 16:01:50 -0400 Message-Id: <20180608200150.7032-1-programmingkidx@gmail.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::244 Subject: [Qemu-devel] [PATCH] ui/cocoa.m: fix absolute mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Fix the cocoa front-end to correctly be able to use absolute mode. Signed-off-by: John Arbuckle --- ui/cocoa.m | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 2991ed4f19..dda99ad638 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -350,9 +350,20 @@ - (BOOL) isOpaque return YES; } =20 -- (BOOL) screenContainsPoint:(NSPoint) p +/* Returns YES if the host mouse cursor is in the QEMU window, NO otherwis= e */ +- (BOOL) mouseInWindow { - return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.hei= ght); + NSPoint p =3D [NSEvent mouseLocation]; + BOOL return_value =3D NO; + float x, y, width, height; + x =3D [normalWindow frame].origin.x; + y =3D [normalWindow frame].origin.y; + width =3D [[normalWindow contentView] frame].size.width; + height =3D [[normalWindow contentView] frame].size.height; + if (p.x >=3D x && p.y >=3D y && p.x <=3D (x + width) && p.y <=3D (y + = height)) { + return_value =3D YES; + } + return return_value; } =20 - (void) hideCursor @@ -637,7 +648,6 @@ - (void) handleEvent:(NSEvent *)event int buttons =3D 0; int keycode =3D 0; bool mouse_event =3D false; - NSPoint p =3D [event locationInWindow]; =20 switch ([event type]) { case NSEventTypeFlagsChanged: @@ -738,17 +748,22 @@ - (void) handleEvent:(NSEvent *)event break; case NSEventTypeMouseMoved: if (isAbsoluteEnabled) { - if (![self screenContainsPoint:p] || ![[self window] isKey= Window]) { + if ([self mouseInWindow]) { + mouse_event =3D true; + } + + if (![self mouseInWindow] || ![[self window] isKeyWindow])= { if (isMouseGrabbed) { [self ungrabMouse]; } } else { - if (!isMouseGrabbed) { + if (!isMouseGrabbed && [self mouseInWindow]) { [self grabMouse]; } } + } else { + mouse_event =3D true; } - mouse_event =3D true; break; case NSEventTypeLeftMouseDown: if ([event modifierFlags] & NSEventModifierFlagCommand) { @@ -784,7 +799,7 @@ - (void) handleEvent:(NSEvent *)event break; case NSEventTypeLeftMouseUp: mouse_event =3D true; - if (!isMouseGrabbed && [self screenContainsPoint:p]) { + if (!isMouseGrabbed && [self mouseInWindow]) { if([[self window] isKeyWindow]) { [self grabMouse]; } @@ -844,7 +859,8 @@ - (void) handleEvent:(NSEvent *)event * The check on screenContainsPoint is to avoid sending ou= t of range values for * clicks in the titlebar. */ - if ([self screenContainsPoint:p]) { + if ([self mouseInWindow]) { + NSPoint p =3D [event locationInWindow]; qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, 0, s= creen.width); qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.he= ight - p.y, 0, screen.height); } --=20 2.14.3 (Apple Git-98)