Skip to contentSkip to conversation

ui/gtk: Restore keyboard focus after Page change

PATCH Superseded John Snow 2 participants 2 messages Jul 8, 2014 – Jul 9, 2014

lore
Share & tools
lore

John Snow

author
#0 lore raw

PATCH 1/1 ui/gtk: Restore keyboard focus after Page change

In the GTK UI, after changing focus to the qemu monitor Notebook Page, when restoring focus to the virtual machine page, the keyboard focus is lost to a hidden GTK widget. Focus can only be restored to the virtual machine by pressing "tab" or any of the four directional arrow keys.

Clicking in the window or grabbing/ungrabbing input does not restore keyboard focus to the child widget.

This patch adjusts the Notebook page switching callback to automatically steal keyboard focus on the Page switch event, so that keyboard input does not appear to break or disappear after tabbing to the QEMU monitor.

---
 ui/gtk.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
ui/gtk.c +6 -3
index b02fcd6..2345d7e 100644
@@ -992,13 +992,16 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
     VirtualConsole *vc = gd_vc_find_by_menu(s);
+    GtkNotebook *nb = GTK_NOTEBOOK(s->notebook);
+    GtkWidget *child;
     gint page;
 
     gtk_release_modifiers(s);
     if (vc) {
-        page = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook),
-                                     vc->tab_item);
-        gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), page);
+        page = gtk_notebook_page_num(nb, vc->tab_item);
+        gtk_notebook_set_current_page(nb, page);
+        child = gtk_notebook_get_nth_page(nb, page);
+        gtk_widget_grab_focus(child);
     }
 }
 
Signature · 1 line
1.9.3
#1 lore raw
Quoted 8 lines · John Snow

In the GTK UI, after changing focus to the qemu monitor Notebook Page, when restoring focus to the virtual machine page, the keyboard focus is lost to a hidden GTK widget. Focus can only be restored to the virtual machine by pressing "tab" or any of the four directional arrow keys.

Clicking in the window or grabbing/ungrabbing input does not restore keyboard focus to the child widget.

Quoted 8 lines

This patch adjusts the Notebook page switching callback to automatically steal keyboard focus on the Page switch event, so that keyboard input does not appear to break or disappear after tabbing to the QEMU monitor.

---
 ui/gtk.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

CCed Gerd who may also be able to review this patch.

If this patch is non-contentious it could be merged for 2.1.

Quoted 28 lines
ui/gtk.c +6 -3
index b02fcd6..2345d7e 100644
@@ -992,13 +992,16 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
     VirtualConsole *vc = gd_vc_find_by_menu(s);
+    GtkNotebook *nb = GTK_NOTEBOOK(s->notebook);
+    GtkWidget *child;
     gint page;
 
     gtk_release_modifiers(s);
     if (vc) {
-        page = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook),
-                                     vc->tab_item);
-        gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), page);
+        page = gtk_notebook_page_num(nb, vc->tab_item);
+        gtk_notebook_set_current_page(nb, page);
+        child = gtk_notebook_get_nth_page(nb, page);
+        gtk_widget_grab_focus(child);
     }
 }
 
Signature · 1 line
1.9.3