From patchwork Thu Feb 25 08:39:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 46223 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 14C20B7C09 for ; Thu, 25 Feb 2010 19:54:51 +1100 (EST) Received: from localhost ([127.0.0.1]:42176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkZUd-0003XS-Px for incoming@patchwork.ozlabs.org; Thu, 25 Feb 2010 03:54:47 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NkZFs-00068g-3s for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:32 -0500 Received: from [199.232.76.173] (port=33649 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkZFq-000682-J6 for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:31 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NkZFn-0007Z5-Ua for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17193) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NkZFn-0007Yn-8l for qemu-devel@nongnu.org; Thu, 25 Feb 2010 03:39:27 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1P8dQgw020547 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Feb 2010 03:39:26 -0500 Received: from zweiblum.home.kraxel.org (vpn1-7-164.ams2.redhat.com [10.36.7.164]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1P8dNtZ032713; Thu, 25 Feb 2010 03:39:23 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 4B70B70113; Thu, 25 Feb 2010 09:39:22 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2010 09:39:18 +0100 Message-Id: <1267087161-15204-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1267087161-15204-1-git-send-email-kraxel@redhat.com> References: <1267087161-15204-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/4] kbd leds: infrastructure 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 Adds infrastructure for keyboard led status tracking to qemu. Signed-off-by: Gerd Hoffmann --- console.h | 14 ++++++++++++++ input.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 0 deletions(-) diff --git a/console.h b/console.h index 916859d..0e969d1 100644 --- a/console.h +++ b/console.h @@ -10,10 +10,15 @@ #define MOUSE_EVENT_RBUTTON 0x02 #define MOUSE_EVENT_MBUTTON 0x04 +#define QEMU_SCROLL_LOCK_LED (1 << 0) +#define QEMU_NUM_LOCK_LED (1 << 1) +#define QEMU_CAPS_LOCK_LED (1 << 2) + /* in ms */ #define GUI_REFRESH_INTERVAL 30 typedef void QEMUPutKBDEvent(void *opaque, int keycode); +typedef void QEMUPutLEDEvent(void *opaque, int ledstate); typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state); typedef struct QEMUPutMouseEntry { @@ -26,13 +31,22 @@ typedef struct QEMUPutMouseEntry { struct QEMUPutMouseEntry *next; } QEMUPutMouseEntry; +typedef struct QEMUPutLEDEntry { + QEMUPutLEDEvent *put_led; + void *opaque; + struct QEMUPutLEDEntry *next; +} QEMUPutLEDEntry; + void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque); QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque, int absolute, const char *name); void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry); +QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque); +void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); void kbd_put_keycode(int keycode); +void kbd_put_ledstate(int ledstate); void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); int kbd_mouse_is_absolute(void); diff --git a/input.c b/input.c index 955b9ab..82bc85c 100644 --- a/input.c +++ b/input.c @@ -31,6 +31,7 @@ static QEMUPutKBDEvent *qemu_put_kbd_event; static void *qemu_put_kbd_event_opaque; +static QEMUPutLEDEntry *qemu_put_led_event_head; static QEMUPutMouseEntry *qemu_put_mouse_event_head; static QEMUPutMouseEntry *qemu_put_mouse_event_current; @@ -102,6 +103,44 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) qemu_free(entry); } +QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, + void *opaque) +{ + QEMUPutLEDEntry *s; + + s = qemu_mallocz(sizeof(QEMUPutLEDEntry)); + + s->put_led = func; + s->opaque = opaque; + s->next = qemu_put_led_event_head; + qemu_put_led_event_head = s; + return s; +} + +void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry) +{ + QEMUPutLEDEntry *prev = NULL, *cursor; + + if (!qemu_put_led_event_head || entry == NULL) + return; + + cursor = qemu_put_led_event_head; + while (cursor != NULL && cursor != entry) { + prev = cursor; + cursor = cursor->next; + } + + if (cursor == NULL) // does not exist or list empty + return; + + if (prev == NULL) { // entry is head + qemu_put_led_event_head = cursor->next; + } else { + prev->next = entry->next; + } + qemu_free(entry); +} + void kbd_put_keycode(int keycode) { if (qemu_put_kbd_event) { @@ -109,6 +148,17 @@ void kbd_put_keycode(int keycode) } } +void kbd_put_ledstate(int ledstate) +{ + QEMUPutLEDEntry *cursor; + + cursor = qemu_put_led_event_head; + while (cursor != NULL) { + cursor->put_led(cursor->opaque, ledstate); + cursor = cursor->next; + } +} + void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) { QEMUPutMouseEvent *mouse_event;