[Spice-commits] 3 commits - configure.ac gtk/Makefile.am gtk/desktop-integration.c gtk/desktop-integration.h gtk/spice-gtk-session.c gtk/spice-session-priv.h gtk/spice-session.c gtk/spice-widget.c
Hans de Goede
jwrdegoede at kemper.freedesktop.org
Fri Jul 6 00:27:18 PDT 2012
configure.ac | 20 ++++
gtk/Makefile.am | 4
gtk/desktop-integration.c | 228 ++++++++++++++++++++++++++++++++++++++++++++++
gtk/desktop-integration.h | 64 ++++++++++++
gtk/spice-gtk-session.c | 23 ++++
gtk/spice-session-priv.h | 2
gtk/spice-session.c | 1
gtk/spice-widget.c | 25 +++--
8 files changed, 360 insertions(+), 7 deletions(-)
New commits:
commit 2157ea0bf87989ccc29814aece3fa7f434f25840
Author: Hans de Goede <hdegoede at redhat.com>
Date: Mon Jun 25 17:04:44 2012 +0200
spice-widget: Don't change usbredir/automount settings while redirecting
The keyboard focus may change while usb-device-manager is in the process of
redirecting a usb-device (as this may show a policykit dialog). Making
autoredir/automount setting changes while this is happening is not a good idea!
Since usb-device-manager already sets keyboard_grab_inhibit when it is
redirecting to allow the policykit dialog to show, we can use that to
inhibit usb-autoredir setting changes.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 2ce8b1a..e892591 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -209,6 +209,22 @@ static void update_size_request(SpiceDisplay *display)
recalc_geometry(GTK_WIDGET(display));
}
+static void update_keyboard_focus(SpiceDisplay *display, gboolean state)
+{
+ SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+
+ d->keyboard_have_focus = state;
+
+ /* keyboard grab gets inhibited by usb-device-manager when it is
+ in the process of redirecting a usb-device (as this may show a
+ policykit dialog). Making autoredir/automount setting changes while
+ this is happening is not a good idea! */
+ if (d->keyboard_grab_inhibit)
+ return;
+
+ spice_gtk_session_request_auto_usbredir(d->gtk_session, state);
+}
+
static void spice_display_set_property(GObject *object,
guint prop_id,
const GValue *value,
@@ -1095,10 +1111,8 @@ static gboolean focus_in_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_UN
release_keys(display);
sync_keyboard_lock_modifiers(display);
- d->keyboard_have_focus = true;
+ update_keyboard_focus(display, true);
try_keyboard_grab(display);
- spice_gtk_session_request_auto_usbredir(d->gtk_session,
- d->keyboard_have_focus);
#ifdef WIN32
focus_window = GDK_WINDOW_HWND(gtk_widget_get_window(widget));
g_return_val_if_fail(focus_window != NULL, true);
@@ -1121,9 +1135,8 @@ static gboolean focus_out_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_U
return true;
release_keys(display);
- d->keyboard_have_focus = false;
- spice_gtk_session_request_auto_usbredir(d->gtk_session,
- d->keyboard_have_focus);
+ update_keyboard_focus(display, false);
+
return true;
}
commit c64a959722dcec76e7988f505b0e8f051e10aff0
Author: Hans de Goede <hdegoede at redhat.com>
Date: Mon Jun 25 16:23:05 2012 +0200
spice-gtk-session: hookup automount inhibiting
Inhibit automounting when usb-autoredirection is active.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
index 1df63f5..0a2c4a1 100644
--- a/gtk/spice-gtk-session.c
+++ b/gtk/spice-gtk-session.c
@@ -18,6 +18,7 @@
#include <gtk/gtk.h>
#include <spice/vd_agent.h>
+#include "desktop-integration.h"
#include "spice-common.h"
#include "spice-gtk-session.h"
#include "spice-gtk-session-priv.h"
@@ -233,8 +234,14 @@ static void spice_gtk_session_set_property(GObject *gobject,
case PROP_AUTO_CLIPBOARD:
s->auto_clipboard_enable = g_value_get_boolean(value);
break;
- case PROP_AUTO_USBREDIR:
+ case PROP_AUTO_USBREDIR: {
+ SpiceDesktopIntegration *desktop_int;
+ gboolean orig_value = s->auto_usbredir_enable;
+
s->auto_usbredir_enable = g_value_get_boolean(value);
+ if (s->auto_usbredir_enable == orig_value)
+ break;
+
if (s->auto_usbredir_reqs) {
SpiceUsbDeviceManager *manager =
spice_usb_device_manager_get(s->session, NULL);
@@ -244,8 +251,15 @@ static void spice_gtk_session_set_property(GObject *gobject,
g_object_set(manager, "auto-connect", s->auto_usbredir_enable,
NULL);
+
+ desktop_int = spice_desktop_integration_get(s->session);
+ if (s->auto_usbredir_enable)
+ spice_desktop_integration_inhibit_automount(desktop_int);
+ else
+ spice_desktop_integration_uninhibit_automount(desktop_int);
}
break;
+ }
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
break;
@@ -843,6 +857,7 @@ void spice_gtk_session_request_auto_usbredir(SpiceGtkSession *self,
g_return_if_fail(SPICE_IS_GTK_SESSION(self));
SpiceGtkSessionPrivate *s = self->priv;
+ SpiceDesktopIntegration *desktop_int;
SpiceUsbDeviceManager *manager;
if (state) {
@@ -864,6 +879,12 @@ void spice_gtk_session_request_auto_usbredir(SpiceGtkSession *self,
return;
g_object_set(manager, "auto-connect", state, NULL);
+
+ desktop_int = spice_desktop_integration_get(s->session);
+ if (state)
+ spice_desktop_integration_inhibit_automount(desktop_int);
+ else
+ spice_desktop_integration_uninhibit_automount(desktop_int);
}
/* ------------------------------------------------------------------ */
commit 633586ba643f474235d1fc0a4656f8e00f2ffcac
Author: Hans de Goede <hdegoede at redhat.com>
Date: Wed Jun 13 15:43:45 2012 +0200
Add a desktop-integration helper class
We need to integrate closely with the desktop environment of the user in
several cases. Some examples are disabling auto-mounting when auto-usbredir
is active (rhbz#812972), and disabling the screensaver when fullscreen
(fdo#34793).
Unfortuntely these kinds of things require desktop environment specific
handling. Therefor this patch introduces a desktop-integration helper class,
which is to server as a container for all sort of desktop environment specific
functions.
For now it just supports disabling automounting under Gnome, but this will be
extended in the future.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/configure.ac b/configure.ac
index 09129b7..3841c56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -566,6 +566,26 @@ fi
AM_CONDITIONAL(WITH_PYTHON, [test "$WITH_PYTHON" = "yes"])
+
+AC_ARG_ENABLE([dbus],
+ AS_HELP_STRING([--enable-dbus=@<:@auto/yes/no@:>@],
+ [Enable dbus support for desktop integration (disabling automount) @<:@default=auto@:>@]),
+ [],
+ [enable_dbus="auto"])
+
+if test "x$enable_dbus" != "xno"; then
+ PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1],
+ [have_dbus=yes],
+ [have_dbus=no])
+ if test "x$enable_dbus" = "xyes" && test "x$have_dbus" = "xno"; then
+ AC_MSG_ERROR([D-Bus support explicitly requested, but some required packages are not available])
+ fi
+
+ if test "x$have_dbus" = "xyes"; then
+ AC_DEFINE(USE_DBUS, [1], [Define if supporting dbus])
+ fi
+fi
+
dnl ===========================================================================
dnl check compiler flags
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0327d65..f5f6bc6 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -77,6 +77,7 @@ SPICE_COMMON_CPPFLAGS = \
$(GLIB2_CFLAGS) \
$(GIO_CFLAGS) \
$(GOBJECT2_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS) \
$(SSL_CFLAGS) \
$(SASL_CFLAGS) \
$(GST_CFLAGS) \
@@ -100,6 +101,7 @@ SPICE_GTK_LIBADD_COMMON = \
libspice-client-glib-2.0.la \
$(GTK_LIBS) \
$(CAIRO_LIBS) \
+ $(DBUS_GLIB_LIBS) \
$(XRANDR_LIBS) \
$(LIBM) \
$(NULL)
@@ -114,6 +116,8 @@ SPICE_GTK_SOURCES_COMMON = \
vncdisplaykeymap.h \
spice-grabsequence.c \
spice-grabsequence.h \
+ desktop-integration.c \
+ desktop-integration.h \
usb-device-widget.c \
$(NULL)
diff --git a/gtk/desktop-integration.c b/gtk/desktop-integration.c
new file mode 100644
index 0000000..34cfdad
--- /dev/null
+++ b/gtk/desktop-integration.c
@@ -0,0 +1,228 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2012 Red Hat, Inc.
+
+ Red Hat Authors:
+ Hans de Goede <hdegoede at redhat.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "config.h"
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#ifdef USE_DBUS
+#include <dbus/dbus-glib.h>
+#endif
+#include "glib-compat.h"
+#include "spice-session-priv.h"
+#include "desktop-integration.h"
+
+#define GNOME_SESSION_INHIBIT_AUTOMOUNT 16
+
+/* ------------------------------------------------------------------ */
+/* gobject glue */
+
+#define SPICE_DESKTOP_INTEGRATION_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SPICE_TYPE_DESKTOP_INTEGRATION, SpiceDesktopIntegrationPrivate))
+
+struct _SpiceDesktopIntegrationPrivate {
+#ifdef USE_DBUS
+ DBusGConnection *dbus_conn;
+ DBusGProxy *gnome_session_proxy;
+ guint gnome_automount_inhibit_cookie;
+#else
+ int dummy;
+#endif
+};
+
+G_DEFINE_TYPE(SpiceDesktopIntegration, spice_desktop_integration, G_TYPE_OBJECT);
+
+/* ------------------------------------------------------------------ */
+/* Gnome specific code */
+
+#ifdef USE_DBUS
+
+static void handle_dbus_call_error(const char *call, GError **_error)
+{
+ GError *error = *_error;
+ const char *message = error->message;
+
+ if (error->domain == DBUS_GERROR &&
+ error->code == DBUS_GERROR_REMOTE_EXCEPTION)
+ message = dbus_g_error_get_name(error);
+ g_warning("Error calling '%s': %s", call, message);
+ g_clear_error(_error);
+}
+
+static gboolean gnome_integration_init(SpiceDesktopIntegration *self)
+{
+ SpiceDesktopIntegrationPrivate *priv = self->priv;
+ GError *error = NULL;
+
+ if (!priv->dbus_conn)
+ return FALSE;
+
+ /* We use for_name_owner, to resolve the name now, as we may not be
+ running under gnome-session manager at all! */
+ priv->gnome_session_proxy = dbus_g_proxy_new_for_name_owner(
+ priv->dbus_conn,
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager",
+ "org.gnome.SessionManager",
+ &error);
+ if (error) {
+ g_debug("Could not create org.gnome.SessionManager dbus proxy: %s",
+ error->message);
+ g_clear_error(&error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void gnome_integration_inhibit_automount(SpiceDesktopIntegration *self)
+{
+ SpiceDesktopIntegrationPrivate *priv = self->priv;
+ GError *error = NULL;
+
+ if (!priv->gnome_session_proxy)
+ return;
+
+ g_return_if_fail(priv->gnome_automount_inhibit_cookie == 0);
+
+ if (!dbus_g_proxy_call(
+ priv->gnome_session_proxy, "Inhibit", &error,
+ G_TYPE_STRING, g_get_prgname(),
+ G_TYPE_UINT, 0,
+ G_TYPE_STRING,
+ _("Automounting has been inhibited for USB auto-redirecting"),
+ G_TYPE_UINT, GNOME_SESSION_INHIBIT_AUTOMOUNT,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &priv->gnome_automount_inhibit_cookie,
+ G_TYPE_INVALID))
+ handle_dbus_call_error("org.gnome.SessionManager.Inhibit", &error);
+}
+
+static void gnome_integration_uninhibit_automount(SpiceDesktopIntegration *self)
+{
+ SpiceDesktopIntegrationPrivate *priv = self->priv;
+ GError *error = NULL;
+
+ if (!priv->gnome_session_proxy)
+ return;
+
+ /* Cookie is 0 when we failed to inhibit (and when called from dispose) */
+ if (priv->gnome_automount_inhibit_cookie == 0)
+ return;
+
+ if (!dbus_g_proxy_call(
+ priv->gnome_session_proxy, "Uninhibit", &error,
+ G_TYPE_UINT, priv->gnome_automount_inhibit_cookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID))
+ handle_dbus_call_error("org.gnome.SessionManager.Uninhibit", &error);
+
+ priv->gnome_automount_inhibit_cookie = 0;
+}
+
+static void gnome_integration_dispose(SpiceDesktopIntegration *self)
+{
+ SpiceDesktopIntegrationPrivate *priv = self->priv;
+
+ g_clear_object(&priv->gnome_session_proxy);
+}
+
+#endif
+
+/* ------------------------------------------------------------------ */
+/* gobject glue */
+
+static void spice_desktop_integration_init(SpiceDesktopIntegration *self)
+{
+ SpiceDesktopIntegrationPrivate *priv;
+#ifdef USE_DBUS
+ GError *error = NULL;
+#endif
+
+ priv = SPICE_DESKTOP_INTEGRATION_GET_PRIVATE(self);
+ self->priv = priv;
+
+#ifdef USE_DBUS
+ priv->dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (!priv->dbus_conn) {
+ g_warning("Error connecting to session dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+ if (!gnome_integration_init(self))
+#endif
+ g_warning("Warning no automount-inhibiting implementation available");
+}
+
+static void spice_desktop_integration_dispose(GObject *gobject)
+{
+ SpiceDesktopIntegration *self = SPICE_DESKTOP_INTEGRATION(gobject);
+
+#ifdef USE_DBUS
+ gnome_integration_dispose(self);
+#endif
+
+ /* Chain up to the parent class */
+ if (G_OBJECT_CLASS(spice_desktop_integration_parent_class)->dispose)
+ G_OBJECT_CLASS(spice_desktop_integration_parent_class)->dispose(gobject);
+}
+
+static void spice_desktop_integration_class_init(SpiceDesktopIntegrationClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = spice_desktop_integration_dispose;
+
+ g_type_class_add_private(klass, sizeof(SpiceDesktopIntegrationPrivate));
+}
+
+/* ------------------------------------------------------------------ */
+/* public methods */
+
+SpiceDesktopIntegration *spice_desktop_integration_get(SpiceSession *session)
+{
+ SpiceDesktopIntegration *self;
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+
+ g_return_val_if_fail(session != NULL, NULL);
+
+ g_static_mutex_lock(&mutex);
+ self = session->priv->desktop_integration;
+ if (self == NULL) {
+ self = g_object_new(SPICE_TYPE_DESKTOP_INTEGRATION, NULL);
+ session->priv->desktop_integration = self;
+ }
+ g_static_mutex_unlock(&mutex);
+
+ return self;
+}
+
+void spice_desktop_integration_inhibit_automount(SpiceDesktopIntegration *self)
+{
+#ifdef USE_DBUS
+ gnome_integration_inhibit_automount(self);
+#endif
+}
+
+void spice_desktop_integration_uninhibit_automount(SpiceDesktopIntegration *self)
+{
+#ifdef USE_DBUS
+ gnome_integration_uninhibit_automount(self);
+#endif
+}
diff --git a/gtk/desktop-integration.h b/gtk/desktop-integration.h
new file mode 100644
index 0000000..3716089
--- /dev/null
+++ b/gtk/desktop-integration.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2012 Red Hat, Inc.
+
+ Red Hat Authors:
+ Hans de Goede <hdegoede at redhat.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __SPICE_DESKTOP_INTEGRATION_H__
+#define __SPICE_DESKTOP_INTEGRATION_H__
+
+#include "spice-client.h"
+
+G_BEGIN_DECLS
+
+#define SPICE_TYPE_DESKTOP_INTEGRATION (spice_desktop_integration_get_type ())
+#define SPICE_DESKTOP_INTEGRATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SPICE_TYPE_DESKTOP_INTEGRATION, SpiceDesktopIntegration))
+#define SPICE_DESKTOP_INTEGRATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SPICE_TYPE_DESKTOP_INTEGRATION, SpiceDesktopIntegrationClass))
+#define SPICE_IS_DESKTOP_INTEGRATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SPICE_TYPE_DESKTOP_INTEGRATION))
+#define SPICE_IS_DESKTOP_INTEGRATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SPICE_TYPE_DESKTOP_INTEGRATION))
+#define SPICE_DESKTOP_INTEGRATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SPICE_TYPE_DESKTOP_INTEGRATION, SpiceDesktopIntegrationClass))
+
+typedef struct _SpiceDesktopIntegration SpiceDesktopIntegration;
+typedef struct _SpiceDesktopIntegrationClass SpiceDesktopIntegrationClass;
+typedef struct _SpiceDesktopIntegrationPrivate SpiceDesktopIntegrationPrivate;
+
+/*
+ * SpiceDesktopIntegration offers helper-functions to do desktop environment
+ * and/or platform specific tasks like disabling automount, disabling the
+ * screen-saver, etc. SpiceDesktopIntegration is for internal spice-gtk usage
+ * only!
+ */
+struct _SpiceDesktopIntegration
+{
+ GObject parent;
+
+ SpiceDesktopIntegrationPrivate *priv;
+};
+
+struct _SpiceDesktopIntegrationClass
+{
+ GObjectClass parent_class;
+};
+
+GType spice_desktop_integration_get_type(void);
+SpiceDesktopIntegration *spice_desktop_integration_get(SpiceSession *session);
+void spice_desktop_integration_inhibit_automount(SpiceDesktopIntegration *self);
+void spice_desktop_integration_uninhibit_automount(SpiceDesktopIntegration *self);
+
+G_END_DECLS
+
+#endif /* __SPICE_DESKTOP_INTEGRATION_H__ */
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 5cef264..c24ef8e 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -20,6 +20,7 @@
#include <glib.h>
#include <gio/gio.h>
+#include "desktop-integration.h"
#include "spice-session.h"
#include "spice-gtk-session.h"
#include "spice-channel-cache.h"
@@ -97,6 +98,7 @@ struct _SpiceSessionPrivate {
/* associated objects */
SpiceAudio *audio_manager;
+ SpiceDesktopIntegration *desktop_integration;
SpiceGtkSession *gtk_session;
SpiceUsbDeviceManager *usb_manager;
};
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index fface67..995b2ed 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -155,6 +155,7 @@ spice_session_dispose(GObject *gobject)
}
g_clear_object(&s->audio_manager);
+ g_clear_object(&s->desktop_integration);
g_clear_object(&s->gtk_session);
g_clear_object(&s->usb_manager);
More information about the Spice-commits
mailing list