summaryrefslogtreecommitdiff
path: root/gtk/gtkstylecontext.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-05-14 21:27:45 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-05-15 14:11:53 -0400
commit8912a6eb757c39a6801358331fa81f8f52ebad8a (patch)
treeb410b78952f174bed33fd9d1fb63615eb20d3082 /gtk/gtkstylecontext.c
parent9b7a73268ea264f5674d04e129d9dabf680d3513 (diff)
downloadgtk+-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/gtkstylecontext.c')
-rw-r--r--gtk/gtkstylecontext.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7c40e4a055..0a11c83007 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -1151,6 +1151,7 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
float aspect_ratio;
PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2;
+ GdkSeat *seat;
GdkDevice *keyboard;
PangoDirection keyboard_direction;
PangoDirection direction2;
@@ -1165,8 +1166,15 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL);
- keyboard = gdk_seat_get_keyboard (gdk_display_get_default_seat (priv->display));
- keyboard_direction = gdk_device_get_direction (keyboard);
+ seat = gdk_display_get_default_seat (priv->display);
+ if (seat)
+ keyboard = gdk_seat_get_keyboard (seat);
+ else
+ keyboard = NULL;
+ if (keyboard)
+ keyboard_direction = gdk_device_get_direction (keyboard);
+ else
+ keyboard_direction = PANGO_DIRECTION_LTR;
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
@@ -1240,6 +1248,7 @@ gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
float aspect_ratio;
PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2;
+ GdkSeat *seat;
GdkDevice *keyboard;
PangoDirection keyboard_direction;
PangoDirection direction2;
@@ -1254,8 +1263,15 @@ gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL);
- keyboard = gdk_seat_get_keyboard (gdk_display_get_default_seat (priv->display));
- keyboard_direction = gdk_device_get_direction (keyboard);
+ seat = gdk_display_get_default_seat (priv->display);
+ if (seat)
+ keyboard = gdk_seat_get_keyboard (seat);
+ else
+ keyboard = NULL;
+ if (keyboard)
+ keyboard_direction = gdk_device_get_direction (keyboard);
+ else
+ keyboard_direction = PANGO_DIRECTION_LTR;
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);