gtk: Stop using keymap apis

Stop using most keymap apis in GTK. Only a few calls
related to virtual modifiers are left.
This commit is contained in:
Matthias Clasen 2020-04-05 01:04:20 -04:00
parent 13213c710f
commit 234a21905c
12 changed files with 102 additions and 82 deletions

View File

@ -1139,8 +1139,8 @@ gtk_accelerator_get_default_mod_mask (void)
return GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK;
default_accel_mod_mask =
gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_DEFAULT_MOD_MASK);
gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_DEFAULT_MOD_MASK);
}
return default_accel_mod_mask;

View File

@ -2999,10 +2999,10 @@ gtk_flow_box_add_move_binding (GtkWidgetClass *widget_class,
display = gdk_display_get_default ();
if (display != NULL)
{
extend_mod_mask = gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask = gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
extend_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
}
gtk_widget_class_add_binding_signal (widget_class,

View File

@ -1034,7 +1034,6 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
GtkIMContextSimplePrivate *priv = context_simple->priv;
GdkSurface *surface = gdk_event_get_surface ((GdkEvent *) event);
GdkDisplay *display = gdk_surface_get_display (surface);
GdkKeymap *keymap = gdk_display_get_keymap (display);
GSList *tmp_list;
int n_compose = 0;
GdkModifierType hex_mod_mask;
@ -1053,10 +1052,10 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
while (priv->compose_buffer[n_compose] != 0)
n_compose++;
keyval = gdk_key_event_get_keyval ((GdkEvent *)event);
state = gdk_event_get_modifier_state ((GdkEvent *)event);
keyval = gdk_key_event_get_keyval (event);
state = gdk_event_get_modifier_state (event);
if (gdk_event_get_event_type ((GdkEvent *) event) == GDK_KEY_RELEASE)
if (gdk_event_get_event_type (event) == GDK_KEY_RELEASE)
{
if (priv->in_hex_sequence &&
(keyval == GDK_KEY_Control_L || keyval == GDK_KEY_Control_R ||
@ -1100,7 +1099,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
if (keyval == gtk_compose_ignore[i])
return FALSE;
hex_mod_mask = gdk_keymap_get_modifier_mask (keymap, GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
hex_mod_mask = gdk_display_get_modifier_mask (display, GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
hex_mod_mask |= GDK_SHIFT_MASK;
if (priv->in_hex_sequence && priv->modifiers_dropped)
@ -1132,7 +1131,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
{
GdkModifierType no_text_input_mask;
no_text_input_mask = gdk_keymap_get_modifier_mask (keymap, GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
no_text_input_mask = gdk_display_get_modifier_mask (display, GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
if (state & no_text_input_mask ||
(priv->in_hex_sequence && priv->modifiers_dropped &&

View File

@ -369,8 +369,8 @@ gtk_im_multicontext_filter_keypress (GtkIMContext *context,
display = gdk_event_get_display (event);
no_text_input_mask =
gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
if (gdk_event_get_event_type (event) == GDK_KEY_PRESS &&
(state & no_text_input_mask) == 0)

View File

@ -5540,8 +5540,9 @@ get_better_cursor (GtkLabel *label,
gint *y)
{
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
GdkKeymap *keymap = gdk_display_get_keymap (gtk_widget_get_display (GTK_WIDGET (label)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
GdkSeat *seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (label)));
GdkDevice *device = gdk_seat_get_keyboard (seat);
PangoDirection keymap_direction = gdk_device_get_direction (device);
PangoDirection cursor_direction = get_cursor_direction (label);
gboolean split_cursor;
PangoRectangle strong_pos, weak_pos;
@ -5644,8 +5645,9 @@ gtk_label_move_visually (GtkLabel *label,
strong = TRUE;
else
{
GdkKeymap *keymap = gdk_display_get_keymap (gtk_widget_get_display (GTK_WIDGET (label)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
GdkSeat *seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (label)));
GdkDevice *device = gdk_seat_get_keyboard (seat);
PangoDirection keymap_direction = gdk_device_get_direction (device);
strong = keymap_direction == get_cursor_direction (label);
}

View File

@ -1432,10 +1432,10 @@ gtk_list_box_add_move_binding (GtkWidgetClass *widget_class,
display = gdk_display_get_default ();
if (display)
{
extend_mod_mask = gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask = gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
extend_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
modify_mod_mask = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
}
gtk_widget_class_add_binding_signal (widget_class,

View File

@ -55,7 +55,7 @@ typedef struct {
GtkWidget *entry;
GtkWidget *icon;
GtkWidget *peek_icon;
GdkKeymap *keymap;
GdkDevice *keyboard;
GMenuModel *extra_menu;
} GtkPasswordEntryPrivate;
@ -81,8 +81,9 @@ G_DEFINE_TYPE_WITH_CODE (GtkPasswordEntry, gtk_password_entry, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_password_entry_editable_init))
static void
keymap_state_changed (GdkKeymap *keymap,
GtkWidget *widget)
caps_lock_state_changed (GdkDevice *device,
GParamSpec *pspec,
GtkWidget *widget)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
@ -90,7 +91,7 @@ keymap_state_changed (GdkKeymap *keymap,
if (gtk_editable_get_editable (GTK_EDITABLE (entry)) &&
gtk_widget_has_focus (priv->entry) &&
!gtk_text_get_visibility (GTK_TEXT (priv->entry)) &&
gdk_keymap_get_caps_lock_state (priv->keymap))
gdk_device_get_caps_lock_state (device))
gtk_widget_show (priv->icon);
else
gtk_widget_hide (priv->icon);
@ -102,8 +103,8 @@ focus_changed (GtkWidget *widget)
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
if (priv->keymap)
keymap_state_changed (priv->keymap, widget);
if (priv->keyboard)
caps_lock_state_changed (priv->keyboard, NULL, widget);
}
static void
@ -134,8 +135,8 @@ visibility_toggled (GObject *object,
gtk_widget_set_tooltip_text (priv->peek_icon, _("Show text"));
}
if (priv->keymap)
keymap_state_changed (priv->keymap, GTK_WIDGET (entry));
if (priv->keyboard)
caps_lock_state_changed (priv->keyboard, NULL, GTK_WIDGET (entry));
}
static void
@ -168,9 +169,9 @@ gtk_password_entry_realize (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_password_entry_parent_class)->realize (widget);
priv->keymap = gdk_display_get_keymap (gtk_widget_get_display (widget));
g_signal_connect (priv->keymap, "state-changed", G_CALLBACK (keymap_state_changed), entry);
keymap_state_changed (priv->keymap, widget);
priv->keyboard = gdk_seat_get_keyboard (gdk_display_get_default_seat (gtk_widget_get_display (widget)));
g_signal_connect (priv->keyboard, "notify::caps-lock-state", G_CALLBACK (caps_lock_state_changed), entry);
caps_lock_state_changed (priv->keyboard, NULL, widget);
}
static void
@ -179,8 +180,8 @@ gtk_password_entry_dispose (GObject *object)
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (object);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
if (priv->keymap)
g_signal_handlers_disconnect_by_func (priv->keymap, keymap_state_changed, entry);
if (priv->keyboard)
g_signal_handlers_disconnect_by_func (priv->keyboard, caps_lock_state_changed, entry);
if (priv->entry)
gtk_editable_finish_delegate (GTK_EDITABLE (entry));
@ -502,7 +503,7 @@ gtk_password_entry_set_show_peek_icon (GtkPasswordEntry *entry,
entry);
}
keymap_state_changed (priv->keymap, GTK_WIDGET (entry));
caps_lock_state_changed (priv->keyboard, NULL, GTK_WIDGET (entry));
g_object_notify_by_pspec (G_OBJECT (entry), props[PROP_SHOW_PEEK_ICON]);
}

View File

@ -196,8 +196,8 @@ _gtk_get_primary_accel_mod (void)
{
GdkDisplay *display = gdk_display_get_default ();
primary = gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
primary = gdk_display_get_modifier_mask (display,
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
primary = _gtk_replace_virtual_modifiers (gdk_display_get_keymap (display),
primary);
}

View File

@ -1253,7 +1253,8 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
gboolean split_cursor;
PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2;
PangoDirection keymap_direction;
GdkDevice *keyboard;
PangoDirection keyboard_direction;
PangoDirection direction2;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
@ -1265,7 +1266,8 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
"gtk-split-cursor", &split_cursor,
NULL);
keymap_direction = gdk_keymap_get_direction (gdk_display_get_keymap (priv->display));
keyboard = gdk_seat_get_keyboard (gdk_display_get_default_seat (priv->display));
keyboard_direction = gdk_device_get_direction (keyboard);
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
@ -1283,7 +1285,7 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
}
else
{
if (keymap_direction == direction)
if (keyboard_direction == direction)
cursor1 = &strong_pos;
else
cursor1 = &weak_pos;
@ -1339,7 +1341,8 @@ gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
float aspect_ratio;
PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2;
PangoDirection keymap_direction;
GdkDevice *keyboard;
PangoDirection keyboard_direction;
PangoDirection direction2;
g_return_if_fail (snapshot != NULL);
@ -1352,7 +1355,8 @@ gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL);
keymap_direction = gdk_keymap_get_direction (gdk_display_get_keymap (priv->display));
keyboard = gdk_seat_get_keyboard (gdk_display_get_default_seat (priv->display));
keyboard_direction = gdk_device_get_direction (keyboard);
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
@ -1370,7 +1374,7 @@ gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
}
else
{
if (keymap_direction == direction)
if (keyboard_direction == direction)
cursor1 = &strong_pos;
else
cursor1 = &weak_pos;

View File

@ -410,7 +410,8 @@ static void gtk_text_insert_emoji (GtkText *self);
static void gtk_text_select_all (GtkText *self);
static void gtk_text_real_activate (GtkText *self);
static void keymap_direction_changed (GdkKeymap *keymap,
static void direction_changed (GdkDevice *keyboard,
GParamSpec *pspec,
GtkText *self);
/* IM Context Callbacks
@ -1880,7 +1881,8 @@ gtk_text_dispose (GObject *object)
{
GtkText *self = GTK_TEXT (object);
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
GdkKeymap *keymap;
GdkSeat *seat;
GdkDevice *keyboard;
GtkWidget *chooser;
priv->current_pos = 0;
@ -1897,8 +1899,9 @@ gtk_text_dispose (GObject *object)
if (chooser)
gtk_widget_unparent (chooser);
keymap = gdk_display_get_keymap (gtk_widget_get_display (GTK_WIDGET (object)));
g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, self);
seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (object)));
keyboard = gdk_seat_get_keyboard (seat);
g_signal_handlers_disconnect_by_func (keyboard, direction_changed, self);
g_clear_pointer (&priv->selection_bubble, gtk_widget_unparent);
g_clear_pointer (&priv->popup_menu, gtk_widget_unparent);
@ -3081,11 +3084,13 @@ gtk_text_focus_in (GtkWidget *widget)
{
GtkText *self = GTK_TEXT (widget);
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
GdkKeymap *keymap;
GdkSeat *seat;
GdkDevice *keyboard;
gtk_widget_queue_draw (widget);
keymap = gdk_display_get_keymap (gtk_widget_get_display (widget));
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
keyboard = gdk_seat_get_keyboard (seat);
if (priv->editable)
{
@ -3093,8 +3098,8 @@ gtk_text_focus_in (GtkWidget *widget)
gtk_im_context_focus_in (priv->im_context);
}
g_signal_connect (keymap, "direction-changed",
G_CALLBACK (keymap_direction_changed), self);
g_signal_connect (keyboard, "notify::direction",
G_CALLBACK (direction_changed), self);
gtk_text_reset_blink_time (self);
gtk_text_check_cursor_blink (self);
@ -3105,7 +3110,8 @@ gtk_text_focus_out (GtkWidget *widget)
{
GtkText *self = GTK_TEXT (widget);
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
GdkKeymap *keymap;
GdkSeat *seat;
GdkDevice *keyboard;
gtk_text_selection_bubble_popup_unset (self);
@ -3114,7 +3120,8 @@ gtk_text_focus_out (GtkWidget *widget)
gtk_widget_queue_draw (widget);
keymap = gdk_display_get_keymap (gtk_widget_get_display (widget));
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
keyboard = gdk_seat_get_keyboard (seat);
if (priv->editable)
{
@ -3124,7 +3131,7 @@ gtk_text_focus_out (GtkWidget *widget)
gtk_text_check_cursor_blink (self);
g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, self);
g_signal_handlers_disconnect_by_func (keyboard, direction_changed, self);
}
static gboolean
@ -3604,8 +3611,9 @@ get_better_cursor_x (GtkText *self,
int offset)
{
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
GdkKeymap *keymap = gdk_display_get_keymap (gtk_widget_get_display (GTK_WIDGET (self)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
GdkSeat *seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (self)));
GdkDevice *keyboard = gdk_seat_get_keyboard (seat);
PangoDirection direction = gdk_device_get_direction (keyboard);
gboolean split_cursor;
PangoLayout *layout = gtk_text_ensure_layout (self, TRUE);
const char *text = pango_layout_get_text (layout);
@ -3621,7 +3629,7 @@ get_better_cursor_x (GtkText *self,
if (split_cursor)
return strong_pos.x / PANGO_SCALE;
else
return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
return (direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
}
static void
@ -4060,8 +4068,9 @@ gtk_text_real_activate (GtkText *self)
}
static void
keymap_direction_changed (GdkKeymap *keymap,
GtkText *self)
direction_changed (GdkDevice *device,
GParamSpec *pspec,
GtkText *self)
{
gtk_text_recompute (self);
}
@ -4326,9 +4335,10 @@ gtk_text_create_layout (GtkText *self,
if (gtk_widget_has_focus (widget))
{
GdkDisplay *display = gtk_widget_get_display (widget);
GdkKeymap *keymap = gdk_display_get_keymap (display);
GdkSeat *seat = gdk_display_get_default_seat (display);
GdkDevice *keyboard = gdk_seat_get_keyboard (seat);
if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
if (gdk_device_get_direction (keyboard) == PANGO_DIRECTION_RTL)
pango_dir = PANGO_DIRECTION_RTL;
else
pango_dir = PANGO_DIRECTION_LTR;
@ -4888,10 +4898,12 @@ gtk_text_move_visually (GtkText *self,
strong = TRUE;
else
{
GdkKeymap *keymap = gdk_display_get_keymap (gtk_widget_get_display (GTK_WIDGET (self)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (self));
GdkSeat *seat = gdk_display_get_default_seat (display);
GdkDevice *keyboard = gdk_seat_get_keyboard (seat);
PangoDirection direction = gdk_device_get_direction (keyboard);
strong = keymap_direction == priv->resolved_dir;
strong = direction == priv->resolved_dir;
}
if (count > 0)

View File

@ -5456,8 +5456,9 @@ gtk_text_view_click_gesture_pressed (GtkGestureClick *gesture,
}
static void
keymap_direction_changed (GdkKeymap *keymap,
GtkTextView *text_view)
direction_changed (GdkDevice *device,
GParamSpec *pspec,
GtkTextView *text_view)
{
gtk_text_view_check_keymap_direction (text_view);
}
@ -5467,6 +5468,8 @@ gtk_text_view_focus_in (GtkWidget *widget)
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
GtkTextViewPrivate *priv = text_view->priv;
GdkSeat *seat;
GdkDevice *keyboard;
gtk_widget_queue_draw (widget);
@ -5480,9 +5483,10 @@ gtk_text_view_focus_in (GtkWidget *widget)
gtk_text_view_check_cursor_blink (text_view);
}
g_signal_connect (gdk_display_get_keymap (gtk_widget_get_display (widget)),
"direction-changed",
G_CALLBACK (keymap_direction_changed), text_view);
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
keyboard = gdk_seat_get_keyboard (seat);
g_signal_connect (keyboard, "notify::direction",
G_CALLBACK (direction_changed), text_view);
gtk_text_view_check_keymap_direction (text_view);
if (priv->editable)
@ -5497,6 +5501,8 @@ gtk_text_view_focus_out (GtkWidget *widget)
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
GtkTextViewPrivate *priv = text_view->priv;
GdkSeat *seat;
GdkDevice *keyboard;
gtk_text_view_end_selection_drag (text_view);
@ -5510,9 +5516,9 @@ gtk_text_view_focus_out (GtkWidget *widget)
gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
}
g_signal_handlers_disconnect_by_func (gdk_display_get_keymap (gtk_widget_get_display (widget)),
keymap_direction_changed,
text_view);
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
keyboard = gdk_seat_get_keyboard (seat);
g_signal_handlers_disconnect_by_func (keyboard, direction_changed, text_view);
gtk_text_view_selection_bubble_popup_unset (text_view);
text_view->priv->text_handles_enabled = FALSE;
@ -7534,7 +7540,8 @@ gtk_text_view_check_keymap_direction (GtkTextView *text_view)
if (priv->layout)
{
GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
GdkKeymap *keymap = gdk_display_get_keymap (gtk_widget_get_display (GTK_WIDGET (text_view)));
GdkSeat *seat = gdk_display_get_default_seat (gtk_widget_get_display (GTK_WIDGET (text_view)));
GdkDevice *keyboard = gdk_seat_get_keyboard (seat);
GtkTextDirection new_cursor_dir;
GtkTextDirection new_keyboard_dir;
gboolean split_cursor;
@ -7543,7 +7550,7 @@ gtk_text_view_check_keymap_direction (GtkTextView *text_view)
"gtk-split-cursor", &split_cursor,
NULL);
if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
if (gdk_device_get_direction (keyboard) == PANGO_DIRECTION_RTL)
new_keyboard_dir = GTK_TEXT_DIR_RTL;
else
new_keyboard_dir = GTK_TEXT_DIR_LTR;

View File

@ -10670,7 +10670,7 @@ gtk_widget_get_style_context (GtkWidget *widget)
* Returns the modifier mask the @widgets windowing system backend
* uses for a particular purpose.
*
* See gdk_keymap_get_modifier_mask().
* See gdk_display_get_modifier_mask().
*
* Returns: the modifier mask used for @intent.
**/
@ -10678,14 +10678,9 @@ GdkModifierType
gtk_widget_get_modifier_mask (GtkWidget *widget,
GdkModifierIntent intent)
{
GdkDisplay *display;
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
display = _gtk_widget_get_display (widget);
return gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
intent);
return gdk_display_get_modifier_mask (_gtk_widget_get_display (widget), intent);
}
static GtkActionMuxer *