diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-05-14 21:27:45 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-15 14:11:53 -0400 |
commit | 8912a6eb757c39a6801358331fa81f8f52ebad8a (patch) | |
tree | b410b78952f174bed33fd9d1fb63615eb20d3082 /gtk/gtktooltip.c | |
parent | 9b7a73268ea264f5674d04e129d9dabf680d3513 (diff) | |
download | gtk+-8912a6eb757c39a6801358331fa81f8f52ebad8a.tar.gz |
gtk: Handle seatless displays
If you run weston with the headless backend, you get a Wayland
display with no seat, which is just fine by the protocol.
gdk_display_get_default_seat() returns NULL in this case. Various
widgets assume that we always have a seat with a keyboard and a
pointer, since that is what X guarantees. Make things survive
without that, so we can run the testsuite under a headless
Wayland compositor.
Diffstat (limited to 'gtk/gtktooltip.c')
-rw-r--r-- | gtk/gtktooltip.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c index 4af709f19e..a6962641af 100644 --- a/gtk/gtktooltip.c +++ b/gtk/gtktooltip.c @@ -371,9 +371,10 @@ void gtk_tooltip_trigger_tooltip_query (GtkWidget *widget) { GdkDisplay *display; - double x, y; - GdkSurface *surface; + GdkSeat *seat; GdkDevice *device; + GdkSurface *surface; + double x, y; GtkWidget *toplevel; int dx, dy; @@ -382,8 +383,15 @@ gtk_tooltip_trigger_tooltip_query (GtkWidget *widget) display = gtk_widget_get_display (widget); /* Trigger logic as if the mouse moved */ - device = gdk_seat_get_pointer (gdk_display_get_default_seat (display)); - surface = gdk_device_get_surface_at_position (device, &x, &y); + seat = gdk_display_get_default_seat (display); + if (seat) + device = gdk_seat_get_pointer (seat); + else + device = NULL; + if (device) + surface = gdk_device_get_surface_at_position (device, &x, &y); + else + surface = NULL; if (!surface) return; @@ -673,6 +681,7 @@ gtk_tooltip_show_tooltip (GdkDisplay *display) gint x, y; GdkSurface *surface; GtkWidget *tooltip_widget; + GdkSeat *seat; GdkDevice *device; GtkTooltip *tooltip; gboolean return_value = FALSE; @@ -684,9 +693,17 @@ gtk_tooltip_show_tooltip (GdkDisplay *display) surface = gtk_native_get_surface (GTK_NATIVE (tooltip->native)); - device = gdk_seat_get_pointer (gdk_display_get_default_seat (display)); + seat = gdk_display_get_default_seat (display); + if (seat) + device = gdk_seat_get_pointer (seat); + else + device = NULL; + + if (device) + gdk_surface_get_device_position (surface, device, &px, &py, NULL); + else + px = py = 0; - gdk_surface_get_device_position (surface, device, &px, &py, NULL); x = round (px); y = round (py); |