aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-05-28 11:18:58 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-05-28 11:18:58 +0100
commit109519fd326f967bf1fffded2430d7a49899d47d (patch)
tree538cb92afec162e79466c0b9959a2cd0d96346ee
parent4aa23452e366790e6c50dea73c8bc5eea44e2f38 (diff)
parent6fa27697514bb45e80fcb57f38054a8833f87ff9 (diff)
Merge remote-tracking branch 'remotes/kraxel/tags/pull-gtk-7' into staging
gtk: ui overhaul, multiwindow support. # gpg: Signature made Mon 26 May 2014 08:54:55 BST using RSA key ID D3E87138 # gpg: Can't check signature: public key not found * remotes/kraxel/tags/pull-gtk-7: (24 commits) gtk: workaround gtk2 vte resize issue gtk: window sizing overhaul gtk: zap unused global_state gtk: Add handling for the xfree86 keycodes gtk: enable untabify for gfx gtk: detached window pointer grabs gtk: update all windows on mouse mode changes gtk: fix grab checks gtk: update gd_update_caption gtk: skip keyboard grab when hover autograb is active gtk: keep track of grab owner gtk: add gd_grab trace event gtk: add tab to trace events gtk: allow moving tabs to windows and back. gtk: simplify resize gtk: use device type as label gtk: support multiple gfx displays gtk: move vga state into VirtualGfxConsole gtk: VirtualConsole restruction gtk: remove page numbering assumtions from the code ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--trace-events7
-rw-r--r--ui/gtk.c1108
2 files changed, 738 insertions, 377 deletions
diff --git a/trace-events b/trace-events
index ea56d5281e..f256ca51b0 100644
--- a/trace-events
+++ b/trace-events
@@ -1042,9 +1042,10 @@ displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]"
ppm_save(const char *filename, void *display_surface) "%s surface=%p"
# ui/gtk.c
-gd_switch(int width, int height) "width=%d, height=%d"
-gd_update(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d"
-gd_key_event(int gdk_keycode, int qemu_keycode, const char *action) "translated GDK keycode %d to QEMU keycode %d (%s)"
+gd_switch(const char *tab, int width, int height) "tab=%s, width=%d, height=%d"
+gd_update(const char *tab, int x, int y, int w, int h) "tab=%s, x=%d, y=%d, w=%d, h=%d"
+gd_key_event(const char *tab, int gdk_keycode, int qemu_keycode, const char *action) "tab=%s, translated GDK keycode %d to QEMU keycode %d (%s)"
+gd_grab(const char *tab, const char *device, bool on) "tab=%s, %s %d"
# ui/input.c
input_event_key_number(int conidx, int number, const char *qcode, bool down) "con %d, key number 0x%x [%s], down %d"
diff --git a/ui/gtk.c b/ui/gtk.c
index 9f5061a1be..b9089360f0 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -67,13 +67,38 @@
#include "x_keymap.h"
#include "keymaps.h"
#include "sysemu/char.h"
+#include "qom/object.h"
+#ifndef _WIN32
+#include <gdk/gdkx.h>
+#include <X11/XKBlib.h>
+#endif
#define MAX_VCS 10
+#define VC_WINDOW_X_MIN 320
+#define VC_WINDOW_Y_MIN 240
+#define VC_TERM_X_MIN 80
+#define VC_TERM_Y_MIN 25
+#define VC_SCALE_MIN 0.25
+#define VC_SCALE_STEP 0.25
#if !defined(CONFIG_VTE)
# define VTE_CHECK_VERSION(a, b, c) 0
#endif
+#if defined(CONFIG_VTE) && !GTK_CHECK_VERSION(3, 0, 0)
+/*
+ * The gtk2 vte terminal widget seriously messes up the window resize
+ * for some reason. You basically can't make the qemu window smaller
+ * any more because the toplevel window geoemtry hints are overridden.
+ *
+ * Workaround that by hiding all vte widgets, except the one in the
+ * current tab.
+ *
+ * Luckily everything works smooth in gtk3.
+ */
+# define VTE_RESIZE_HACK 1
+#endif
+
/* Compatibility define to let us build on both Gtk2 and Gtk3 */
#if GTK_CHECK_VERSION(3, 0, 0)
static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
@@ -105,18 +130,48 @@ static const int modifier_keycode[] = {
0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
};
-typedef struct VirtualConsole
-{
- GtkWidget *menu_item;
- GtkWidget *terminal;
+typedef struct GtkDisplayState GtkDisplayState;
+
+typedef struct VirtualGfxConsole {
+ GtkWidget *drawing_area;
+ DisplayChangeListener dcl;
+ DisplaySurface *ds;
+ pixman_image_t *convert;
+ cairo_surface_t *surface;
+ double scale_x;
+ double scale_y;
+} VirtualGfxConsole;
+
#if defined(CONFIG_VTE)
- GtkWidget *scrolled_window;
+typedef struct VirtualVteConsole {
+ GtkWidget *box;
+ GtkWidget *scrollbar;
+ GtkWidget *terminal;
CharDriverState *chr;
+} VirtualVteConsole;
#endif
+
+typedef enum VirtualConsoleType {
+ GD_VC_GFX,
+ GD_VC_VTE,
+} VirtualConsoleType;
+
+typedef struct VirtualConsole {
+ GtkDisplayState *s;
+ char *label;
+ GtkWidget *window;
+ GtkWidget *menu_item;
+ GtkWidget *tab_item;
+ VirtualConsoleType type;
+ union {
+ VirtualGfxConsole gfx;
+#if defined(CONFIG_VTE)
+ VirtualVteConsole vte;
+#endif
+ };
} VirtualConsole;
-typedef struct GtkDisplayState
-{
+struct GtkDisplayState {
GtkWidget *window;
GtkWidget *menu_bar;
@@ -139,29 +194,24 @@ typedef struct GtkDisplayState
GtkWidget *zoom_fit_item;
GtkWidget *grab_item;
GtkWidget *grab_on_hover_item;
- GtkWidget *vga_item;
int nb_vcs;
VirtualConsole vc[MAX_VCS];
GtkWidget *show_tabs_item;
+ GtkWidget *untabify_item;
GtkWidget *vbox;
GtkWidget *notebook;
- GtkWidget *drawing_area;
- cairo_surface_t *surface;
- pixman_image_t *convert;
- DisplayChangeListener dcl;
- DisplaySurface *ds;
int button_mask;
gboolean last_set;
int last_x;
int last_y;
int grab_x_root;
int grab_y_root;
+ VirtualConsole *kbd_owner;
+ VirtualConsole *ptr_owner;
- double scale_x;
- double scale_y;
gboolean full_screen;
GdkCursor *null_cursor;
@@ -171,12 +221,52 @@ typedef struct GtkDisplayState
bool external_pause_update;
bool modifier_pressed[ARRAY_SIZE(modifier_keycode)];
-} GtkDisplayState;
+ bool has_evdev;
+};
-static GtkDisplayState *global_state;
+static void gd_grab_pointer(VirtualConsole *vc);
+static void gd_ungrab_pointer(GtkDisplayState *s);
/** Utility Functions **/
+static VirtualConsole *gd_vc_find_by_menu(GtkDisplayState *s)
+{
+ VirtualConsole *vc;
+ gint i;
+
+ for (i = 0; i < s->nb_vcs; i++) {
+ vc = &s->vc[i];
+ if (gtk_check_menu_item_get_active
+ (GTK_CHECK_MENU_ITEM(vc->menu_item))) {
+ return vc;
+ }
+ }
+ return NULL;
+}
+
+static VirtualConsole *gd_vc_find_by_page(GtkDisplayState *s, gint page)
+{
+ VirtualConsole *vc;
+ gint i, p;
+
+ for (i = 0; i < s->nb_vcs; i++) {
+ vc = &s->vc[i];
+ p = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook), vc->tab_item);
+ if (p == page) {
+ return vc;
+ }
+ }
+ return NULL;
+}
+
+static VirtualConsole *gd_vc_find_current(GtkDisplayState *s)
+{
+ gint page;
+
+ page = gtk_notebook_get_current_page(GTK_NOTEBOOK(s->notebook));
+ return gd_vc_find_by_page(s, page);
+}
+
static bool gd_is_grab_active(GtkDisplayState *s)
{
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_item));
@@ -187,22 +277,17 @@ static bool gd_grab_on_hover(GtkDisplayState *s)
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_on_hover_item));
}
-static bool gd_on_vga(GtkDisplayState *s)
-{
- return gtk_notebook_get_current_page(GTK_NOTEBOOK(s->notebook)) == 0;
-}
-
-static void gd_update_cursor(GtkDisplayState *s, gboolean override)
+static void gd_update_cursor(VirtualConsole *vc)
{
+ GtkDisplayState *s = vc->s;
GdkWindow *window;
- bool on_vga;
- window = gtk_widget_get_window(GTK_WIDGET(s->drawing_area));
-
- on_vga = gd_on_vga(s);
+ if (vc->type != GD_VC_GFX) {
+ return;
+ }
- if ((override || on_vga) &&
- (s->full_screen || qemu_input_is_absolute() || gd_is_grab_active(s))) {
+ window = gtk_widget_get_window(GTK_WIDGET(vc->gfx.drawing_area));
+ if (s->full_screen || qemu_input_is_absolute() || s->ptr_owner == vc) {
gdk_window_set_cursor(window, s->null_cursor);
} else {
gdk_window_set_cursor(window, NULL);
@@ -212,11 +297,20 @@ static void gd_update_cursor(GtkDisplayState *s, gboolean override)
static void gd_update_caption(GtkDisplayState *s)
{
const char *status = "";
+ gchar *prefix;
gchar *title;
const char *grab = "";
bool is_paused = !runstate_is_running();
+ int i;
- if (gd_is_grab_active(s)) {
+ if (qemu_name) {
+ prefix = g_strdup_printf("QEMU (%s)", qemu_name);
+ } else {
+ prefix = g_strdup_printf("QEMU");
+ }
+
+ if (s->ptr_owner != NULL &&
+ s->ptr_owner->window == NULL) {
grab = _(" - Press Ctrl+Alt+G to release grab");
}
@@ -228,60 +322,100 @@ static void gd_update_caption(GtkDisplayState *s)
is_paused);
s->external_pause_update = false;
- if (qemu_name) {
- title = g_strdup_printf("QEMU (%s)%s%s", qemu_name, status, grab);
- } else {
- title = g_strdup_printf("QEMU%s%s", status, grab);
- }
-
+ title = g_strdup_printf("%s%s%s", prefix, status, grab);
gtk_window_set_title(GTK_WINDOW(s->window), title);
-
g_free(title);
+
+ for (i = 0; i < s->nb_vcs; i++) {
+ VirtualConsole *vc = &s->vc[i];
+
+ if (!vc->window) {
+ continue;
+ }
+ title = g_strdup_printf("%s: %s%s%s", prefix, vc->label,
+ vc == s->kbd_owner ? " +kbd" : "",
+ vc == s->ptr_owner ? " +ptr" : "");
+ gtk_window_set_title(GTK_WINDOW(vc->window), title);
+ g_free(title);
+ }
+
+ g_free(prefix);
}
-static void gd_update_windowsize(GtkDisplayState *s)
+static void gd_update_geometry_hints(VirtualConsole *vc)
{
- if (!s->full_screen) {
- GtkRequisition req;
- double sx, sy;
+ GtkDisplayState *s = vc->s;
+ GdkWindowHints mask = 0;
+ GdkGeometry geo = {};
+ GtkWidget *geo_widget = NULL;
+ GtkWindow *geo_window;
+ if (vc->type == GD_VC_GFX) {
if (s->free_scale) {
- sx = s->scale_x;
- sy = s->scale_y;
-
- s->scale_y = 1.0;
- s->scale_x = 1.0;
+ geo.min_width = surface_width(vc->gfx.ds) * VC_SCALE_MIN;
+ geo.min_height = surface_height(vc->gfx.ds) * VC_SCALE_MIN;
+ mask |= GDK_HINT_MIN_SIZE;
} else {
- sx = 1.0;
- sy = 1.0;
+ geo.min_width = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
+ geo.min_height = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
+ mask |= GDK_HINT_MIN_SIZE;
}
+ geo_widget = vc->gfx.drawing_area;
+ gtk_widget_set_size_request(geo_widget, geo.min_width, geo.min_height);
- gtk_widget_set_size_request(s->drawing_area,
- surface_width(s->ds) * s->scale_x,
- surface_height(s->ds) * s->scale_y);
-#if GTK_CHECK_VERSION(3, 0, 0)
- gtk_widget_get_preferred_size(s->vbox, NULL, &req);
-#else
- gtk_widget_size_request(s->vbox, &req);
+#if defined(CONFIG_VTE)
+ } else if (vc->type == GD_VC_VTE) {
+ VteTerminal *term = VTE_TERMINAL(vc->vte.terminal);
+ GtkBorder *ib;
+
+ geo.width_inc = vte_terminal_get_char_width(term);
+ geo.height_inc = vte_terminal_get_char_height(term);
+ mask |= GDK_HINT_RESIZE_INC;
+ geo.base_width = geo.width_inc;
+ geo.base_height = geo.height_inc;
+ mask |= GDK_HINT_BASE_SIZE;
+ geo.min_width = geo.width_inc * VC_TERM_X_MIN;
+ geo.min_height = geo.height_inc * VC_TERM_Y_MIN;
+ mask |= GDK_HINT_MIN_SIZE;
+ gtk_widget_style_get(vc->vte.terminal, "inner-border", &ib, NULL);
+ geo.base_width += ib->left + ib->right;
+ geo.base_height += ib->top + ib->bottom;
+ geo.min_width += ib->left + ib->right;
+ geo.min_height += ib->top + ib->bottom;
+ geo_widget = vc->vte.terminal;
#endif
+ }
+
+ geo_window = GTK_WINDOW(vc->window ? vc->window : s->window);
+ gtk_window_set_geometry_hints(geo_window, geo_widget, &geo, mask);
+}
+
+static void gd_update_windowsize(VirtualConsole *vc)
+{
+ GtkDisplayState *s = vc->s;
+
+ gd_update_geometry_hints(vc);
- gtk_window_resize(GTK_WINDOW(s->window),
- req.width * sx, req.height * sy);
+ if (vc->type == GD_VC_GFX && !s->full_screen && !s->free_scale) {
+ gtk_window_resize(GTK_WINDOW(vc->window ? vc->window : s->window),
+ VC_WINDOW_X_MIN, VC_WINDOW_Y_MIN);
}
}
-static void gd_update_full_redraw(GtkDisplayState *s)
+static void gd_update_full_redraw(VirtualConsole *vc)
{
+ GtkWidget *area = vc->gfx.drawing_area;
int ww, wh;
- gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
- gtk_widget_queue_draw_area(s->drawing_area, 0, 0, ww, wh);
+ gdk_drawable_get_size(gtk_widget_get_window(area), &ww, &wh);
+ gtk_widget_queue_draw_area(area, 0, 0, ww, wh);
}
static void gtk_release_modifiers(GtkDisplayState *s)
{
+ VirtualConsole *vc = gd_vc_find_current(s);
int i, keycode;
- if (!gd_on_vga(s)) {
+ if (vc->type != GD_VC_GFX) {
return;
}
for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) {
@@ -289,7 +423,7 @@ static void gtk_release_modifiers(GtkDisplayState *s)
if (!s->modifier_pressed[i]) {
continue;
}
- qemu_input_event_send_key_number(s->dcl.con, keycode, false);
+ qemu_input_event_send_key_number(vc->gfx.dcl.con, keycode, false);
s->modifier_pressed[i] = false;
}
}
@@ -299,29 +433,31 @@ static void gtk_release_modifiers(GtkDisplayState *s)
static void gd_update(DisplayChangeListener *dcl,
int x, int y, int w, int h)
{
- GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
+ VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
int x1, x2, y1, y2;
int mx, my;
int fbw, fbh;
int ww, wh;
- trace_gd_update(x, y, w, h);
+ trace_gd_update(vc->label, x, y, w, h);
- if (s->convert) {
- pixman_image_composite(PIXMAN_OP_SRC, s->ds->image, NULL, s->convert,
+ if (vc->gfx.convert) {
+ pixman_image_composite(PIXMAN_OP_SRC, vc->gfx.ds->image,
+ NULL, vc->gfx.convert,
x, y, 0, 0, x, y, w, h);
}
- x1 = floor(x * s->scale_x);
- y1 = floor(y * s->scale_y);
+ x1 = floor(x * vc->gfx.scale_x);
+ y1 = floor(y * vc->gfx.scale_y);
- x2 = ceil(x * s->scale_x + w * s->scale_x);
- y2 = ceil(y * s->scale_y + h * s->scale_y);
+ x2 = ceil(x * vc->gfx.scale_x + w * vc->gfx.scale_x);
+ y2 = ceil(y * vc->gfx.scale_y + h * vc->gfx.scale_y);
- fbw = surface_width(s->ds) * s->scale_x;
- fbh = surface_height(s->ds) * s->scale_y;
+ fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
+ fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
- gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
+ gdk_drawable_get_size(gtk_widget_get_window(vc->gfx.drawing_area),
+ &ww, &wh);
mx = my = 0;
if (ww > fbw) {
@@ -331,7 +467,8 @@ static void gd_update(DisplayChangeListener *dcl,
my = (wh - fbh) / 2;
}
- gtk_widget_queue_draw_area(s->drawing_area, mx + x1, my + y1, (x2 - x1), (y2 - y1));
+ gtk_widget_queue_draw_area(vc->gfx.drawing_area,
+ mx + x1, my + y1, (x2 - x1), (y2 - y1));
}
static void gd_refresh(DisplayChangeListener *dcl)
@@ -343,7 +480,7 @@ static void gd_refresh(DisplayChangeListener *dcl)
static void gd_mouse_set(DisplayChangeListener *dcl,
int x, int y, int visible)
{
- GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
+ VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
GdkDisplay *dpy;
GdkDeviceManager *mgr;
gint x_root, y_root;
@@ -352,29 +489,29 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
return;
}
- dpy = gtk_widget_get_display(s->drawing_area);
+ dpy = gtk_widget_get_display(vc->gfx.drawing_area);
mgr = gdk_display_get_device_manager(dpy);
- gdk_window_get_root_coords(gtk_widget_get_window(s->drawing_area),
+ gdk_window_get_root_coords(gtk_widget_get_window(vc->gfx.drawing_area),
x, y, &x_root, &y_root);
gdk_device_warp(gdk_device_manager_get_client_pointer(mgr),
- gtk_widget_get_screen(s->drawing_area),
+ gtk_widget_get_screen(vc->gfx.drawing_area),
x_root, y_root);
}
#else
static void gd_mouse_set(DisplayChangeListener *dcl,
int x, int y, int visible)
{
- GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
+ VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
gint x_root, y_root;
if (qemu_input_is_absolute()) {
return;
}
- gdk_window_get_root_coords(gtk_widget_get_window(s->drawing_area),
+ gdk_window_get_root_coords(gtk_widget_get_window(vc->gfx.drawing_area),
x, y, &x_root, &y_root);
- gdk_display_warp_pointer(gtk_widget_get_display(s->drawing_area),
- gtk_widget_get_screen(s->drawing_area),
+ gdk_display_warp_pointer(gtk_widget_get_display(vc->gfx.drawing_area),
+ gtk_widget_get_screen(vc->gfx.drawing_area),
x_root, y_root);
}
#endif
@@ -382,7 +519,7 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
static void gd_cursor_define(DisplayChangeListener *dcl,
QEMUCursor *c)
{
- GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
+ VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
GdkPixbuf *pixbuf;
GdkCursor *cursor;
@@ -390,9 +527,10 @@ static void gd_cursor_define(DisplayChangeListener *dcl,
GDK_COLORSPACE_RGB, true, 8,
c->width, c->height, c->width * 4,
NULL, NULL);
- cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(s->drawing_area),
- pixbuf, c->hot_x, c->hot_y);
- gdk_window_set_cursor(gtk_widget_get_window(s->drawing_area), cursor);
+ cursor = gdk_cursor_new_from_pixbuf
+ (gtk_widget_get_display(vc->gfx.drawing_area),
+ pixbuf, c->hot_x, c->hot_y);
+ gdk_window_set_cursor(gtk_widget_get_window(vc->gfx.drawing_area), cursor);
g_object_unref(pixbuf);
#if !GTK_CHECK_VERSION(3, 0, 0)
gdk_cursor_unref(cursor);
@@ -404,25 +542,25 @@ static void gd_cursor_define(DisplayChangeListener *dcl,
static void gd_switch(DisplayChangeListener *dcl,
DisplaySurface *surface)
{
- GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
+ VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
bool resized = true;
- trace_gd_switch(surface_width(surface), surface_height(surface));
+ trace_gd_switch(vc->label, surface_width(surface), surface_height(surface));
- if (s->surface) {
- cairo_surface_destroy(s->surface);
+ if (vc->gfx.surface) {
+ cairo_surface_destroy(vc->gfx.surface);
}
- if (s->ds &&
- surface_width(s->ds) == surface_width(surface) &&
- surface_height(s->ds) == surface_height(surface)) {
+ if (vc->gfx.ds &&
+ surface_width(vc->gfx.ds) == surface_width(surface) &&
+ surface_height(vc->gfx.ds) == surface_height(surface)) {
resized = false;
}
- s->ds = surface;
+ vc->gfx.ds = surface;
- if (s->convert) {
- pixman_image_unref(s->convert);
- s->convert = NULL;
+ if (vc->gfx.convert) {
+ pixman_image_unref(vc->gfx.convert);
+ vc->gfx.convert = NULL;
}
if (surface->format == PIXMAN_x8r8g8b8) {
@@ -432,7 +570,7 @@ static void gd_switch(DisplayChangeListener *dcl,
* No need to convert, use surface directly. Should be the
* common case as this is qemu_default_pixelformat(32) too.
*/
- s->surface = cairo_image_surface_create_for_data
+ vc->gfx.surface = cairo_image_surface_create_for_data
(surface_data(surface),
CAIRO_FORMAT_RGB24,
surface_width(surface),
@@ -440,26 +578,27 @@ static void gd_switch(DisplayChangeListener *dcl,
surface_stride(surface));
} else {
/* Must convert surface, use pixman to do it. */
- s->convert = pixman_image_create_bits(PIXMAN_x8r8g8b8,
- surface_width(surface),
- surface_height(surface),
- NULL, 0);
- s->surface = cairo_image_surface_create_for_data
- ((void *)pixman_image_get_data(s->convert),
+ vc->gfx.convert = pixman_image_create_bits(PIXMAN_x8r8g8b8,
+ surface_width(surface),
+ surface_height(surface),
+ NULL, 0);
+ vc->gfx.surface = cairo_image_surface_create_for_data
+ ((void *)pixman_image_get_data(vc->gfx.convert),
CAIRO_FORMAT_RGB24,
- pixman_image_get_width(s->convert),
- pixman_image_get_height(s->convert),
- pixman_image_get_stride(s->convert));
- pixman_image_composite(PIXMAN_OP_SRC, s->ds->image, NULL, s->convert,
+ pixman_image_get_width(vc->gfx.convert),
+ pixman_image_get_height(vc->gfx.convert),
+ pixman_image_get_stride(vc->gfx.convert));
+ pixman_image_composite(PIXMAN_OP_SRC, vc->gfx.ds->image,
+ NULL, vc->gfx.convert,
0, 0, 0, 0, 0, 0,
- pixman_image_get_width(s->convert),
- pixman_image_get_height(s->convert));
+ pixman_image_get_width(vc->gfx.convert),
+ pixman_image_get_height(vc->gfx.convert));
}
if (resized) {
- gd_update_windowsize(s);
+ gd_update_windowsize(vc);
} else {
- gd_update_full_redraw(s);
+ gd_update_full_redraw(vc);
}
}
@@ -475,6 +614,7 @@ static void gd_change_runstate(void *opaque, int running, RunState state)
static void gd_mouse_mode_change(Notifier *notify, void *data)
{
GtkDisplayState *s;
+ int i;
s = container_of(notify, GtkDisplayState, mouse_mode_notifier);
/* release the grab at switching to absolute mode */
@@ -482,7 +622,10 @@ static void gd_mouse_mode_change(Notifier *notify, void *data)
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
FALSE);
}
- gd_update_cursor(s, FALSE);
+ for (i = 0; i < s->nb_vcs; i++) {
+ VirtualConsole *vc = &s->vc[i];
+ gd_update_cursor(vc);
+ }
}
/** GTK Events **/
@@ -491,9 +634,15 @@ static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event,
void *opaque)
{
GtkDisplayState *s = opaque;
+ int i;
if (!no_quit) {
- unregister_displaychangelistener(&s->dcl);
+ for (i = 0; i < s->nb_vcs; i++) {
+ if (s->vc[i].type != GD_VC_GFX) {
+ continue;
+ }
+ unregister_displaychangelistener(&s->vc[i].gfx.dcl);
+ }
qmp_quit(NULL);
return FALSE;
}
@@ -503,7 +652,8 @@ static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event,
static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
{
- GtkDisplayState *s = opaque;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
int mx, my;
int ww, wh;
int fbw, fbh;
@@ -512,25 +662,25 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
return FALSE;
}
- fbw = surface_width(s->ds);
- fbh = surface_height(s->ds);
+ fbw = surface_width(vc->gfx.ds);
+ fbh = surface_height(vc->gfx.ds);
gdk_drawable_get_size(gtk_widget_get_window(widget), &ww, &wh);
if (s->full_screen) {
- s->scale_x = (double)ww / fbw;
- s->scale_y = (double)wh / fbh;
+ vc->gfx.scale_x = (double)ww / fbw;
+ vc->gfx.scale_y = (double)wh / fbh;
} else if (s->free_scale) {
double sx, sy;
sx = (double)ww / fbw;
sy = (double)wh / fbh;
- s->scale_x = s->scale_y = MIN(sx, sy);
+ vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
}
- fbw *= s->scale_x;
- fbh *= s->scale_y;
+ fbw *= vc->gfx.scale_x;
+ fbh *= vc->gfx.scale_y;
mx = my = 0;
if (ww > fbw) {
@@ -551,8 +701,9 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
-1 * fbw, fbh);
cairo_fill(cr);
- cairo_scale(cr, s->scale_x, s->scale_y);
- cairo_set_source_surface(cr, s->surface, mx / s->scale_x, my / s->scale_y);
+ cairo_scale(cr, vc->gfx.scale_x, vc->gfx.scale_y);
+ cairo_set_source_surface(cr, vc->gfx.surface,
+ mx / vc->gfx.scale_x, my / vc->gfx.scale_y);
cairo_paint(cr);
return TRUE;
@@ -584,16 +735,18 @@ static gboolean gd_expose_event(GtkWidget *widget, GdkEventExpose *expose,
static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
void *opaque)
{
- GtkDisplayState *s = opaque;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
int x, y;
int mx, my;
int fbh, fbw;
int ww, wh;
- fbw = surface_width(s->ds) * s->scale_x;
- fbh = surface_height(s->ds) * s->scale_y;
+ fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
+ fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
- gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
+ gdk_drawable_get_size(gtk_widget_get_window(vc->gfx.drawing_area),
+ &ww, &wh);
mx = my = 0;
if (ww > fbw) {
@@ -603,31 +756,31 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
my = (wh - fbh) / 2;
}
- x = (motion->x - mx) / s->scale_x;
- y = (motion->y - my) / s->scale_y;
+ x = (motion->x - mx) / vc->gfx.scale_x;
+ y = (motion->y - my) / vc->gfx.scale_y;
if (qemu_input_is_absolute()) {
if (x < 0 || y < 0 ||
- x >= surface_width(s->ds) ||
- y >= surface_height(s->ds)) {
+ x >= surface_width(vc->gfx.ds) ||
+ y >= surface_height(vc->gfx.ds)) {
return TRUE;
}
- qemu_input_queue_abs(s->dcl.con, INPUT_AXIS_X, x,
- surface_width(s->ds));
- qemu_input_queue_abs(s->dcl.con, INPUT_AXIS_Y, y,
- surface_height(s->ds));
+ qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_X, x,
+ surface_width(vc->gfx.ds));
+ qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_Y, y,
+ surface_height(vc->gfx.ds));
qemu_input_event_sync();
- } else if (s->last_set && gd_is_grab_active(s)) {
- qemu_input_queue_rel(s->dcl.con, INPUT_AXIS_X, x - s->last_x);
- qemu_input_queue_rel(s->dcl.con, INPUT_AXIS_Y, y - s->last_y);
+ } else if (s->last_set && s->ptr_owner == vc) {
+ qemu_input_queue_rel(vc->gfx.dcl.con, INPUT_AXIS_X, x - s->last_x);
+ qemu_input_queue_rel(vc->gfx.dcl.con, INPUT_AXIS_Y, y - s->last_y);
qemu_input_event_sync();
}
s->last_x = x;
s->last_y = y;
s->last_set = TRUE;
- if (!qemu_input_is_absolute() && gd_is_grab_active(s)) {
- GdkScreen *screen = gtk_widget_get_screen(s->drawing_area);
+ if (!qemu_input_is_absolute() && s->ptr_owner == vc) {
+ GdkScreen *screen = gtk_widget_get_screen(vc->gfx.drawing_area);
int x = (int)motion->x_root;
int y = (int)motion->y_root;
@@ -669,14 +822,21 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
void *opaque)
{
- GtkDisplayState *s = opaque;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
InputButton btn;
/* implicitly grab the input at the first click in the relative mode */
if (button->button == 1 && button->type == GDK_BUTTON_PRESS &&
- !qemu_input_is_absolute() && !gd_is_grab_active(s)) {
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
- TRUE);
+ !qemu_input_is_absolute() && s->ptr_owner != vc) {
+ gd_ungrab_pointer(s);
+ if (!vc->window) {
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
+ TRUE);
+ } else {
+ gd_grab_pointer(vc);
+ gd_update_caption(s);
+ }
return TRUE;
}
@@ -690,7 +850,8 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
return TRUE;
}
- qemu_input_queue_btn(s->dcl.con, btn, button->type == GDK_BUTTON_PRESS);
+ qemu_input_queue_btn(vc->gfx.dcl.con, btn,
+ button->type == GDK_BUTTON_PRESS);
qemu_input_event_sync();
return TRUE;
}
@@ -698,7 +859,7 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll,
void *opaque)
{
- GtkDisplayState *s = opaque;
+ VirtualConsole *vc = opaque;
InputButton btn;
if (scroll->direction == GDK_SCROLL_UP) {
@@ -709,16 +870,17 @@ static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll,
return TRUE;
}
- qemu_input_queue_btn(s->dcl.con, btn, true);
+ qemu_input_queue_btn(vc->gfx.dcl.con, btn, true);
qemu_input_event_sync();
- qemu_input_queue_btn(s->dcl.con, btn, false);
+ qemu_input_queue_btn(vc->gfx.dcl.con, btn, false);
qemu_input_event_sync();
return TRUE;
}
static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
{
- GtkDisplayState *s = opaque;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
int gdk_keycode = key->hardware_keycode;
int i;
@@ -737,7 +899,11 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
} else if (gdk_keycode < 97) {
qemu_keycode = gdk_keycode - 8;
} else if (gdk_keycode < 158) {
- qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+ if (s->has_evdev) {
+ qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+ } else {
+ qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
+ }
} else if (gdk_keycode == 208) { /* Hiragana_Katakana */
qemu_keycode = 0x70;
} else if (gdk_keycode == 211) { /* backslash */
@@ -747,7 +913,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
}
#endif
- trace_gd_key_event(gdk_keycode, qemu_keycode,
+ trace_gd_key_event(vc->label, gdk_keycode, qemu_keycode,
(key->type == GDK_KEY_PRESS) ? "down" : "up");
for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) {
@@ -756,7 +922,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
}
}
- qemu_input_event_send_key_number(s->dcl.con, qemu_keycode,
+ qemu_input_event_send_key_number(vc->gfx.dcl.con, qemu_keycode,
key->type == GDK_KEY_PRESS);
return TRUE;
@@ -804,19 +970,14 @@ static void gd_menu_quit(GtkMenuItem *item, void *opaque)
static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_by_menu(s);
+ gint page;
- if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->vga_item))) {
- gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), 0);
- } 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);
- break;
- }
- }
+ 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);
}
}
@@ -831,94 +992,159 @@ static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque)
}
}
+static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event,
+ void *opaque)
+{
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
+
+ gtk_widget_set_sensitive(vc->menu_item, true);
+ gtk_widget_reparent(vc->tab_item, s->notebook);
+ gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(s->notebook),
+ vc->tab_item, vc->label);
+ gtk_widget_destroy(vc->window);
+ vc->window = NULL;
+ return TRUE;
+}
+
+static gboolean gd_win_grab(void *opaque)
+{
+ VirtualConsole *vc = opaque;
+
+ fprintf(stderr, "%s: %s\n", __func__, vc->label);
+ if (vc->s->ptr_owner) {
+ gd_ungrab_pointer(vc->s);
+ } else {
+ gd_grab_pointer(vc);
+ }
+ gd_update_caption(vc->s);
+ return TRUE;
+}
+
+static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
+{
+ GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
+
+ if (vc->type == GD_VC_GFX) {
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
+ FALSE);
+ }
+ if (!vc->window) {
+ gtk_widget_set_sensitive(vc->menu_item, false);
+ vc->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_reparent(vc->tab_item, vc->window);
+
+ g_signal_connect(vc->window, "delete-event",
+ G_CALLBACK(gd_tab_window_close), vc);
+ gtk_widget_show_all(vc->window);
+
+ GtkAccelGroup *ag = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
+
+ GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab), vc, NULL);
+ gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
+
+ gd_update_geometry_hints(vc);
+ gd_update_caption(s);
+ }
+}
+
static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
if (!s->full_screen) {
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
gtk_widget_set_size_request(s->menu_bar, 0, 0);
- gtk_widget_set_size_request(s->drawing_area, -1, -1);
- gtk_window_fullscreen(GTK_WINDOW(s->window));
- if (gd_on_vga(s)) {
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), TRUE);
+ if (vc->type == GD_VC_GFX) {
+ gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
+ TRUE);
}
+ gtk_window_fullscreen(GTK_WINDOW(s->window));
s->full_screen = TRUE;
} else {
gtk_window_unfullscreen(GTK_WINDOW(s->window));
gd_menu_show_tabs(GTK_MENU_ITEM(s->show_tabs_item), s);
gtk_widget_set_size_request(s->menu_bar, -1, -1);
- gtk_widget_set_size_request(s->drawing_area,
- surface_width(s->ds),
- surface_height(s->ds));
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), FALSE);
s->full_screen = FALSE;
- s->scale_x = 1.0;
- s->scale_y = 1.0;
+ if (vc->type == GD_VC_GFX) {
+ vc->gfx.scale_x = 1.0;
+ vc->gfx.scale_y = 1.0;
+ gd_update_windowsize(vc);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
+ FALSE);
+ }
}
- gd_update_cursor(s, FALSE);
+ gd_update_cursor(vc);
}
static void gd_menu_zoom_in(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
FALSE);
- s->scale_x += .25;
- s->scale_y += .25;
+ vc->gfx.scale_x += VC_SCALE_STEP;
+ vc->gfx.scale_y += VC_SCALE_STEP;
- gd_update_windowsize(s);
+ gd_update_windowsize(vc);
}
static void gd_menu_zoom_out(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
FALSE);
- s->scale_x -= .25;
- s->scale_y -= .25;
+ vc->gfx.scale_x -= VC_SCALE_STEP;
+ vc->gfx.scale_y -= VC_SCALE_STEP;
- s->scale_x = MAX(s->scale_x, .25);
- s->scale_y = MAX(s->scale_y, .25);
+ vc->gfx.scale_x = MAX(vc->gfx.scale_x, VC_SCALE_MIN);
+ vc->gfx.scale_y = MAX(vc->gfx.scale_y, VC_SCALE_MIN);
- gd_update_windowsize(s);
+ gd_update_windowsize(vc);
}
static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
- s->scale_x = 1.0;
- s->scale_y = 1.0;
+ vc->gfx.scale_x = 1.0;
+ vc->gfx.scale_y = 1.0;
- gd_update_windowsize(s);
+ gd_update_windowsize(vc);
}
static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item))) {
s->free_scale = TRUE;
} else {
s->free_scale = FALSE;
- s->scale_x = 1.0;
- s->scale_y = 1.0;
- gd_update_windowsize(s);
+ vc->gfx.scale_x = 1.0;
+ vc->gfx.scale_y = 1.0;
}
- gd_update_full_redraw(s);
+ gd_update_windowsize(vc);
+ gd_update_full_redraw(vc);
}
-static void gd_grab_keyboard(GtkDisplayState *s)
+static void gd_grab_keyboard(VirtualConsole *vc)
{
#if GTK_CHECK_VERSION(3, 0, 0)
- GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
+ GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
GList *devices = gdk_device_manager_list_devices(mgr,
GDK_DEVICE_TYPE_MASTER);
@@ -927,7 +1153,7 @@ static void gd_grab_keyboard(GtkDisplayState *s)
GdkDevice *dev = tmp->data;
if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) {
gdk_device_grab(dev,
- gtk_widget_get_window(s->drawing_area),
+ gtk_widget_get_window(vc->gfx.drawing_area),
GDK_OWNERSHIP_NONE,
FALSE,
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
@@ -938,16 +1164,25 @@ static void gd_grab_keyboard(GtkDisplayState *s)
}
g_list_free(devices);
#else
- gdk_keyboard_grab(gtk_widget_get_window(s->drawing_area),
+ gdk_keyboard_grab(gtk_widget_get_window(vc->gfx.drawing_area),
FALSE,
GDK_CURRENT_TIME);
#endif
+ vc->s->kbd_owner = vc;
+ trace_gd_grab(vc->label, "kbd", true);
}
static void gd_ungrab_keyboard(GtkDisplayState *s)
{
+ VirtualConsole *vc = s->kbd_owner;
+
+ if (vc == NULL) {
+ return;
+ }
+ s->kbd_owner = NULL;
+
#if GTK_CHECK_VERSION(3, 0, 0)
- GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
+ GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
GList *devices = gdk_device_manager_list_devices(mgr,
GDK_DEVICE_TYPE_MASTER);
@@ -964,11 +1199,12 @@ static void gd_ungrab_keyboard(GtkDisplayState *s)
#else
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
#endif
+ trace_gd_grab(vc->label, "kbd", false);
}
-static void gd_grab_pointer(GtkDisplayState *s)
+static void gd_grab_pointer(VirtualConsole *vc)
{
- GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
+ GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
#if GTK_CHECK_VERSION(3, 0, 0)
GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
GList *devices = gdk_device_manager_list_devices(mgr,
@@ -978,7 +1214,7 @@ static void gd_grab_pointer(GtkDisplayState *s)
GdkDevice *dev = tmp->data;
if (gdk_device_get_source(dev) == GDK_SOURCE_MOUSE) {
gdk_device_grab(dev,
- gtk_widget_get_window(s->drawing_area),
+ gtk_widget_get_window(vc->gfx.drawing_area),
GDK_OWNERSHIP_NONE,
FALSE, /* All events to come to our
window directly */
@@ -987,16 +1223,16 @@ static void gd_grab_pointer(GtkDisplayState *s)
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON_MOTION_MASK |
GDK_SCROLL_MASK,
- s->null_cursor,
+ vc->s->null_cursor,
GDK_CURRENT_TIME);
}
tmp = tmp->next;
}
g_list_free(devices);
gdk_device_get_position(gdk_device_manager_get_client_pointer(mgr),
- NULL, &s->grab_x_root, &s->grab_y_root);
+ NULL, &vc->s->grab_x_root, &vc->s->grab_y_root);
#else
- gdk_pointer_grab(gtk_widget_get_window(s->drawing_area),
+ gdk_pointer_grab(gtk_widget_get_window(vc->gfx.drawing_area),
FALSE, /* All events to come to our window directly */
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
@@ -1004,16 +1240,25 @@ static void gd_grab_pointer(GtkDisplayState *s)
GDK_BUTTON_MOTION_MASK |
GDK_SCROLL_MASK,
NULL, /* Allow cursor to move over entire desktop */
- s->null_cursor,
+ vc->s->null_cursor,
GDK_CURRENT_TIME);
gdk_display_get_pointer(display, NULL,
- &s->grab_x_root, &s->grab_y_root, NULL);
+ &vc->s->grab_x_root, &vc->s->grab_y_root, NULL);
#endif
+ vc->s->ptr_owner = vc;
+ trace_gd_grab(vc->label, "ptr", true);
}
static void gd_ungrab_pointer(GtkDisplayState *s)
{
- GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
+ VirtualConsole *vc = s->ptr_owner;
+
+ if (vc == NULL) {
+ return;
+ }
+ s->ptr_owner = NULL;
+
+ GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
#if GTK_CHECK_VERSION(3, 0, 0)
GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
GList *devices = gdk_device_manager_list_devices(mgr,
@@ -1029,51 +1274,65 @@ static void gd_ungrab_pointer(GtkDisplayState *s)
}
g_list_free(devices);
gdk_device_warp(gdk_device_manager_get_client_pointer(mgr),
- gtk_widget_get_screen(s->drawing_area),
- s->grab_x_root, s->grab_y_root);
+ gtk_widget_get_screen(vc->gfx.drawing_area),
+ vc->s->grab_x_root, vc->s->grab_y_root);
#else
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gdk_display_warp_pointer(display,
- gtk_widget_get_screen(s->drawing_area),
- s->grab_x_root, s->grab_y_root);
+ gtk_widget_get_screen(vc->gfx.drawing_area),
+ vc->s->grab_x_root, vc->s->grab_y_root);
#endif
+ trace_gd_grab(vc->label, "ptr", false);
}
static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
{
GtkDisplayState *s = opaque;
+ VirtualConsole *vc = gd_vc_find_current(s);
if (gd_is_grab_active(s)) {
- gd_grab_keyboard(s);
- gd_grab_pointer(s);
+ if (!gd_grab_on_hover(s)) {
+ gd_grab_keyboard(vc);
+ }
+ gd_grab_pointer(vc);
} else {
gd_ungrab_keyboard(s);
gd_ungrab_pointer(s);
}
gd_update_caption(s);
- gd_update_cursor(s, FALSE);
+ gd_update_cursor(vc);
}
static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
gpointer data)
{
GtkDisplayState *s = data;
- guint last_page;
+ VirtualConsole *vc;
gboolean on_vga;
if (!gtk_widget_get_realized(s->notebook)) {
return;
}
- last_page = gtk_notebook_get_current_page(nb);
-
- if (last_page) {
- gtk_widget_set_size_request(s->vc[last_page - 1].terminal, -1, -1);
+#ifdef VTE_RESIZE_HACK
+ vc = gd_vc_find_current(s);
+ if (vc && vc->type == GD_VC_VTE) {
+ gtk_widget_hide(vc->vte.terminal);
}
-
- on_vga = arg2 == 0;
-
+#endif
+ vc = gd_vc_find_by_page(s, arg2);
+ if (!vc) {
+ return;
+ }
+#ifdef VTE_RESIZE_HACK
+ if (vc->type == GD_VC_VTE) {
+ gtk_widget_show(vc->vte.terminal);
+ }
+#endif
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item),
+ TRUE);
+ on_vga = (vc->type == GD_VC_GFX);
if (!on_vga) {
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
FALSE);
@@ -1081,71 +1340,88 @@ static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
TRUE);
}
-
- if (arg2 == 0) {
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->vga_item), TRUE);
- } else {
-#if defined(CONFIG_VTE)
- VirtualConsole *vc = &s->vc[arg2 - 1];
- VteTerminal *term = VTE_TERMINAL(vc->terminal);
- int width, height;
-
- width = 80 * vte_terminal_get_char_width(term);
- height = 25 * vte_terminal_get_char_height(term);
-
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE);
- gtk_widget_set_size_request(vc->terminal, width, height);
-#else
- g_assert_not_reached();
-#endif
- }
-
gtk_widget_set_sensitive(s->grab_item, on_vga);
- gd_update_cursor(s, TRUE);
+ gd_update_windowsize(vc);
+ gd_update_cursor(vc);
}
-static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing, gpointer data)
+static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing,
+ gpointer opaque)
{
- GtkDisplayState *s = data;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
- if (!gd_is_grab_active(s) && gd_grab_on_hover(s)) {
- gd_grab_keyboard(s);
+ if (gd_grab_on_hover(s)) {
+ gd_ungrab_keyboard(s);
+ gd_grab_keyboard(vc);
+ gd_update_caption(s);
}
-
return TRUE;
}
-static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing, gpointer data)
+static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing,
+ gpointer opaque)
{
- GtkDisplayState *s = data;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
- if (!gd_is_grab_active(s) && gd_grab_on_hover(s)) {
+ if (gd_grab_on_hover(s)) {
gd_ungrab_keyboard(s);
+ gd_update_caption(s);
}
-
return TRUE;
}
static gboolean gd_focus_out_event(GtkWidget *widget,
- GdkEventCrossing *crossing, gpointer data)
+ GdkEventCrossing *crossing, gpointer opaque)
{
- GtkDisplayState *s = data;
+ VirtualConsole *vc = opaque;
+ GtkDisplayState *s = vc->s;
gtk_release_modifiers(s);
-
return TRUE;
}
/** Virtual Console Callbacks **/
-static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
+static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
+ int idx, GSList *group, GtkWidget *view_menu)
{
+ char path[32];
+
+ snprintf(path, sizeof(path), "<QEMU>/View/VC%d", idx);
+
+ vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, vc->label);
+ group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
+ gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc->menu_item), path);
+ gtk_accel_map_add_entry(path, GDK_KEY_1 + idx, HOTKEY_MODIFIERS);
+
+ g_signal_connect(vc->menu_item, "activate",
+ G_CALLBACK(gd_menu_switch_vc), s);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
+
+ return group;
+}
+
#if defined(CONFIG_VTE)
+static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
+{
+ VirtualConsole *vc = opaque;
+
+ if (gtk_adjustment_get_upper(adjustment) >
+ gtk_adjustment_get_page_size(adjustment)) {
+ gtk_widget_show(vc->vte.scrollbar);
+ } else {
+ gtk_widget_hide(vc->vte.scrollbar);
+ }
+}
+
+static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
+{
VirtualConsole *vc = chr->opaque;
- vte_terminal_feed(VTE_TERMINAL(vc->terminal), (const char *)buf, len);
-#endif
+ vte_terminal_feed(VTE_TERMINAL(vc->vte.terminal), (const char *)buf, len);
return len;
}
@@ -1166,115 +1442,132 @@ static CharDriverState *gd_vc_handler(ChardevVC *unused)
return chr;
}
-void early_gtk_display_init(void)
-{
- register_vc_handler(gd_vc_handler);
-}
-
-#if defined(CONFIG_VTE)
static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
gpointer user_data)
{
VirtualConsole *vc = user_data;
- qemu_chr_be_write(vc->chr, (uint8_t *)text, (unsigned int)size);
+ qemu_chr_be_write(vc->vte.chr, (uint8_t *)text, (unsigned int)size);
return TRUE;
}
-#endif
-static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSList *group,
- GtkWidget *view_menu)
+static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
+ CharDriverState *chr, int idx,
+ GSList *group, GtkWidget *view_menu)
{
-#if defined(CONFIG_VTE)
- const char *label;
char buffer[32];
- char path[32];
- GtkWidget *scrolled_window;
+ GtkWidget *box;
+ GtkWidget *scrollbar;
GtkAdjustment *vadjustment;
- snprintf(buffer, sizeof(buffer), "vc%d", index);
- snprintf(path, sizeof(path), "<QEMU>/View/VC%d", index);
-
- vc->chr = vcs[index];
-
- if (vc->chr->label) {
- label = vc->chr->label;
- } else {
- label = buffer;
- }
+ vc->s = s;
+ vc->vte.chr = chr;
- vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, label);
- group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
- gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc->menu_item), path);
- gtk_accel_map_add_entry(path, GDK_KEY_2 + index, HOTKEY_MODIFIERS);
+ snprintf(buffer, sizeof(buffer), "vc%d", idx);
+ vc->label = g_strdup_printf("%s", vc->vte.chr->label
+ ? vc->vte.chr->label : buffer);
+ group = gd_vc_menu_init(s, vc, idx, group, view_menu);
- vc->terminal = vte_terminal_new();
- g_signal_connect(vc->terminal, "commit", G_CALLBACK(gd_vc_in), vc);
+ vc->vte.terminal = vte_terminal_new();
+ g_signal_connect(vc->vte.terminal, "commit", G_CALLBACK(gd_vc_in), vc);
- vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->terminal), -1);
+ vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->vte.terminal), -1);
+ vte_terminal_set_size(VTE_TERMINAL(vc->vte.terminal),
+ VC_TERM_X_MIN, VC_TERM_Y_MIN);
#if VTE_CHECK_VERSION(0, 28, 0) && GTK_CHECK_VERSION(3, 0, 0)
- vadjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vc->terminal));
+ vadjustment = gtk_scrollable_get_vadjustment
+ (GTK_SCROLLABLE(vc->vte.terminal));
#else
- vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->terminal));
+ vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->vte.terminal));
#endif
- scrolled_window = gtk_scrolled_window_new(NULL, vadjustment);
- gtk_container_add(GTK_CONTAINER(scrolled_window), vc->terminal);
-
- vte_terminal_set_size(VTE_TERMINAL(vc->terminal), 80, 25);
+#if GTK_CHECK_VERSION(3, 0, 0)
+ box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
+ scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, vadjustment);
+#else
+ box = gtk_hbox_new(false, 2);
+ scrollbar = gtk_vscrollbar_new(vadjustment);
+#endif
- vc->chr->opaque = vc;
- vc->scrolled_window = scrolled_window;
+ gtk_box_pack_start(GTK_BOX(box), vc->vte.terminal, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(box), scrollbar, FALSE, FALSE, 0);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vc->scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ vc->vte.chr->opaque = vc;
+ vc->vte.box = box;
+ vc->vte.scrollbar = scrollbar;
- gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), scrolled_window, gtk_label_new(label));
- g_signal_connect(vc->menu_item, "activate",
- G_CALLBACK(gd_menu_switch_vc), s);
+ g_signal_connect(vadjustment, "changed",
+ G_CALLBACK(gd_vc_adjustment_changed), vc);
- gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
+ vc->type = GD_VC_VTE;
+ vc->tab_item = box;
+ gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), vc->tab_item,
+ gtk_label_new(vc->label));
- qemu_chr_be_generic_open(vc->chr);
- if (vc->chr->init) {
- vc->chr->init(vc->chr);
+ qemu_chr_be_generic_open(vc->vte.chr);
+ if (vc->vte.chr->init) {
+ vc->vte.chr->init(vc->vte.chr);
}
-#endif /* CONFIG_VTE */
return group;
}
+static void gd_vcs_init(GtkDisplayState *s, GSList *group,
+ GtkWidget *view_menu)
+{
+ int i;
+
+ for (i = 0; i < nb_vcs; i++) {
+ VirtualConsole *vc = &s->vc[s->nb_vcs];
+ group = gd_vc_vte_init(s, vc, vcs[i], s->nb_vcs, group, view_menu);
+ s->nb_vcs++;
+ }
+}
+#endif /* CONFIG_VTE */
+
/** Window Creation **/
+static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
+{
+#if GTK_CHECK_VERSION(3, 0, 0)
+ g_signal_connect(vc->gfx.drawing_area, "draw",
+ G_CALLBACK(gd_draw_event), vc);
+#else
+ g_signal_connect(vc->gfx.drawing_area, "expose-event",
+ G_CALLBACK(gd_expose_event), vc);
+#endif
+ g_signal_connect(vc->gfx.drawing_area, "event",
+ G_CALLBACK(gd_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "button-press-event",
+ G_CALLBACK(gd_button_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "button-release-event",
+ G_CALLBACK(gd_button_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "scroll-event",
+ G_CALLBACK(gd_scroll_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "key-press-event",
+ G_CALLBACK(gd_key_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "key-release-event",
+ G_CALLBACK(gd_key_event), vc);
+
+ g_signal_connect(vc->gfx.drawing_area, "enter-notify-event",
+ G_CALLBACK(gd_enter_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "leave-notify-event",
+ G_CALLBACK(gd_leave_event), vc);
+ g_signal_connect(vc->gfx.drawing_area, "focus-out-event",
+ G_CALLBACK(gd_focus_out_event), vc);
+}
+
static void gd_connect_signals(GtkDisplayState *s)
{
g_signal_connect(s->show_tabs_item, "activate",
G_CALLBACK(gd_menu_show_tabs), s);
+ g_signal_connect(s->untabify_item, "activate",
+ G_CALLBACK(gd_menu_untabify), s);
g_signal_connect(s->window, "delete-event",
G_CALLBACK(gd_window_close), s);
-#if GTK_CHECK_VERSION(3, 0, 0)
- g_signal_connect(s->drawing_area, "draw",
- G_CALLBACK(gd_draw_event), s);
-#else
- g_signal_connect(s->drawing_area, "expose-event",
- G_CALLBACK(gd_expose_event), s);
-#endif
- g_signal_connect(s->drawing_area, "event",
- G_CALLBACK(gd_event), s);
- g_signal_connect(s->drawing_area, "button-press-event",
- G_CALLBACK(gd_button_event), s);
- g_signal_connect(s->drawing_area, "button-release-event",
- G_CALLBACK(gd_button_event), s);
- g_signal_connect(s->drawing_area, "scroll-event",
- G_CALLBACK(gd_scroll_event), s);
- g_signal_connect(s->drawing_area, "key-press-event",
- G_CALLBACK(gd_key_event), s);
- g_signal_connect(s->drawing_area, "key-release-event",
- G_CALLBACK(gd_key_event), s);
-
g_signal_connect(s->pause_item, "activate",
G_CALLBACK(gd_menu_pause), s);
g_signal_connect(s->reset_item, "activate",
@@ -1293,18 +1586,10 @@ static void gd_connect_signals(GtkDisplayState *s)
G_CALLBACK(gd_menu_zoom_fixed), s);
g_signal_connect(s->zoom_fit_item, "activate",
G_CALLBACK(gd_menu_zoom_fit), s);
- g_signal_connect(s->vga_item, "activate",
- G_CALLBACK(gd_menu_switch_vc), s);
g_signal_connect(s->grab_item, "activate",
G_CALLBACK(gd_menu_grab_input), s);
g_signal_connect(s->notebook, "switch-page",
G_CALLBACK(gd_change_page), s);
- g_signal_connect(s->drawing_area, "enter-notify-event",
- 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 GtkWidget *gd_create_menu_machine(GtkDisplayState *s, GtkAccelGroup *accel_group)
@@ -1340,12 +1625,68 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayState *s, GtkAccelGroup *acce
return machine_menu;
}
+static const DisplayChangeListenerOps dcl_ops = {
+ .dpy_name = "gtk",
+ .dpy_gfx_update = gd_update,
+ .dpy_gfx_switch = gd_switch,
+ .dpy_refresh = gd_refresh,
+ .dpy_mouse_set = gd_mouse_set,
+ .dpy_cursor_define = gd_cursor_define,
+};
+
+static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
+ QemuConsole *con, int idx,
+ GSList *group, GtkWidget *view_menu)
+{
+ Error *local_err = NULL;
+ Object *obj;
+
+ obj = object_property_get_link(OBJECT(con), "device", &local_err);
+ if (obj) {
+ vc->label = g_strdup_printf("%s", object_get_typename(obj));
+ } else {
+ vc->label = g_strdup_printf("VGA");
+ }
+
+ vc->s = s;
+ vc->gfx.scale_x = 1.0;
+ vc->gfx.scale_y = 1.0;
+
+ vc->gfx.drawing_area = gtk_drawing_area_new();
+ gtk_widget_add_events(vc->gfx.drawing_area,
+ GDK_POINTER_MOTION_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_BUTTON_MOTION_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK |
+ GDK_SCROLL_MASK |
+ GDK_KEY_PRESS_MASK);
+ gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
+ gtk_widget_set_can_focus(vc->gfx.drawing_area, TRUE);
+
+ vc->type = GD_VC_GFX;
+ vc->tab_item = vc->gfx.drawing_area;
+ gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook),
+ vc->tab_item, gtk_label_new(vc->label));
+ gd_connect_vc_gfx_signals(vc);
+
+ group = gd_vc_menu_init(s, vc, idx, group, view_menu);
+
+ vc->gfx.dcl.ops = &dcl_ops;
+ vc->gfx.dcl.con = con;
+ register_displaychangelistener(&vc->gfx.dcl);
+
+ return group;
+}
+
static GtkWidget *gd_create_menu_view(GtkDisplayState *s, GtkAccelGroup *accel_group)
{
GSList *group = NULL;
GtkWidget *view_menu;
GtkWidget *separator;
- int i;
+ QemuConsole *con;
+ int vc;
view_menu = gtk_menu_new();
gtk_menu_set_accel_group(GTK_MENU(view_menu), accel_group);
@@ -1400,26 +1741,31 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s, GtkAccelGroup *accel_g
separator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
- s->vga_item = gtk_radio_menu_item_new_with_mnemonic(group, "_VGA");
- group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(s->vga_item));
- gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->vga_item),
- "<QEMU>/View/VGA");
- gtk_accel_map_add_entry("<QEMU>/View/VGA", GDK_KEY_1, HOTKEY_MODIFIERS);
- gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->vga_item);
-
- for (i = 0; i < nb_vcs; i++) {
- VirtualConsole *vc = &s->vc[i];
-
- group = gd_vc_init(s, vc, i, group, view_menu);
+ /* gfx */
+ for (vc = 0;; vc++) {
+ con = qemu_console_lookup_by_index(vc);
+ if (!con || !qemu_console_is_graphic(con)) {
+ break;
+ }
+ group = gd_vc_gfx_init(s, &s->vc[vc], con,
+ vc, group, view_menu);
s->nb_vcs++;
}
+#if defined(CONFIG_VTE)
+ /* vte */
+ gd_vcs_init(s, group, view_menu);
+#endif
+
separator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
s->show_tabs_item = gtk_check_menu_item_new_with_mnemonic(_("Show _Tabs"));
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->show_tabs_item);
+ s->untabify_item = gtk_menu_item_new_with_mnemonic(_("Detach Tab"));
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->untabify_item);
+
return view_menu;
}
@@ -1445,14 +1791,28 @@ static void gd_create_menus(GtkDisplayState *s)
s->accel_group = accel_group;
}
-static const DisplayChangeListenerOps dcl_ops = {
- .dpy_name = "gtk",
- .dpy_gfx_update = gd_update,
- .dpy_gfx_switch = gd_switch,
- .dpy_refresh = gd_refresh,
- .dpy_mouse_set = gd_mouse_set,
- .dpy_cursor_define = gd_cursor_define,
-};
+static void gd_set_keycode_type(GtkDisplayState *s)
+{
+#ifndef _WIN32
+ char *keycodes = NULL;
+ GdkDisplay *display = gtk_widget_get_display(s->window);
+ Display *x11_display = gdk_x11_display_get_xdisplay(display);
+ XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask,
+ XkbUseCoreKbd);
+
+ if (desc && desc->names) {
+ keycodes = XGetAtomName(x11_display, desc->names->keycodes);
+ }
+ if (keycodes == NULL) {
+ fprintf(stderr, "could not lookup keycode name\n");
+ } else if (strstart(keycodes, "evdev", NULL)) {
+ s->has_evdev = true;
+ } else if (!strstart(keycodes, "xfree86", NULL)) {
+ fprintf(stderr, "unknown keycodes `%s', please report to "
+ "qemu-devel@nongnu.org\n", keycodes);
+ }
+#endif
+}
void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
{
@@ -1461,9 +1821,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
gtk_init(NULL, NULL);
- s->dcl.ops = &dcl_ops;
- s->dcl.con = qemu_console_lookup_by_index(0);
-
s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
#if GTK_CHECK_VERSION(3, 2, 0)
s->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -1471,11 +1828,8 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
s->vbox = gtk_vbox_new(FALSE, 0);
#endif
s->notebook = gtk_notebook_new();
- s->drawing_area = gtk_drawing_area_new();
s->menu_bar = gtk_menu_bar_new();
- s->scale_x = 1.0;
- s->scale_y = 1.0;
s->free_scale = FALSE;
setlocale(LC_ALL, "");
@@ -1488,8 +1842,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier);
qemu_add_vm_change_state_handler(gd_change_runstate, s);
- gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), s->drawing_area, gtk_label_new("VGA"));
-
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu_logo_no_text.svg");
if (filename) {
GError *error = NULL;
@@ -1506,18 +1858,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
gd_connect_signals(s);
- gtk_widget_add_events(s->drawing_area,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_MOTION_MASK |
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK |
- GDK_SCROLL_MASK |
- GDK_KEY_PRESS_MASK);
- gtk_widget_set_double_buffered(s->drawing_area, FALSE);
- gtk_widget_set_can_focus(s->drawing_area, TRUE);
-
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
gtk_notebook_set_show_border(GTK_NOTEBOOK(s->notebook), FALSE);
@@ -1530,6 +1870,21 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
gtk_widget_show_all(s->window);
+#ifdef VTE_RESIZE_HACK
+ {
+ VirtualConsole *cur = gd_vc_find_current(s);
+ int i;
+
+ for (i = 0; i < s->nb_vcs; i++) {
+ VirtualConsole *vc = &s->vc[i];
+ if (vc && vc->type == GD_VC_VTE && vc != cur) {
+ gtk_widget_hide(vc->vte.terminal);
+ }
+ }
+ gd_update_windowsize(cur);
+ }
+#endif
+
if (full_screen) {
gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
}
@@ -1537,7 +1892,12 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_on_hover_item));
}
- register_displaychangelistener(&s->dcl);
+ gd_set_keycode_type(s);
+}
- global_state = s;
+void early_gtk_display_init(void)
+{
+#if defined(CONFIG_VTE)
+ register_vc_handler(gd_vc_handler);
+#endif
}