[Spice-commits] 5 commits - src/spice-widget.c
Pavel Grunt
pgrunt at kemper.freedesktop.org
Tue Feb 21 13:38:25 UTC 2017
src/spice-widget.c | 138 ++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 105 insertions(+), 33 deletions(-)
New commits:
commit ef7a6fa1798c8e53c0b77330b398a78181cf90e5
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Fri Feb 17 11:24:54 2017 +0100
gtk: Avoid deprecated gdk_pointer_grab
gdk_pointer_grab() was deprecated in 3.0 for gdk_device_grab()
but that was also deprecated for gdk_seat_grab() in 3.20
Acked-by: Victor Toso <victortoso at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 4433fac..ed9a664 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -1031,6 +1031,17 @@ static gboolean do_pointer_grab(SpiceDisplay *display)
#endif
try_keyboard_grab(display);
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+#if GTK_CHECK_VERSION(3, 20, 0)
+ status = gdk_seat_grab(spice_display_get_default_seat(display),
+ window,
+ GDK_SEAT_CAPABILITY_ALL_POINTING,
+ TRUE,
+ blank,
+ NULL,
+ NULL,
+ NULL);
+#else
/*
* from gtk-vnc:
* For relative mouse to work correctly when grabbed we need to
@@ -1040,8 +1051,6 @@ static gboolean do_pointer_grab(SpiceDisplay *display)
* what window the pointer is actally over, so use 'FALSE' for
* 'owner_events' parameter
*/
- /* FIXME: gdk_pointer_grab() is deprecated */
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
status = gdk_pointer_grab(window, FALSE,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
@@ -1051,6 +1060,7 @@ static gboolean do_pointer_grab(SpiceDisplay *display)
NULL,
blank,
GDK_CURRENT_TIME);
+#endif
G_GNUC_END_IGNORE_DEPRECATIONS
grab_successful = (status == GDK_GRAB_SUCCESS);
if (!grab_successful) {
@@ -1151,9 +1161,6 @@ static void mouse_wrap(SpiceDisplay *display, GdkEventMotion *motion)
}
-/* FIXME: gdk_pointer_ungrab() is deprecated */
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-
static void try_mouse_ungrab(SpiceDisplay *display)
{
SpiceDisplayPrivate *d = display->priv;
@@ -1164,7 +1171,13 @@ static void try_mouse_ungrab(SpiceDisplay *display)
if (!d->mouse_grab_active)
return;
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+#if GTK_CHECK_VERSION(3, 20, 0)
+ gdk_seat_ungrab(spice_display_get_default_seat(display));
+#else
gdk_pointer_ungrab(GDK_CURRENT_TIME);
+#endif
+ G_GNUC_END_IGNORE_DEPRECATIONS
gtk_grab_remove(GTK_WIDGET(display));
#ifdef G_OS_WIN32
ClipCursor(NULL);
@@ -1188,7 +1201,6 @@ static void try_mouse_ungrab(SpiceDisplay *display)
g_signal_emit(display, signals[SPICE_DISPLAY_MOUSE_GRAB], 0, false);
spice_gtk_session_set_pointer_grabbed(d->gtk_session, false);
}
-G_GNUC_END_IGNORE_DEPRECATIONS
static void update_mouse_grab(SpiceDisplay *display)
{
@@ -2034,7 +2046,11 @@ static gboolean button_event(GtkWidget *widget, GdkEventButton *button)
*/
/* FIXME: gdk_pointer_ungrab() is deprecated */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+#if GTK_CHECK_VERSION(3, 20, 0)
+ gdk_seat_ungrab(spice_display_get_default_seat(display));
+#else
gdk_pointer_ungrab(GDK_CURRENT_TIME);
+#endif
G_GNUC_END_IGNORE_DEPRECATIONS
}
commit 3f4c5bcc88ca5db125ec48ebf696cb23a8e6339a
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Fri Feb 17 11:24:53 2017 +0100
gtk: Avoid deprecated gdk_keyboard_grab
gdk_keyboard_grab() was deprecated in 3.0 for gdk_device_grab()
but that was also deprecated for gdk_seat_grab() in 3.20
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 6d49d08..4433fac 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -819,6 +819,17 @@ SpiceGrabSequence *spice_display_get_grab_keys(SpiceDisplay *display)
return d->grabseq;
}
+#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
+
/* FIXME: gdk_keyboard_grab/ungrab() is deprecated */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@@ -857,8 +868,19 @@ static void try_keyboard_grab(SpiceDisplay *display)
GetModuleHandle(NULL), 0);
g_warn_if_fail(d->keyboard_hook != NULL);
#endif
+#if GTK_CHECK_VERSION(3, 20, 0)
+ status = gdk_seat_grab(spice_display_get_default_seat(display),
+ gtk_widget_get_window(widget),
+ GDK_SEAT_CAPABILITY_KEYBOARD,
+ FALSE,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+#else
status = gdk_keyboard_grab(gtk_widget_get_window(widget), FALSE,
GDK_CURRENT_TIME);
+#endif
if (status != GDK_GRAB_SUCCESS) {
g_warning("keyboard grab failed %u", status);
d->keyboard_grab_active = false;
@@ -877,7 +899,11 @@ static void try_keyboard_ungrab(SpiceDisplay *display)
return;
SPICE_DEBUG("ungrab keyboard");
+#if GTK_CHECK_VERSION(3, 20, 0)
+ gdk_seat_ungrab(spice_display_get_default_seat(display));
+#else
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
+#endif
#ifdef G_OS_WIN32
// do not use g_clear_pointer as Windows API have different linkage
if (d->keyboard_hook) {
commit 0f53fa1056394ff8d9bb2d7ab648a3f6b35ae499
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Fri Feb 17 11:24:52 2017 +0100
gtk: Use gdk_device_warp
gdk_display_warp_pointer has been deprecated since Gtk 3.0
In Wayland gdk_device_warp is noop making server mouse mode
unusable, see: https://bugzilla.redhat.com/show_bug.cgi?id=1285378
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 49a6c98..6d49d08 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -119,6 +119,7 @@ static void release_keys(SpiceDisplay *display);
static void size_allocate(GtkWidget *widget, GtkAllocation *conf, gpointer data);
static gboolean draw_event(GtkWidget *widget, cairo_t *cr, gpointer data);
static void update_size_request(SpiceDisplay *display);
+static GdkDevice *spice_gdk_window_get_pointing_device(GdkWindow *window);
/* ---------------------------------------------------------------- */
@@ -1112,14 +1113,11 @@ static void mouse_wrap(SpiceDisplay *display, GdkEventMotion *motion)
yr = gdk_screen_get_height(screen) / 2;
if (xr != (gint)motion->x_root || yr != (gint)motion->y_root) {
+ GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
/* FIXME: we try our best to ignore that next pointer move event.. */
gdk_display_sync(gdk_screen_get_display(screen));
- /* FIXME: gdk_display_warp_pointer() is deprecated */
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gdk_display_warp_pointer(gtk_widget_get_display(GTK_WIDGET(display)),
- screen, xr, yr);
- G_GNUC_END_IGNORE_DEPRECATIONS
+ gdk_device_warp(spice_gdk_window_get_pointing_device(window), screen, xr, yr);
d->mouse_last_x = -1;
d->mouse_last_y = -1;
}
@@ -1127,7 +1125,7 @@ static void mouse_wrap(SpiceDisplay *display, GdkEventMotion *motion)
}
-/* FIXME: gdk_pointer_ungrab()/gdk_display_warp_pointer() are deprecated */
+/* FIXME: gdk_pointer_ungrab() is deprecated */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void try_mouse_ungrab(SpiceDisplay *display)
@@ -1135,6 +1133,7 @@ static void try_mouse_ungrab(SpiceDisplay *display)
SpiceDisplayPrivate *d = display->priv;
double s;
int x, y;
+ GdkWindow *window;
if (!d->mouse_grab_active)
return;
@@ -1150,14 +1149,15 @@ static void try_mouse_ungrab(SpiceDisplay *display)
spice_display_get_scaling(display, &s, &x, &y, NULL, NULL);
- gdk_window_get_root_coords(gtk_widget_get_window(GTK_WIDGET(display)),
+ window = gtk_widget_get_window(GTK_WIDGET(display));
+ gdk_window_get_root_coords(window,
x + d->mouse_guest_x * s,
y + d->mouse_guest_y * s,
&x, &y);
- gdk_display_warp_pointer(gtk_widget_get_display(GTK_WIDGET(display)),
- gtk_widget_get_screen(GTK_WIDGET(display)),
- x, y);
+ gdk_device_warp(spice_gdk_window_get_pointing_device(window),
+ gtk_widget_get_screen(GTK_WIDGET(display)),
+ x, y);
g_signal_emit(display, signals[SPICE_DISPLAY_MOUSE_GRAB], 0, false);
spice_gtk_session_set_pointer_grabbed(d->gtk_session, false);
commit 283f41cd289084689fbdf1151da55aa451ba343c
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Fri Feb 17 11:24:51 2017 +0100
gtk: Use gdk_window_get_device_position
gdk_window_get_pointer has been deprecated since Gtk 3.0
Introduce helper functions for getting the display's pointing
device and modifiers to keep the update_mouse_mode simple
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/src/spice-widget.c b/src/spice-widget.c
index ea7b135..49a6c98 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -2361,11 +2361,40 @@ 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)
+static GdkDevice *spice_gdk_window_get_pointing_device(GdkWindow *window)
+{
+ GdkDisplay *gdk_display = gdk_window_get_display(window);
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+#if GTK_CHECK_VERSION(3, 20, 0)
+ return gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_display));
+#else
+ 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_gdk_window_get_pointing_device(window),
+ NULL,
+ NULL,
+ &modifiers);
+
+ return modifiers;
+}
+
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 +2407,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:
commit 62f9144d6c5ac06cd76b76176644622c43c08541
Author: Pavel Grunt <pgrunt at redhat.com>
Date: Fri Feb 17 11:24:50 2017 +0100
gtk: Use gdk_cursor_new_from_name
gdk_cursor_new has been deprecated since Gtk 3.16
A difference is that the helper function for creating the cursor
returns early if the widget is not realized.
Also allow to hide the cursor under Wayland
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 72fbbc8..ea7b135 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -460,12 +460,19 @@ static void spice_display_finalize(GObject *obj)
G_OBJECT_CLASS(spice_display_parent_class)->finalize(obj);
}
-static GdkCursor* get_blank_cursor(void)
+static GdkCursor* spice_display_get_blank_cursor(SpiceDisplay *display)
{
- if (g_getenv("SPICE_DEBUG_CURSOR"))
- return gdk_cursor_new(GDK_DOT);
+ GdkDisplay *gdk_display;
+ const gchar *cursor_name;
+ GdkWindow *gdk_window = GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display)));
- return gdk_cursor_new(GDK_BLANK_CURSOR);
+ if (gdk_window == NULL)
+ return NULL;
+
+ gdk_display = gdk_window_get_display(gdk_window);
+ cursor_name = g_getenv("SPICE_DEBUG_CURSOR") ? "crosshair" : "none";
+
+ return gdk_cursor_new_from_name(gdk_display, cursor_name);
}
static gboolean grab_broken(SpiceDisplay *self, GdkEventGrabBroken *event,
@@ -676,7 +683,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
d->grabseq = spice_grab_sequence_new_from_string("Control_L+Alt_L");
d->activeseq = g_new0(gboolean, d->grabseq->nkeysyms);
- d->mouse_cursor = get_blank_cursor();
}
static GObject *
@@ -986,7 +992,7 @@ static gboolean do_pointer_grab(SpiceDisplay *display)
SpiceDisplayPrivate *d = display->priv;
GdkWindow *window = GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display)));
GdkGrabStatus status;
- GdkCursor *blank = get_blank_cursor();
+ GdkCursor *blank = spice_display_get_blank_cursor(display);
gboolean grab_successful = FALSE;
if (!gtk_widget_get_realized(GTK_WIDGET(display)))
@@ -2579,7 +2585,9 @@ static void cursor_set(SpiceCursorChannel *channel,
}
}
- g_object_unref(d->mouse_cursor);
+ if (d->mouse_cursor != NULL) {
+ g_object_unref(d->mouse_cursor);
+ }
d->mouse_cursor = cursor;
update_mouse_pointer(display);
@@ -2596,7 +2604,7 @@ static void cursor_hide(SpiceCursorChannel *channel, gpointer data)
cursor_invalidate(display);
d->show_cursor = d->mouse_cursor;
- d->mouse_cursor = get_blank_cursor();
+ d->mouse_cursor = spice_display_get_blank_cursor(display);
update_mouse_pointer(display);
}
More information about the Spice-commits
mailing list