# HG changeset patch
# Node ID 9afa01da5ad9
# Parent  79f814e6b5cb
diff --git a/talkatu/data/input.ui b/talkatu/data/input.ui
--- a/talkatu/data/input.ui
+++ b/talkatu/data/input.ui
@@ -34,5 +34,10 @@
   <template class="TalkatuInput" parent="TalkatuView">
     <property name="extra-menu">model</property>
     <signal name="notify::buffer" handler="talkatu_input_buffer_set_cb"/>
+    <child>
+      <object class="GtkEventControllerKey">
+        <signal name="key-pressed" handler="talkatu_input_key_pressed_cb" object="TalkatuInput" swapped="no"/>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/talkatu/talkatuinput.c b/talkatu/talkatuinput.c
--- a/talkatu/talkatuinput.c
+++ b/talkatu/talkatuinput.c
@@ -361,22 +361,36 @@
 	gtk_widget_grab_focus(widget);
 }
 
-static void
-talkatu_input_should_send_message_cb(GtkWidget *widget,
-                                     G_GNUC_UNUSED const gchar *action_name,
-                                     GVariant *parameter)
+static gboolean
+talkatu_input_key_pressed_cb(G_GNUC_UNUSED GtkEventControllerKey* self,
+                             guint keyval, G_GNUC_UNUSED guint keycode,
+                             GdkModifierType state, gpointer data)
 {
-	TalkatuInput *input = TALKATU_INPUT(widget);
+	TalkatuInput *input = data;
 	TalkatuInputPrivate *priv = talkatu_input_get_instance_private(input);
-	TalkatuInputSendBinding binding = g_variant_get_uint32(parameter);
+	TalkatuInputSendBinding binding = 0;
+	gboolean handled = FALSE;
 
-	if((priv->send_binding & binding) != 0) {
-		talkatu_input_send_message(input);
-	} else if(gtk_text_view_get_editable(GTK_TEXT_VIEW(input))) {
-		GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(input));
+	if(keyval == GDK_KEY_Return) {
+		if(state == GDK_SHIFT_MASK) {
+			binding = TALKATU_INPUT_SEND_BINDING_SHIFT_RETURN;
+		} else if(state == GDK_CONTROL_MASK) {
+			binding = TALKATU_INPUT_SEND_BINDING_CONTROL_RETURN;
+		} else {
+			binding = TALKATU_INPUT_SEND_BINDING_RETURN;
+		}
+	} else if(keyval == GDK_KEY_KP_Enter) {
+		binding = TALKATU_INPUT_SEND_BINDING_KP_ENTER;
+	}
 
-		gtk_text_buffer_insert_at_cursor(buffer, "\n", 1);
+	if(binding != 0) {
+		if((priv->send_binding & binding) != 0) {
+			talkatu_input_send_message(input);
+			handled = TRUE;
+		}
 	}
+
+	return handled;
 }
 
 static void
@@ -700,8 +714,6 @@
 	/* Setup actions */
 	gtk_widget_class_install_action(widget_class, "message.send", NULL,
 	                                talkatu_input_send_message_cb);
-	gtk_widget_class_install_action(widget_class, "message.should-send", NULL,
-	                                talkatu_input_should_send_message_cb);
 
 	/* Template setup */
 	gtk_widget_class_set_template_from_resource(
@@ -711,24 +723,8 @@
 
 	gtk_widget_class_bind_template_callback(widget_class,
 	                                        talkatu_input_buffer_set_cb);
-
-	/* setup key bindings */
-	gtk_widget_class_add_binding_action(widget_class,
-	                                    GDK_KEY_Return, 0,
-	                                    "message.should-send", "u",
-	                                    TALKATU_INPUT_SEND_BINDING_RETURN);
-	gtk_widget_class_add_binding_action(widget_class,
-	                                    GDK_KEY_Return, GDK_SHIFT_MASK,
-	                                    "message.should-send", "u",
-	                                    TALKATU_INPUT_SEND_BINDING_SHIFT_RETURN);
-	gtk_widget_class_add_binding_action(widget_class,
-	                                    GDK_KEY_Return, GDK_CONTROL_MASK,
-	                                    "message.should-send", "u",
-	                                    TALKATU_INPUT_SEND_BINDING_CONTROL_RETURN);
-	gtk_widget_class_add_binding_action(widget_class,
-	                                    GDK_KEY_KP_Enter, 0,
-	                                    "message.should-send", "u",
-	                                    TALKATU_INPUT_SEND_BINDING_KP_ENTER);
+	gtk_widget_class_bind_template_callback(widget_class,
+	                                        talkatu_input_key_pressed_cb);
 }
 
 /******************************************************************************
