Update to optionally build with GTK3

This commit is contained in:
Daniel P. Berrange 2011-07-01 15:26:33 +01:00 committed by Daniel P. Berrange
parent cff795065a
commit 7f91cdf4ab
10 changed files with 179 additions and 42 deletions

6
README
View File

@ -8,6 +8,12 @@ the future as user demand dicatates. The viewer can connect
directly to both local and remotely hosted guest OS, optionally
using SSL/TLS encryption.
Virt Viewer can be built with either GTK2 or GTK3, with the
default option currently being GTK2. The choice can be made
with:
./configure --with-gtk=3.0 (or =2.0)
Virt Viewer uses the GTK-VNC widget to provide a display
of the VNC protocol. This is available from

View File

@ -14,6 +14,7 @@ GLIB2_REQUIRED=2.12.0
LIBXML2_REQUIRED="2.6.0"
LIBVIRT_REQUIRED="0.6.0"
GTK2_REQUIRED="2.12.0"
GTK3_REQUIRED="3.0"
GTK_VNC_REQUIRED="0.3.8"
SPICE_GTK_REQUIRED="0.6"
@ -39,13 +40,47 @@ PKG_CHECK_MODULES(GLIB2, gmodule-export-2.0 >= $GLIB2_REQUIRED)
PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= $LIBXML2_REQUIRED)
PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= $GTK2_REQUIRED)
PKG_CHECK_MODULES(GTKVNC, gtk-vnc-1.0 >= $GTK_VNC_REQUIRED)
AC_MSG_CHECKING([which gtk+ version to compile against])
AC_ARG_WITH([gtk],
[AS_HELP_STRING([--with-gtk=2.0|3.0],[which gtk+ version to compile against (default: 2.0)])],
[case "$with_gtk" in
2.0|3.0) ;;
*) AC_MSG_ERROR([invalid gtk version specified]) ;;
esac],
[with_gtk=2.0])
AC_MSG_RESULT([$with_gtk])
case "$with_gtk" in
2.0) GTK_API_VERSION=2.0
GTK_REQUIRED=$GTK2_REQUIRED
GTK_VNC_API_VERSION=1.0
SPICE_GTK_API_VERSION=2.0
;;
3.0) GTK_API_VERSION=3.0
GTK_REQUIRED=$GTK3_REQUIRED
GTK_VNC_API_VERSION=2.0
SPICE_GTK_API_VERSION=3.0
;;
esac
AC_SUBST([GTK_API_VERSION])
AC_SUBST([GTK_REQUIRED])
AC_SUBST([GTK_VNC_API_VERSION])
AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
PKG_CHECK_MODULES(GTK, gtk+-$GTK_API_VERSION >= $GTK_REQUIRED)
PKG_CHECK_MODULES(GTK_VNC, gtk-vnc-$GTK_VNC_API_VERSION >= $GTK_VNC_REQUIRED)
AC_ARG_WITH([spice-gtk],
AS_HELP_STRING([--without-spice-gtk], [Ignore presence of spice-gtk and disable it]))
AS_IF([test "x$with_spice_gtk" != "xno"],
[PKG_CHECK_MODULES(SPICEGTK, spice-client-gtk-2.0 >= $SPICE_GTK_REQUIRED, [have_spice_gtk=yes], [have_spice_gtk=no])],
[PKG_CHECK_MODULES(SPICE_GTK,
spice-client-gtk-$SPICE_GTK_API_VERSION >= $SPICE_GTK_REQUIRED,
[have_spice_gtk=yes], [have_spice_gtk=no])],
[have_spice_gtk=no])
AS_IF([test "x$have_spice_gtk" = "xyes"],

View File

@ -33,18 +33,18 @@ virt_viewer_SOURCES += \
endif
virt_viewer_LDADD = \
@GTKVNC_LIBS@ \
@SPICEGTK_LIBS@ \
@GTK_VNC_LIBS@ \
@SPICE_GTK_LIBS@ \
@GLIB2_LIBS@ \
@GTK2_LIBS@ \
@GTK_LIBS@ \
@LIBXML2_LIBS@ \
@LIBVIRT_LIBS@
virt_viewer_CFLAGS = \
@GTKVNC_CFLAGS@ \
@SPICEGTK_CFLAGS@ \
@GTK_VNC_CFLAGS@ \
@SPICE_GTK_CFLAGS@ \
@GLIB2_CFLAGS@ \
@GTK2_CFLAGS@ \
@GTK_CFLAGS@ \
@LIBXML2_CFLAGS@ \
@LIBVIRT_CFLAGS@ \
@WARN_CFLAGS@ \

View File

@ -475,7 +475,6 @@ ViewOvBoxUnrealize(GtkWidget *widget) // IN
*
*-----------------------------------------------------------------------------
*/
static void
ViewOvBoxSizeRequest(GtkWidget *widget, // IN
GtkRequisition *requisition) // OUT
@ -505,7 +504,7 @@ ViewOvBoxSizeRequest(GtkWidget *widget, // IN
requisition->height = MAX(underR.height + min, priv->overR.height);
}
#ifdef WITH_GTK3
#if GTK_CHECK_VERSION(3, 0, 0)
static void
ViewOvBox_get_preferred_width (GtkWidget *widget,
gint *minimal_width,
@ -529,7 +528,6 @@ ViewOvBox_get_preferred_height (GtkWidget *widget,
*minimal_height = *natural_height = requisition.height;
}
#else
#endif
@ -712,7 +710,7 @@ ViewOvBoxClassInit(ViewOvBoxClass *klass) // IN
widgetClass->unmap = ViewOvBoxUnmap;
widgetClass->realize = ViewOvBoxRealize;
widgetClass->unrealize = ViewOvBoxUnrealize;
#if WITH_GTK3
#if GTK_CHECK_VERSION(3, 0, 0)
widgetClass->get_preferred_width = ViewOvBox_get_preferred_width;
widgetClass->get_preferred_height = ViewOvBox_get_preferred_height;
#else

View File

@ -25,6 +25,7 @@
#include <locale.h>
#include "virt-viewer-align.h"
#include "virt-viewer-util.h"
#define VIRT_VIEWER_ALIGN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_ALIGN, VirtViewerAlignPrivate))
@ -40,6 +41,14 @@ struct _VirtViewerAlignPrivate
static void virt_viewer_align_size_request(GtkWidget *widget,
GtkRequisition *requisition);
#if GTK_CHECK_VERSION(3, 0, 0)
static void virt_viewer_align_get_preferred_width(GtkWidget *widget,
int *minwidth,
int *defwidth);
static void virt_viewer_align_get_preferred_height(GtkWidget *widget,
int *minheight,
int *defheight);
#endif
static void virt_viewer_align_size_allocate(GtkWidget *widget,
GtkAllocation *allocation);
static void virt_viewer_align_set_property(GObject *object,
@ -70,11 +79,16 @@ virt_viewer_align_class_init(VirtViewerAlignClass *class)
gobject_class = (GObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
gobject_class->set_property = virt_viewer_align_set_property;
gobject_class->get_property = virt_viewer_align_get_property;
#if GTK_CHECK_VERSION(3, 0, 0)
widget_class->get_preferred_width = virt_viewer_align_get_preferred_width;
widget_class->get_preferred_height = virt_viewer_align_get_preferred_height;
#else
widget_class->size_request = virt_viewer_align_size_request;
#endif
widget_class->size_allocate = virt_viewer_align_size_allocate;
g_object_class_install_property(gobject_class,
@ -111,8 +125,8 @@ virt_viewer_align_class_init(VirtViewerAlignClass *class)
400,
100,
G_PARAM_READWRITE));
g_type_class_add_private(gobject_class, sizeof(VirtViewerAlignPrivate));
g_type_class_add_private(gobject_class, sizeof(VirtViewerAlignPrivate));
}
static void
@ -203,9 +217,10 @@ virt_viewer_align_size_request(GtkWidget *widget,
{
VirtViewerAlign *align = VIRT_VIEWER_ALIGN(widget);
VirtViewerAlignPrivate *priv = align->priv;
int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget));
requisition->width = GTK_CONTAINER(widget)->border_width * 2;
requisition->height = GTK_CONTAINER(widget)->border_width * 2;
requisition->width = border_width * 2;
requisition->height = border_width * 2;
if (priv->dirty) {
if (priv->zoom)
@ -224,12 +239,38 @@ virt_viewer_align_size_request(GtkWidget *widget,
requisition->height += 50;
}
if (priv->dirty) {
g_idle_add(virt_viewer_align_idle, widget);
priv->dirty = FALSE;
}
DEBUG_LOG("Align size request %dx%d (preferred %dx%d)",
requisition->width, requisition->height,
priv->preferred_width, priv->preferred_height);
}
#if GTK_CHECK_VERSION(3, 0, 0)
static void virt_viewer_align_get_preferred_width(GtkWidget *widget,
int *minwidth,
int *defwidth)
{
GtkRequisition req;
virt_viewer_align_size_request(widget, &req);
*minwidth = *defwidth = req.width;
}
static void virt_viewer_align_get_preferred_height(GtkWidget *widget,
int *minheight,
int *defheight)
{
GtkRequisition req;
virt_viewer_align_size_request(widget, &req);
*minheight = *defheight = req.height;
}
#endif
static void
virt_viewer_align_size_allocate(GtkWidget *widget,
GtkAllocation *allocation)
@ -242,13 +283,15 @@ virt_viewer_align_size_allocate(GtkWidget *widget,
gint border_width;
double preferredAspect;
double actualAspect;
GtkWidget *child = gtk_bin_get_child(bin);
DEBUG_LOG("Allocated %dx%d", allocation->width, allocation->height);
gtk_widget_set_allocation(widget, allocation);
widget->allocation = *allocation;
preferredAspect = (double)priv->preferred_width / (double)priv->preferred_height;
if (bin->child && gtk_widget_get_visible(bin->child)) {
border_width = GTK_CONTAINER(align)->border_width;
if (child && gtk_widget_get_visible(child)) {
border_width = gtk_container_get_border_width(GTK_CONTAINER(align));
width = MAX(1, allocation->width - 2 * border_width);
height = MAX(1, allocation->height - 2 * border_width);
@ -265,7 +308,17 @@ virt_viewer_align_size_allocate(GtkWidget *widget,
child_allocation.x = 0.5 * (width - child_allocation.width) + allocation->x + border_width;
child_allocation.y = 0.5 * (height - child_allocation.height) + allocation->y + border_width;
gtk_widget_size_allocate(bin->child, &child_allocation);
DEBUG_LOG("Child allocate %dx%d", child_allocation.width, child_allocation.height);
gtk_widget_size_allocate(child, &child_allocation);
}
/* This unsets the size request, so that the user can
* manually resize the window smaller again
*/
if (priv->dirty) {
g_idle_add(virt_viewer_align_idle, widget);
priv->dirty = FALSE;
}
}
@ -287,7 +340,7 @@ void virt_viewer_align_set_zoom_level(VirtViewerAlign *align,
guint zoom)
{
VirtViewerAlignPrivate *priv = align->priv;
GtkBin *bin = GTK_BIN(align);
GtkWidget *child = gtk_bin_get_child(GTK_BIN(align));
if (zoom < 10)
zoom = 10;
@ -295,7 +348,7 @@ void virt_viewer_align_set_zoom_level(VirtViewerAlign *align,
zoom = 400;
priv->zoom_level = zoom;
if (bin->child && gtk_widget_get_visible(bin->child)) {
if (child && gtk_widget_get_visible(child)) {
priv->dirty = TRUE;
gtk_widget_queue_resize(GTK_WIDGET(align));
}
@ -324,10 +377,10 @@ void virt_viewer_align_set_zoom(VirtViewerAlign *align,
gboolean zoom)
{
VirtViewerAlignPrivate *priv = align->priv;
GtkBin *bin = GTK_BIN(align);
GtkWidget *child = gtk_bin_get_child(GTK_BIN(align));
priv->zoom = zoom;
if (bin->child && gtk_widget_get_visible(bin->child)) {
if (child && gtk_widget_get_visible(child)) {
priv->dirty = TRUE;
gtk_widget_queue_resize(GTK_WIDGET(align));
}

View File

@ -155,7 +155,7 @@ static void
virt_viewer_display_vnc_bell(VirtViewer *viewer,
gpointer data G_GNUC_UNUSED)
{
gdk_window_beep(GTK_WIDGET(viewer->window)->window);
gdk_window_beep(gtk_widget_get_window(GTK_WIDGET(viewer->window)));
}
static void

View File

@ -63,7 +63,7 @@ virt_viewer_events_dispatch_handle(GIOChannel *source G_GNUC_UNUSED,
if (condition & G_IO_ERR)
events |= VIR_EVENT_HANDLE_ERROR;
DEBUG_LOG("Dispatch handler %d %d %p\n", data->fd, events, data->opaque);
DEBUG_LOG("Dispatch handler %d %d %p", data->fd, events, data->opaque);
(data->cb)(data->watch, data->fd, events, data->opaque);
@ -98,7 +98,7 @@ int virt_viewer_events_add_handle(int fd,
data->channel = g_io_channel_unix_new(fd);
data->ff = ff;
DEBUG_LOG("Add handle %d %d %p\n", data->fd, events, data->opaque);
DEBUG_LOG("Add handle %d %d %p", data->fd, events, data->opaque);
data->source = g_io_add_watch(data->channel,
cond,
@ -170,7 +170,7 @@ virt_viewer_events_remove_handle(int watch)
return -1;
}
DEBUG_LOG("Remove handle %d %d\n", watch, data->fd);
DEBUG_LOG("Remove handle %d %d", watch, data->fd);
g_source_remove(data->source);
data->source = 0;
@ -201,7 +201,7 @@ static gboolean
virt_viewer_events_dispatch_timeout(void *opaque)
{
struct virt_viewer_events_timeout *data = opaque;
DEBUG_LOG("Dispatch timeout %p %p %d %p\n", data, data->cb, data->timer, data->opaque);
DEBUG_LOG("Dispatch timeout %p %p %d %p", data, data->cb, data->timer, data->opaque);
(data->cb)(data->timer, data->opaque);
return TRUE;
@ -231,7 +231,7 @@ virt_viewer_events_add_timeout(int interval,
timeouts[ntimeouts++] = data;
DEBUG_LOG("Add timeout %p %d %p %p %d\n", data, interval, cb, opaque, data->timer);
DEBUG_LOG("Add timeout %p %d %p %p %d", data, interval, cb, opaque, data->timer);
return data->timer;
}
@ -260,7 +260,7 @@ virt_viewer_events_update_timeout(int timer,
return;
}
DEBUG_LOG("Update timeout %p %d %d\n", data, timer, interval);
DEBUG_LOG("Update timeout %p %d %d", data, timer, interval);
if (interval >= 0) {
if (data->source)
@ -289,7 +289,7 @@ virt_viewer_events_remove_timeout(int timer)
return -1;
}
DEBUG_LOG("Remove timeout %p %d\n", data, timer);
DEBUG_LOG("Remove timeout %p %d", data, timer);
if (!data->source)
return -1;

View File

@ -102,6 +102,8 @@ struct _VirtViewerSize {
VirtViewer *viewer;
gint width, height;
gulong sig_id;
gulong sig_id_h;
gulong sig_id_w;
};
void virt_viewer_connected(VirtViewer *viewer);

View File

@ -81,6 +81,26 @@ static const char * const menuNames[LAST_MENU] = {
};
#if GTK_CHECK_VERSION(3, 0, 0)
#define GDK_Control_L GDK_KEY_Control_L
#define GDK_Alt_L GDK_KEY_Alt_L
#define GDK_Delete GDK_KEY_Delete
#define GDK_BackSpace GDK_KEY_BackSpace
#define GDK_Print GDK_KEY_Print
#define GDK_F1 GDK_KEY_F1
#define GDK_F2 GDK_KEY_F2
#define GDK_F3 GDK_KEY_F3
#define GDK_F4 GDK_KEY_F4
#define GDK_F5 GDK_KEY_F5
#define GDK_F6 GDK_KEY_F6
#define GDK_F7 GDK_KEY_F7
#define GDK_F8 GDK_KEY_F8
#define GDK_F9 GDK_KEY_F9
#define GDK_F10 GDK_KEY_F10
#define GDK_F11 GDK_KEY_F11
#define GDK_F12 GDK_KEY_F12
#endif
#define MAX_KEY_COMBO 3
struct keyComboDef {
guint keys[MAX_KEY_COMBO];
@ -184,7 +204,7 @@ virt_viewer_resize_main_window(VirtViewer *viewer)
gtk_window_resize(GTK_WINDOW (viewer->window), 1, 1);
screen = gdk_drawable_get_screen(gtk_widget_get_window(viewer->window));
screen = gtk_widget_get_screen(viewer->window);
gdk_screen_get_monitor_geometry(screen,
gdk_screen_get_monitor_at_window
(screen, gtk_widget_get_window(viewer->window)),
@ -209,6 +229,10 @@ virt_viewer_resize_main_window(VirtViewer *viewer)
height = viewer->desktopHeight;
}
DEBUG_LOG("Decided todo %dx%d (desktop is %dx%d, fullscreen is %dx%d",
width, height, viewer->desktopWidth, viewer->desktopHeight,
fullscreen.width, fullscreen.height);
virt_viewer_align_set_preferred_size(VIRT_VIEWER_ALIGN(viewer->align),
width, height);
}
@ -1322,6 +1346,8 @@ virt_viewer_start(const char *uri,
viewer->domkey = g_strdup(name);
viewer->uri = g_strdup(uri);
viewer->desktopWidth = viewer->desktopHeight = 400;
g_value_init(&viewer->accelSetting, G_TYPE_STRING);
virt_viewer_events_register();
@ -1380,6 +1406,9 @@ virt_viewer_start(const char *uri,
viewer->container = window;
viewer->window = window;
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
#if GTK_CHECK_VERSION(3, 0, 0)
gtk_window_set_has_resize_grip(GTK_WINDOW(window), FALSE);
#endif
viewer->accelEnabled = TRUE;
accels = gtk_accel_groups_from_object(G_OBJECT(window));
for ( ; accels ; accels = accels->next) {

View File

@ -4,8 +4,13 @@
# a security audit at very least
%define _with_plugin %{?with_plugin:1}%{!?with_plugin:0}
%define with_gtk3 0
%if 0%{?fedora} >= 15
%define with_gtk3 1
%endif
%define with_spice 0
%if 0%{?fedora} >= 14
%if 0%{?fedora} >= 16
%define with_spice 1
%endif
@ -20,10 +25,13 @@ Source0: http://virt-manager.org/download/sources/%{name}/%{name}-%{version}.tar
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: openssh-clients
%if %{with_gtk3}
BuildRequires: gtk3-devel >= 3.0.0
%else
BuildRequires: gtk2-devel >= 2.12.0
%endif
BuildRequires: libvirt-devel >= 0.6.0
BuildRequires: libxml2-devel
BuildRequires: libglade2-devel
BuildRequires: gtk-vnc-devel >= 0.3.8
%if %{with_spice}
BuildRequires: spice-gtk-devel >= 0.6
@ -75,7 +83,13 @@ browsers.
%define spice_arg --disable-spice
%endif
%configure %{spice_arg} %{plugin_arg}
%if %{with_gtk3}
%define gtk_arg --with-gtk=3.0
%else
%define gtk_arg --with-gtk=2.0
%endif
%configure %{spice_arg} %{plugin_arg} %{gtk_arg}
%__make %{?_smp_mflags}