[Spice-commits] 7 commits - configure.ac gtk/channel-main.c gtk/spice-channel.c gtk/spice-channel-priv.h gtk/spice-util.c gtk/spice-util-priv.h gtk/spice-widget.c gtk/spicy.c

Marc-André Lureau elmarco at kemper.freedesktop.org
Sun Mar 18 12:17:53 PDT 2012


 configure.ac             |    7 ++
 gtk/channel-main.c       |   29 +++++++++--
 gtk/spice-channel-priv.h |    3 -
 gtk/spice-channel.c      |   20 +++----
 gtk/spice-util-priv.h    |   15 +++++
 gtk/spice-util.c         |    6 ++
 gtk/spice-widget.c       |    2 
 gtk/spicy.c              |  122 ++++++++++++++++++++++++++++-------------------
 8 files changed, 140 insertions(+), 64 deletions(-)

New commits:
commit 82a4703fea93ca792542a8d45d72bd1db49bb6e4
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sun Mar 18 18:38:53 2012 +0100

    Do not grab display widget
    
    We used to gtk_grab_add() after mouse grab to limit the mouse events
    to the display. But it isn't necessary if the display has its own
    window, since gdk_pointer_grab() will be limited to it.
    
    Note the widget has the keyboard focus & is focused, so this doesn't
    affect keyboard events.
    
    However, this allows application to keep global accelerators
    functionning if they want to (like virt-viewer with custom key
    bindings).

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index fb40d1a..850fd5b 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -364,6 +364,7 @@ static void spice_display_init(SpiceDisplay *display)
                           GDK_KEY_PRESS_MASK);
     gtk_widget_set_double_buffered(widget, false);
     gtk_widget_set_can_focus(widget, true);
+    gtk_widget_set_has_window(widget, true);
 
     d->keycode_map = vnc_display_keymap_gdk2xtkbd_table(&d->keycode_maplen);
     d->grabseq = spice_grab_sequence_new_from_string("Control_L+Alt_L");
@@ -610,7 +611,6 @@ static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
         ClipCursor(&client_rect);
     }
 #endif
-    gtk_grab_add(GTK_WIDGET(display));
 
 #ifdef GDK_WINDOWING_X11
     if (status == GDK_GRAB_SUCCESS) {
commit a01677289c0a2d0ada32b254762bc2c15fa660ad
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sun Mar 18 16:21:13 2012 +0100

    Notify agent-connected property change

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 170610a..86e6fba 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -1057,6 +1057,16 @@ static void agent_clipboard_release(SpiceMainChannel *channel, guint selection)
 }
 
 /* coroutine context  */
+static void set_agent_connected(SpiceMainChannel *channel, gboolean connected)
+{
+    SpiceMainChannelPrivate *c = channel->priv;
+
+    c->agent_connected = connected;
+    SPICE_DEBUG("agent connected: %s", spice_yes_no(connected));
+    g_object_notify_main_context(G_OBJECT(channel), "agent-connected");
+}
+
+/* coroutine context  */
 static void agent_start(SpiceMainChannel *channel)
 {
     SpiceMainChannelPrivate *c = channel->priv;
@@ -1065,7 +1075,7 @@ static void agent_start(SpiceMainChannel *channel)
     };
     SpiceMsgOut *out;
 
-    c->agent_connected = true;
+    set_agent_connected(channel, TRUE);
     c->agent_caps_received = false;
     emit_main_context(channel, SPICE_MAIN_AGENT_UPDATE);
 
