From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: avg.tolik@gmail.com, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 15/17] wctablet: switch to new input interface
Date: Fri, 6 Jan 2017 09:55:43 +0100 [thread overview]
Message-ID: <1483692945-9866-16-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1483692945-9866-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
backends/wctablet.c | 65 +++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 53 insertions(+), 12 deletions(-)
diff --git a/backends/wctablet.c b/backends/wctablet.c
index 29b75b4..7263671 100644
--- a/backends/wctablet.c
+++ b/backends/wctablet.c
@@ -66,6 +66,7 @@ uint8_t WC_FULL_CONFIG_STRING[WC_FULL_CONFIG_STRING_LENGTH + 1] = {
/* This structure is used to save private info for Wacom Tablet. */
typedef struct {
CharDriverState *chr;
+ QemuInputHandlerState *hs;
/* Query string from serial */
uint8_t query[100];
@@ -76,6 +77,9 @@ typedef struct {
int outlen;
int line_speed;
+ int axis[INPUT_AXIS__MAX];
+ bool btns[INPUT_BUTTON__MAX];
+
} TabletState;
static void wctablet_chr_accept_input(CharDriverState *chr);
@@ -105,19 +109,16 @@ static void wctablet_reset(TabletState *tablet)
tablet->outlen = 0;
}
-static void wctablet_event(void *opaque, int x,
- int y, int dz, int buttons_state)
+static void wctablet_queue_event(TabletState *tablet)
{
- CharDriverState *chr = (CharDriverState *) opaque;
- TabletState *tablet = (TabletState *) chr->opaque;
uint8_t codes[8] = { 0xe0, 0, 0, 0, 0, 0, 0 };
if (tablet->line_speed != 9600) {
return;
}
- int newX = x * 0.1537;
- int nexY = y * 0.1152;
+ int newX = tablet->axis[INPUT_AXIS_X] * 0.1537;
+ int nexY = tablet->axis[INPUT_AXIS_Y] * 0.1152;
codes[0] = codes[0] | WC_H2(newX);
codes[1] = codes[1] | WC_M7(newX);
@@ -127,13 +128,51 @@ static void wctablet_event(void *opaque, int x,
codes[4] = codes[4] | WC_M7(nexY);
codes[5] = codes[5] | WC_L7(nexY);
- if (buttons_state == 0x01) {
+ if (tablet->btns[INPUT_BUTTON_LEFT]) {
codes[0] = 0xa0;
}
wctablet_queue_output(tablet, codes, 7);
}
+static void wctablet_input_event(DeviceState *dev, QemuConsole *src,
+ InputEvent *evt)
+{
+ TabletState *tablet = (TabletState *)dev;
+ InputMoveEvent *move;
+ InputBtnEvent *btn;
+
+ switch (evt->type) {
+ case INPUT_EVENT_KIND_ABS:
+ move = evt->u.abs.data;
+ tablet->axis[move->axis] = move->value;
+ break;
+
+ case INPUT_EVENT_KIND_BTN:
+ btn = evt->u.btn.data;
+ tablet->btns[btn->button] = btn->down;
+ break;
+
+ default:
+ /* keep gcc happy */
+ break;
+ }
+}
+
+static void wctablet_input_sync(DeviceState *dev)
+{
+ TabletState *tablet = (TabletState *)dev;
+
+ wctablet_queue_event(tablet);
+}
+
+static QemuInputHandler wctablet_handler = {
+ .name = "QEMU Wacome Pen Tablet",
+ .mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_ABS,
+ .event = wctablet_input_event,
+ .sync = wctablet_input_sync,
+};
+
static void wctablet_chr_accept_input(CharDriverState *chr)
{
TabletState *tablet = (TabletState *) chr->opaque;
@@ -253,8 +292,11 @@ static int wctablet_chr_ioctl(CharDriverState *s, int cmd, void *arg)
static void wctablet_chr_free(struct CharDriverState *chr)
{
- g_free (chr->opaque);
- g_free (chr);
+ TabletState *tablet = (TabletState *) chr->opaque;
+
+ qemu_input_handler_unregister(tablet->hs);
+ g_free(chr->opaque);
+ g_free(chr);
}
static CharDriverState *qemu_chr_open_wctablet(const char *id,
@@ -286,9 +328,8 @@ static CharDriverState *qemu_chr_open_wctablet(const char *id,
chr->opaque = tablet;
tablet->chr = chr;
- qemu_add_mouse_event_handler(wctablet_event, chr, 1,
- "QEMU Wacome Pen Tablet");
-
+ tablet->hs = qemu_input_handler_register((DeviceState *)tablet,
+ &wctablet_handler);
return chr;
}
--
1.8.3.1
next prev parent reply other threads:[~2017-01-06 8:56 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-06 8:55 [Qemu-devel] [PATCH 00/17] add serial wacom tablet emulation (gsoc 2016) Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 01/17] Add wctablet device Gerd Hoffmann
2017-01-06 13:15 ` Eric Blake
2017-01-06 8:55 ` [Qemu-devel] [PATCH 02/17] wctablet: add wctablet_queue_output helper Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 03/17] wctablet: save all chars in the query buffer Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 04/17] wctablet: drop wctablet_commands_names Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 05/17] wctablet: strip leading \r + \n from buffer Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 06/17] wctablet: track line speed, reset on speed changes Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 07/17] wctablet: operate on line speed 9600 Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 08/17] wctablet: drop debug code from wctablet_handler Gerd Hoffmann
2017-01-06 13:17 ` Eric Blake
2017-01-09 7:50 ` Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 09/17] wctablet: add wctablet_shift_input Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 10/17] wctablet: move init/detect sequence Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 11/17] wctablet: revamp command parser Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 12/17] wctablet: drop timer, hook into chr->accept_input instead Gerd Hoffmann
2017-01-06 8:55 ` [Qemu-devel] [PATCH 13/17] wctablet: drop DPRINTF, add trace events instead Gerd Hoffmann
2017-01-06 13:19 ` Eric Blake
2017-01-06 8:55 ` [Qemu-devel] [PATCH 14/17] wctablet: misc cleanups Gerd Hoffmann
2017-01-06 13:19 ` Eric Blake
2017-01-06 8:55 ` Gerd Hoffmann [this message]
2017-01-06 8:55 ` [Qemu-devel] [PATCH 16/17] wctablet: update file comment Gerd Hoffmann
2017-01-06 13:20 ` Eric Blake
2017-01-06 8:55 ` [Qemu-devel] [PATCH 17/17] wctablet: implement ST and SP commands Gerd Hoffmann
2017-01-06 9:22 ` [Qemu-devel] [PATCH 00/17] add serial wacom tablet emulation (gsoc 2016) no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1483692945-9866-16-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=avg.tolik@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).