[Spice-devel] [PATCH spice-gtk 5/8] Add disable-inputs on Spice widget
Hans de Goede
hdegoede at redhat.com
Wed Nov 23 06:24:57 PST 2011
Hi,
Some small remarks below, also I'm afraid that this conflicts
with my "Release our keyboard grab when we're going to invoke
the usb acl helper" patch, which I just pushed. I should have
pushed it sooner, but I was waiting to get my additional 3
patches in shape and push them all in one go, sorry about that.
On 11/23/2011 01:23 PM, Marc-André Lureau wrote:
> ---
> gtk/spice-widget-priv.h | 1 +
> gtk/spice-widget.c | 111 +++++++++++++++++++++++++++++++++++-----------
> gtk/spicy.c | 6 +++
> 3 files changed, 91 insertions(+), 27 deletions(-)
>
> diff --git a/gtk/spice-widget-priv.h b/gtk/spice-widget-priv.h
> index a5791a4..5065f7c 100644
> --- a/gtk/spice-widget-priv.h
> +++ b/gtk/spice-widget-priv.h
> @@ -61,6 +61,7 @@ struct _SpiceDisplayPrivate {
> bool convert;
> bool have_mitshm;
> gboolean allow_scaling;
> + gboolean disable_inputs;
>
> /* TODO: make a display object instead? */
> #ifdef WITH_X11
> diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
> index cec9aaa..fa347a1 100644
> --- a/gtk/spice-widget.c
> +++ b/gtk/spice-widget.c
> @@ -34,6 +34,7 @@
> #include "spice-widget-priv.h"
> #include "spice-gtk-session-priv.h"
> #include "vncdisplaykeymap.h"
> +#include "spice-util-priv.h"
>
> /* Some compatibility defines to let us build on both Gtk2 and Gtk3 */
> #if GTK_CHECK_VERSION (2, 91, 0)
Since spice_g_signal_connect_object was moved to spice-util.h, this
chunk seems unnecessary (or the include should be spice-util.h not
spice-util-priv.h).
> @@ -86,6 +87,7 @@ enum {
> PROP_RESIZE_GUEST,
> PROP_AUTO_CLIPBOARD,
> PROP_SCALING,
> + PROP_DISABLE_INPUTS,
> };
>
> /* Signals */
> @@ -102,10 +104,12 @@ static guint signals[SPICE_DISPLAY_LAST_SIGNAL];
> static HWND focus_window = NULL;
> #endif
>
> +static void update_keyboard_grab(SpiceDisplay *display);
> static void try_keyboard_grab(SpiceDisplay *display);
> static void try_keyboard_ungrab(SpiceDisplay *display);
> -static void try_mouse_grab(GtkWidget *widget);
> -static void try_mouse_ungrab(GtkWidget *widget);
> +static void update_mouse_grab(SpiceDisplay *display);
> +static void try_mouse_grab(SpiceDisplay *display);
> +static void try_mouse_ungrab(SpiceDisplay *display);
> static void recalc_geometry(GtkWidget *widget, gboolean set_display);
> static void disconnect_main(SpiceDisplay *display);
> static void disconnect_cursor(SpiceDisplay *display);
> @@ -148,6 +152,9 @@ static void spice_display_get_property(GObject *object,
> case PROP_SCALING:
> g_value_set_boolean(value, d->allow_scaling);
> break;
> + case PROP_DISABLE_INPUTS:
> + g_value_set_boolean(value, d->disable_inputs);
> + break;
> default:
> G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
> break;
> @@ -172,17 +179,11 @@ static void spice_display_set_property(GObject *object,
> break;
> case PROP_KEYBOARD_GRAB:
> d->keyboard_grab_enable = g_value_get_boolean(value);
> - if (d->keyboard_grab_enable) {
> - try_keyboard_grab(display);
> - } else {
> - try_keyboard_ungrab(display);
> - }
> + update_keyboard_grab(display);
> break;
> case PROP_MOUSE_GRAB:
> d->mouse_grab_enable = g_value_get_boolean(value);
> - if (!d->mouse_grab_enable) {
> - try_mouse_ungrab(GTK_WIDGET(display));
> - }
> + update_mouse_grab(display);
> break;
> case PROP_RESIZE_GUEST:
> d->resize_guest_enable = g_value_get_boolean(value);
> @@ -207,6 +208,12 @@ static void spice_display_set_property(GObject *object,
> g_object_set(d->gtk_session, "auto-clipboard",
> g_value_get_boolean(value), NULL);
> break;
> + case PROP_DISABLE_INPUTS:
> + d->disable_inputs = g_value_get_boolean(value);
> + gtk_widget_set_can_focus(GTK_WIDGET(display), !d->disable_inputs);
> + update_keyboard_grab(display);
> + update_mouse_grab(display);
> + break;
> default:
> G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
> break;
> @@ -327,8 +334,8 @@ spice_display_constructor(GType gtype,
> }
> g_list_free(list);
>
> - g_signal_connect(d->gtk_session, "notify::auto-clipboard",
> - G_CALLBACK(gtk_session_property_changed), display);
> + spice_g_signal_connect_object(d->gtk_session, "notify::auto-clipboard",
> + G_CALLBACK(gtk_session_property_changed), display, 0);
>
> return obj;
> }
> @@ -410,12 +417,12 @@ static void try_keyboard_grab(SpiceDisplay *display)
>
> if (g_getenv("SPICE_NOGRAB"))
> return;
> -
> - if (d->keyboard_grab_active)
> + if (d->disable_inputs)
> return;
> -
> if (!d->keyboard_grab_enable)
> return;
> + if (d->keyboard_grab_active)
> + return;
> if (!d->keyboard_have_focus)
> return;
> if (!d->mouse_have_pointer)
> @@ -441,7 +448,6 @@ static void try_keyboard_grab(SpiceDisplay *display)
> }
> }
>
> -
> static void try_keyboard_ungrab(SpiceDisplay *display)
> {
> SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
> @@ -460,6 +466,16 @@ static void try_keyboard_ungrab(SpiceDisplay *display)
> g_signal_emit(widget, signals[SPICE_DISPLAY_KEYBOARD_GRAB], 0, false);
> }
>
> +static void update_keyboard_grab(SpiceDisplay *display)
> +{
> + SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
> +
> + if (d->keyboard_grab_enable&& !d->disable_inputs)
> + try_keyboard_grab(display);
> + else
> + try_keyboard_ungrab(display);
> +}
> +
> static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
> {
> SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
> @@ -514,8 +530,9 @@ static void update_mouse_pointer(SpiceDisplay *display)
> if (!d->mouse_grab_active) {
> gdk_window_set_cursor(window, NULL);
> } else {
> + // FIXME: should it be transparent instead?
> gdk_window_set_cursor(window, d->mouse_cursor);
> - try_mouse_grab(GTK_WIDGET(display));
> + try_mouse_grab(display);
> }
> break;
> default:
> @@ -524,13 +541,14 @@ static void update_mouse_pointer(SpiceDisplay *display)
> }
> }
>
> -static void try_mouse_grab(GtkWidget *widget)
> +static void try_mouse_grab(SpiceDisplay *display)
> {
> - SpiceDisplay *display = SPICE_DISPLAY(widget);
> SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
>
> if (g_getenv("SPICE_NOGRAB"))
> return;
> + if (d->disable_inputs)
> + return;
>
> if (!d->mouse_grab_enable)
> return;
> @@ -579,9 +597,8 @@ static void mouse_check_edges(GtkWidget *widget, GdkEventMotion *motion)
> }
> }
>
> -static void try_mouse_ungrab(GtkWidget *widget)
> +static void try_mouse_ungrab(SpiceDisplay *display)
> {
> - SpiceDisplay *display = SPICE_DISPLAY(widget);
> SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
>
> if (!d->mouse_grab_active)
This change of the prototype of try_mouse_[un]grab seems an unrelated
cleanup patch to me, IMHO it would be better to have this in a separate
patch.
> @@ -590,7 +607,17 @@ static void try_mouse_ungrab(GtkWidget *widget)
> gdk_pointer_ungrab(GDK_CURRENT_TIME);
> d->mouse_grab_active = false;
> update_mouse_pointer(display);
> - g_signal_emit(widget, signals[SPICE_DISPLAY_MOUSE_GRAB], 0, false);
> + g_signal_emit(display, signals[SPICE_DISPLAY_MOUSE_GRAB], 0, false);
> +}
> +
> +static void update_mouse_grab(SpiceDisplay *display)
> +{
> + SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
> +
> + if (d->mouse_grab_enable&& !d->disable_inputs)
> + update_mouse_pointer(display);
> + else
> + try_mouse_ungrab(display);
> }
>
> static void recalc_geometry(GtkWidget *widget, gboolean set_display)
<snip>
Regards,
Hans
More information about the Spice-devel
mailing list