From 497fe072fc93e64911e7242e9b799befb25f3b01 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Tue, 17 Sep 2019 14:09:33 +0200 Subject: [PATCH] Replace HdyDialer with HdyKeypad and bump libhandy to 0.0.12 HdyDialer was deprecated and therefore is replaced with HdyKeypad. HdyDialer used a `gchr *` to store the entered phone number. On every button press the entire text of the display entry was replaced with the new string, which messed up selection and cursor position. HdyKeypad connects directly to a GtkEntry and inserts each button press the same way as a keyboard stroke would do. In the case of the `call display` entry every new digit is appended to the end of the input and therefore it also moves the cursor to the end of the entry. Instead of making the Entry not editable, only the events which would remove text form the entry are blocked, via the `delete-text` signal. And the signal `insert-text` is used to block unwanted chars from beeing inserted. Same as for the `call display` entry also the `new call box` entry is made editable and the signal `insert-text` is used to block unwanted chars. All other user action possible on a entry arn't blocked e.g. repositioning the cursor. The advantage of making the Entry editable is that we can show the cursor position. It also allows the user to select the position where new digits are inserted in the `new call box`. On a button press the focus is set to the Entry to give the correct feedback to the user. This centers the text on the entry, as required by the design. This also makes the delete button remove only one char at the time, to move closer to the desired UX. Related: https://source.puri.sm/Librem5/calls/issues/58 Fixes: https://source.puri.sm/Librem5/calls/issues/82 --- debian/control | 2 +- src/calls-call-display.c | 46 ++++++++++++++++++++++++++++----------- src/calls-new-call-box.c | 47 +++++++--------------------------------- src/meson.build | 2 +- src/ui/call-display.ui | 25 ++++++++++----------- src/ui/new-call-box.ui | 40 ++++++++++++---------------------- 6 files changed, 69 insertions(+), 93 deletions(-) diff --git a/debian/control b/debian/control index 9eb6cb4..c5739d4 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: Bob Ham Build-Depends: debhelper (>= 11), - libhandy-0.0-dev (>= 0.0.10), + libhandy-0.0-dev (>= 0.0.12), libgtk-3-dev, modemmanager-dev, libmm-glib-dev (>= 1.12.0), diff --git a/src/calls-call-display.c b/src/calls-call-display.c index ac213fd..bc09d71 100644 --- a/src/calls-call-display.c +++ b/src/calls-call-display.c @@ -56,7 +56,6 @@ struct _CallsCallDisplay GtkButton *answer; GtkRevealer *dial_pad_revealer; - GtkEntry *dial_pad_display; }; G_DEFINE_TYPE (CallsCallDisplay, calls_call_display, GTK_TYPE_OVERLAY); @@ -118,16 +117,6 @@ add_call_clicked_cb (GtkButton *button, } -static void -dial_pad_symbol_clicked_cb (CallsCallDisplay *self, - gchar symbol, - HdyDialer *dialer) -{ - calls_call_tone_start (self->call, symbol); - - calls_entry_append (self->dial_pad_display, symbol); -} - static void hide_dial_pad_clicked_cb (CallsCallDisplay *self) { @@ -536,6 +525,37 @@ constructed (GObject *object) parent_class->constructed (object); } + +static void +block_delete_cb (GtkWidget *widget) +{ + g_signal_stop_emission_by_name (widget, "delete-text"); +} + + +static void +insert_text_cb (GtkEditable *editable, + gchar *text, + gint length, + gint *position, + CallsCallDisplay *self) +{ + gint end_pos = -1; + + calls_call_tone_start (self->call, *text); + + // Make sure that new chars are inserted at the end of the input + *position = end_pos; + g_signal_handlers_block_by_func (editable, + (gpointer) insert_text_cb, self); + gtk_editable_insert_text (editable, text, length, &end_pos); + g_signal_handlers_unblock_by_func (editable, + (gpointer) insert_text_cb, self); + + g_signal_stop_emission_by_name (editable, "insert-text"); +} + + static void calls_call_display_init (CallsCallDisplay *self) { @@ -600,13 +620,13 @@ calls_call_display_class_init (CallsCallDisplayClass *klass) gtk_widget_class_bind_template_child (widget_class, CallsCallDisplay, hang_up); gtk_widget_class_bind_template_child (widget_class, CallsCallDisplay, answer); gtk_widget_class_bind_template_child (widget_class, CallsCallDisplay, dial_pad_revealer); - gtk_widget_class_bind_template_child (widget_class, CallsCallDisplay, dial_pad_display); gtk_widget_class_bind_template_callback (widget_class, answer_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, hang_up_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, hold_toggled_cb); gtk_widget_class_bind_template_callback (widget_class, mute_toggled_cb); gtk_widget_class_bind_template_callback (widget_class, speaker_toggled_cb); gtk_widget_class_bind_template_callback (widget_class, add_call_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, dial_pad_symbol_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, hide_dial_pad_clicked_cb); + gtk_widget_class_bind_template_callback (widget_class, block_delete_cb); + gtk_widget_class_bind_template_callback (widget_class, insert_text_cb); } diff --git a/src/calls-new-call-box.c b/src/calls-new-call-box.c index 58d2dd6..cfaaee8 100644 --- a/src/calls-new-call-box.c +++ b/src/calls-new-call-box.c @@ -36,9 +36,8 @@ struct _CallsNewCallBox GtkListStore *origin_store; GtkComboBox *origin_box; - GtkEntry *number_entry; GtkButton *backspace; - HdyDialer *dial_pad; + HdyKeypad *keypad; GtkButton *dial; GtkLabel *status; @@ -88,47 +87,18 @@ get_origin (CallsNewCallBox *self) static void backspace_clicked_cb (CallsNewCallBox *self) { - const gchar *old; - size_t len; - gchar *new; - - old = hdy_dialer_get_number (self->dial_pad); - g_assert (old != NULL); - - len = strlen (old); - if (len == 0) - { - return; - } - - new = g_strndup (old, strlen (old) - 1); - hdy_dialer_set_number (self->dial_pad, new); - g_free (new); -} - - -static void -dial_pad_notify_number_cb (CallsNewCallBox *self, - GParamSpec *pspec, - GObject *gobject) -{ - const gchar *number; - - g_assert (strcmp(g_param_spec_get_name (pspec), "number") == 0); - - number = hdy_dialer_get_number (self->dial_pad); - gtk_entry_set_text (self->number_entry, number); - gtk_widget_set_visible (GTK_WIDGET (self->backspace), - strlen (number) > 0); + GtkWidget *entry = hdy_keypad_get_entry (self->keypad); + g_signal_emit_by_name (entry, "backspace", NULL); } static void dial_clicked_cb (CallsNewCallBox *self) { + GtkWidget *entry = hdy_keypad_get_entry (self->keypad); calls_new_call_box_dial (self, - gtk_entry_get_text (GTK_ENTRY (self->number_entry))); + gtk_entry_get_text (GTK_ENTRY (entry))); } @@ -333,12 +303,13 @@ constructed (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); CallsNewCallBox *self = CALLS_NEW_CALL_BOX (object); + GtkWidget *entry = hdy_keypad_get_entry (self->keypad); PangoAttrList *attrs; // Increase the size of the number entry text attrs = pango_attr_list_new (); pango_attr_list_insert (attrs, pango_attr_scale_new (1.2)); - gtk_entry_set_attributes (self->number_entry, attrs); + gtk_entry_set_attributes (GTK_ENTRY (entry), attrs); pango_attr_list_unref (attrs); parent_class->constructed (object); @@ -386,13 +357,11 @@ calls_new_call_box_class_init (CallsNewCallBoxClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/calls/ui/new-call-box.ui"); gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, origin_store); gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, origin_box); - gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, number_entry); gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, backspace); - gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, dial_pad); + gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, keypad); gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, dial); gtk_widget_class_bind_template_child (widget_class, CallsNewCallBox, status); gtk_widget_class_bind_template_callback (widget_class, dial_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, dial_pad_notify_number_cb); gtk_widget_class_bind_template_callback (widget_class, backspace_clicked_cb); } diff --git a/src/meson.build b/src/meson.build index 24d09f5..bf42c86 100644 --- a/src/meson.build +++ b/src/meson.build @@ -30,7 +30,7 @@ calls_includes = [ top_include, src_include ] calls_deps = [ dependency('gobject-2.0'), dependency('gtk+-3.0'), - dependency('libhandy-0.0', version: '>= 0.0.10'), + dependency('libhandy-0.0', version: '>= 0.0.12'), dependency('gsound'), dependency('libpeas-1.0'), dependency('gom-1.0'), diff --git a/src/ui/call-display.ui b/src/ui/call-display.ui index e202b55..5aea0dd 100644 --- a/src/ui/call-display.ui +++ b/src/ui/call-display.ui @@ -388,7 +388,7 @@ - + True False vertical @@ -397,24 +397,23 @@ 12 10 - + True - False + False + True 0.5 - 8 - simple + + - + True - True - 10 - True - 8 - False - False - + False + 16 + 10 + center + keypad_entry diff --git a/src/ui/new-call-box.ui b/src/ui/new-call-box.ui index 4ea8686..2edf88f 100644 --- a/src/ui/new-call-box.ui +++ b/src/ui/new-call-box.ui @@ -47,28 +47,21 @@ False horizontal - - False - phone - no-emoji|inhibit-osk + True - False + True + True + 0.5 + 6 - - True - True - True True - none - False + True + False - Backspace through number @@ -78,7 +71,6 @@ True edit-clear-symbolic - 2 @@ -90,18 +82,14 @@ - + True - True - 10 - 20 - 20 - True - 8 - False - 300 - False - + 16 + 10 + center + 18 + 18 + keypad_entry False