2013-02-20 14:43:20 +01:00
|
|
|
/*
|
|
|
|
* GTK UI
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
2019-02-21 07:51:42 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-02-20 14:43:20 +01:00
|
|
|
*
|
2019-02-21 07:51:42 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Portions from gtk-vnc (originally licensed under the LGPL v2+):
|
2013-02-20 14:43:20 +01:00
|
|
|
*
|
|
|
|
* GTK VNC Widget
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
|
|
|
|
* Copyright (C) 2009-2010 Daniel P. Berrange <dan@berrange.com>
|
|
|
|
*/
|
|
|
|
|
2013-02-20 14:43:24 +01:00
|
|
|
#define GETTEXT_PACKAGE "qemu"
|
|
|
|
#define LOCALEDIR "po"
|
|
|
|
|
2016-01-29 18:49:51 +01:00
|
|
|
#include "qemu/osdep.h"
|
2018-02-01 12:18:31 +01:00
|
|
|
#include "qapi/error.h"
|
2020-01-29 11:22:37 +01:00
|
|
|
#include "qapi/qapi-commands-control.h"
|
2018-02-27 00:13:27 +01:00
|
|
|
#include "qapi/qapi-commands-misc.h"
|
2016-03-20 18:16:19 +01:00
|
|
|
#include "qemu/cutils.h"
|
2013-02-22 21:08:51 +01:00
|
|
|
|
2015-03-04 15:37:27 +01:00
|
|
|
#include "ui/console.h"
|
|
|
|
#include "ui/gtk.h"
|
2020-05-16 09:20:05 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <gdk/gdkwin32.h>
|
|
|
|
#endif
|
|
|
|
#include "ui/win32-kbd-hook.h"
|
2013-02-22 21:08:51 +01:00
|
|
|
|
2013-02-20 14:43:24 +01:00
|
|
|
#include <glib/gi18n.h>
|
2013-02-22 07:28:01 +01:00
|
|
|
#include <locale.h>
|
2014-02-19 07:04:34 +01:00
|
|
|
#if defined(CONFIG_VTE)
|
2013-02-20 14:43:20 +01:00
|
|
|
#include <vte/vte.h>
|
2014-02-19 07:04:34 +01:00
|
|
|
#endif
|
2013-02-20 14:43:20 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2013-11-10 16:24:02 +01:00
|
|
|
#include "trace.h"
|
2020-08-18 11:59:27 +02:00
|
|
|
#include "qemu/cutils.h"
|
2013-11-28 11:40:27 +01:00
|
|
|
#include "ui/input.h"
|
2019-08-12 07:23:59 +02:00
|
|
|
#include "sysemu/runstate.h"
|
2013-02-20 14:43:20 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "keymaps.h"
|
2017-01-26 14:19:46 +01:00
|
|
|
#include "chardev/char.h"
|
2014-05-05 14:36:56 +02:00
|
|
|
#include "qom/object.h"
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-02-20 14:43:21 +01:00
|
|
|
#define MAX_VCS 10
|
2014-05-16 12:26:12 +02:00
|
|
|
#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
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2018-01-17 17:47:15 +01:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
2018-05-03 21:51:00 +02:00
|
|
|
#include "x_keymap.h"
|
2018-01-17 17:47:15 +01:00
|
|
|
|
|
|
|
/* Gtk2 compat */
|
|
|
|
#ifndef GDK_IS_X11_DISPLAY
|
|
|
|
#define GDK_IS_X11_DISPLAY(dpy) (dpy != NULL)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
/* Gtk2 compat */
|
|
|
|
#ifndef GDK_IS_WAYLAND_DISPLAY
|
|
|
|
#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy != NULL)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
/* Gtk2 compat */
|
|
|
|
#ifndef GDK_IS_WIN32_DISPLAY
|
|
|
|
#define GDK_IS_WIN32_DISPLAY(dpy) (dpy != NULL)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
|
|
|
/* Gtk2 compat */
|
|
|
|
#ifndef GDK_IS_BROADWAY_DISPLAY
|
|
|
|
#define GDK_IS_BROADWAY_DISPLAY(dpy) (dpy != NULL)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_QUARTZ
|
|
|
|
/* Gtk2 compat */
|
|
|
|
#ifndef GDK_IS_QUARTZ_DISPLAY
|
|
|
|
#define GDK_IS_QUARTZ_DISPLAY(dpy) (dpy != NULL)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-02-19 07:04:34 +01:00
|
|
|
#if !defined(CONFIG_VTE)
|
|
|
|
# define VTE_CHECK_VERSION(a, b, c) 0
|
|
|
|
#endif
|
2013-02-25 16:20:34 +01:00
|
|
|
|
2013-07-22 09:04:32 +02:00
|
|
|
#define HOTKEY_MODIFIERS (GDK_CONTROL_MASK | GDK_MOD1_MASK)
|
|
|
|
|
2018-01-17 17:47:15 +01:00
|
|
|
static const guint16 *keycode_map;
|
|
|
|
static size_t keycode_maplen;
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
struct GtkDisplayState {
|
2013-02-20 14:43:20 +01:00
|
|
|
GtkWidget *window;
|
|
|
|
|
|
|
|
GtkWidget *menu_bar;
|
|
|
|
|
2013-02-20 14:43:26 +01:00
|
|
|
GtkAccelGroup *accel_group;
|
|
|
|
|
2013-02-22 20:53:33 +01:00
|
|
|
GtkWidget *machine_menu_item;
|
|
|
|
GtkWidget *machine_menu;
|
|
|
|
GtkWidget *pause_item;
|
|
|
|
GtkWidget *reset_item;
|
|
|
|
GtkWidget *powerdown_item;
|
2013-02-20 14:43:20 +01:00
|
|
|
GtkWidget *quit_item;
|
|
|
|
|
|
|
|
GtkWidget *view_menu_item;
|
|
|
|
GtkWidget *view_menu;
|
2013-02-20 14:43:23 +01:00
|
|
|
GtkWidget *full_screen_item;
|
2016-04-17 22:25:54 +02:00
|
|
|
GtkWidget *copy_item;
|
2013-02-20 14:43:23 +01:00
|
|
|
GtkWidget *zoom_in_item;
|
|
|
|
GtkWidget *zoom_out_item;
|
|
|
|
GtkWidget *zoom_fixed_item;
|
|
|
|
GtkWidget *zoom_fit_item;
|
2013-02-20 14:43:22 +01:00
|
|
|
GtkWidget *grab_item;
|
|
|
|
GtkWidget *grab_on_hover_item;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-02-20 14:43:21 +01:00
|
|
|
int nb_vcs;
|
|
|
|
VirtualConsole vc[MAX_VCS];
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
GtkWidget *show_tabs_item;
|
2014-05-05 16:23:33 +02:00
|
|
|
GtkWidget *untabify_item;
|
2018-05-11 01:07:38 +02:00
|
|
|
GtkWidget *show_menubar_item;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *notebook;
|
|
|
|
int button_mask;
|
2014-04-04 12:41:22 +02:00
|
|
|
gboolean last_set;
|
2013-02-20 14:43:20 +01:00
|
|
|
int last_x;
|
|
|
|
int last_y;
|
2014-04-04 12:41:23 +02:00
|
|
|
int grab_x_root;
|
|
|
|
int grab_y_root;
|
2014-05-06 11:01:31 +02:00
|
|
|
VirtualConsole *kbd_owner;
|
|
|
|
VirtualConsole *ptr_owner;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
gboolean full_screen;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
GdkCursor *null_cursor;
|
|
|
|
Notifier mouse_mode_notifier;
|
2013-02-20 14:43:23 +01:00
|
|
|
gboolean free_scale;
|
2013-02-22 20:53:33 +01:00
|
|
|
|
|
|
|
bool external_pause_update;
|
2013-03-24 19:10:02 +01:00
|
|
|
|
2018-02-02 12:10:14 +01:00
|
|
|
DisplayOptions *opts;
|
2014-04-30 16:30:07 +02:00
|
|
|
};
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct VCChardev {
|
2016-12-07 14:20:22 +01:00
|
|
|
Chardev parent;
|
2016-10-21 22:44:44 +02:00
|
|
|
VirtualConsole *console;
|
|
|
|
bool echo;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
|
|
|
typedef struct VCChardev VCChardev;
|
2016-10-21 22:44:44 +02:00
|
|
|
|
2016-12-07 16:39:10 +01:00
|
|
|
#define TYPE_CHARDEV_VC "chardev-vc"
|
2020-08-31 23:07:33 +02:00
|
|
|
DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV,
|
|
|
|
TYPE_CHARDEV_VC)
|
2016-12-07 16:39:10 +01:00
|
|
|
|
2018-03-06 10:09:46 +01:00
|
|
|
bool gtk_use_gl_area;
|
|
|
|
|
2015-09-09 10:12:20 +02:00
|
|
|
static void gd_grab_pointer(VirtualConsole *vc, const char *reason);
|
2014-05-06 11:45:30 +02:00
|
|
|
static void gd_ungrab_pointer(GtkDisplayState *s);
|
2015-09-09 10:12:20 +02:00
|
|
|
static void gd_grab_keyboard(VirtualConsole *vc, const char *reason);
|
2015-09-09 09:57:01 +02:00
|
|
|
static void gd_ungrab_keyboard(GtkDisplayState *s);
|
2014-05-06 11:45:30 +02:00
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
/** Utility Functions **/
|
|
|
|
|
2014-04-30 13:53:16 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:22 +01:00
|
|
|
static bool gd_is_grab_active(GtkDisplayState *s)
|
|
|
|
{
|
|
|
|
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_item));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool gd_grab_on_hover(GtkDisplayState *s)
|
|
|
|
{
|
|
|
|
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_on_hover_item));
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
static void gd_update_cursor(VirtualConsole *vc)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
GtkDisplayState *s = vc->s;
|
2013-02-20 14:43:20 +01:00
|
|
|
GdkWindow *window;
|
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
if (vc->type != GD_VC_GFX ||
|
|
|
|
!qemu_console_is_graphic(vc->gfx.dcl.con)) {
|
2014-04-30 16:30:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2015-03-24 20:08:48 +01:00
|
|
|
if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
window = gtk_widget_get_window(GTK_WIDGET(vc->gfx.drawing_area));
|
2014-05-06 11:45:30 +02:00
|
|
|
if (s->full_screen || qemu_input_is_absolute() || s->ptr_owner == vc) {
|
2013-02-20 14:43:20 +01:00
|
|
|
gdk_window_set_cursor(window, s->null_cursor);
|
|
|
|
} else {
|
|
|
|
gdk_window_set_cursor(window, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_update_caption(GtkDisplayState *s)
|
|
|
|
{
|
|
|
|
const char *status = "";
|
2014-05-06 11:20:17 +02:00
|
|
|
gchar *prefix;
|
2013-02-20 14:43:20 +01:00
|
|
|
gchar *title;
|
2013-02-20 14:43:22 +01:00
|
|
|
const char *grab = "";
|
2013-02-22 20:53:33 +01:00
|
|
|
bool is_paused = !runstate_is_running();
|
2014-05-06 11:20:17 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (qemu_name) {
|
|
|
|
prefix = g_strdup_printf("QEMU (%s)", qemu_name);
|
|
|
|
} else {
|
|
|
|
prefix = g_strdup_printf("QEMU");
|
|
|
|
}
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2014-05-06 11:20:17 +02:00
|
|
|
if (s->ptr_owner != NULL &&
|
|
|
|
s->ptr_owner->window == NULL) {
|
2013-04-01 19:12:02 +02:00
|
|
|
grab = _(" - Press Ctrl+Alt+G to release grab");
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-02-22 20:53:33 +01:00
|
|
|
if (is_paused) {
|
2013-04-01 19:12:02 +02:00
|
|
|
status = _(" [Paused]");
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
2013-02-22 20:53:33 +01:00
|
|
|
s->external_pause_update = true;
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->pause_item),
|
|
|
|
is_paused);
|
|
|
|
s->external_pause_update = false;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-05-06 11:20:17 +02:00
|
|
|
title = g_strdup_printf("%s%s%s", prefix, status, grab);
|
2013-02-20 14:43:20 +01:00
|
|
|
gtk_window_set_title(GTK_WINDOW(s->window), title);
|
|
|
|
g_free(title);
|
2014-05-06 11:20:17 +02:00
|
|
|
|
|
|
|
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);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
static void gd_update_geometry_hints(VirtualConsole *vc)
|
2013-02-28 16:10:02 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
GtkDisplayState *s = vc->s;
|
2014-05-16 12:26:12 +02:00
|
|
|
GdkWindowHints mask = 0;
|
|
|
|
GdkGeometry geo = {};
|
|
|
|
GtkWidget *geo_widget = NULL;
|
|
|
|
GtkWindow *geo_window;
|
2014-04-30 16:30:07 +02:00
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
if (vc->type == GD_VC_GFX) {
|
2015-02-27 14:36:09 +01:00
|
|
|
if (!vc->gfx.ds) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-16 12:26:12 +02:00
|
|
|
if (s->free_scale) {
|
|
|
|
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 {
|
|
|
|
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);
|
2013-02-28 16:10:02 +01:00
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
#if defined(CONFIG_VTE)
|
|
|
|
} else if (vc->type == GD_VC_VTE) {
|
|
|
|
VteTerminal *term = VTE_TERMINAL(vc->vte.terminal);
|
2016-05-13 10:20:54 +02:00
|
|
|
GtkBorder padding = { 0 };
|
2014-05-16 12:26:12 +02:00
|
|
|
|
2016-05-06 20:03:13 +02:00
|
|
|
#if VTE_CHECK_VERSION(0, 37, 0)
|
|
|
|
gtk_style_context_get_padding(
|
|
|
|
gtk_widget_get_style_context(vc->vte.terminal),
|
|
|
|
gtk_widget_get_state_flags(vc->vte.terminal),
|
|
|
|
&padding);
|
|
|
|
#else
|
2016-05-13 10:20:54 +02:00
|
|
|
{
|
|
|
|
GtkBorder *ib = NULL;
|
|
|
|
gtk_widget_style_get(vc->vte.terminal, "inner-border", &ib, NULL);
|
|
|
|
if (ib) {
|
|
|
|
padding = *ib;
|
|
|
|
gtk_border_free(ib);
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 20:03:13 +02:00
|
|
|
#endif
|
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
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;
|
2016-05-06 20:03:13 +02:00
|
|
|
|
2016-05-13 10:20:54 +02:00
|
|
|
geo.base_width += padding.left + padding.right;
|
|
|
|
geo.base_height += padding.top + padding.bottom;
|
|
|
|
geo.min_width += padding.left + padding.right;
|
|
|
|
geo.min_height += padding.top + padding.bottom;
|
2014-05-16 12:26:12 +02:00
|
|
|
geo_widget = vc->vte.terminal;
|
|
|
|
#endif
|
2013-02-28 16:10:02 +01:00
|
|
|
}
|
2014-05-16 12:26:12 +02:00
|
|
|
|
|
|
|
geo_window = GTK_WINDOW(vc->window ? vc->window : s->window);
|
|
|
|
gtk_window_set_geometry_hints(geo_window, geo_widget, &geo, mask);
|
|
|
|
}
|
|
|
|
|
2015-01-20 12:43:28 +01:00
|
|
|
void gd_update_windowsize(VirtualConsole *vc)
|
2014-05-16 12:26:12 +02:00
|
|
|
{
|
|
|
|
GtkDisplayState *s = vc->s;
|
|
|
|
|
|
|
|
gd_update_geometry_hints(vc);
|
|
|
|
|
|
|
|
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);
|
2014-05-06 10:20:53 +02:00
|
|
|
}
|
2013-02-28 16:10:02 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
static void gd_update_full_redraw(VirtualConsole *vc)
|
2013-02-28 16:10:02 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
GtkWidget *area = vc->gfx.drawing_area;
|
2013-02-28 16:10:02 +01:00
|
|
|
int ww, wh;
|
2018-08-22 15:15:52 +02:00
|
|
|
ww = gdk_window_get_width(gtk_widget_get_window(area));
|
|
|
|
wh = gdk_window_get_height(gtk_widget_get_window(area));
|
2015-05-26 12:26:21 +02:00
|
|
|
#if defined(CONFIG_GTK_GL)
|
2018-03-06 10:09:46 +01:00
|
|
|
if (vc->gfx.gls && gtk_use_gl_area) {
|
2015-05-26 12:26:21 +02:00
|
|
|
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-30 16:30:07 +02:00
|
|
|
gtk_widget_queue_draw_area(area, 0, 0, ww, wh);
|
2013-02-28 16:10:02 +01:00
|
|
|
}
|
|
|
|
|
2013-03-24 19:10:02 +01:00
|
|
|
static void gtk_release_modifiers(GtkDisplayState *s)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-03-24 19:10:02 +01:00
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
if (vc->type != GD_VC_GFX ||
|
|
|
|
!qemu_console_is_graphic(vc->gfx.dcl.con)) {
|
2013-03-24 19:10:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-01-22 10:28:11 +01:00
|
|
|
qkbd_state_lift_all_keys(vc->gfx.kbd);
|
2013-03-24 19:10:02 +01:00
|
|
|
}
|
|
|
|
|
2014-10-23 17:21:00 +02:00
|
|
|
static void gd_widget_reparent(GtkWidget *from, GtkWidget *to,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_object_ref(G_OBJECT(widget));
|
|
|
|
gtk_container_remove(GTK_CONTAINER(from), widget);
|
|
|
|
gtk_container_add(GTK_CONTAINER(to), widget);
|
|
|
|
g_object_unref(G_OBJECT(widget));
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:20:05 +02:00
|
|
|
static void *gd_win32_get_hwnd(VirtualConsole *vc)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
return gdk_win32_window_get_impl_hwnd(
|
|
|
|
gtk_widget_get_window(vc->window ? vc->window : vc->s->window));
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
/** DisplayState Callbacks **/
|
|
|
|
|
2012-11-13 14:51:41 +01:00
|
|
|
static void gd_update(DisplayChangeListener *dcl,
|
2013-03-01 13:03:04 +01:00
|
|
|
int x, int y, int w, int h)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
2014-05-22 11:08:54 +02:00
|
|
|
GdkWindow *win;
|
2013-02-20 14:43:20 +01:00
|
|
|
int x1, x2, y1, y2;
|
2013-02-20 14:43:23 +01:00
|
|
|
int mx, my;
|
|
|
|
int fbw, fbh;
|
|
|
|
int ww, wh;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-05-06 10:27:54 +02:00
|
|
|
trace_gd_update(vc->label, x, y, w, h);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2015-03-24 20:08:48 +01:00
|
|
|
if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
if (vc->gfx.convert) {
|
|
|
|
pixman_image_composite(PIXMAN_OP_SRC, vc->gfx.ds->image,
|
|
|
|
NULL, vc->gfx.convert,
|
2013-06-25 10:48:54 +02:00
|
|
|
x, y, 0, 0, x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
x1 = floor(x * vc->gfx.scale_x);
|
|
|
|
y1 = floor(y * vc->gfx.scale_y);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
x2 = ceil(x * vc->gfx.scale_x + w * vc->gfx.scale_x);
|
|
|
|
y2 = ceil(y * vc->gfx.scale_y + h * vc->gfx.scale_y);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
|
|
|
|
fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
win = gtk_widget_get_window(vc->gfx.drawing_area);
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-22 15:15:52 +02:00
|
|
|
ww = gdk_window_get_width(win);
|
|
|
|
wh = gdk_window_get_height(win);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
mx = my = 0;
|
|
|
|
if (ww > fbw) {
|
|
|
|
mx = (ww - fbw) / 2;
|
|
|
|
}
|
|
|
|
if (wh > fbh) {
|
|
|
|
my = (wh - fbh) / 2;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gtk_widget_queue_draw_area(vc->gfx.drawing_area,
|
|
|
|
mx + x1, my + y1, (x2 - x1), (y2 - y1));
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 13:03:04 +01:00
|
|
|
static void gd_refresh(DisplayChangeListener *dcl)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2013-03-15 15:45:54 +01:00
|
|
|
graphic_hw_update(dcl->con);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2016-05-06 20:03:14 +02:00
|
|
|
static GdkDevice *gd_get_pointer(GdkDisplay *dpy)
|
|
|
|
{
|
|
|
|
return gdk_seat_get_pointer(gdk_display_get_default_seat(dpy));
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:59:45 +02:00
|
|
|
static void gd_mouse_set(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int visible)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
2013-05-10 16:59:45 +02:00
|
|
|
GdkDisplay *dpy;
|
|
|
|
gint x_root, y_root;
|
|
|
|
|
2014-03-13 20:30:24 +01:00
|
|
|
if (qemu_input_is_absolute()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
dpy = gtk_widget_get_display(vc->gfx.drawing_area);
|
|
|
|
gdk_window_get_root_coords(gtk_widget_get_window(vc->gfx.drawing_area),
|
2013-05-10 16:59:45 +02:00
|
|
|
x, y, &x_root, &y_root);
|
2016-05-06 20:03:14 +02:00
|
|
|
gdk_device_warp(gd_get_pointer(dpy),
|
2014-04-30 16:30:07 +02:00
|
|
|
gtk_widget_get_screen(vc->gfx.drawing_area),
|
2014-03-13 20:30:23 +01:00
|
|
|
x_root, y_root);
|
2014-07-01 19:12:45 +02:00
|
|
|
vc->s->last_x = x;
|
|
|
|
vc->s->last_y = y;
|
2013-05-10 16:59:45 +02:00
|
|
|
}
|
2013-03-20 09:11:41 +01:00
|
|
|
|
|
|
|
static void gd_cursor_define(DisplayChangeListener *dcl,
|
|
|
|
QEMUCursor *c)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
2013-03-20 09:11:41 +01:00
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GdkCursor *cursor;
|
|
|
|
|
2015-03-24 20:08:48 +01:00
|
|
|
if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-20 09:11:41 +01:00
|
|
|
pixbuf = gdk_pixbuf_new_from_data((guchar *)(c->data),
|
|
|
|
GDK_COLORSPACE_RGB, true, 8,
|
|
|
|
c->width, c->height, c->width * 4,
|
|
|
|
NULL, NULL);
|
2014-04-30 16:30:07 +02:00
|
|
|
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);
|
2013-03-20 09:11:41 +01:00
|
|
|
g_object_unref(pixbuf);
|
2013-06-16 16:13:07 +02:00
|
|
|
g_object_unref(cursor);
|
2013-03-20 09:11:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-28 15:03:04 +01:00
|
|
|
static void gd_switch(DisplayChangeListener *dcl,
|
|
|
|
DisplaySurface *surface)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
2013-02-28 16:10:02 +01:00
|
|
|
bool resized = true;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2015-02-27 14:36:09 +01:00
|
|
|
trace_gd_switch(vc->label,
|
|
|
|
surface ? surface_width(surface) : 0,
|
|
|
|
surface ? surface_height(surface) : 0);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
if (vc->gfx.surface) {
|
|
|
|
cairo_surface_destroy(vc->gfx.surface);
|
2015-02-27 14:36:09 +01:00
|
|
|
vc->gfx.surface = NULL;
|
|
|
|
}
|
|
|
|
if (vc->gfx.convert) {
|
|
|
|
pixman_image_unref(vc->gfx.convert);
|
|
|
|
vc->gfx.convert = NULL;
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 14:36:09 +01:00
|
|
|
if (vc->gfx.ds && surface &&
|
2014-04-30 16:30:07 +02:00
|
|
|
surface_width(vc->gfx.ds) == surface_width(surface) &&
|
|
|
|
surface_height(vc->gfx.ds) == surface_height(surface)) {
|
2013-02-28 16:10:02 +01:00
|
|
|
resized = false;
|
|
|
|
}
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.ds = surface;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2015-02-27 14:36:09 +01:00
|
|
|
if (!surface) {
|
|
|
|
return;
|
2013-06-25 10:48:54 +02:00
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-06-25 10:48:54 +02:00
|
|
|
if (surface->format == PIXMAN_x8r8g8b8) {
|
|
|
|
/*
|
|
|
|
* PIXMAN_x8r8g8b8 == CAIRO_FORMAT_RGB24
|
|
|
|
*
|
|
|
|
* No need to convert, use surface directly. Should be the
|
|
|
|
* common case as this is qemu_default_pixelformat(32) too.
|
|
|
|
*/
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.surface = cairo_image_surface_create_for_data
|
2013-06-25 10:48:54 +02:00
|
|
|
(surface_data(surface),
|
|
|
|
CAIRO_FORMAT_RGB24,
|
|
|
|
surface_width(surface),
|
|
|
|
surface_height(surface),
|
|
|
|
surface_stride(surface));
|
|
|
|
} else {
|
|
|
|
/* Must convert surface, use pixman to do it. */
|
2014-04-30 16:30:07 +02:00
|
|
|
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),
|
2013-06-25 10:48:54 +02:00
|
|
|
CAIRO_FORMAT_RGB24,
|
2014-04-30 16:30:07 +02:00
|
|
|
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,
|
2013-06-25 10:48:54 +02:00
|
|
|
0, 0, 0, 0, 0, 0,
|
2014-04-30 16:30:07 +02:00
|
|
|
pixman_image_get_width(vc->gfx.convert),
|
|
|
|
pixman_image_get_height(vc->gfx.convert));
|
2013-06-25 10:48:54 +02:00
|
|
|
}
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2013-02-28 16:10:02 +01:00
|
|
|
if (resized) {
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_windowsize(vc);
|
2013-02-28 16:10:02 +01:00
|
|
|
} else {
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_full_redraw(vc);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2015-01-20 12:43:28 +01:00
|
|
|
static const DisplayChangeListenerOps dcl_ops = {
|
|
|
|
.dpy_name = "gtk",
|
|
|
|
.dpy_gfx_update = gd_update,
|
|
|
|
.dpy_gfx_switch = gd_switch,
|
|
|
|
.dpy_gfx_check_format = qemu_pixman_check_format,
|
|
|
|
.dpy_refresh = gd_refresh,
|
|
|
|
.dpy_mouse_set = gd_mouse_set,
|
|
|
|
.dpy_cursor_define = gd_cursor_define,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_OPENGL)
|
|
|
|
|
|
|
|
/** DisplayState Callbacks (opengl version) **/
|
|
|
|
|
2015-05-26 12:26:21 +02:00
|
|
|
#if defined(CONFIG_GTK_GL)
|
|
|
|
|
|
|
|
static const DisplayChangeListenerOps dcl_gl_area_ops = {
|
|
|
|
.dpy_name = "gtk-egl",
|
|
|
|
.dpy_gfx_update = gd_gl_area_update,
|
|
|
|
.dpy_gfx_switch = gd_gl_area_switch,
|
|
|
|
.dpy_gfx_check_format = console_gl_check_format,
|
|
|
|
.dpy_refresh = gd_gl_area_refresh,
|
|
|
|
.dpy_mouse_set = gd_mouse_set,
|
|
|
|
.dpy_cursor_define = gd_cursor_define,
|
|
|
|
|
|
|
|
.dpy_gl_ctx_create = gd_gl_area_create_context,
|
|
|
|
.dpy_gl_ctx_destroy = gd_gl_area_destroy_context,
|
|
|
|
.dpy_gl_ctx_make_current = gd_gl_area_make_current,
|
|
|
|
.dpy_gl_ctx_get_current = gd_gl_area_get_current_context,
|
2017-02-21 10:37:16 +01:00
|
|
|
.dpy_gl_scanout_texture = gd_gl_area_scanout_texture,
|
2015-05-26 12:26:21 +02:00
|
|
|
.dpy_gl_update = gd_gl_area_scanout_flush,
|
|
|
|
};
|
|
|
|
|
2018-03-06 10:09:46 +01:00
|
|
|
#endif /* CONFIG_GTK_GL */
|
2015-05-26 12:26:21 +02:00
|
|
|
|
2015-01-20 12:43:28 +01:00
|
|
|
static const DisplayChangeListenerOps dcl_egl_ops = {
|
|
|
|
.dpy_name = "gtk-egl",
|
|
|
|
.dpy_gfx_update = gd_egl_update,
|
|
|
|
.dpy_gfx_switch = gd_egl_switch,
|
|
|
|
.dpy_gfx_check_format = console_gl_check_format,
|
|
|
|
.dpy_refresh = gd_egl_refresh,
|
|
|
|
.dpy_mouse_set = gd_mouse_set,
|
|
|
|
.dpy_cursor_define = gd_cursor_define,
|
2015-05-08 11:30:51 +02:00
|
|
|
|
|
|
|
.dpy_gl_ctx_create = gd_egl_create_context,
|
|
|
|
.dpy_gl_ctx_destroy = qemu_egl_destroy_context,
|
|
|
|
.dpy_gl_ctx_make_current = gd_egl_make_current,
|
|
|
|
.dpy_gl_ctx_get_current = qemu_egl_get_current_context,
|
2017-02-21 10:37:21 +01:00
|
|
|
.dpy_gl_scanout_disable = gd_egl_scanout_disable,
|
2017-02-21 10:37:16 +01:00
|
|
|
.dpy_gl_scanout_texture = gd_egl_scanout_texture,
|
2018-03-06 10:09:50 +01:00
|
|
|
.dpy_gl_scanout_dmabuf = gd_egl_scanout_dmabuf,
|
2018-03-06 10:09:51 +01:00
|
|
|
.dpy_gl_cursor_dmabuf = gd_egl_cursor_dmabuf,
|
|
|
|
.dpy_gl_cursor_position = gd_egl_cursor_position,
|
2018-03-06 10:09:50 +01:00
|
|
|
.dpy_gl_release_dmabuf = gd_egl_release_dmabuf,
|
2015-05-08 11:30:51 +02:00
|
|
|
.dpy_gl_update = gd_egl_scanout_flush,
|
2015-01-20 12:43:28 +01:00
|
|
|
};
|
|
|
|
|
2015-05-26 12:26:21 +02:00
|
|
|
#endif /* CONFIG_OPENGL */
|
2015-01-20 12:43:28 +01:00
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
/** QEMU Events **/
|
|
|
|
|
|
|
|
static void gd_change_runstate(void *opaque, int running, RunState state)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
|
|
|
|
gd_update_caption(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_mouse_mode_change(Notifier *notify, void *data)
|
|
|
|
{
|
2014-04-08 11:26:45 +02:00
|
|
|
GtkDisplayState *s;
|
2014-05-06 11:48:28 +02:00
|
|
|
int i;
|
2014-04-08 11:26:45 +02:00
|
|
|
|
|
|
|
s = container_of(notify, GtkDisplayState, mouse_mode_notifier);
|
|
|
|
/* release the grab at switching to absolute mode */
|
|
|
|
if (qemu_input_is_absolute() && gd_is_grab_active(s)) {
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
|
|
|
|
FALSE);
|
|
|
|
}
|
2014-05-06 11:48:28 +02:00
|
|
|
for (i = 0; i < s->nb_vcs; i++) {
|
|
|
|
VirtualConsole *vc = &s->vc[i];
|
|
|
|
gd_update_cursor(vc);
|
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** GTK Events **/
|
|
|
|
|
|
|
|
static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2018-02-02 12:10:14 +01:00
|
|
|
bool allow_close = true;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2018-02-02 12:10:14 +01:00
|
|
|
if (s->opts->has_window_close && !s->opts->window_close) {
|
|
|
|
allow_close = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allow_close) {
|
2013-02-20 14:43:20 +01:00
|
|
|
qmp_quit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-05-26 12:26:21 +02:00
|
|
|
static void gd_set_ui_info(VirtualConsole *vc, gint width, gint height)
|
|
|
|
{
|
|
|
|
QemuUIInfo info;
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
info.width = width;
|
|
|
|
info.height = height;
|
|
|
|
dpy_set_ui_info(vc->gfx.dcl.con, &info);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_GTK_GL)
|
|
|
|
|
|
|
|
static gboolean gd_render_event(GtkGLArea *area, GdkGLContext *context,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
|
|
|
|
if (vc->gfx.gls) {
|
|
|
|
gd_gl_area_draw(vc);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_resize_event(GtkGLArea *area,
|
|
|
|
gint width, gint height, gpointer *opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = (void *)opaque;
|
|
|
|
|
|
|
|
gd_set_ui_info(vc, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-08-17 19:23:31 +02:00
|
|
|
/*
|
|
|
|
* If available, return the refresh rate of the display in milli-Hertz,
|
|
|
|
* else return 0.
|
|
|
|
*/
|
|
|
|
static int gd_refresh_rate_millihz(GtkWidget *window)
|
|
|
|
{
|
|
|
|
#ifdef GDK_VERSION_3_22
|
|
|
|
GdkWindow *win = gtk_widget_get_window(window);
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
GdkDisplay *dpy = gtk_widget_get_display(window);
|
|
|
|
GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
|
|
|
|
|
|
|
|
return gdk_monitor_get_refresh_rate(monitor);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
2013-02-20 14:43:23 +01:00
|
|
|
int mx, my;
|
2013-02-20 14:43:20 +01:00
|
|
|
int ww, wh;
|
|
|
|
int fbw, fbh;
|
2020-08-17 19:23:31 +02:00
|
|
|
int refresh_rate_millihz;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2015-01-20 12:43:28 +01:00
|
|
|
#if defined(CONFIG_OPENGL)
|
|
|
|
if (vc->gfx.gls) {
|
2018-03-06 10:09:46 +01:00
|
|
|
if (gtk_use_gl_area) {
|
|
|
|
/* invoke render callback please */
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
gd_egl_draw(vc);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-01-20 12:43:28 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
if (!gtk_widget_get_realized(widget)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-27 14:36:09 +01:00
|
|
|
if (!vc->gfx.ds) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2020-08-17 19:23:31 +02:00
|
|
|
refresh_rate_millihz = gd_refresh_rate_millihz(vc->window ?
|
|
|
|
vc->window : s->window);
|
|
|
|
if (refresh_rate_millihz) {
|
|
|
|
vc->gfx.dcl.update_interval = MILLISEC_PER_SEC / refresh_rate_millihz;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
fbw = surface_width(vc->gfx.ds);
|
|
|
|
fbh = surface_height(vc->gfx.ds);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2018-08-22 15:15:52 +02:00
|
|
|
ww = gdk_window_get_width(gtk_widget_get_window(widget));
|
|
|
|
wh = gdk_window_get_height(gtk_widget_get_window(widget));
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
if (s->full_screen) {
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.scale_x = (double)ww / fbw;
|
|
|
|
vc->gfx.scale_y = (double)wh / fbh;
|
2013-02-20 14:43:23 +01:00
|
|
|
} else if (s->free_scale) {
|
|
|
|
double sx, sy;
|
|
|
|
|
|
|
|
sx = (double)ww / fbw;
|
|
|
|
sy = (double)wh / fbh;
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
fbw *= vc->gfx.scale_x;
|
|
|
|
fbh *= vc->gfx.scale_y;
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
mx = my = 0;
|
|
|
|
if (ww > fbw) {
|
|
|
|
mx = (ww - fbw) / 2;
|
|
|
|
}
|
|
|
|
if (wh > fbh) {
|
|
|
|
my = (wh - fbh) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_rectangle(cr, 0, 0, ww, wh);
|
|
|
|
|
|
|
|
/* Optionally cut out the inner area where the pixmap
|
|
|
|
will be drawn. This avoids 'flashing' since we're
|
|
|
|
not double-buffering. Note we're using the undocumented
|
|
|
|
behaviour of drawing the rectangle from right to left
|
|
|
|
to cut out the whole */
|
|
|
|
cairo_rectangle(cr, mx + fbw, my,
|
|
|
|
-1 * fbw, fbh);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
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);
|
2013-02-20 14:43:20 +01:00
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
2013-02-20 14:43:20 +01:00
|
|
|
int x, y;
|
2013-02-20 14:43:23 +01:00
|
|
|
int mx, my;
|
|
|
|
int fbh, fbw;
|
|
|
|
int ww, wh;
|
|
|
|
|
2015-02-27 14:36:09 +01:00
|
|
|
if (!vc->gfx.ds) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
|
|
|
|
fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2018-08-22 15:15:52 +02:00
|
|
|
ww = gdk_window_get_width(gtk_widget_get_window(vc->gfx.drawing_area));
|
|
|
|
wh = gdk_window_get_height(gtk_widget_get_window(vc->gfx.drawing_area));
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
mx = my = 0;
|
|
|
|
if (ww > fbw) {
|
|
|
|
mx = (ww - fbw) / 2;
|
|
|
|
}
|
|
|
|
if (wh > fbh) {
|
|
|
|
my = (wh - fbh) / 2;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
x = (motion->x - mx) / vc->gfx.scale_x;
|
|
|
|
y = (motion->y - my) / vc->gfx.scale_y;
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2013-11-28 12:06:04 +01:00
|
|
|
if (qemu_input_is_absolute()) {
|
2014-04-04 12:41:22 +02:00
|
|
|
if (x < 0 || y < 0 ||
|
2014-04-30 16:30:07 +02:00
|
|
|
x >= surface_width(vc->gfx.ds) ||
|
|
|
|
y >= surface_height(vc->gfx.ds)) {
|
2014-04-04 12:41:22 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-04-30 16:30:07 +02:00
|
|
|
qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_X, x,
|
2017-05-05 15:39:52 +02:00
|
|
|
0, surface_width(vc->gfx.ds));
|
2014-04-30 16:30:07 +02:00
|
|
|
qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_Y, y,
|
2017-05-05 15:39:52 +02:00
|
|
|
0, surface_height(vc->gfx.ds));
|
2013-11-28 12:06:04 +01:00
|
|
|
qemu_input_event_sync();
|
2014-05-06 11:45:30 +02:00
|
|
|
} else if (s->last_set && s->ptr_owner == vc) {
|
2014-04-30 16:30:07 +02:00
|
|
|
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);
|
2013-11-28 12:06:04 +01:00
|
|
|
qemu_input_event_sync();
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
s->last_x = x;
|
|
|
|
s->last_y = y;
|
2014-04-04 12:41:22 +02:00
|
|
|
s->last_set = TRUE;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-05-06 11:45:30 +02:00
|
|
|
if (!qemu_input_is_absolute() && s->ptr_owner == vc) {
|
2014-04-30 16:30:07 +02:00
|
|
|
GdkScreen *screen = gtk_widget_get_screen(vc->gfx.drawing_area);
|
2020-05-16 09:20:14 +02:00
|
|
|
GdkDisplay *dpy = gtk_widget_get_display(widget);
|
|
|
|
GdkWindow *win = gtk_widget_get_window(widget);
|
|
|
|
GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
|
|
|
|
GdkRectangle geometry;
|
2016-10-26 17:21:08 +02:00
|
|
|
int screen_width, screen_height;
|
|
|
|
|
2013-02-20 14:43:22 +01:00
|
|
|
int x = (int)motion->x_root;
|
|
|
|
int y = (int)motion->y_root;
|
|
|
|
|
2020-05-16 09:20:14 +02:00
|
|
|
gdk_monitor_get_geometry(monitor, &geometry);
|
|
|
|
screen_width = geometry.width;
|
|
|
|
screen_height = geometry.height;
|
2016-10-26 17:21:08 +02:00
|
|
|
|
2013-02-20 14:43:22 +01:00
|
|
|
/* In relative mode check to see if client pointer hit
|
|
|
|
* one of the screen edges, and if so move it back by
|
|
|
|
* 200 pixels. This is important because the pointer
|
|
|
|
* in the server doesn't correspond 1-for-1, and so
|
|
|
|
* may still be only half way across the screen. Without
|
|
|
|
* this warp, the server pointer would thus appear to hit
|
|
|
|
* an invisible wall */
|
|
|
|
if (x == 0) {
|
|
|
|
x += 200;
|
|
|
|
}
|
|
|
|
if (y == 0) {
|
|
|
|
y += 200;
|
|
|
|
}
|
2016-10-26 17:21:08 +02:00
|
|
|
if (x == (screen_width - 1)) {
|
2013-02-20 14:43:22 +01:00
|
|
|
x -= 200;
|
|
|
|
}
|
2016-10-26 17:21:08 +02:00
|
|
|
if (y == (screen_height - 1)) {
|
2013-02-20 14:43:22 +01:00
|
|
|
y -= 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x != (int)motion->x_root || y != (int)motion->y_root) {
|
2013-02-25 16:20:40 +01:00
|
|
|
GdkDevice *dev = gdk_event_get_device((GdkEvent *)motion);
|
|
|
|
gdk_device_warp(dev, screen, x, y);
|
2014-04-04 12:41:22 +02:00
|
|
|
s->last_set = FALSE;
|
2013-02-20 14:43:22 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
2013-11-28 12:06:04 +01:00
|
|
|
InputButton btn;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-08 11:26:45 +02:00
|
|
|
/* implicitly grab the input at the first click in the relative mode */
|
|
|
|
if (button->button == 1 && button->type == GDK_BUTTON_PRESS &&
|
2014-05-06 11:45:30 +02:00
|
|
|
!qemu_input_is_absolute() && s->ptr_owner != vc) {
|
|
|
|
if (!vc->window) {
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
|
|
|
|
TRUE);
|
|
|
|
} else {
|
2015-09-09 10:12:20 +02:00
|
|
|
gd_grab_pointer(vc, "relative-mode-click");
|
2014-05-06 11:45:30 +02:00
|
|
|
}
|
2014-04-08 11:26:45 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
if (button->button == 1) {
|
2013-11-28 12:06:04 +01:00
|
|
|
btn = INPUT_BUTTON_LEFT;
|
2013-02-20 14:43:20 +01:00
|
|
|
} else if (button->button == 2) {
|
2013-11-28 12:06:04 +01:00
|
|
|
btn = INPUT_BUTTON_MIDDLE;
|
2013-02-20 14:43:20 +01:00
|
|
|
} else if (button->button == 3) {
|
2013-11-28 12:06:04 +01:00
|
|
|
btn = INPUT_BUTTON_RIGHT;
|
2016-12-06 20:00:07 +01:00
|
|
|
} else if (button->button == 8) {
|
|
|
|
btn = INPUT_BUTTON_SIDE;
|
|
|
|
} else if (button->button == 9) {
|
|
|
|
btn = INPUT_BUTTON_EXTRA;
|
2013-02-20 14:43:20 +01:00
|
|
|
} else {
|
2013-11-28 12:06:04 +01:00
|
|
|
return TRUE;
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
qemu_input_queue_btn(vc->gfx.dcl.con, btn,
|
|
|
|
button->type == GDK_BUTTON_PRESS);
|
2013-11-28 12:06:04 +01:00
|
|
|
qemu_input_event_sync();
|
2013-02-20 14:43:20 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-11 17:26:44 +01:00
|
|
|
static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
2014-03-11 17:26:44 +01:00
|
|
|
InputButton btn;
|
|
|
|
|
|
|
|
if (scroll->direction == GDK_SCROLL_UP) {
|
2016-01-12 12:14:12 +01:00
|
|
|
btn = INPUT_BUTTON_WHEEL_UP;
|
2014-03-11 17:26:44 +01:00
|
|
|
} else if (scroll->direction == GDK_SCROLL_DOWN) {
|
2016-01-12 12:14:12 +01:00
|
|
|
btn = INPUT_BUTTON_WHEEL_DOWN;
|
2017-01-04 21:41:16 +01:00
|
|
|
} else if (scroll->direction == GDK_SCROLL_SMOOTH) {
|
|
|
|
gdouble delta_x, delta_y;
|
|
|
|
if (!gdk_event_get_scroll_deltas((GdkEvent *)scroll,
|
|
|
|
&delta_x, &delta_y)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-04 13:20:43 +01:00
|
|
|
if (delta_y == 0) {
|
|
|
|
return TRUE;
|
|
|
|
} else if (delta_y > 0) {
|
2017-01-04 21:41:16 +01:00
|
|
|
btn = INPUT_BUTTON_WHEEL_DOWN;
|
|
|
|
} else {
|
|
|
|
btn = INPUT_BUTTON_WHEEL_UP;
|
|
|
|
}
|
2014-03-11 17:26:44 +01:00
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
qemu_input_queue_btn(vc->gfx.dcl.con, btn, true);
|
2014-03-11 17:26:44 +01:00
|
|
|
qemu_input_event_sync();
|
2014-04-30 16:30:07 +02:00
|
|
|
qemu_input_queue_btn(vc->gfx.dcl.con, btn, false);
|
2014-03-11 17:26:44 +01:00
|
|
|
qemu_input_event_sync();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-01-17 17:47:15 +01:00
|
|
|
|
|
|
|
static const guint16 *gd_get_keymap(size_t *maplen)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2018-01-17 17:47:15 +01:00
|
|
|
GdkDisplay *dpy = gdk_display_get_default();
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
if (GDK_IS_X11_DISPLAY(dpy)) {
|
|
|
|
trace_gd_keymap_windowing("x11");
|
|
|
|
return qemu_xkeymap_mapping_table(
|
|
|
|
gdk_x11_display_get_xdisplay(dpy), maplen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
if (GDK_IS_WAYLAND_DISPLAY(dpy)) {
|
|
|
|
trace_gd_keymap_windowing("wayland");
|
|
|
|
*maplen = qemu_input_map_xorgevdev_to_qcode_len;
|
|
|
|
return qemu_input_map_xorgevdev_to_qcode;
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-05-28 22:33:06 +02:00
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
if (GDK_IS_WIN32_DISPLAY(dpy)) {
|
2018-01-17 17:47:15 +01:00
|
|
|
trace_gd_keymap_windowing("win32");
|
2020-05-16 09:20:13 +02:00
|
|
|
*maplen = qemu_input_map_atset1_to_qcode_len;
|
|
|
|
return qemu_input_map_atset1_to_qcode;
|
2013-12-07 16:25:17 +01:00
|
|
|
}
|
2014-05-28 22:33:06 +02:00
|
|
|
#endif
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2018-01-17 17:47:15 +01:00
|
|
|
#ifdef GDK_WINDOWING_QUARTZ
|
|
|
|
if (GDK_IS_QUARTZ_DISPLAY(dpy)) {
|
|
|
|
trace_gd_keymap_windowing("quartz");
|
|
|
|
*maplen = qemu_input_map_osx_to_qcode_len;
|
|
|
|
return qemu_input_map_osx_to_qcode;
|
|
|
|
}
|
2016-12-01 10:41:17 +01:00
|
|
|
#endif
|
2018-01-17 17:47:15 +01:00
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
|
|
|
if (GDK_IS_BROADWAY_DISPLAY(dpy)) {
|
|
|
|
trace_gd_keymap_windowing("broadway");
|
|
|
|
g_warning("experimental: using broadway, x11 virtual keysym\n"
|
|
|
|
"mapping - with very limited support. See also\n"
|
|
|
|
"https://bugzilla.gnome.org/show_bug.cgi?id=700105");
|
|
|
|
*maplen = qemu_input_map_x11_to_qcode_len;
|
|
|
|
return qemu_input_map_x11_to_qcode;
|
|
|
|
}
|
2014-05-28 22:33:06 +02:00
|
|
|
#endif
|
2018-01-17 17:47:15 +01:00
|
|
|
|
|
|
|
g_warning("Unsupported GDK Windowing platform.\n"
|
|
|
|
"Disabling extended keycode tables.\n"
|
|
|
|
"Please report to qemu-devel@nongnu.org\n"
|
|
|
|
"including the following information:\n"
|
|
|
|
"\n"
|
|
|
|
" - Operating system\n"
|
|
|
|
" - GDK Windowing system build\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int gd_map_keycode(int scancode)
|
|
|
|
{
|
|
|
|
if (!keycode_map) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (scancode > keycode_maplen) {
|
|
|
|
return 0;
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2018-01-17 17:47:15 +01:00
|
|
|
return keycode_map[scancode];
|
2014-06-03 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 09:20:13 +02:00
|
|
|
static int gd_get_keycode(GdkEventKey *key)
|
|
|
|
{
|
2020-05-16 09:20:14 +02:00
|
|
|
#ifdef G_OS_WIN32
|
2020-05-16 09:20:13 +02:00
|
|
|
int scancode = gdk_event_get_scancode((GdkEvent *)key);
|
|
|
|
|
|
|
|
/* translate Windows native scancodes to atset1 keycodes */
|
|
|
|
switch (scancode & (KF_EXTENDED | 0xff)) {
|
|
|
|
case 0x145: /* NUMLOCK */
|
|
|
|
return scancode & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scancode & KF_EXTENDED ?
|
|
|
|
0xe000 | (scancode & 0xff) : scancode & 0xff;
|
|
|
|
|
|
|
|
#else
|
|
|
|
return key->hardware_keycode;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
static gboolean gd_text_key_down(GtkWidget *widget,
|
|
|
|
GdkEventKey *key, void *opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
QemuConsole *con = vc->gfx.dcl.con;
|
|
|
|
|
2016-10-27 14:17:27 +02:00
|
|
|
if (key->keyval == GDK_KEY_Delete) {
|
2018-03-21 14:50:36 +01:00
|
|
|
kbd_put_qcode_console(con, Q_KEY_CODE_DELETE, false);
|
2016-10-27 14:17:27 +02:00
|
|
|
} else if (key->length) {
|
2014-05-22 11:08:54 +02:00
|
|
|
kbd_put_string_console(con, key->string, key->length);
|
|
|
|
} else {
|
2020-05-16 09:20:13 +02:00
|
|
|
int qcode = gd_map_keycode(gd_get_keycode(key));
|
2018-03-21 14:50:36 +01:00
|
|
|
kbd_put_qcode_console(con, qcode, false);
|
2014-05-22 11:08:54 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-06-03 09:18:23 +02:00
|
|
|
static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = opaque;
|
2020-05-16 09:20:13 +02:00
|
|
|
int keycode, qcode;
|
2014-06-03 09:18:23 +02:00
|
|
|
|
2020-05-16 09:20:12 +02:00
|
|
|
#ifdef G_OS_WIN32
|
2018-01-17 17:47:17 +01:00
|
|
|
/* on windows, we ought to ignore the reserved key event? */
|
|
|
|
if (key->hardware_keycode == 0xff)
|
|
|
|
return false;
|
2020-05-16 09:20:12 +02:00
|
|
|
|
|
|
|
if (!vc->s->kbd_owner) {
|
|
|
|
if (key->hardware_keycode == VK_LWIN ||
|
|
|
|
key->hardware_keycode == VK_RWIN) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2018-01-17 17:47:17 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-17 17:47:16 +01:00
|
|
|
if (key->keyval == GDK_KEY_Pause
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* for some reason GDK does not fill keyval for VK_PAUSE
|
|
|
|
* See https://bugzilla.gnome.org/show_bug.cgi?id=769214
|
|
|
|
*/
|
|
|
|
|| key->hardware_keycode == VK_PAUSE
|
|
|
|
#endif
|
|
|
|
) {
|
2019-01-22 10:28:11 +01:00
|
|
|
qkbd_state_key_event(vc->gfx.kbd, Q_KEY_CODE_PAUSE,
|
|
|
|
key->type == GDK_KEY_PRESS);
|
2014-09-16 16:04:40 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:20:13 +02:00
|
|
|
keycode = gd_get_keycode(key);
|
|
|
|
qcode = gd_map_keycode(keycode);
|
2014-06-03 09:18:23 +02:00
|
|
|
|
2020-05-16 09:20:13 +02:00
|
|
|
trace_gd_key_event(vc->label, keycode, qcode,
|
2013-11-10 16:24:02 +01:00
|
|
|
(key->type == GDK_KEY_PRESS) ? "down" : "up");
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2019-01-22 10:28:11 +01:00
|
|
|
qkbd_state_key_event(vc->gfx.kbd, qcode,
|
|
|
|
key->type == GDK_KEY_PRESS);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:20:06 +02:00
|
|
|
static gboolean gd_grab_broken_event(GtkWidget *widget,
|
|
|
|
GdkEventGrabBroken *event, void *opaque)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_WIN32
|
|
|
|
/*
|
|
|
|
* On Windows the Ctrl-Alt-Del key combination can't be grabbed. This
|
|
|
|
* key combination leaves all three keys in a stuck condition. We use
|
|
|
|
* the grab-broken-event to release all keys.
|
|
|
|
*/
|
|
|
|
if (event->keyboard) {
|
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
|
|
|
|
|
|
|
gtk_release_modifiers(s);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-04 12:41:21 +02:00
|
|
|
static gboolean gd_event(GtkWidget *widget, GdkEvent *event, void *opaque)
|
|
|
|
{
|
|
|
|
if (event->type == GDK_MOTION_NOTIFY) {
|
|
|
|
return gd_motion_event(widget, &event->motion, opaque);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
/** Window Menu Actions **/
|
|
|
|
|
2013-02-22 20:53:33 +01:00
|
|
|
static void gd_menu_pause(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
|
|
|
|
if (s->external_pause_update) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (runstate_is_running()) {
|
|
|
|
qmp_stop(NULL);
|
|
|
|
} else {
|
|
|
|
qmp_cont(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_menu_reset(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
qmp_system_reset(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_menu_powerdown(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
qmp_system_powerdown(NULL);
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
static void gd_menu_quit(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
qmp_quit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_by_menu(s);
|
2014-07-08 20:28:57 +02:00
|
|
|
GtkNotebook *nb = GTK_NOTEBOOK(s->notebook);
|
2014-04-30 12:56:53 +02:00
|
|
|
gint page;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gtk_release_modifiers(s);
|
|
|
|
if (vc) {
|
2014-07-08 20:28:57 +02:00
|
|
|
page = gtk_notebook_page_num(nb, vc->tab_item);
|
|
|
|
gtk_notebook_set_current_page(nb, page);
|
2015-04-26 21:04:20 +02:00
|
|
|
gtk_widget_grab_focus(vc->focus);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 20:34:34 +01:00
|
|
|
static void gd_accel_switch_vc(void *opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = opaque;
|
2015-04-26 21:04:21 +02:00
|
|
|
|
2014-10-30 20:34:34 +01:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE);
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-05-22 08:19:48 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->show_tabs_item))) {
|
|
|
|
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), TRUE);
|
|
|
|
} else {
|
|
|
|
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
|
|
|
|
}
|
2014-05-22 08:19:48 +02:00
|
|
|
gd_update_windowsize(vc);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-05-05 16:23:33 +02:00
|
|
|
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);
|
2014-10-23 17:21:00 +02:00
|
|
|
gd_widget_reparent(vc->window, s->notebook, vc->tab_item);
|
2014-05-05 16:23:33 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:51:00 +02:00
|
|
|
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 {
|
2015-09-09 10:12:20 +02:00
|
|
|
gd_grab_pointer(vc, "user-request-detached-tab");
|
2014-05-06 12:51:00 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-05 16:23:33 +02:00
|
|
|
static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
if (vc->type == GD_VC_GFX &&
|
|
|
|
qemu_console_is_graphic(vc->gfx.dcl.con)) {
|
2014-05-06 10:20:53 +02:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
|
|
|
|
FALSE);
|
2014-05-05 16:23:33 +02:00
|
|
|
}
|
|
|
|
if (!vc->window) {
|
|
|
|
gtk_widget_set_sensitive(vc->menu_item, false);
|
|
|
|
vc->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
2014-10-23 17:21:00 +02:00
|
|
|
gd_widget_reparent(s->notebook, vc->window, vc->tab_item);
|
2014-05-05 16:23:33 +02:00
|
|
|
|
|
|
|
g_signal_connect(vc->window, "delete-event",
|
|
|
|
G_CALLBACK(gd_tab_window_close), vc);
|
|
|
|
gtk_widget_show_all(vc->window);
|
2014-05-06 11:20:17 +02:00
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
|
|
|
|
GtkAccelGroup *ag = gtk_accel_group_new();
|
|
|
|
gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
|
2014-05-06 12:51:00 +02:00
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-05-06 12:51:00 +02:00
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
gd_update_geometry_hints(vc);
|
2014-05-06 11:20:17 +02:00
|
|
|
gd_update_caption(s);
|
2014-05-05 16:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 01:07:38 +02:00
|
|
|
static void gd_menu_show_menubar(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
|
|
|
|
|
|
|
if (s->full_screen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gtk_check_menu_item_get_active(
|
|
|
|
GTK_CHECK_MENU_ITEM(s->show_menubar_item))) {
|
|
|
|
gtk_widget_show(s->menu_bar);
|
|
|
|
} else {
|
|
|
|
gtk_widget_hide(s->menu_bar);
|
|
|
|
}
|
|
|
|
gd_update_windowsize(vc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_accel_show_menubar(void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
gtk_menu_item_activate(GTK_MENU_ITEM(s->show_menubar_item));
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2013-02-22 20:33:34 +01:00
|
|
|
if (!s->full_screen) {
|
2013-02-20 14:43:23 +01:00
|
|
|
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
|
2014-10-30 20:34:35 +01:00
|
|
|
gtk_widget_hide(s->menu_bar);
|
2014-04-30 16:30:07 +02:00
|
|
|
if (vc->type == GD_VC_GFX) {
|
|
|
|
gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
2014-04-30 16:30:07 +02:00
|
|
|
gtk_window_fullscreen(GTK_WINDOW(s->window));
|
2013-02-20 14:43:23 +01:00
|
|
|
s->full_screen = TRUE;
|
|
|
|
} else {
|
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(s->window));
|
|
|
|
gd_menu_show_tabs(GTK_MENU_ITEM(s->show_tabs_item), s);
|
2018-05-11 01:07:38 +02:00
|
|
|
if (gtk_check_menu_item_get_active(
|
|
|
|
GTK_CHECK_MENU_ITEM(s->show_menubar_item))) {
|
|
|
|
gtk_widget_show(s->menu_bar);
|
|
|
|
}
|
2013-02-20 14:43:23 +01:00
|
|
|
s->full_screen = FALSE;
|
2014-04-30 16:30:07 +02:00
|
|
|
if (vc->type == GD_VC_GFX) {
|
|
|
|
vc->gfx.scale_x = 1.0;
|
|
|
|
vc->gfx.scale_y = 1.0;
|
2014-05-16 12:26:12 +02:00
|
|
|
gd_update_windowsize(vc);
|
2014-04-30 16:30:07 +02:00
|
|
|
}
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_cursor(vc);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
2014-10-30 20:34:33 +01:00
|
|
|
static void gd_accel_full_screen(void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
static void gd_menu_zoom_in(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
|
|
|
|
FALSE);
|
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
vc->gfx.scale_x += VC_SCALE_STEP;
|
|
|
|
vc->gfx.scale_y += VC_SCALE_STEP;
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_windowsize(vc);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 02:32:15 +01:00
|
|
|
static void gd_accel_zoom_in(void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
gtk_menu_item_activate(GTK_MENU_ITEM(s->zoom_in_item));
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
static void gd_menu_zoom_out(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
|
|
|
|
FALSE);
|
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
vc->gfx.scale_x -= VC_SCALE_STEP;
|
|
|
|
vc->gfx.scale_y -= VC_SCALE_STEP;
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
vc->gfx.scale_x = MAX(vc->gfx.scale_x, VC_SCALE_MIN);
|
|
|
|
vc->gfx.scale_y = MAX(vc->gfx.scale_y, VC_SCALE_MIN);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_windowsize(vc);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.scale_x = 1.0;
|
|
|
|
vc->gfx.scale_y = 1.0;
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_windowsize(vc);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item))) {
|
|
|
|
s->free_scale = TRUE;
|
|
|
|
} else {
|
|
|
|
s->free_scale = FALSE;
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.scale_x = 1.0;
|
|
|
|
vc->gfx.scale_y = 1.0;
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
gd_update_windowsize(vc);
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_full_redraw(vc);
|
2013-02-20 14:43:23 +01:00
|
|
|
}
|
|
|
|
|
2016-05-12 09:29:06 +02:00
|
|
|
static void gd_grab_update(VirtualConsole *vc, bool kbd, bool ptr)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
|
|
|
|
GdkSeat *seat = gdk_display_get_default_seat(display);
|
|
|
|
GdkWindow *window = gtk_widget_get_window(vc->gfx.drawing_area);
|
|
|
|
GdkSeatCapabilities caps = 0;
|
|
|
|
GdkCursor *cursor = NULL;
|
|
|
|
|
|
|
|
if (kbd) {
|
|
|
|
caps |= GDK_SEAT_CAPABILITY_KEYBOARD;
|
|
|
|
}
|
|
|
|
if (ptr) {
|
|
|
|
caps |= GDK_SEAT_CAPABILITY_ALL_POINTING;
|
|
|
|
cursor = vc->s->null_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps) {
|
|
|
|
gdk_seat_grab(seat, window, caps, false, cursor,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
} else {
|
|
|
|
gdk_seat_ungrab(seat);
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 11:52:18 +02:00
|
|
|
|
2015-09-09 10:12:20 +02:00
|
|
|
static void gd_grab_keyboard(VirtualConsole *vc, const char *reason)
|
2014-05-19 11:52:18 +02:00
|
|
|
{
|
2015-09-09 09:57:01 +02:00
|
|
|
if (vc->s->kbd_owner) {
|
|
|
|
if (vc->s->kbd_owner == vc) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
gd_ungrab_keyboard(vc->s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:20:05 +02:00
|
|
|
win32_kbd_set_grab(true);
|
2016-05-12 09:29:06 +02:00
|
|
|
gd_grab_update(vc, true, vc->s->ptr_owner == vc);
|
2014-05-06 11:01:31 +02:00
|
|
|
vc->s->kbd_owner = vc;
|
2015-09-09 10:03:59 +02:00
|
|
|
gd_update_caption(vc->s);
|
2015-09-09 10:12:20 +02:00
|
|
|
trace_gd_grab(vc->label, "kbd", reason);
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
|
2014-05-06 11:01:31 +02:00
|
|
|
static void gd_ungrab_keyboard(GtkDisplayState *s)
|
2013-02-20 14:43:22 +01:00
|
|
|
{
|
2014-05-06 11:01:31 +02:00
|
|
|
VirtualConsole *vc = s->kbd_owner;
|
|
|
|
|
|
|
|
if (vc == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->kbd_owner = NULL;
|
|
|
|
|
2020-05-16 09:20:05 +02:00
|
|
|
win32_kbd_set_grab(false);
|
2016-05-12 09:29:06 +02:00
|
|
|
gd_grab_update(vc, false, vc->s->ptr_owner == vc);
|
2015-09-09 10:03:59 +02:00
|
|
|
gd_update_caption(s);
|
2015-09-09 10:12:20 +02:00
|
|
|
trace_gd_ungrab(vc->label, "kbd");
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
|
2015-09-09 10:12:20 +02:00
|
|
|
static void gd_grab_pointer(VirtualConsole *vc, const char *reason)
|
2013-02-25 16:20:37 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
|
2015-09-09 09:57:01 +02:00
|
|
|
|
|
|
|
if (vc->s->ptr_owner) {
|
|
|
|
if (vc->s->ptr_owner == vc) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
gd_ungrab_pointer(vc->s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 09:29:06 +02:00
|
|
|
gd_grab_update(vc, vc->s->kbd_owner == vc, true);
|
|
|
|
gdk_device_get_position(gd_get_pointer(display),
|
|
|
|
NULL, &vc->s->grab_x_root, &vc->s->grab_y_root);
|
2014-05-06 11:01:31 +02:00
|
|
|
vc->s->ptr_owner = vc;
|
2015-09-09 10:03:59 +02:00
|
|
|
gd_update_caption(vc->s);
|
2015-09-09 10:12:20 +02:00
|
|
|
trace_gd_grab(vc->label, "ptr", reason);
|
2013-02-25 16:20:37 +01:00
|
|
|
}
|
|
|
|
|
2014-05-06 11:01:31 +02:00
|
|
|
static void gd_ungrab_pointer(GtkDisplayState *s)
|
2013-02-25 16:20:37 +01:00
|
|
|
{
|
2014-05-06 11:01:31 +02:00
|
|
|
VirtualConsole *vc = s->ptr_owner;
|
2016-05-20 11:49:08 +02:00
|
|
|
GdkDisplay *display;
|
2014-05-06 11:01:31 +02:00
|
|
|
|
|
|
|
if (vc == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->ptr_owner = NULL;
|
|
|
|
|
2016-05-20 11:49:08 +02:00
|
|
|
display = gtk_widget_get_display(vc->gfx.drawing_area);
|
2016-05-12 09:29:06 +02:00
|
|
|
gd_grab_update(vc, vc->s->kbd_owner == vc, false);
|
|
|
|
gdk_device_warp(gd_get_pointer(display),
|
|
|
|
gtk_widget_get_screen(vc->gfx.drawing_area),
|
|
|
|
vc->s->grab_x_root, vc->s->grab_y_root);
|
2015-09-09 10:03:59 +02:00
|
|
|
gd_update_caption(s);
|
2015-09-09 10:12:20 +02:00
|
|
|
trace_gd_ungrab(vc->label, "ptr");
|
2013-02-25 16:20:37 +01:00
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:22 +01:00
|
|
|
static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
2013-02-20 14:43:22 +01:00
|
|
|
|
|
|
|
if (gd_is_grab_active(s)) {
|
2015-09-09 10:12:20 +02:00
|
|
|
gd_grab_keyboard(vc, "user-request-main-window");
|
|
|
|
gd_grab_pointer(vc, "user-request-main-window");
|
2013-02-20 14:43:22 +01:00
|
|
|
} else {
|
2014-05-06 11:01:31 +02:00
|
|
|
gd_ungrab_keyboard(s);
|
|
|
|
gd_ungrab_pointer(s);
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_cursor(vc);
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = data;
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc;
|
2013-02-20 14:43:22 +01:00
|
|
|
gboolean on_vga;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
if (!gtk_widget_get_realized(s->notebook)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
vc = gd_vc_find_by_page(s, arg2);
|
|
|
|
if (!vc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item),
|
|
|
|
TRUE);
|
2014-05-22 11:08:54 +02:00
|
|
|
on_vga = (vc->type == GD_VC_GFX &&
|
|
|
|
qemu_console_is_graphic(vc->gfx.dcl.con));
|
2013-02-20 14:43:22 +01:00
|
|
|
if (!on_vga) {
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
|
|
|
|
FALSE);
|
2013-02-20 14:43:23 +01:00
|
|
|
} else if (s->full_screen) {
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
|
|
|
|
TRUE);
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
gtk_widget_set_sensitive(s->grab_item, on_vga);
|
2016-12-14 15:25:18 +01:00
|
|
|
#ifdef CONFIG_VTE
|
|
|
|
gtk_widget_set_sensitive(s->copy_item, vc->type == GD_VC_VTE);
|
|
|
|
#endif
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2014-05-16 12:26:12 +02:00
|
|
|
gd_update_windowsize(vc);
|
2014-04-30 16:30:07 +02:00
|
|
|
gd_update_cursor(vc);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing,
|
|
|
|
gpointer opaque)
|
2013-02-20 14:43:22 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2014-05-06 11:45:30 +02:00
|
|
|
if (gd_grab_on_hover(s)) {
|
2015-09-09 10:12:20 +02:00
|
|
|
gd_grab_keyboard(vc, "grab-on-hover");
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing,
|
|
|
|
gpointer opaque)
|
2013-02-20 14:43:22 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2014-05-06 11:45:30 +02:00
|
|
|
if (gd_grab_on_hover(s)) {
|
2014-05-06 11:01:31 +02:00
|
|
|
gd_ungrab_keyboard(s);
|
2013-02-20 14:43:22 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:20:05 +02:00
|
|
|
static gboolean gd_focus_in_event(GtkWidget *widget,
|
|
|
|
GdkEventFocus *event, gpointer opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
|
|
|
|
win32_kbd_set_window(gd_win32_get_hwnd(vc));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-24 19:10:02 +01:00
|
|
|
static gboolean gd_focus_out_event(GtkWidget *widget,
|
2020-05-16 09:20:05 +02:00
|
|
|
GdkEventFocus *event, gpointer opaque)
|
2013-03-24 19:10:02 +01:00
|
|
|
{
|
2014-04-30 16:30:07 +02:00
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
GtkDisplayState *s = vc->s;
|
2013-03-24 19:10:02 +01:00
|
|
|
|
2020-05-16 09:20:05 +02:00
|
|
|
win32_kbd_set_window(NULL);
|
2013-03-24 19:10:02 +01:00
|
|
|
gtk_release_modifiers(s);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-13 12:47:00 +01:00
|
|
|
static gboolean gd_configure(GtkWidget *widget,
|
|
|
|
GdkEventConfigure *cfg, gpointer opaque)
|
|
|
|
{
|
|
|
|
VirtualConsole *vc = opaque;
|
|
|
|
|
2015-05-26 12:26:21 +02:00
|
|
|
gd_set_ui_info(vc, cfg->width, cfg->height);
|
2015-03-13 12:47:00 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:21 +01:00
|
|
|
/** Virtual Console Callbacks **/
|
|
|
|
|
2014-04-30 16:39:18 +02:00
|
|
|
static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
|
2014-05-05 16:23:33 +02:00
|
|
|
int idx, GSList *group, GtkWidget *view_menu)
|
2014-04-30 16:39:18 +02:00
|
|
|
{
|
2014-05-05 16:23:33 +02:00
|
|
|
vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, vc->label);
|
2014-10-30 20:34:34 +01:00
|
|
|
gtk_accel_group_connect(s->accel_group, GDK_KEY_1 + idx,
|
|
|
|
HOTKEY_MODIFIERS, 0,
|
|
|
|
g_cclosure_new_swap(G_CALLBACK(gd_accel_switch_vc), vc, NULL));
|
|
|
|
gtk_accel_label_set_accel(
|
|
|
|
GTK_ACCEL_LABEL(gtk_bin_get_child(GTK_BIN(vc->menu_item))),
|
|
|
|
GDK_KEY_1 + idx, HOTKEY_MODIFIERS);
|
2014-04-30 16:39:18 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-04-01 18:53:14 +02:00
|
|
|
return gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
|
2014-04-30 16:39:18 +02:00
|
|
|
}
|
|
|
|
|
2014-04-29 15:39:37 +02:00
|
|
|
#if defined(CONFIG_VTE)
|
2016-04-17 22:25:54 +02:00
|
|
|
static void gd_menu_copy(GtkMenuItem *item, void *opaque)
|
|
|
|
{
|
|
|
|
GtkDisplayState *s = opaque;
|
|
|
|
VirtualConsole *vc = gd_vc_find_current(s);
|
|
|
|
|
2017-10-10 12:24:18 +02:00
|
|
|
#if VTE_CHECK_VERSION(0, 50, 0)
|
|
|
|
vte_terminal_copy_clipboard_format(VTE_TERMINAL(vc->vte.terminal),
|
|
|
|
VTE_FORMAT_TEXT);
|
|
|
|
#else
|
2016-04-17 22:25:54 +02:00
|
|
|
vte_terminal_copy_clipboard(VTE_TERMINAL(vc->vte.terminal));
|
2017-10-10 12:24:18 +02:00
|
|
|
#endif
|
2016-04-17 22:25:54 +02:00
|
|
|
}
|
|
|
|
|
2014-04-29 21:24:32 +02:00
|
|
|
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)) {
|
2014-04-30 13:53:16 +02:00
|
|
|
gtk_widget_show(vc->vte.scrollbar);
|
2014-04-29 21:24:32 +02:00
|
|
|
} else {
|
2014-04-30 13:53:16 +02:00
|
|
|
gtk_widget_hide(vc->vte.scrollbar);
|
2014-04-29 21:24:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 14:20:22 +01:00
|
|
|
static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
|
2013-02-20 14:43:21 +01:00
|
|
|
{
|
2016-12-07 16:39:10 +01:00
|
|
|
VCChardev *vcd = VC_CHARDEV(chr);
|
2016-10-21 22:44:44 +02:00
|
|
|
VirtualConsole *vc = vcd->console;
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2014-04-30 13:53:16 +02:00
|
|
|
vte_terminal_feed(VTE_TERMINAL(vc->vte.terminal), (const char *)buf, len);
|
2014-04-24 19:35:54 +02:00
|
|
|
return len;
|
2013-02-20 14:43:21 +01:00
|
|
|
}
|
|
|
|
|
2016-12-07 14:20:22 +01:00
|
|
|
static void gd_vc_chr_set_echo(Chardev *chr, bool echo)
|
2015-12-17 13:47:02 +01:00
|
|
|
{
|
2016-12-07 16:39:10 +01:00
|
|
|
VCChardev *vcd = VC_CHARDEV(chr);
|
2016-10-21 22:44:44 +02:00
|
|
|
VirtualConsole *vc = vcd->console;
|
2015-12-17 13:47:02 +01:00
|
|
|
|
2016-10-21 22:44:44 +02:00
|
|
|
if (vc) {
|
|
|
|
vc->vte.echo = echo;
|
|
|
|
} else {
|
|
|
|
vcd->echo = echo;
|
|
|
|
}
|
2015-12-17 13:47:02 +01:00
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:21 +01:00
|
|
|
static int nb_vcs;
|
2016-12-07 14:20:22 +01:00
|
|
|
static Chardev *vcs[MAX_VCS];
|
2016-12-07 16:39:10 +01:00
|
|
|
static void gd_vc_open(Chardev *chr,
|
|
|
|
ChardevBackend *backend,
|
|
|
|
bool *be_opened,
|
|
|
|
Error **errp)
|
2013-02-20 14:43:21 +01:00
|
|
|
{
|
2016-12-07 11:55:11 +01:00
|
|
|
if (nb_vcs == MAX_VCS) {
|
|
|
|
error_setg(errp, "Maximum number of consoles reached");
|
2016-12-07 16:39:10 +01:00
|
|
|
return;
|
2016-01-21 12:56:26 +01:00
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:21 +01:00
|
|
|
vcs[nb_vcs++] = chr;
|
|
|
|
|
2016-12-07 13:13:50 +01:00
|
|
|
/* console/chardev init sometimes completes elsewhere in a 2nd
|
|
|
|
* stage, so defer OPENED events until they are fully initialized
|
|
|
|
*/
|
|
|
|
*be_opened = false;
|
2016-12-07 16:39:10 +01:00
|
|
|
}
|
2016-12-07 13:13:50 +01:00
|
|
|
|
2016-12-07 16:39:10 +01:00
|
|
|
static void char_gd_vc_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
ChardevClass *cc = CHARDEV_CLASS(oc);
|
|
|
|
|
2016-12-08 22:50:12 +01:00
|
|
|
cc->parse = qemu_chr_parse_vc;
|
2016-12-07 16:39:10 +01:00
|
|
|
cc->open = gd_vc_open;
|
|
|
|
cc->chr_write = gd_vc_chr_write;
|
|
|
|
cc->chr_set_echo = gd_vc_chr_set_echo;
|
2013-02-20 14:43:21 +01:00
|
|
|
}
|
|
|
|
|
2016-12-07 16:39:10 +01:00
|
|
|
static const TypeInfo char_gd_vc_type_info = {
|
|
|
|
.name = TYPE_CHARDEV_VC,
|
|
|
|
.parent = TYPE_CHARDEV,
|
2016-12-07 13:13:50 +01:00
|
|
|
.instance_size = sizeof(VCChardev),
|
2016-12-07 16:39:10 +01:00
|
|
|
.class_init = char_gd_vc_class_init,
|
|
|
|
};
|
|
|
|
|
2014-04-24 19:35:54 +02:00
|
|
|
static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
|
|
|
|
gpointer user_data)
|
2013-02-20 14:43:21 +01:00
|
|
|
{
|
2014-04-24 19:35:54 +02:00
|
|
|
VirtualConsole *vc = user_data;
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2015-12-17 13:47:02 +01:00
|
|
|
if (vc->vte.echo) {
|
|
|
|
VteTerminal *term = VTE_TERMINAL(vc->vte.terminal);
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
uint8_t c = text[i];
|
|
|
|
if (c >= 128 || isprint(c)) {
|
|
|
|
/* 8-bit characters are considered printable. */
|
|
|
|
vte_terminal_feed(term, &text[i], 1);
|
|
|
|
} else if (c == '\r' || c == '\n') {
|
|
|
|
vte_terminal_feed(term, "\r\n", 2);
|
|
|
|
} else {
|
|
|
|
char ctrl[2] = { '^', 0};
|
|
|
|
ctrl[1] = text[i] ^ 64;
|
|
|
|
vte_terminal_feed(term, ctrl, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:53:16 +02:00
|
|
|
qemu_chr_be_write(vc->vte.chr, (uint8_t *)text, (unsigned int)size);
|
2013-02-20 14:43:21 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:39:18 +02:00
|
|
|
static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
|
2016-12-07 14:20:22 +01:00
|
|
|
Chardev *chr, int idx,
|
2014-04-30 16:30:07 +02:00
|
|
|
GSList *group, GtkWidget *view_menu)
|
2013-02-20 14:43:21 +01:00
|
|
|
{
|
|
|
|
char buffer[32];
|
2014-04-29 21:24:32 +02:00
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *scrollbar;
|
|
|
|
GtkAdjustment *vadjustment;
|
2016-12-07 16:39:10 +01:00
|
|
|
VCChardev *vcd = VC_CHARDEV(chr);
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->s = s;
|
2016-10-21 22:44:44 +02:00
|
|
|
vc->vte.echo = vcd->echo;
|
2014-04-30 16:39:18 +02:00
|
|
|
vc->vte.chr = chr;
|
2016-10-21 22:44:44 +02:00
|
|
|
vcd->console = vc;
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2014-04-30 16:39:18 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "vc%d", idx);
|
2014-05-05 16:23:33 +02:00
|
|
|
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);
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2014-04-30 13:53:16 +02:00
|
|
|
vc->vte.terminal = vte_terminal_new();
|
|
|
|
g_signal_connect(vc->vte.terminal, "commit", G_CALLBACK(gd_vc_in), vc);
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2015-12-17 13:47:02 +01:00
|
|
|
/* The documentation says that the default is UTF-8, but actually it is
|
2018-10-11 17:30:39 +02:00
|
|
|
* 7-bit ASCII at least in VTE 0.38. The function is deprecated since
|
|
|
|
* VTE 0.54 (only UTF-8 is supported now). */
|
|
|
|
#if !VTE_CHECK_VERSION(0, 54, 0)
|
2016-06-08 23:43:52 +02:00
|
|
|
#if VTE_CHECK_VERSION(0, 38, 0)
|
2015-12-17 13:47:02 +01:00
|
|
|
vte_terminal_set_encoding(VTE_TERMINAL(vc->vte.terminal), "UTF-8", NULL);
|
|
|
|
#else
|
|
|
|
vte_terminal_set_encoding(VTE_TERMINAL(vc->vte.terminal), "UTF-8");
|
2018-10-11 17:30:39 +02:00
|
|
|
#endif
|
2015-12-17 13:47:02 +01:00
|
|
|
#endif
|
|
|
|
|
2014-04-30 13:53:16 +02:00
|
|
|
vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->vte.terminal), -1);
|
2014-05-16 12:26:12 +02:00
|
|
|
vte_terminal_set_size(VTE_TERMINAL(vc->vte.terminal),
|
|
|
|
VC_TERM_X_MIN, VC_TERM_Y_MIN);
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2018-08-22 15:15:52 +02:00
|
|
|
#if VTE_CHECK_VERSION(0, 28, 0)
|
2014-04-30 13:53:16 +02:00
|
|
|
vadjustment = gtk_scrollable_get_vadjustment
|
|
|
|
(GTK_SCROLLABLE(vc->vte.terminal));
|
2014-04-29 21:24:32 +02:00
|
|
|
#else
|
2014-04-30 13:53:16 +02:00
|
|
|
vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->vte.terminal));
|
2014-04-29 21:24:32 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, vadjustment);
|
|
|
|
|
2018-02-17 12:26:49 +01:00
|
|
|
gtk_box_pack_end(GTK_BOX(box), scrollbar, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_end(GTK_BOX(box), vc->vte.terminal, TRUE, TRUE, 0);
|
2014-04-29 21:24:32 +02:00
|
|
|
|
2014-04-30 13:53:16 +02:00
|
|
|
vc->vte.box = box;
|
|
|
|
vc->vte.scrollbar = scrollbar;
|
2014-04-29 21:24:32 +02:00
|
|
|
|
|
|
|
g_signal_connect(vadjustment, "changed",
|
|
|
|
G_CALLBACK(gd_vc_adjustment_changed), vc);
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->type = GD_VC_VTE;
|
2014-04-30 13:53:16 +02:00
|
|
|
vc->tab_item = box;
|
2015-04-26 21:04:20 +02:00
|
|
|
vc->focus = vc->vte.terminal;
|
2014-04-30 13:53:16 +02:00
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), vc->tab_item,
|
2014-05-05 16:23:33 +02:00
|
|
|
gtk_label_new(vc->label));
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2016-12-14 12:23:02 +01:00
|
|
|
qemu_chr_be_event(vc->vte.chr, CHR_EVENT_OPENED);
|
2013-02-20 14:43:21 +01:00
|
|
|
|
|
|
|
return group;
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:39:18 +02:00
|
|
|
static void gd_vcs_init(GtkDisplayState *s, GSList *group,
|
2014-04-29 15:39:37 +02:00
|
|
|
GtkWidget *view_menu)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_vcs; i++) {
|
2014-04-30 16:39:18 +02:00
|
|
|
VirtualConsole *vc = &s->vc[s->nb_vcs];
|
|
|
|
group = gd_vc_vte_init(s, vc, vcs[i], s->nb_vcs, group, view_menu);
|
2014-04-29 15:39:37 +02:00
|
|
|
s->nb_vcs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_VTE */
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
/** Window Creation **/
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
|
|
|
|
{
|
|
|
|
g_signal_connect(vc->gfx.drawing_area, "draw",
|
|
|
|
G_CALLBACK(gd_draw_event), vc);
|
2015-05-26 12:26:21 +02:00
|
|
|
#if defined(CONFIG_GTK_GL)
|
2018-03-06 10:09:46 +01:00
|
|
|
if (gtk_use_gl_area) {
|
2015-05-26 12:26:21 +02:00
|
|
|
/* wire up GtkGlArea events */
|
|
|
|
g_signal_connect(vc->gfx.drawing_area, "render",
|
|
|
|
G_CALLBACK(gd_render_event), vc);
|
|
|
|
g_signal_connect(vc->gfx.drawing_area, "resize",
|
|
|
|
G_CALLBACK(gd_resize_event), vc);
|
|
|
|
}
|
2014-04-30 16:30:07 +02:00
|
|
|
#endif
|
2014-05-22 11:08:54 +02:00
|
|
|
if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
|
|
|
|
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);
|
2020-05-16 09:20:05 +02:00
|
|
|
g_signal_connect(vc->gfx.drawing_area, "focus-in-event",
|
|
|
|
G_CALLBACK(gd_focus_in_event), vc);
|
2014-05-22 11:08:54 +02:00
|
|
|
g_signal_connect(vc->gfx.drawing_area, "focus-out-event",
|
|
|
|
G_CALLBACK(gd_focus_out_event), vc);
|
2015-03-13 12:47:00 +01:00
|
|
|
g_signal_connect(vc->gfx.drawing_area, "configure-event",
|
|
|
|
G_CALLBACK(gd_configure), vc);
|
2020-05-16 09:20:06 +02:00
|
|
|
g_signal_connect(vc->gfx.drawing_area, "grab-broken-event",
|
|
|
|
G_CALLBACK(gd_grab_broken_event), vc);
|
2014-05-22 11:08:54 +02:00
|
|
|
} else {
|
|
|
|
g_signal_connect(vc->gfx.drawing_area, "key-press-event",
|
|
|
|
G_CALLBACK(gd_text_key_down), vc);
|
|
|
|
}
|
2014-04-30 16:30:07 +02:00
|
|
|
}
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
static void gd_connect_signals(GtkDisplayState *s)
|
|
|
|
{
|
|
|
|
g_signal_connect(s->show_tabs_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_show_tabs), s);
|
2014-05-05 16:23:33 +02:00
|
|
|
g_signal_connect(s->untabify_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_untabify), s);
|
2018-05-11 01:07:38 +02:00
|
|
|
g_signal_connect(s->show_menubar_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_show_menubar), s);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
g_signal_connect(s->window, "delete-event",
|
|
|
|
G_CALLBACK(gd_window_close), s);
|
|
|
|
|
2013-02-22 20:53:33 +01:00
|
|
|
g_signal_connect(s->pause_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_pause), s);
|
|
|
|
g_signal_connect(s->reset_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_reset), s);
|
|
|
|
g_signal_connect(s->powerdown_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_powerdown), s);
|
2013-02-20 14:43:20 +01:00
|
|
|
g_signal_connect(s->quit_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_quit), s);
|
2016-04-17 22:25:54 +02:00
|
|
|
#if defined(CONFIG_VTE)
|
|
|
|
g_signal_connect(s->copy_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_copy), s);
|
|
|
|
#endif
|
2013-02-20 14:43:23 +01:00
|
|
|
g_signal_connect(s->full_screen_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_full_screen), s);
|
|
|
|
g_signal_connect(s->zoom_in_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_zoom_in), s);
|
|
|
|
g_signal_connect(s->zoom_out_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_zoom_out), s);
|
|
|
|
g_signal_connect(s->zoom_fixed_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_zoom_fixed), s);
|
|
|
|
g_signal_connect(s->zoom_fit_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_zoom_fit), s);
|
2013-02-20 14:43:22 +01:00
|
|
|
g_signal_connect(s->grab_item, "activate",
|
|
|
|
G_CALLBACK(gd_menu_grab_input), s);
|
2013-02-20 14:43:20 +01:00
|
|
|
g_signal_connect(s->notebook, "switch-page",
|
|
|
|
G_CALLBACK(gd_change_page), s);
|
|
|
|
}
|
|
|
|
|
2014-10-30 20:34:32 +01:00
|
|
|
static GtkWidget *gd_create_menu_machine(GtkDisplayState *s)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2013-04-26 15:48:46 +02:00
|
|
|
GtkWidget *machine_menu;
|
2013-02-20 14:43:20 +01:00
|
|
|
GtkWidget *separator;
|
|
|
|
|
2013-04-26 15:48:46 +02:00
|
|
|
machine_menu = gtk_menu_new();
|
2014-10-30 20:34:32 +01:00
|
|
|
gtk_menu_set_accel_group(GTK_MENU(machine_menu), s->accel_group);
|
2013-02-22 20:53:33 +01:00
|
|
|
|
|
|
|
s->pause_item = gtk_check_menu_item_new_with_mnemonic(_("_Pause"));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->pause_item);
|
2013-02-22 20:53:33 +01:00
|
|
|
|
|
|
|
separator = gtk_separator_menu_item_new();
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), separator);
|
2013-02-22 20:53:33 +01:00
|
|
|
|
2014-03-17 21:06:24 +01:00
|
|
|
s->reset_item = gtk_menu_item_new_with_mnemonic(_("_Reset"));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->reset_item);
|
2013-02-22 20:53:33 +01:00
|
|
|
|
2014-03-17 21:06:24 +01:00
|
|
|
s->powerdown_item = gtk_menu_item_new_with_mnemonic(_("Power _Down"));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->powerdown_item);
|
2013-02-22 20:53:33 +01:00
|
|
|
|
|
|
|
separator = gtk_separator_menu_item_new();
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), separator);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-03-17 21:06:26 +01:00
|
|
|
s->quit_item = gtk_menu_item_new_with_mnemonic(_("_Quit"));
|
2013-02-20 14:43:20 +01:00
|
|
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->quit_item),
|
2013-02-22 20:53:33 +01:00
|
|
|
"<QEMU>/Machine/Quit");
|
2014-03-17 21:06:26 +01:00
|
|
|
gtk_accel_map_add_entry("<QEMU>/Machine/Quit",
|
2014-03-17 21:06:27 +01:00
|
|
|
GDK_KEY_q, HOTKEY_MODIFIERS);
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->quit_item);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-04-26 15:48:46 +02:00
|
|
|
return machine_menu;
|
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
|
2014-04-30 16:39:18 +02:00
|
|
|
QemuConsole *con, int idx,
|
2014-04-30 16:30:07 +02:00
|
|
|
GSList *group, GtkWidget *view_menu)
|
|
|
|
{
|
2018-10-03 14:11:38 +02:00
|
|
|
bool zoom_to_fit = false;
|
2020-01-08 13:13:42 +01:00
|
|
|
|
2015-02-17 10:41:08 +01:00
|
|
|
vc->label = qemu_console_get_label(con);
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->s = s;
|
|
|
|
vc->gfx.scale_x = 1.0;
|
|
|
|
vc->gfx.scale_y = 1.0;
|
|
|
|
|
2015-01-20 12:43:28 +01:00
|
|
|
#if defined(CONFIG_OPENGL)
|
|
|
|
if (display_opengl) {
|
2015-05-26 12:26:21 +02:00
|
|
|
#if defined(CONFIG_GTK_GL)
|
2018-03-06 10:09:46 +01:00
|
|
|
if (gtk_use_gl_area) {
|
|
|
|
vc->gfx.drawing_area = gtk_gl_area_new();
|
|
|
|
vc->gfx.dcl.ops = &dcl_gl_area_ops;
|
|
|
|
} else
|
|
|
|
#endif /* CONFIG_GTK_GL */
|
|
|
|
{
|
|
|
|
vc->gfx.drawing_area = gtk_drawing_area_new();
|
|
|
|
/*
|
|
|
|
* gtk_widget_set_double_buffered() was deprecated in 3.14.
|
|
|
|
* It is required for opengl rendering on X11 though. A
|
|
|
|
* proper replacement (native opengl support) is only
|
|
|
|
* available in 3.16+. Silence the warning if possible.
|
|
|
|
*/
|
2015-01-20 12:43:28 +01:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2018-03-06 10:09:46 +01:00
|
|
|
gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE);
|
2015-01-20 12:43:28 +01:00
|
|
|
#pragma GCC diagnostic pop
|
2018-03-06 10:09:46 +01:00
|
|
|
vc->gfx.dcl.ops = &dcl_egl_ops;
|
|
|
|
}
|
2015-01-20 12:43:28 +01:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-26 12:26:21 +02:00
|
|
|
vc->gfx.drawing_area = gtk_drawing_area_new();
|
2015-01-20 12:43:28 +01:00
|
|
|
vc->gfx.dcl.ops = &dcl_ops;
|
|
|
|
}
|
|
|
|
|
2015-05-26 12:26:21 +02:00
|
|
|
|
|
|
|
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 |
|
2019-02-04 13:08:23 +01:00
|
|
|
GDK_SMOOTH_SCROLL_MASK |
|
2015-05-26 12:26:21 +02:00
|
|
|
GDK_KEY_PRESS_MASK);
|
|
|
|
gtk_widget_set_can_focus(vc->gfx.drawing_area, TRUE);
|
|
|
|
|
|
|
|
vc->type = GD_VC_GFX;
|
|
|
|
vc->tab_item = vc->gfx.drawing_area;
|
|
|
|
vc->focus = vc->gfx.drawing_area;
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook),
|
|
|
|
vc->tab_item, gtk_label_new(vc->label));
|
|
|
|
|
2019-01-22 10:28:11 +01:00
|
|
|
vc->gfx.kbd = qkbd_state_init(con);
|
2014-04-30 16:30:07 +02:00
|
|
|
vc->gfx.dcl.con = con;
|
2020-01-08 13:13:42 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
register_displaychangelistener(&vc->gfx.dcl);
|
|
|
|
|
2014-05-22 11:08:54 +02:00
|
|
|
gd_connect_vc_gfx_signals(vc);
|
|
|
|
group = gd_vc_menu_init(s, vc, idx, group, view_menu);
|
|
|
|
|
2015-03-13 12:47:00 +01:00
|
|
|
if (dpy_ui_info_supported(vc->gfx.dcl.con)) {
|
2018-08-27 11:56:20 +02:00
|
|
|
zoom_to_fit = true;
|
|
|
|
}
|
|
|
|
if (s->opts->u.gtk.has_zoom_to_fit) {
|
|
|
|
zoom_to_fit = s->opts->u.gtk.zoom_to_fit;
|
|
|
|
}
|
|
|
|
if (zoom_to_fit) {
|
2015-03-13 12:47:00 +01:00
|
|
|
gtk_menu_item_activate(GTK_MENU_ITEM(s->zoom_fit_item));
|
2015-09-09 10:34:41 +02:00
|
|
|
s->free_scale = true;
|
2015-03-13 12:47:00 +01:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2014-10-30 20:34:32 +01:00
|
|
|
static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
|
2013-04-26 15:48:46 +02:00
|
|
|
{
|
|
|
|
GSList *group = NULL;
|
|
|
|
GtkWidget *view_menu;
|
|
|
|
GtkWidget *separator;
|
2014-04-30 16:39:18 +02:00
|
|
|
QemuConsole *con;
|
|
|
|
int vc;
|
2013-04-26 15:48:46 +02:00
|
|
|
|
|
|
|
view_menu = gtk_menu_new();
|
2014-10-30 20:34:32 +01:00
|
|
|
gtk_menu_set_accel_group(GTK_MENU(view_menu), s->accel_group);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-03-17 21:06:26 +01:00
|
|
|
s->full_screen_item = gtk_menu_item_new_with_mnemonic(_("_Fullscreen"));
|
2014-10-30 20:34:33 +01:00
|
|
|
|
2016-04-17 22:25:54 +02:00
|
|
|
#if defined(CONFIG_VTE)
|
|
|
|
s->copy_item = gtk_menu_item_new_with_mnemonic(_("_Copy"));
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->copy_item);
|
|
|
|
#endif
|
|
|
|
|
2014-10-30 20:34:33 +01:00
|
|
|
gtk_accel_group_connect(s->accel_group, GDK_KEY_f, HOTKEY_MODIFIERS, 0,
|
|
|
|
g_cclosure_new_swap(G_CALLBACK(gd_accel_full_screen), s, NULL));
|
|
|
|
gtk_accel_label_set_accel(
|
|
|
|
GTK_ACCEL_LABEL(gtk_bin_get_child(GTK_BIN(s->full_screen_item))),
|
|
|
|
GDK_KEY_f, HOTKEY_MODIFIERS);
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->full_screen_item);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
separator = gtk_separator_menu_item_new();
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-03-17 21:06:26 +01:00
|
|
|
s->zoom_in_item = gtk_menu_item_new_with_mnemonic(_("Zoom _In"));
|
2013-02-20 14:43:23 +01:00
|
|
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item),
|
|
|
|
"<QEMU>/View/Zoom In");
|
2013-07-22 09:04:32 +02:00
|
|
|
gtk_accel_map_add_entry("<QEMU>/View/Zoom In", GDK_KEY_plus,
|
|
|
|
HOTKEY_MODIFIERS);
|
2017-01-31 02:32:15 +01:00
|
|
|
gtk_accel_group_connect(s->accel_group, GDK_KEY_equal, HOTKEY_MODIFIERS, 0,
|
|
|
|
g_cclosure_new_swap(G_CALLBACK(gd_accel_zoom_in), s, NULL));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_in_item);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-03-17 21:06:26 +01:00
|
|
|
s->zoom_out_item = gtk_menu_item_new_with_mnemonic(_("Zoom _Out"));
|
2013-02-20 14:43:23 +01:00
|
|
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item),
|
|
|
|
"<QEMU>/View/Zoom Out");
|
2013-07-22 09:04:32 +02:00
|
|
|
gtk_accel_map_add_entry("<QEMU>/View/Zoom Out", GDK_KEY_minus,
|
|
|
|
HOTKEY_MODIFIERS);
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_out_item);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2014-03-17 21:06:26 +01:00
|
|
|
s->zoom_fixed_item = gtk_menu_item_new_with_mnemonic(_("Best _Fit"));
|
2013-02-20 14:43:23 +01:00
|
|
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item),
|
|
|
|
"<QEMU>/View/Zoom Fixed");
|
2013-07-22 09:04:32 +02:00
|
|
|
gtk_accel_map_add_entry("<QEMU>/View/Zoom Fixed", GDK_KEY_0,
|
|
|
|
HOTKEY_MODIFIERS);
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fixed_item);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2013-02-20 14:43:24 +01:00
|
|
|
s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit"));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fit_item);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
|
|
|
separator = gtk_separator_menu_item_new();
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
|
2013-02-20 14:43:23 +01:00
|
|
|
|
2013-02-20 14:43:24 +01:00
|
|
|
s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover"));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2013-02-20 14:43:24 +01:00
|
|
|
s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
|
2013-02-20 14:43:22 +01:00
|
|
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
|
|
|
|
"<QEMU>/View/Grab Input");
|
2013-07-22 09:04:32 +02:00
|
|
|
gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g,
|
|
|
|
HOTKEY_MODIFIERS);
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
|
2013-02-20 14:43:22 +01:00
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
separator = gtk_separator_menu_item_new();
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-30 16:30:07 +02:00
|
|
|
/* gfx */
|
2014-04-30 16:39:18 +02:00
|
|
|
for (vc = 0;; vc++) {
|
|
|
|
con = qemu_console_lookup_by_index(vc);
|
2014-05-22 11:08:54 +02:00
|
|
|
if (!con) {
|
2014-04-30 16:39:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
group = gd_vc_gfx_init(s, &s->vc[vc], con,
|
|
|
|
vc, group, view_menu);
|
|
|
|
s->nb_vcs++;
|
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-04-29 15:39:37 +02:00
|
|
|
#if defined(CONFIG_VTE)
|
2014-04-30 16:30:07 +02:00
|
|
|
/* vte */
|
2014-04-30 16:39:18 +02:00
|
|
|
gd_vcs_init(s, group, view_menu);
|
2014-04-29 15:39:37 +02:00
|
|
|
#endif
|
2013-02-20 14:43:21 +01:00
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
separator = gtk_separator_menu_item_new();
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-02-20 14:43:24 +01:00
|
|
|
s->show_tabs_item = gtk_check_menu_item_new_with_mnemonic(_("Show _Tabs"));
|
2013-04-26 15:48:46 +02:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->show_tabs_item);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2014-05-05 16:23:33 +02:00
|
|
|
s->untabify_item = gtk_menu_item_new_with_mnemonic(_("Detach Tab"));
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->untabify_item);
|
|
|
|
|
2018-05-11 01:07:38 +02:00
|
|
|
s->show_menubar_item = gtk_check_menu_item_new_with_mnemonic(
|
|
|
|
_("Show Menubar"));
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->show_menubar_item),
|
|
|
|
TRUE);
|
|
|
|
gtk_accel_group_connect(s->accel_group, GDK_KEY_m, HOTKEY_MODIFIERS, 0,
|
|
|
|
g_cclosure_new_swap(G_CALLBACK(gd_accel_show_menubar), s, NULL));
|
|
|
|
gtk_accel_label_set_accel(
|
|
|
|
GTK_ACCEL_LABEL(gtk_bin_get_child(GTK_BIN(s->show_menubar_item))),
|
|
|
|
GDK_KEY_m, HOTKEY_MODIFIERS);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->show_menubar_item);
|
|
|
|
|
2013-04-26 15:48:46 +02:00
|
|
|
return view_menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gd_create_menus(GtkDisplayState *s)
|
|
|
|
{
|
2018-05-11 01:07:39 +02:00
|
|
|
GtkSettings *settings;
|
|
|
|
|
2014-10-30 20:34:32 +01:00
|
|
|
s->accel_group = gtk_accel_group_new();
|
|
|
|
s->machine_menu = gd_create_menu_machine(s);
|
|
|
|
s->view_menu = gd_create_menu_view(s);
|
2013-04-26 15:48:46 +02:00
|
|
|
|
|
|
|
s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
|
2013-02-22 20:53:33 +01:00
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item),
|
|
|
|
s->machine_menu);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->machine_menu_item);
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2013-04-26 15:48:46 +02:00
|
|
|
s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
|
2013-02-20 14:43:20 +01:00
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item);
|
2013-04-26 15:48:46 +02:00
|
|
|
|
2014-10-30 20:34:32 +01:00
|
|
|
g_object_set_data(G_OBJECT(s->window), "accel_group", s->accel_group);
|
|
|
|
gtk_window_add_accel_group(GTK_WINDOW(s->window), s->accel_group);
|
2018-05-11 01:07:39 +02:00
|
|
|
|
|
|
|
/* Disable the default "F10" menu shortcut. */
|
|
|
|
settings = gtk_widget_get_settings(s->window);
|
|
|
|
g_object_set(G_OBJECT(settings), "gtk-menu-bar-accel", "", NULL);
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 04:29:42 +02:00
|
|
|
|
2015-06-05 13:07:58 +02:00
|
|
|
static gboolean gtkinit;
|
|
|
|
|
2018-03-01 11:05:35 +01:00
|
|
|
static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
|
2013-02-20 14:43:20 +01:00
|
|
|
{
|
2017-01-01 10:39:45 +01:00
|
|
|
VirtualConsole *vc;
|
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
GtkDisplayState *s = g_malloc0(sizeof(*s));
|
2015-05-20 15:35:31 +02:00
|
|
|
GdkDisplay *window_display;
|
2019-01-10 13:00:45 +01:00
|
|
|
GtkIconTheme *theme;
|
2020-08-18 11:59:27 +02:00
|
|
|
char *dir;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2015-06-05 13:07:58 +02:00
|
|
|
if (!gtkinit) {
|
|
|
|
fprintf(stderr, "gtk initialization failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-02-02 12:10:14 +01:00
|
|
|
assert(opts->type == DISPLAY_TYPE_GTK);
|
|
|
|
s->opts = opts;
|
2015-06-05 13:07:58 +02:00
|
|
|
|
2019-01-10 13:00:45 +01:00
|
|
|
theme = gtk_icon_theme_get_default();
|
2020-08-18 11:59:27 +02:00
|
|
|
dir = get_relocated_path(CONFIG_QEMU_ICONDIR);
|
|
|
|
gtk_icon_theme_prepend_search_path(theme, dir);
|
|
|
|
g_free(dir);
|
2019-01-10 13:00:46 +01:00
|
|
|
g_set_prgname("qemu");
|
2019-01-10 13:00:45 +01:00
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
2013-02-25 16:20:38 +01:00
|
|
|
s->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
2013-02-20 14:43:20 +01:00
|
|
|
s->notebook = gtk_notebook_new();
|
|
|
|
s->menu_bar = gtk_menu_bar_new();
|
|
|
|
|
2013-02-20 14:43:23 +01:00
|
|
|
s->free_scale = FALSE;
|
2013-02-20 14:43:20 +01:00
|
|
|
|
2017-01-31 11:09:45 +01:00
|
|
|
/* Mostly LC_MESSAGES only. See early_gtk_display_init() for details. For
|
|
|
|
* LC_CTYPE, we need to make sure that non-ASCII characters are considered
|
|
|
|
* printable, but without changing any of the character classes to make
|
|
|
|
* sure that we don't accidentally break implicit assumptions. */
|
2015-09-10 17:19:32 +02:00
|
|
|
setlocale(LC_MESSAGES, "");
|
2017-01-31 11:09:45 +01:00
|
|
|
setlocale(LC_CTYPE, "C.UTF-8");
|
2020-08-18 11:59:27 +02:00
|
|
|
dir = get_relocated_path(CONFIG_QEMU_LOCALEDIR);
|
|
|
|
bindtextdomain("qemu", dir);
|
|
|
|
g_free(dir);
|
2019-11-16 04:10:37 +01:00
|
|
|
bind_textdomain_codeset("qemu", "UTF-8");
|
2013-02-20 14:43:24 +01:00
|
|
|
textdomain("qemu");
|
|
|
|
|
2015-05-20 15:35:31 +02:00
|
|
|
window_display = gtk_widget_get_display(s->window);
|
2020-01-31 11:54:48 +01:00
|
|
|
if (s->opts->has_show_cursor && s->opts->show_cursor) {
|
|
|
|
s->null_cursor = NULL; /* default pointer */
|
|
|
|
} else {
|
|
|
|
s->null_cursor = gdk_cursor_new_for_display(window_display,
|
|
|
|
GDK_BLANK_CURSOR);
|
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
|
|
|
|
s->mouse_mode_notifier.notify = gd_mouse_mode_change;
|
|
|
|
qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier);
|
|
|
|
qemu_add_vm_change_state_handler(gd_change_runstate, s);
|
|
|
|
|
2019-01-10 13:00:45 +01:00
|
|
|
gtk_window_set_icon_name(GTK_WINDOW(s->window), "qemu");
|
2013-03-30 15:21:40 +01:00
|
|
|
|
2013-02-20 14:43:20 +01:00
|
|
|
gd_create_menus(s);
|
|
|
|
|
|
|
|
gd_connect_signals(s);
|
|
|
|
|
|
|
|
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
|
|
|
|
gtk_notebook_set_show_border(GTK_NOTEBOOK(s->notebook), FALSE);
|
|
|
|
|
|
|
|
gd_update_caption(s);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(s->vbox), s->menu_bar, FALSE, TRUE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(s->vbox), s->notebook, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(s->window), s->vbox);
|
|
|
|
|
|
|
|
gtk_widget_show_all(s->window);
|
|
|
|
|
2017-01-01 10:39:45 +01:00
|
|
|
vc = gd_vc_find_current(s);
|
|
|
|
gtk_widget_set_sensitive(s->view_menu, vc != NULL);
|
2016-12-14 15:25:18 +01:00
|
|
|
#ifdef CONFIG_VTE
|
|
|
|
gtk_widget_set_sensitive(s->copy_item,
|
2017-01-01 10:39:45 +01:00
|
|
|
vc && vc->type == GD_VC_VTE);
|
2016-12-14 15:25:18 +01:00
|
|
|
#endif
|
|
|
|
|
2018-02-02 12:10:14 +01:00
|
|
|
if (opts->has_full_screen &&
|
|
|
|
opts->full_screen) {
|
2013-06-10 20:04:43 +02:00
|
|
|
gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
|
|
|
|
}
|
2018-02-02 12:10:14 +01:00
|
|
|
if (opts->u.gtk.has_grab_on_hover &&
|
|
|
|
opts->u.gtk.grab_on_hover) {
|
2014-03-12 08:33:50 +01:00
|
|
|
gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_on_hover_item));
|
|
|
|
}
|
2013-02-20 14:43:20 +01:00
|
|
|
}
|
2014-04-29 15:39:37 +02:00
|
|
|
|
2018-03-01 11:05:35 +01:00
|
|
|
static void early_gtk_display_init(DisplayOptions *opts)
|
2014-04-29 15:39:37 +02:00
|
|
|
{
|
2015-09-10 17:19:32 +02:00
|
|
|
/* The QEMU code relies on the assumption that it's always run in
|
|
|
|
* the C locale. Therefore it is not prepared to deal with
|
|
|
|
* operations that produce different results depending on the
|
|
|
|
* locale, such as printf's formatting of decimal numbers, and
|
|
|
|
* possibly others.
|
|
|
|
*
|
|
|
|
* Since GTK+ calls setlocale() by default -importing the locale
|
|
|
|
* settings from the environment- we must prevent it from doing so
|
|
|
|
* using gtk_disable_setlocale().
|
|
|
|
*
|
|
|
|
* QEMU's GTK+ UI, however, _does_ have translations for some of
|
|
|
|
* the menu items. As a trade-off between a functionally correct
|
|
|
|
* QEMU and a fully internationalized UI we support importing
|
|
|
|
* LC_MESSAGES from the environment (see the setlocale() call
|
|
|
|
* earlier in this file). This allows us to display translated
|
|
|
|
* messages leaving everything else untouched.
|
|
|
|
*/
|
|
|
|
gtk_disable_setlocale();
|
2015-06-05 13:07:58 +02:00
|
|
|
gtkinit = gtk_init_check(NULL, NULL);
|
|
|
|
if (!gtkinit) {
|
|
|
|
/* don't exit yet, that'll break -help */
|
|
|
|
return;
|
|
|
|
}
|
2015-01-20 12:43:28 +01:00
|
|
|
|
2018-02-02 12:10:14 +01:00
|
|
|
assert(opts->type == DISPLAY_TYPE_GTK);
|
2018-05-07 11:55:38 +02:00
|
|
|
if (opts->has_gl && opts->gl != DISPLAYGL_MODE_OFF) {
|
2015-01-20 12:43:28 +01:00
|
|
|
#if defined(CONFIG_OPENGL)
|
2018-03-06 10:09:49 +01:00
|
|
|
#if defined(CONFIG_GTK_GL) && defined(GDK_WINDOWING_WAYLAND)
|
|
|
|
if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
|
|
|
|
gtk_use_gl_area = true;
|
|
|
|
gtk_gl_area_init();
|
2018-05-07 15:42:37 +02:00
|
|
|
} else
|
2015-05-26 12:26:21 +02:00
|
|
|
#endif
|
2018-03-06 10:09:49 +01:00
|
|
|
{
|
2018-06-18 13:21:41 +02:00
|
|
|
DisplayGLMode mode = opts->has_gl ? opts->gl : DISPLAYGL_MODE_ON;
|
|
|
|
gtk_egl_init(mode);
|
2018-03-06 10:09:49 +01:00
|
|
|
}
|
2015-01-20 12:43:28 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-17 17:47:15 +01:00
|
|
|
keycode_map = gd_get_keymap(&keycode_maplen);
|
|
|
|
|
2014-04-29 15:39:37 +02:00
|
|
|
#if defined(CONFIG_VTE)
|
2016-12-07 16:39:10 +01:00
|
|
|
type_register(&char_gd_vc_type_info);
|
2014-04-29 15:39:37 +02:00
|
|
|
#endif
|
|
|
|
}
|
2018-03-01 11:05:35 +01:00
|
|
|
|
|
|
|
static QemuDisplay qemu_display_gtk = {
|
|
|
|
.type = DISPLAY_TYPE_GTK,
|
|
|
|
.early_init = early_gtk_display_init,
|
|
|
|
.init = gtk_display_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_gtk(void)
|
|
|
|
{
|
|
|
|
qemu_display_register(&qemu_display_gtk);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_gtk);
|