From 813957a92fe580ec0e2fa2076a233994a0d08ce8 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 28 Jul 2018 20:07:10 +0200 Subject: [PATCH] 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. --- docs/reference/gdk/gdk4-sections.txt | 1 - gdk/gdkevents.c | 31 -------------------- gdk/gdkevents.h | 3 -- gtk/a11y/gtkaccessibilityutil.c | 12 ++------ gtk/gtkfilechooserwidget.c | 44 ++++++++++++++++------------ 5 files changed, 28 insertions(+), 63 deletions(-) diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 278ce01db5..671982e3d8 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -655,7 +655,6 @@ gdk_event_get_key_is_modifier gdk_event_get_pad_axis_value gdk_event_get_pad_button gdk_event_get_pad_group_mode -gdk_event_get_string gdk_event_get_touch_emulating_pointer gdk_event_get_touchpad_angle_delta gdk_event_get_touchpad_deltas diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index b25d27b366..4a8dcb71f1 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -1293,37 +1293,6 @@ gdk_event_get_key_group (const GdkEvent *event, 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: * @event: a #GdkEvent diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h index 291b6d34f8..8ec949c606 100644 --- a/gdk/gdkevents.h +++ b/gdk/gdkevents.h @@ -403,9 +403,6 @@ gboolean gdk_event_get_key_is_modifier (const GdkEvent *event, GDK_AVAILABLE_IN_ALL gboolean gdk_event_get_key_group (const GdkEvent *event, guint *group); -GDK_AVAILABLE_IN_ALL -gboolean gdk_event_get_string (const GdkEvent *event, - const char **string); GDK_AVAILABLE_IN_ALL gboolean gdk_event_get_scroll_direction (const GdkEvent *event, diff --git a/gtk/a11y/gtkaccessibilityutil.c b/gtk/a11y/gtkaccessibilityutil.c index 48d6b4b283..1b840f80e1 100644 --- a/gtk/a11y/gtkaccessibilityutil.c +++ b/gtk/a11y/gtkaccessibilityutil.c @@ -116,13 +116,11 @@ atk_key_event_from_gdk_event_key (GdkEventKey *key, GdkModifierType state; guint keyval; guint16 keycode; - const char *string; type = gdk_event_get_event_type ((GdkEvent *)key); gdk_event_get_state ((GdkEvent *)key, &state); gdk_event_get_keyval ((GdkEvent *)key, &keyval); gdk_event_get_keycode ((GdkEvent *)key, &keycode); - gdk_event_get_string ((GdkEvent *)key, &string); if (type == GDK_KEY_PRESS) event->type = ATK_KEY_EVENT_PRESS; @@ -133,14 +131,8 @@ atk_key_event_from_gdk_event_key (GdkEventKey *key, event->state = state; event->keyval = keyval; - if (string && string[0] && - (state & GDK_CONTROL_MASK || - g_unichar_isgraph (g_utf8_get_char (string)))) - event->string = (char *) string; - else - event->string = gdk_keyval_name (keyval); - - event->length = strlen (string); + event->string = gdk_keyval_name (keyval); + event->length = strlen (event->string); event->keycode = keycode; event->timestamp = gdk_event_get_time ((GdkEvent *)key); } diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 2c1e2ed48b..a3c5361795 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -1281,7 +1281,8 @@ key_is_left_or_right (const GdkEvent *event) static gboolean should_trigger_location_entry (GtkFileChooserWidget *impl, guint keyval, - GdkModifierType state) + GdkModifierType state, + const char **string) { GdkModifierType no_text_input_mask; @@ -1291,16 +1292,27 @@ should_trigger_location_entry (GtkFileChooserWidget *impl, no_text_input_mask = gtk_widget_get_modifier_mask (GTK_WIDGET (impl), GDK_MODIFIER_INTENT_NO_TEXT_INPUT); - if ((keyval == GDK_KEY_slash - || keyval == GDK_KEY_KP_Divide - || keyval == GDK_KEY_period -#ifdef G_OS_UNIX - || keyval == GDK_KEY_asciitilde -#endif - ) && !(state & no_text_input_mask)) - return TRUE; + if (state & no_text_input_mask) + return FALSE; - 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 @@ -1317,16 +1329,14 @@ key_press_cb (GtkEventController *controller, GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data; GtkFileChooserWidgetPrivate *priv = impl->priv; const GdkEvent *event; + const char *string; 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_SELECT_FOLDER)) { - const char *string; - - gdk_event_get_string ((GdkEvent *)event, &string); location_popup_handler (impl, string); return GDK_EVENT_STOP; } @@ -1388,17 +1398,15 @@ widget_key_press_cb (GtkEventController *controller, GtkFileChooserWidgetPrivate *priv = impl->priv; gboolean handled = FALSE; GdkEvent *event; + const char *string; 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 || priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) { - const char *string; - - gdk_event_get_string (event, &string); location_popup_handler (impl, string); handled = TRUE; }