From patchwork Wed Mar 10 16:51:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 47264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 86F1CB7CD5 for ; Thu, 11 Mar 2010 04:06:16 +1100 (EST) Received: from localhost ([127.0.0.1]:45547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpPMH-0007eC-HV for incoming@patchwork.ozlabs.org; Wed, 10 Mar 2010 12:06:09 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NpP8H-0004wc-HZ for qemu-devel@nongnu.org; Wed, 10 Mar 2010 11:51:41 -0500 Received: from [199.232.76.173] (port=58957 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpP8F-0004vD-Rw for qemu-devel@nongnu.org; Wed, 10 Mar 2010 11:51:40 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NpP8E-0001Za-Fq for qemu-devel@nongnu.org; Wed, 10 Mar 2010 11:51:39 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:46262) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NpP8D-0001Z4-De for qemu-devel@nongnu.org; Wed, 10 Mar 2010 11:51:38 -0500 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by e35.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o2AGlNs9022551 for ; Wed, 10 Mar 2010 09:47:23 -0700 Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2AGpGGY129312 for ; Wed, 10 Mar 2010 09:51:18 -0700 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2AGrcWT004863 for ; Wed, 10 Mar 2010 09:53:39 -0700 Received: from localhost.localdomain (dyn95341159.austin.ibm.com [9.53.41.159]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2AGrbH0004788; Wed, 10 Mar 2010 09:53:38 -0700 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 10 Mar 2010 10:51:06 -0600 Message-Id: <1268239869-16058-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1268239869-16058-1-git-send-email-aliguori@us.ibm.com> References: <1268239869-16058-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori , Gerd Hoffman , Luiz Capitulino Subject: [Qemu-devel] [PATCH 4/7] Add notifier for mouse mode changes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Right now, DisplayState clients rely on polling the mouse mode to determine when the device is changed to an absolute device. Use a notification list to add an explicit notification. Signed-off-by: Anthony Liguori --- console.h | 3 +++ input.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletions(-) diff --git a/console.h b/console.h index f3c619f..cb928cf 100644 --- a/console.h +++ b/console.h @@ -3,6 +3,7 @@ #include "qemu-char.h" #include "qdict.h" +#include "notify.h" /* keyboard/mouse support */ @@ -56,6 +57,8 @@ void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); /* Does the current mouse generate absolute events */ int kbd_mouse_is_absolute(void); +void qemu_add_mouse_mode_change_notifier(QEMUNotifier *notify); +void qemu_remove_mouse_mode_change_notifier(QEMUNotifier *notify); /* Of all the mice, is there one that generates absolute events */ int kbd_mouse_has_absolute(void); diff --git a/input.c b/input.c index 8d5a14d..cbf55b7 100644 --- a/input.c +++ b/input.c @@ -28,12 +28,13 @@ #include "console.h" #include "qjson.h" - static QEMUPutKBDEvent *qemu_put_kbd_event; static void *qemu_put_kbd_event_opaque; static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers); static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers = QTAILQ_HEAD_INITIALIZER(mouse_handlers); +static QEMUNotifierList mouse_mode_notifiers = + QEMU_NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers); void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) { @@ -41,6 +42,24 @@ void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) qemu_put_kbd_event = func; } +static void check_mode_change(void) +{ + static int current_is_absolute, current_has_absolute; + int is_absolute; + int has_absolute; + + is_absolute = kbd_mouse_is_absolute(); + has_absolute = kbd_mouse_has_absolute(); + + if (is_absolute != current_is_absolute || + has_absolute != current_has_absolute) { + qemu_notifier_list_notify(&mouse_mode_notifiers); + } + + current_is_absolute = is_absolute; + current_has_absolute = has_absolute; +} + QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque, int absolute, const char *name) @@ -58,6 +77,8 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, QTAILQ_INSERT_TAIL(&mouse_handlers, s, node); + check_mode_change(); + return s; } @@ -75,6 +96,8 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) qemu_free(entry->qemu_put_mouse_event_name); qemu_free(entry); + + check_mode_change(); } QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, @@ -256,4 +279,16 @@ void do_mouse_set(Monitor *mon, const QDict *qdict) if (!found) { monitor_printf(mon, "Mouse at given index not found\n"); } + + check_mode_change(); +} + +void qemu_add_mouse_mode_change_notifier(QEMUNotifier *notify) +{ + qemu_notifier_list_add(&mouse_mode_notifiers, notify); +} + +void qemu_remove_mouse_mode_change_notifier(QEMUNotifier *notify) +{ + qemu_notifier_list_remove(&mouse_mode_notifiers, notify); }