@@ -1084,7 +1094,7 @@ static void agent_stopped(SpiceMainChannel *channel)
 {
     SpiceMainChannelPrivate *c = SPICE_MAIN_CHANNEL(channel)->priv;
 
-    c->agent_connected = false;
+    set_agent_connected(channel, FALSE);
     c->agent_caps_received = false;
     c->agent_display_config_sent = false;
     emit_main_context(channel, SPICE_MAIN_AGENT_UPDATE);
diff --git a/gtk/spice-util-priv.h b/gtk/spice-util-priv.h
index 1be0edf..7449667 100644
--- a/gtk/spice-util-priv.h
+++ b/gtk/spice-util-priv.h
@@ -26,6 +26,7 @@ G_BEGIN_DECLS
 
 gboolean spice_strv_contains(const GStrv strv, const gchar *str);
 gchar* spice_uuid_to_string(const guint8 uuid[16]);
+const gchar* spice_yes_no(gboolean value);
 
 #if GLIB_CHECK_VERSION(2,32,0)
 #define STATIC_MUTEX            GMutex
diff --git a/gtk/spice-util.c b/gtk/spice-util.c
index 6092a80..1c5d10f 100644
--- a/gtk/spice-util.c
+++ b/gtk/spice-util.c
@@ -204,3 +204,9 @@ gulong spice_g_signal_connect_object (gpointer instance,
 
     return ctx->handler_id;
 }
+
+G_GNUC_INTERNAL
+const gchar* spice_yes_no(gboolean value)
+{
+    return value ? "yes" : "no";
+}
commit b0706c6d832f6ae5e2f91ba0a3c02e37043c1589
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sun Mar 18 15:10:21 2012 +0100

    Improve spice_main_set_display_enabled()
    
    Check given display id is within the range of array.
    Allows to be call with -1 to turn set all displays.

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 50025b0..170610a 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -1951,7 +1951,7 @@ void spice_main_clipboard_selection_request(SpiceMainChannel *channel, guint sel
 /**
  * spice_main_set_display_enabled:
  * @channel: a #SpiceMainChannel
- * @id: display channel ID
+ * @id: display channel ID (if -1: set all displays)
  * @enabled: wether display @id is enabled
  *
  * When sending monitor configuration to agent guest, don't set
@@ -1965,7 +1965,16 @@ void spice_main_set_display_enabled(SpiceMainChannel *channel, int id, gboolean
 {
     g_return_if_fail(channel != NULL);
     g_return_if_fail(SPICE_IS_MAIN_CHANNEL(channel));
+    g_return_if_fail(id >= -1);
 
     SpiceMainChannelPrivate *c = channel->priv;
-    c->display[id].enabled = enabled;
+
+    if (id == -1) {
+        gint i;
+        for (i = 0; i < G_N_ELEMENTS(c->display); i++)
+            c->display[i].enabled = enabled;
+    } else {
+        g_return_if_fail(id < G_N_ELEMENTS(c->display));
+        c->display[id].enabled = enabled;
+    }
 }
commit 0e0d3a43039b09dbdebac2fc662a8445443619b9
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sat Mar 17 03:49:05 2012 +0100

    Fix non-semi-seamless migration in spicy
    
    The windows are destroyed during non-semi-seamless migrations, but the
    gtk session and connected handlers remains. When a property changes
    again on it, it will signal a destroyed window and lead to a crash.
    
    The signal handler should be disconnected when the window is
    destroyed. Since we have N numbers of handlers, it's easier to use
    spice_signal_connect_object() helper to handle this for us by turning
    spice_window structure into a basic GObject.
    
    That GObject code could be improved, but that wasn't the goal of this
    patch.

diff --git a/gtk/spicy.c b/gtk/spicy.c
index 2261488..d3f2f29 100644
--- a/gtk/spicy.c
+++ b/gtk/spicy.c
@@ -40,9 +40,7 @@
 #include "spice-option.h"
 #include "usb-device-widget.h"
 
-/* config */
-static gboolean fullscreen = false;
-static gboolean version = false;
+typedef struct spice_connection spice_connection;
 
 enum {
     STATE_SCROLL_LOCK,
@@ -51,10 +49,18 @@ enum {
     STATE_MAX,
 };
 
-typedef struct spice_window spice_window;
-typedef struct spice_connection spice_connection;
+#define SPICE_TYPE_WINDOW                  (spice_window_get_type ())
+#define SPICE_WINDOW(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), SPICE_TYPE_WINDOW, SpiceWindow))
+#define SPICE_IS_WINDOW(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SPICE_TYPE_WINDOW))
+#define SPICE_WINDOW_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), SPICE_TYPE_WINDOW, SpiceWindowClass))
+#define SPICE_IS_WINDOW_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), SPICE_TYPE_WINDOW))
+#define SPICE_WINDOW_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), SPICE_TYPE_WINDOW, SpiceWindowClass))
+
+typedef struct _SpiceWindow SpiceWindow;
+typedef struct _SpiceWindowClass SpiceWindowClass;
 
-struct spice_window {
+struct _SpiceWindow {
+    GObject          object;
     spice_connection *conn;
     int              id;
     GtkWidget        *toplevel, *spice;
@@ -74,10 +80,17 @@ struct spice_window {
     bool             enable_mnemonics_save;
 };
 
+struct _SpiceWindowClass
+{
+  GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (SpiceWindow, spice_window, G_TYPE_OBJECT);
+
 struct spice_connection {
     SpiceSession     *session;
     SpiceGtkSession  *gtk_session;
-    spice_window     *wins[4];
+    SpiceWindow     *wins[4];
     SpiceAudio       *audio;
     const char       *mouse_state;
     const char       *agent_state;
@@ -86,25 +99,29 @@ struct spice_connection {
     int              disconnecting;
 };
 
-static GMainLoop     *mainloop = NULL;
-static int           connections = 0;
-static GKeyFile      *keyfile = NULL;
-static GnomeRRScreen *rrscreen = NULL;
-static GnomeRRConfig *rrsaved = NULL;
-static GnomeRRConfig *rrcurrent = NULL;
-
 static spice_connection *connection_new(void);
 static void connection_connect(spice_connection *conn);
 static void connection_disconnect(spice_connection *conn);
 static void connection_destroy(spice_connection *conn);
-static void resolution_fullscreen(struct spice_window *win);
-static void resolution_restore(struct spice_window *win);
+static void resolution_fullscreen(SpiceWindow *win);
+static void resolution_restore(SpiceWindow *win);
 static void usb_connect_failed(GObject               *object,
                                SpiceUsbDevice        *device,
                                GError                *error,
                                gpointer               data);
 static gboolean is_gtk_session_property(const gchar *property);
 
+/* options */
+static gboolean fullscreen = false;
+static gboolean version = false;
+/* globals */
+static GMainLoop     *mainloop = NULL;
+static int           connections = 0;
+static GKeyFile      *keyfile = NULL;
+static GnomeRRScreen *rrscreen = NULL;
+static GnomeRRConfig *rrsaved = NULL;
+static GnomeRRConfig *rrcurrent = NULL;
+
 /* ------------------------------------------------------------------ */
 
 static int ask_user(GtkWidget *parent, char *title, char *message,
@@ -276,7 +293,7 @@ static int connect_dialog(SpiceSession *session)
 
 /* ------------------------------------------------------------------ */
 
-static void update_status_window(struct spice_window *win)
+static void update_status_window(SpiceWindow *win)
 {
     char status[256];
 
@@ -312,26 +329,26 @@ static void menu_cb_connect(GtkAction *action, void *data)
 
 static void menu_cb_close(GtkAction *action, void *data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     connection_disconnect(win->conn);
 }
 
 static void menu_cb_copy(GtkAction *action, void *data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     spice_gtk_session_copy_to_guest(win->conn->gtk_session);
 }
 
 static void menu_cb_paste(GtkAction *action, void *data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     spice_gtk_session_paste_from_guest(win->conn->gtk_session);
 }
 
-static void window_set_fullscreen(struct spice_window *win, gboolean fs)
+static void window_set_fullscreen(SpiceWindow *win, gboolean fs)
 {
     if (fs) {
 #ifdef WIN32
@@ -348,20 +365,20 @@ static void window_set_fullscreen(struct spice_window *win, gboolean fs)
 
 static void menu_cb_fullscreen(GtkAction *action, void *data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     window_set_fullscreen(win, !win->fullscreen);
 }
 
 static void menu_cb_ungrab(GtkAction *action, void *data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     spice_display_mouse_ungrab(SPICE_DISPLAY(win->spice));
 }
 
 #ifdef USE_SMARTCARD
-static void enable_smartcard_actions(spice_window *win, VReader *reader,
+static void enable_smartcard_actions(SpiceWindow *win, VReader *reader,
                                      gboolean can_insert, gboolean can_remove)
 {
     GtkAction *action;
@@ -427,7 +444,7 @@ static void remove_cb(GtkContainer *container, GtkWidget *widget, void *data)
 static void menu_cb_select_usb_devices(GtkAction *action, void *data)
 {
     GtkWidget *dialog, *area, *usb_device_widget;
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     /* Create the widgets */
     dialog = gtk_dialog_new_with_buttons(
@@ -461,7 +478,7 @@ static void menu_cb_select_usb_devices(GtkAction *action, void *data)
 
 static void menu_cb_bool_prop(GtkToggleAction *action, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
     gboolean state = gtk_toggle_action_get_active(action);
     const char *name;
     gpointer object;
@@ -483,7 +500,7 @@ static void menu_cb_conn_bool_prop_changed(GObject    *gobject,
                                            GParamSpec *pspec,
                                            gpointer    user_data)
 {
-    struct spice_window *win = user_data;
+    SpiceWindow *win = user_data;
     const gchar *property = g_param_spec_get_name(pspec);
     GtkAction *toggle;
     gboolean state;
@@ -495,7 +512,7 @@ static void menu_cb_conn_bool_prop_changed(GObject    *gobject,
 
 static void menu_cb_toolbar(GtkToggleAction *action, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
     gboolean state = gtk_toggle_action_get_active(action);
 
     gtk_widget_set_visible(win->toolbar, state);
@@ -504,7 +521,7 @@ static void menu_cb_toolbar(GtkToggleAction *action, gpointer data)
 
 static void menu_cb_statusbar(GtkToggleAction *action, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
     gboolean state = gtk_toggle_action_get_active(action);
 
     gtk_widget_set_visible(win->statusbar, state);
@@ -520,7 +537,7 @@ static void menu_cb_about(GtkAction *action, void *data)
     static const char *authors[] = { "Gerd Hoffmann <kraxel at redhat.com>",
                                "Marc-André Lureau <marcandre.lureau at redhat.com>",
                                NULL };
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     gtk_show_about_dialog(GTK_WINDOW(win->toplevel),
                           "authors",         authors,
@@ -535,7 +552,7 @@ static void menu_cb_about(GtkAction *action, void *data)
 
 static gboolean delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     connection_disconnect(win->conn);
     return true;
@@ -544,7 +561,7 @@ static gboolean delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
 static gboolean window_state_cb(GtkWidget *widget, GdkEventWindowState *event,
                                 gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
     if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
         win->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
         if (win->fullscreen) {
@@ -570,7 +587,7 @@ static gboolean window_state_cb(GtkWidget *widget, GdkEventWindowState *event,
 
 static void grab_keys_pressed_cb(GtkWidget *widget, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     /* since mnemonics are disabled, we leave fullscreen when
        ungrabbing mouse. Perhaps we should have a different handling
@@ -580,7 +597,7 @@ static void grab_keys_pressed_cb(GtkWidget *widget, gpointer data)
 
 static void mouse_grab_cb(GtkWidget *widget, gint grabbed, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     win->mouse_grabbed = grabbed;
     update_status(win->conn);
@@ -588,7 +605,7 @@ static void mouse_grab_cb(GtkWidget *widget, gint grabbed, gpointer data)
 
 static void keyboard_grab_cb(GtkWidget *widget, gint grabbed, gpointer data)
 {
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
     GtkSettings *settings = gtk_widget_get_settings (widget);
 
     if (grabbed) {
@@ -609,7 +626,7 @@ static void keyboard_grab_cb(GtkWidget *widget, gint grabbed, gpointer data)
     }
 }
 
-static void restore_configuration(struct spice_window *win)
+static void restore_configuration(SpiceWindow *win)
 {
     gboolean state;
     gchar *str;
@@ -1016,7 +1033,7 @@ end:
     g_clear_error(&error);
 }
 
-static void resolution_fullscreen(struct spice_window *win)
+static void resolution_fullscreen(SpiceWindow *win)
 {
     GnomeRROutputInfo *output;
     int x, y, width, height;
@@ -1046,7 +1063,7 @@ static void resolution_fullscreen(struct spice_window *win)
 #endif
 }
 
-static void resolution_restore(struct spice_window *win)
+static void resolution_restore(SpiceWindow *win)
 {
     GnomeRROutputInfo *output, *saved;
     int x, y, width, height;
@@ -1097,7 +1114,7 @@ static gboolean configure_event_cb(GtkWidget         *widget,
                                    gpointer           data)
 {
     gboolean resize_guest;
-    struct spice_window *win = data;
+    SpiceWindow *win = data;
 
     g_return_val_if_fail(win != NULL, FALSE);
     g_return_val_if_fail(win->conn != NULL, FALSE);
@@ -1114,10 +1131,20 @@ static gboolean configure_event_cb(GtkWidget         *widget,
     return FALSE;
 }
 
-static spice_window *create_spice_window(spice_connection *conn, int id, SpiceChannel *channel)
+static void
+spice_window_class_init (SpiceWindowClass *klass)
+{
+}
+
+static void
+spice_window_init (SpiceWindow *self)
+{
+}
+
+static SpiceWindow *create_spice_window(spice_connection *conn, int id, SpiceChannel *channel)
 {
     char title[32];
-    struct spice_window *win;
+    SpiceWindow *win;
     GtkAction *toggle;
     gboolean state;
     GtkWidget *vbox, *frame;
@@ -1125,7 +1152,7 @@ static spice_window *create_spice_window(spice_connection *conn, int id, SpiceCh
     int i;
     SpiceGrabSequence *seq;
 
-    win = g_new0(struct spice_window, 1);
+    win = g_object_new(SPICE_TYPE_WINDOW, NULL);
     win->id = id;
     win->conn = conn;
     win->display_channel = channel;
@@ -1253,8 +1280,9 @@ static spice_window *create_spice_window(spice_connection *conn, int id, SpiceCh
 
         snprintf(notify, sizeof(notify), "notify::%s",
                  spice_gtk_session_properties[i]);
-        g_signal_connect(win->conn->gtk_session, notify,
-                         G_CALLBACK(menu_cb_conn_bool_prop_changed), win);
+        spice_g_signal_connect_object(win->conn->gtk_session, notify,
+                                      G_CALLBACK(menu_cb_conn_bool_prop_changed),
+                                      win, 0);
     }
 
     toggle = gtk_action_group_get_action(win->ag, "Toolbar");
@@ -1294,13 +1322,13 @@ static spice_window *create_spice_window(spice_connection *conn, int id, SpiceCh
     return win;
 }
 
-static void destroy_spice_window(spice_window *win)
+static void destroy_spice_window(SpiceWindow *win)
 {
     SPICE_DEBUG("destroy window (#%d)", win->id);
     g_object_unref(win->ag);
     g_object_unref(win->ui);
     gtk_widget_destroy(win->toplevel);
-    free(win);
+    g_object_unref(win);
 }
 
 /* ------------------------------------------------------------------ */
@@ -1432,7 +1460,7 @@ static void inputs_modifiers(SpiceChannel *channel, gpointer data)
     }
 }
 
-static void display_mark(SpiceChannel *channel, gint mark, spice_window *win)
+static void display_mark(SpiceChannel *channel, gint mark, SpiceWindow *win)
 {
     g_return_if_fail(win != NULL);
     g_return_if_fail(win->toplevel != NULL);
commit 31248276ff216805a0266edb8242598afcaacbec
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Fri Mar 16 23:47:37 2012 +0100

    Use given color depth in monitor configuration
    
    The main channel only relied on
    VD_AGENT_DISPLAY_CONFIG_FLAG_SET_COLOR_DEPTH to set color depth when
    connecting to a guest. However, that doesn't seem to be
    enough. Instead send given color depth with monitor configuration.
    
    Fix --spice-color-depth option not "apparently" working.

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index bd64662..50025b0 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -838,7 +838,7 @@ gboolean spice_main_send_monitor_config(SpiceMainChannel *channel)
     for (i = 0; i < SPICE_N_ELEMENTS(c->display); i++) {
         if (!c->display[i].enabled)
             continue;
-        mon->monitors[j].depth  = 32;
+        mon->monitors[j].depth  = c->display_color_depth ? c->display_color_depth : 32;
         mon->monitors[j].width  = c->display[j].width;
         mon->monitors[j].height = c->display[j].height;
         mon->monitors[j].x = c->display[j].x;
commit 0c11bfc9d589e6e1073c34c0b22f4115c9ae37a9
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Fri Mar 16 17:12:20 2012 +0100

    build-sys: if stow is installed, default prefix to it
    
    This is going to make life easier for stow users, including myself.

diff --git a/configure.ac b/configure.ac
index 760736a..1ac291f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,13 @@ if test "x$ac_cv_prog_cc_c99" = xno; then
     AC_MSG_ERROR([C99 compiler is required.])
 fi
 
+
+AC_CHECK_PROG([STOW], [stow], [yes], [no])
+AS_IF([test "x$STOW" = "xyes" && test -d /usr/local/stow], [
+    AC_MSG_NOTICE([*** Found /usr/local/stow: default install prefix set to /usr/local/stow/${PACKAGE_NAME} ***])
+    ac_default_prefix="/usr/local/stow/${PACKAGE_NAME}"
+])
+
 AC_PROG_INSTALL
 AC_CANONICAL_HOST
 AC_PROG_LIBTOOL
commit 837b98d043d10b1d6360d8e1079f88606b37ac84
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Fri Mar 16 15:40:05 2012 +0100

    build: fix build with glib < 2.32
    
    Using GMutex as a static mutex is only possible since 2.32.

diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 88611d0..299b581 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -29,6 +29,7 @@
 #include <sasl/sasl.h>
 #endif
 
+#include "spice-util-priv.h"
 #include "coroutine.h"
 #include "gio-coroutine.h"
 
@@ -100,7 +101,7 @@ struct _SpiceChannelPrivate {
 
     GQueue                      xmit_queue;
     gboolean                    xmit_queue_blocked;
-    GMutex                      xmit_queue_lock;
+    STATIC_MUTEX                xmit_queue_lock;
     guint                       xmit_queue_wakeup_id;
 
     char                        name[16];
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index be95f00..0b7dff8 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -110,7 +110,7 @@ static void spice_channel_init(SpiceChannel *channel)
     spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION);
     spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_MINI_HEADER);
     g_queue_init(&c->xmit_queue);
-    g_mutex_init(&c->xmit_queue_lock);
+    STATIC_MUTEX_INIT(c->xmit_queue_lock);
 }
 
 static void spice_channel_constructed(GObject *gobject)
@@ -162,7 +162,7 @@ static void spice_channel_finalize(GObject *gobject)
 
     g_idle_remove_by_data(gobject);
 
-    g_mutex_clear(&c->xmit_queue_lock);
+    STATIC_MUTEX_CLEAR(c->xmit_queue_lock);
 
     if (c->caps)
         g_array_free(c->caps, TRUE);
@@ -667,9 +667,9 @@ static gboolean spice_channel_idle_wakeup(gpointer user_data)
      *   5) xmit_queue_wakeup_id now says there is a wakeup pending which is
      *      false
      */
-    g_mutex_lock(&c->xmit_queue_lock);
+    STATIC_MUTEX_LOCK(c->xmit_queue_lock);
     c->xmit_queue_wakeup_id = 0;
-    g_mutex_unlock(&c->xmit_queue_lock);
+    STATIC_MUTEX_UNLOCK(c->xmit_queue_lock);
 
     spice_channel_wakeup(channel, FALSE);
 
@@ -685,7 +685,7 @@ void spice_msg_out_send(SpiceMsgOut *out)
     g_return_if_fail(out != NULL);
     g_return_if_fail(out->channel != NULL);
 
-    g_mutex_lock(&out->channel->priv->xmit_queue_lock);
+    STATIC_MUTEX_LOCK(out->channel->priv->xmit_queue_lock);
     if (out->channel->priv->xmit_queue_blocked) {
         g_warning("message queue is blocked, dropping message");
         goto end;
@@ -705,7 +705,7 @@ void spice_msg_out_send(SpiceMsgOut *out)
     }
 
 end:
-    g_mutex_unlock(&out->channel->priv->xmit_queue_lock);
+    STATIC_MUTEX_UNLOCK(out->channel->priv->xmit_queue_lock);
 }
 
 /* coroutine context */
@@ -1972,9 +1972,9 @@ static void spice_channel_iterate_write(SpiceChannel *channel)
     SpiceMsgOut *out;
 
     do {
-        g_mutex_lock(&c->xmit_queue_lock);
+        STATIC_MUTEX_LOCK(c->xmit_queue_lock);
         out = g_queue_pop_head(&c->xmit_queue);
-        g_mutex_unlock(&c->xmit_queue_lock);
+        STATIC_MUTEX_UNLOCK(c->xmit_queue_lock);
         if (out)
             spice_channel_write_msg(channel, out);
     } while (out);
@@ -2373,7 +2373,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
     c->peer_msg = NULL;
     c->peer_pos = 0;
 
-    g_mutex_lock(&c->xmit_queue_lock);
+    STATIC_MUTEX_LOCK(c->xmit_queue_lock);
     c->xmit_queue_blocked = TRUE; /* Disallow queuing new messages */
     g_queue_foreach(&c->xmit_queue, (GFunc)spice_msg_out_unref, NULL);
     g_queue_clear(&c->xmit_queue);
@@ -2381,7 +2381,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
         g_source_remove(c->xmit_queue_wakeup_id);
         c->xmit_queue_wakeup_id = 0;
     }
-    g_mutex_unlock(&c->xmit_queue_lock);
+    STATIC_MUTEX_UNLOCK(c->xmit_queue_lock);
 
     g_array_set_size(c->remote_common_caps, 0);
     g_array_set_size(c->remote_caps, 0);
diff --git a/gtk/spice-util-priv.h b/gtk/spice-util-priv.h
index 4d52100..1be0edf 100644
--- a/gtk/spice-util-priv.h
+++ b/gtk/spice-util-priv.h
@@ -27,6 +27,20 @@ G_BEGIN_DECLS
 gboolean spice_strv_contains(const GStrv strv, const gchar *str);
 gchar* spice_uuid_to_string(const guint8 uuid[16]);
 
+#if GLIB_CHECK_VERSION(2,32,0)
+#define STATIC_MUTEX            GMutex
+#define STATIC_MUTEX_INIT(m)    g_mutex_init(&(m))
+#define STATIC_MUTEX_CLEAR(m)   g_mutex_clear(&(m))
+#define STATIC_MUTEX_LOCK(m)    g_mutex_lock(&(m))
+#define STATIC_MUTEX_UNLOCK(m)  g_mutex_unlock(&(m))
+#else
+#define STATIC_MUTEX            GStaticMutex
+#define STATIC_MUTEX_INIT(m)    g_static_mutex_init(&(m))
+#define STATIC_MUTEX_CLEAR(m)   g_static_mutex_free(&(m))
+#define STATIC_MUTEX_LOCK(m)    g_static_mutex_lock(&(m))
+#define STATIC_MUTEX_UNLOCK(m)  g_static_mutex_unlock(&(m))
+#endif
+
 G_END_DECLS
 
 #endif /* SPICE_UTIL_PRIV_H */


More information about the Spice-commits mailing list