[Spice-devel] [PATCH spice-gtk v3 2/6] gtk: Use gdk_window_get_device_position
Victor Toso
victortoso at redhat.com
Mon Jan 23 11:52:36 UTC 2017
Hi,
On Fri, Jan 20, 2017 at 04:53:49PM +0100, Pavel Grunt wrote:
> gdk_window_get_pointer has been deprecated since Gtk 3.0
> ---
> src/spice-widget.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 44 insertions(+), 10 deletions(-)
>
> diff --git a/src/spice-widget.c b/src/spice-widget.c
> index 7678c12..c8ee4bb 100644
> --- a/src/spice-widget.c
> +++ b/src/spice-widget.c
> @@ -2361,11 +2361,52 @@ static void spice_display_class_init(SpiceDisplayClass *klass)
> #define SPICE_GDK_BUTTONS_MASK \
> (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK|GDK_BUTTON4_MASK|GDK_BUTTON5_MASK)
>
> +#if GTK_CHECK_VERSION(3, 20, 0)
> +static GdkSeat *spice_display_get_default_seat(SpiceDisplay *display)
> +{
> + GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
> + GdkDisplay *gdk_display = gdk_window_get_display(window);
> + G_GNUC_BEGIN_IGNORE_DEPRECATIONS
> + return gdk_display_get_default_seat(gdk_display);
> + G_GNUC_END_IGNORE_DEPRECATIONS
> +}
> +#endif
I think you can remove spice_display_get_default_seat() function for now
and move logic to spice_display_get_pointer() (and getting ride of
second GTK_CHECK_VERSION, G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS)
> +
> +static GdkDevice *spice_display_get_pointer(SpiceDisplay *display)
I'm terrible with name, so just a minor suggestion:
spice_display_get_pointer -> spice_display_get_device_pointer ?
> +{
> + G_GNUC_BEGIN_IGNORE_DEPRECATIONS
> +#if GTK_CHECK_VERSION(3, 20, 0)
> + return gdk_seat_get_pointer(spice_display_get_default_seat(display));
> +#else
> + GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
The GdkWindow is also requested and check in
spice_display_get_modifiers_state() so I think you could change the
argument from SpiceDisplay *display to GdkWindow *window and use that.
> + GdkDisplay *gdk_display = gdk_window_get_display(window);
> + return gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_display));
> +#endif
> + G_GNUC_END_IGNORE_DEPRECATIONS
> +}
> +
> +static GdkModifierType spice_display_get_modifiers_state(SpiceDisplay *display)
> +{
> + GdkModifierType modifiers;
> + GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
> +
> + if (window == NULL) {
> + return 0;
> + }
> +
> + gdk_window_get_device_position(window,
> + spice_display_get_pointer(display),
> + NULL,
> + NULL,
> + &modifiers);
> +
> + return modifiers;
> +}
> +
Other than that, looks good in my quick test :)
Reviewed-by: Victor Toso <victortoso at redhat.com>
> static void update_mouse_mode(SpiceChannel *channel, gpointer data)
> {
> SpiceDisplay *display = data;
> SpiceDisplayPrivate *d = display->priv;
> - GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
>
> g_object_get(channel, "mouse-mode", &d->mouse_mode, NULL);
> SPICE_DEBUG("mouse mode %u", d->mouse_mode);
> @@ -2378,15 +2419,8 @@ static void update_mouse_mode(SpiceChannel *channel, gpointer data)
> d->mouse_guest_x = -1;
> d->mouse_guest_y = -1;
>
> - if (window != NULL) {
> - GdkModifierType modifiers;
> - /* FIXME: gdk_window_get_pointer() is deprecated */
> - G_GNUC_BEGIN_IGNORE_DEPRECATIONS
> - gdk_window_get_pointer(window, NULL, NULL, &modifiers);
> - G_GNUC_END_IGNORE_DEPRECATIONS
> -
> - if (modifiers & SPICE_GDK_BUTTONS_MASK)
> - try_mouse_grab(display);
> + if (spice_display_get_modifiers_state(display) & SPICE_GDK_BUTTONS_MASK) {
> + try_mouse_grab(display);
> }
> break;
> default:
> --
> 2.11.0
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170123/45c256c2/attachment.sig>
More information about the Spice-devel
mailing list