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/gtklabel.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/gtklabel.c')
-rw-r--r-- | gtk/gtklabel.c | 80 |
1 files changed, 51 insertions, 29 deletions
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 2aac9270d0..a66581cb48 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -4937,25 +4937,37 @@ gtk_label_get_single_line_mode (GtkLabel *self) */ static void get_better_cursor (GtkLabel *self, - gint index, - gint *x, - gint *y) -{ - GdkSeat *seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (self))); - GdkDevice *device = gdk_seat_get_keyboard (seat); - PangoDirection keymap_direction = gdk_device_get_direction (device); - PangoDirection cursor_direction = get_cursor_direction (self); + int index, + int *x, + int *y) +{ + GdkSeat *seat; + GdkDevice *keyboard; + PangoDirection keymap_direction; + PangoDirection cursor_direction; gboolean split_cursor; PangoRectangle strong_pos, weak_pos; - + + seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (self))); + if (seat) + keyboard = gdk_seat_get_keyboard (seat); + else + keyboard = NULL; + if (keyboard) + keymap_direction = gdk_device_get_direction (keyboard); + else + keymap_direction = PANGO_DIRECTION_LTR; + + cursor_direction = get_cursor_direction (self); + g_object_get (gtk_widget_get_settings (GTK_WIDGET (self)), - "gtk-split-cursor", &split_cursor, - NULL); + "gtk-split-cursor", &split_cursor, + NULL); gtk_label_ensure_layout (self); - + pango_layout_get_cursor_pos (self->layout, index, - &strong_pos, &weak_pos); + &strong_pos, &weak_pos); if (split_cursor) { @@ -4965,15 +4977,15 @@ get_better_cursor (GtkLabel *self, else { if (keymap_direction == cursor_direction) - { - *x = strong_pos.x / PANGO_SCALE; - *y = strong_pos.y / PANGO_SCALE; - } + { + *x = strong_pos.x / PANGO_SCALE; + *y = strong_pos.y / PANGO_SCALE; + } else - { - *x = weak_pos.x / PANGO_SCALE; - *y = weak_pos.y / PANGO_SCALE; - } + { + *x = weak_pos.x / PANGO_SCALE; + *y = weak_pos.y / PANGO_SCALE; + } } } @@ -5041,16 +5053,26 @@ gtk_label_move_visually (GtkLabel *self, NULL); if (split_cursor) - strong = TRUE; + strong = TRUE; else - { - GdkSeat *seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (self))); - GdkDevice *device = gdk_seat_get_keyboard (seat); - PangoDirection keymap_direction = gdk_device_get_direction (device); + { + GdkSeat *seat; + GdkDevice *keyboard; + PangoDirection keymap_direction; + + seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (self))); + if (seat) + keyboard = gdk_seat_get_keyboard (seat); + else + keyboard = NULL; + if (keyboard) + keymap_direction = gdk_device_get_direction (keyboard); + else + keymap_direction = PANGO_DIRECTION_LTR; + + strong = keymap_direction == get_cursor_direction (self); + } - strong = keymap_direction == get_cursor_direction (self); - } - if (count > 0) { pango_layout_move_cursor_visually (self->layout, strong, index, 0, 1, &new_index, &new_trailing); |