From: Jan Kiszka <jan.kiszka@web.de>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v3] gtk: Release modifier when graphic console loses keyboard focus
Date: Sun, 24 Mar 2013 19:10:02 +0100 [thread overview]
Message-ID: <514F417A.6010908@web.de> (raw)
From: Jan Kiszka <jan.kiszka@siemens.com>
This solves, e.g., sticky ALT when selecting a GTK menu, switching to a
different window or selecting a different virtual console.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
Changes in v3:
- rebased
ui/gtk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/ui/gtk.c b/ui/gtk.c
index a249059..c04656a 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -102,6 +102,11 @@ static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
#define IGNORE_MODIFIER_MASK \
(GDK_MODIFIER_MASK & ~(GDK_LOCK_MASK | GDK_MOD2_MASK))
+static const int modifier_keycode[] = {
+ /* shift, control, alt keys, meta keys, both left & right */
+ 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
+};
+
typedef struct VirtualConsole
{
GtkWidget *menu_item;
@@ -161,6 +166,8 @@ typedef struct GtkDisplayState
gboolean free_scale;
bool external_pause_update;
+
+ bool modifier_pressed[ARRAY_SIZE(modifier_keycode)];
} GtkDisplayState;
static GtkDisplayState *global_state;
@@ -267,6 +274,26 @@ static void gd_update_full_redraw(GtkDisplayState *s)
gtk_widget_queue_draw_area(s->drawing_area, 0, 0, ww, wh);
}
+static void gtk_release_modifiers(GtkDisplayState *s)
+{
+ int i, keycode;
+
+ if (!gd_on_vga(s)) {
+ return;
+ }
+ for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) {
+ keycode = modifier_keycode[i];
+ if (!s->modifier_pressed[i]) {
+ continue;
+ }
+ if (keycode & SCANCODE_GREY) {
+ kbd_put_keycode(SCANCODE_EMUL0);
+ }
+ kbd_put_keycode(keycode | SCANCODE_UP);
+ s->modifier_pressed[i] = false;
+ }
+}
+
/** DisplayState Callbacks **/
static void gd_update(DisplayChangeListener *dcl,
@@ -385,8 +412,9 @@ static gboolean gd_window_key_event(GtkWidget *widget, GdkEventKey *key, void *o
(key->state & IGNORE_MODIFIER_MASK) == HOTKEY_MODIFIERS) {
handled = gtk_window_activate_key(GTK_WINDOW(widget), key);
}
-
- if (!handled) {
+ if (handled) {
+ gtk_release_modifiers(s);
+ } else {
handled = gtk_window_propagate_key_event(GTK_WINDOW(widget), key);
}
@@ -616,8 +644,10 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
{
+ GtkDisplayState *s = opaque;
int gdk_keycode;
int qemu_keycode;
+ int i;
gdk_keycode = key->hardware_keycode;
@@ -639,6 +669,12 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
gdk_keycode, qemu_keycode,
(key->type == GDK_KEY_PRESS) ? "down" : "up");
+ for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) {
+ if (qemu_keycode == modifier_keycode[i]) {
+ s->modifier_pressed[i] = (key->type == GDK_KEY_PRESS);
+ }
+ }
+
if (qemu_keycode & SCANCODE_GREY) {
kbd_put_keycode(SCANCODE_EMUL0);
}
@@ -694,6 +730,7 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
} else {
int i;
+ gtk_release_modifiers(s);
for (i = 0; i < s->nb_vcs; i++) {
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->vc[i].menu_item))) {
gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), i + 1);
@@ -994,6 +1031,16 @@ static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing, gp
return TRUE;
}
+static gboolean gd_focus_out_event(GtkWidget *widget,
+ GdkEventCrossing *crossing, gpointer data)
+{
+ GtkDisplayState *s = data;
+
+ gtk_release_modifiers(s);
+
+ return TRUE;
+}
+
/** Virtual Console Callbacks **/
static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
@@ -1177,6 +1224,8 @@ static void gd_connect_signals(GtkDisplayState *s)
G_CALLBACK(gd_enter_event), s);
g_signal_connect(s->drawing_area, "leave-notify-event",
G_CALLBACK(gd_leave_event), s);
+ g_signal_connect(s->drawing_area, "focus-out-event",
+ G_CALLBACK(gd_focus_out_event), s);
}
static void gd_create_menus(GtkDisplayState *s)
--
1.7.3.4
next reply other threads:[~2013-03-24 18:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-24 18:10 Jan Kiszka [this message]
2013-03-25 7:41 ` [Qemu-devel] [PATCH v3] gtk: Release modifier when graphic console loses keyboard focus Stefan Hajnoczi
2013-03-25 20:21 ` Anthony Liguori
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=514F417A.6010908@web.de \
--to=jan.kiszka@web.de \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).