gdk: Remove gdk_event_get_string()

You want to use an IM module to get strings out of keypresses, not some
crude hack that only works on X11 and Wayland anyway.
This commit is contained in:
Benjamin Otte 2018-07-28 20:07:10 +02:00
parent 36ed4c2a29
commit 813957a92f
5 changed files with 28 additions and 63 deletions

View File

@ -655,7 +655,6 @@ gdk_event_get_key_is_modifier
gdk_event_get_pad_axis_value gdk_event_get_pad_axis_value
gdk_event_get_pad_button gdk_event_get_pad_button
gdk_event_get_pad_group_mode gdk_event_get_pad_group_mode
gdk_event_get_string
gdk_event_get_touch_emulating_pointer gdk_event_get_touch_emulating_pointer
gdk_event_get_touchpad_angle_delta gdk_event_get_touchpad_angle_delta
gdk_event_get_touchpad_deltas gdk_event_get_touchpad_deltas

View File

@ -1293,37 +1293,6 @@ gdk_event_get_key_group (const GdkEvent *event,
return fetched; return fetched;
} }
/**
* gdk_event_get_string:
* @event: a #GdkEvent
* @string: (out) (transfer none): return location for the string
*
* Extracts a string from an event. The string is an
* approximation of the keyval in a key event.
*
* Returns: %TRUE on success, otherwise %FALSE
**/
gboolean
gdk_event_get_string (const GdkEvent *event,
const char **string)
{
gboolean fetched = TRUE;
switch ((guint) event->any.type)
{
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
*string = event->key.string;
break;
default:
*string = NULL;
fetched = FALSE;
break;
}
return fetched;
}
/** /**
* gdk_event_get_key_is_modifier: * gdk_event_get_key_is_modifier:
* @event: a #GdkEvent * @event: a #GdkEvent

View File

@ -403,9 +403,6 @@ gboolean gdk_event_get_key_is_modifier (const GdkEvent *event,
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_key_group (const GdkEvent *event, gboolean gdk_event_get_key_group (const GdkEvent *event,
guint *group); guint *group);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_string (const GdkEvent *event,
const char **string);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_scroll_direction (const GdkEvent *event, gboolean gdk_event_get_scroll_direction (const GdkEvent *event,

View File

@ -116,13 +116,11 @@ atk_key_event_from_gdk_event_key (GdkEventKey *key,
GdkModifierType state; GdkModifierType state;
guint keyval; guint keyval;
guint16 keycode; guint16 keycode;
const char *string;
type = gdk_event_get_event_type ((GdkEvent *)key); type = gdk_event_get_event_type ((GdkEvent *)key);
gdk_event_get_state ((GdkEvent *)key, &state); gdk_event_get_state ((GdkEvent *)key, &state);
gdk_event_get_keyval ((GdkEvent *)key, &keyval); gdk_event_get_keyval ((GdkEvent *)key, &keyval);
gdk_event_get_keycode ((GdkEvent *)key, &keycode); gdk_event_get_keycode ((GdkEvent *)key, &keycode);
gdk_event_get_string ((GdkEvent *)key, &string);
if (type == GDK_KEY_PRESS) if (type == GDK_KEY_PRESS)
event->type = ATK_KEY_EVENT_PRESS; event->type = ATK_KEY_EVENT_PRESS;
@ -133,14 +131,8 @@ atk_key_event_from_gdk_event_key (GdkEventKey *key,
event->state = state; event->state = state;
event->keyval = keyval; event->keyval = keyval;
if (string && string[0] && event->string = gdk_keyval_name (keyval);
(state & GDK_CONTROL_MASK || event->length = strlen (event->string);
g_unichar_isgraph (g_utf8_get_char (string))))
event->string = (char *) string;
else
event->string = gdk_keyval_name (keyval);
event->length = strlen (string);
event->keycode = keycode; event->keycode = keycode;
event->timestamp = gdk_event_get_time ((GdkEvent *)key); event->timestamp = gdk_event_get_time ((GdkEvent *)key);
} }

View File

@ -1281,7 +1281,8 @@ key_is_left_or_right (const GdkEvent *event)
static gboolean static gboolean
should_trigger_location_entry (GtkFileChooserWidget *impl, should_trigger_location_entry (GtkFileChooserWidget *impl,
guint keyval, guint keyval,
GdkModifierType state) GdkModifierType state,
const char **string)
{ {
GdkModifierType no_text_input_mask; GdkModifierType no_text_input_mask;
@ -1291,16 +1292,27 @@ should_trigger_location_entry (GtkFileChooserWidget *impl,
no_text_input_mask = no_text_input_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (impl), GDK_MODIFIER_INTENT_NO_TEXT_INPUT); gtk_widget_get_modifier_mask (GTK_WIDGET (impl), GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
if ((keyval == GDK_KEY_slash if (state & no_text_input_mask)
|| keyval == GDK_KEY_KP_Divide return FALSE;
|| keyval == GDK_KEY_period
#ifdef G_OS_UNIX
|| keyval == GDK_KEY_asciitilde
#endif
) && !(state & no_text_input_mask))
return TRUE;
return FALSE; switch (keyval)
{
case GDK_KEY_slash:
case GDK_KEY_KP_Divide:
*string = "/";
return TRUE;
case GDK_KEY_period:
*string = ".";
return TRUE;
case GDK_KEY_asciitilde:
*string = "~";
return TRUE;
default:
return FALSE;
}
} }
/* Handles key press events on the file list, so that we can trap Enter to /* Handles key press events on the file list, so that we can trap Enter to
@ -1317,16 +1329,14 @@ key_press_cb (GtkEventController *controller,
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data; GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data;
GtkFileChooserWidgetPrivate *priv = impl->priv; GtkFileChooserWidgetPrivate *priv = impl->priv;
const GdkEvent *event; const GdkEvent *event;
const char *string;
event = gtk_get_current_event (); event = gtk_get_current_event ();
if (should_trigger_location_entry (impl, keyval, state) && if (should_trigger_location_entry (impl, keyval, state, &string) &&
(priv->action == GTK_FILE_CHOOSER_ACTION_OPEN || (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)) priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
{ {
const char *string;
gdk_event_get_string ((GdkEvent *)event, &string);
location_popup_handler (impl, string); location_popup_handler (impl, string);
return GDK_EVENT_STOP; return GDK_EVENT_STOP;
} }
@ -1388,17 +1398,15 @@ widget_key_press_cb (GtkEventController *controller,
GtkFileChooserWidgetPrivate *priv = impl->priv; GtkFileChooserWidgetPrivate *priv = impl->priv;
gboolean handled = FALSE; gboolean handled = FALSE;
GdkEvent *event; GdkEvent *event;
const char *string;
event = gtk_get_current_event (); event = gtk_get_current_event ();
if (should_trigger_location_entry (impl, keyval, state)) if (should_trigger_location_entry (impl, keyval, state, &string))
{ {
if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN || if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
{ {
const char *string;
gdk_event_get_string (event, &string);
location_popup_handler (impl, string); location_popup_handler (impl, string);
handled = TRUE; handled = TRUE;
} }