[Spice-devel,spice-gtk,v2,1/2] widget: Extend mouse mode debug

Submitted by Pavel Grunt on March 23, 2017, 5:27 p.m.

Details

Message ID 20170323172759.18374-1-pgrunt@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Pavel Grunt March 23, 2017, 5:27 p.m.
---
I always forget the enum value and have to check the spice-protocol
---
 src/spice-widget.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/spice-widget.c b/src/spice-widget.c
index f548b0d..ef320eb 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -2444,13 +2444,26 @@  static GdkModifierType spice_display_get_modifiers_state(SpiceDisplay *display)
     return modifiers;
 }
 
+static const gchar* mouse_mode_to_str(guint mode)
+{
+    const gchar *mouse_mode_str[] = {
+        [SPICE_MOUSE_MODE_CLIENT] = "client",
+        [SPICE_MOUSE_MODE_SERVER] = "server",
+    };
+
+    if (mode < G_N_ELEMENTS(mouse_mode_str) && mouse_mode_str[mode] != NULL) {
+        return mouse_mode_str[mode];
+    }
+    return "unknown";
+}
+
 static void update_mouse_mode(SpiceChannel *channel, gpointer data)
 {
     SpiceDisplay *display = data;
     SpiceDisplayPrivate *d = display->priv;
 
     g_object_get(channel, "mouse-mode", &d->mouse_mode, NULL);
-    SPICE_DEBUG("mouse mode %u", d->mouse_mode);
+    SPICE_DEBUG("mouse mode %u (%s)", d->mouse_mode, mouse_mode_to_str(d->mouse_mode));
 
     switch (d->mouse_mode) {
     case SPICE_MOUSE_MODE_CLIENT:

Comments

> 
> ---
> I always forget the enum value and have to check the spice-protocol
> ---
>  src/spice-widget.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/src/spice-widget.c b/src/spice-widget.c
> index f548b0d..ef320eb 100644
> --- a/src/spice-widget.c
> +++ b/src/spice-widget.c
> @@ -2444,13 +2444,26 @@ static GdkModifierType
> spice_display_get_modifiers_state(SpiceDisplay *display)
>      return modifiers;
>  }
>  
> +static const gchar* mouse_mode_to_str(guint mode)
> +{
> +    const gchar *mouse_mode_str[] = {

I would say

   static const gchar *const mouse_mode_str[] = {

> +        [SPICE_MOUSE_MODE_CLIENT] = "client",
> +        [SPICE_MOUSE_MODE_SERVER] = "server",
> +    };
> +
> +    if (mode < G_N_ELEMENTS(mouse_mode_str) && mouse_mode_str[mode] != NULL)
> {
> +        return mouse_mode_str[mode];
> +    }
> +    return "unknown";
> +}
> +
>  static void update_mouse_mode(SpiceChannel *channel, gpointer data)
>  {
>      SpiceDisplay *display = data;
>      SpiceDisplayPrivate *d = display->priv;
>  
>      g_object_get(channel, "mouse-mode", &d->mouse_mode, NULL);
> -    SPICE_DEBUG("mouse mode %u", d->mouse_mode);
> +    SPICE_DEBUG("mouse mode %u (%s)", d->mouse_mode,
> mouse_mode_to_str(d->mouse_mode));
>  
>      switch (d->mouse_mode) {
>      case SPICE_MOUSE_MODE_CLIENT:

Beside that looks fine.

Frediano