# HG changeset patch
# Node ID c4ba6afabf1e038a6d39cecb9292a22339b5fe9f
# Parent  c7b0c4b88dfbe203fe432154dd1f60e734a85707
diff --git a/im.pidgin.Pidgin3.yml b/im.pidgin.Pidgin3.yml
--- a/im.pidgin.Pidgin3.yml
+++ b/im.pidgin.Pidgin3.yml
@@ -104,6 +104,15 @@
         archive-type: tar-xz
         url: https://sourceforge.net/projects/pidgin/files/seagull/0.1.1/seagull-0.1.1.tar.xz
         sha256: 499fc45b6a8539bc2293b362fec1c847fe25697355a0572f07ace3f359a38873
+  - name: libspelling
+    buildsystem: meson
+    config-opts:
+      - "--wrap-mode=nofallback"
+    sources:
+      - type: archive
+        archive-type: tar-xz
+        url: https://download.gnome.org/sources/libspelling/0.4/libspelling-0.4.6.tar.xz
+        sha256: 3248a9b5336ea2f727d2db912d2f0083accc0505ce707679b3d9b8266c0101f5
   - name: pidgin3
     buildsystem: meson
     config-opts:
diff --git a/meson.build b/meson.build
--- a/meson.build
+++ b/meson.build
@@ -195,6 +195,7 @@
 if get_option('gtkui')
 	gtk = dependency('gtk4', version : '>= 4.10.0')
 	libadwaita = dependency('libadwaita-1', version : '>= 1.5')
+	libspelling = dependency('libspelling-1', version : '>= 0.4.0')
 	add_project_arguments(
 		'-DADW_VERSION_MIN_REQUIRED=ADW_VERSION_1_5',
 		'-DADW_VERSION_MAX_ALLOWED=ADW_VERSION_1_5',
diff --git a/pidgin/meson.build b/pidgin/meson.build
--- a/pidgin/meson.build
+++ b/pidgin/meson.build
@@ -135,6 +135,7 @@
 	gtk,
 	json,
 	libadwaita,
+	libspelling,
 	math,
 	libpurple_dep,
 ]
diff --git a/pidgin/pidginconversation.c b/pidgin/pidginconversation.c
--- a/pidgin/pidginconversation.c
+++ b/pidgin/pidginconversation.c
@@ -22,6 +22,10 @@
 
 #include <glib/gi18n-lib.h>
 
+#include <libspelling.h>
+
+#include <gtksourceview/gtksourceview.h>
+
 #include <purple.h>
 
 #include "pidginautoadjustment.h"
@@ -53,6 +57,7 @@
 	GtkCustomSorter *member_list_sorter;
 
 	GtkWidget *input;
+	GtkSourceBuffer *input_buffer;
 
 	GtkWidget *typing_label;
 	GtkWidget *status_label;
@@ -403,6 +408,10 @@
 
 static void
 pidgin_conversation_init(PidginConversation *conversation) {
+	SpellingChecker *checker = NULL;
+	SpellingTextBufferAdapter *adapter = NULL;
+	GMenuModel *menu = NULL;
+
 	gtk_widget_init_template(GTK_WIDGET(conversation));
 
 	gtk_custom_sorter_set_sort_func(conversation->member_list_sorter,
@@ -412,6 +421,20 @@
 	gtk_custom_filter_set_filter_func(conversation->member_list_filter,
 	                                  (GtkCustomFilterFunc)pidgin_conversation_member_list_filter,
 	                                  conversation, NULL);
+
+	/* Create the spell checking adapter. */
+	checker = spelling_checker_get_default();
+	adapter = spelling_text_buffer_adapter_new(conversation->input_buffer,
+	                                           checker);
+
+	/* Add the spell checking menu items and actions. */
+	menu = spelling_text_buffer_adapter_get_menu_model(adapter);
+	gtk_text_view_set_extra_menu(GTK_TEXT_VIEW(conversation->input), menu);
+	gtk_widget_insert_action_group(conversation->input, "spelling",
+	                               G_ACTION_GROUP(adapter));
+	spelling_text_buffer_adapter_set_enabled(adapter, TRUE);
+
+	g_clear_object(&adapter);
 }
 
 static void
@@ -458,6 +481,8 @@
 	gtk_widget_class_bind_template_child(widget_class, PidginConversation,
 	                                     input);
 	gtk_widget_class_bind_template_child(widget_class, PidginConversation,
+	                                     input_buffer);
+	gtk_widget_class_bind_template_child(widget_class, PidginConversation,
 	                                     typing_label);
 	gtk_widget_class_bind_template_child(widget_class, PidginConversation,
 	                                     status_label);
diff --git a/pidgin/resources/Conversations/conversation.ui b/pidgin/resources/Conversations/conversation.ui
--- a/pidgin/resources/Conversations/conversation.ui
+++ b/pidgin/resources/Conversations/conversation.ui
@@ -228,7 +228,7 @@
             <property name="input-purpose">free-form</property>
             <property name="input-hints">emoji|spellcheck|word-completion</property>
             <property name="buffer">
-              <object class="GtkTextBuffer">
+              <object class="GtkSourceBuffer" id="input_buffer">
                 <signal name="delete-range" handler="pidgin_conversation_input_delete_range_cb" after="yes"/>
                 <signal name="insert-text" handler="pidgin_conversation_input_insert_text_cb"/>
               </object>
diff --git a/subprojects/gtksourceview5.wrap b/subprojects/gtksourceview5.wrap
new file mode 100644
--- /dev/null
+++ b/subprojects/gtksourceview5.wrap
@@ -0,0 +1,5 @@
+[wrap-file]
+directory = gtksourceview-5.9.0
+source_url = https://download.gnome.org/sources/gtksourceview/5.9/gtksourceview-5.9.0.tar.xz
+source_filename = gtksourceview-5.9.0.tar.xz
+source_hash = 55cf74d37b5bcc1d3109cde5fc758b64b7dd2e8309a19ac8e97f3cbbbb184d56
diff --git a/subprojects/libspelling.wrap b/subprojects/libspelling.wrap
new file mode 100644
--- /dev/null
+++ b/subprojects/libspelling.wrap
@@ -0,0 +1,5 @@
+[wrap-file]
+directory = libspelling-0.4.6
+source_url = https://download.gnome.org/sources/libspelling/0.4/libspelling-0.4.6.tar.xz
+source_filename = libspelling-0.4.6.tar.xz
+source_hash = 3248a9b5336ea2f727d2db912d2f0083accc0505ce707679b3d9b8266c0101f5
