From patchwork Mon Dec 16 10:48:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 301694 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 19E912C009F for ; Mon, 16 Dec 2013 23:06:59 +1100 (EST) Received: from localhost ([::1]:55309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsVsv-0006J4-Jr for incoming@patchwork.ozlabs.org; Mon, 16 Dec 2013 05:58:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsVk1-0001Ag-GE for qemu-devel@nongnu.org; Mon, 16 Dec 2013 05:49:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsVjt-0000rw-TC for qemu-devel@nongnu.org; Mon, 16 Dec 2013 05:49:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsVjt-0000rQ-L6 for qemu-devel@nongnu.org; Mon, 16 Dec 2013 05:49:29 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBGAnSau000470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Dec 2013 05:49:28 -0500 Received: from nilsson.home.kraxel.org (vpn1-5-237.ams2.redhat.com [10.36.5.237]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBGAnP7K025304; Mon, 16 Dec 2013 05:49:27 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id DD53D81909; Mon, 16 Dec 2013 11:49:23 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 16 Dec 2013 11:48:55 +0100 Message-Id: <1387190958-19470-20-git-send-email-kraxel@redhat.com> In-Reply-To: <1387190958-19470-1-git-send-email-kraxel@redhat.com> References: <1387190958-19470-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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 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); +}