From patchwork Wed Jan 22 16:20:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 313311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4AB812C0099 for ; Thu, 23 Jan 2014 03:33:33 +1100 (EST) Received: from localhost ([::1]:36169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W60k6-0007wL-Ty for incoming@patchwork.ozlabs.org; Wed, 22 Jan 2014 11:33:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W60YD-0006X9-5d for qemu-devel@nongnu.org; Wed, 22 Jan 2014 11:21:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W60Y0-0005r7-Jb for qemu-devel@nongnu.org; Wed, 22 Jan 2014 11:21:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44376) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W60Y0-0005qP-CR for qemu-devel@nongnu.org; Wed, 22 Jan 2014 11:21:00 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0MGKwqd023397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 22 Jan 2014 11:20:59 -0500 Received: from nilsson.home.kraxel.org (vpn1-5-23.ams2.redhat.com [10.36.5.23]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0MGKtTd018334; Wed, 22 Jan 2014 11:20:57 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 671E780F24; Wed, 22 Jan 2014 17:20:54 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 22 Jan 2014 17:20:24 +0100 Message-Id: <1390407647-8659-20-git-send-email-kraxel@redhat.com> In-Reply-To: <1390407647-8659-1-git-send-email-kraxel@redhat.com> References: <1390407647-8659-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann , Anthony Liguori Subject: [Qemu-devel] [PATCH v2 19/42] input: mouse: add helpers functions to core X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Likewise a bunch of helper functions to manage mouse button and movement events, again to make life easier for the ui code. Signed-off-by: Gerd Hoffmann --- include/ui/input.h | 14 +++++++++++ ui/input.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/include/ui/input.h b/include/ui/input.h index 189f131..c6f50c2 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -8,6 +8,8 @@ #define INPUT_EVENT_MASK_REL (1<qcode = q; qemu_input_event_send_key(src, key, down); } + +InputEvent *qemu_input_event_new_btn(InputButton btn, bool down) +{ + InputEvent *evt = g_new0(InputEvent, 1); + evt->btn = g_new0(InputBtnEvent, 1); + evt->kind = INPUT_EVENT_KIND_BTN; + evt->btn->button = btn; + evt->btn->down = down; + return evt; +} + +void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down) +{ + InputEvent *evt; + evt = qemu_input_event_new_btn(btn, down); + qemu_input_event_send(src, evt); + qapi_free_InputEvent(evt); +} + +void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, + uint32_t button_old, uint32_t button_new) +{ + InputButton btn; + uint32_t mask; + + for (btn = 0; btn < INPUT_BUTTON_MAX; btn++) { + mask = button_map[btn]; + if ((button_old & mask) == (button_new & mask)) { + continue; + } + qemu_input_queue_btn(src, btn, button_new & mask); + } +} + +int qemu_input_scale_axis(int value, int size_in, int size_out) +{ + if (size_in < 2) { + return size_out / 2; + } + return (int64_t)value * (size_out - 1) / (size_in - 1); +} + +InputEvent *qemu_input_event_new_move(InputEventKind kind, + InputAxis axis, int value) +{ + InputEvent *evt = g_new0(InputEvent, 1); + InputMoveEvent *move = g_new0(InputMoveEvent, 1); + + evt->kind = kind; + evt->data = move; + move->axis = axis; + move->value = value; + return evt; +} + +void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) +{ + InputEvent *evt; + evt = qemu_input_event_new_move(INPUT_EVENT_KIND_REL, axis, value); + qemu_input_event_send(src, evt); + qapi_free_InputEvent(evt); +} + +void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size) +{ + InputEvent *evt; + int scaled = qemu_input_scale_axis(value, size, INPUT_EVENT_ABS_SIZE); + evt = qemu_input_event_new_move(INPUT_EVENT_KIND_ABS, axis, scaled); + qemu_input_event_send(src, evt); + qapi_free_InputEvent(evt); +}