diff options
| author | Yuuki Harano | 2020-05-24 19:41:51 +0900 |
|---|---|---|
| committer | Jeff Walsh | 2020-11-24 12:24:40 +1100 |
| commit | f761a09c98c98c27f4621f77edc1fe4ca60e6fcf (patch) | |
| tree | f05e1c61cac56c7d35269e91e8fd5ac4da1e4a91 /src | |
| parent | 0056ca2d06ce47b0a272d2b1e3650a28dee91cf3 (diff) | |
| download | emacs-f761a09c98c98c27f4621f77edc1fe4ca60e6fcf.tar.gz emacs-f761a09c98c98c27f4621f77edc1fe4ca60e6fcf.zip | |
* src/pgtkim.c: Change coding style
Diffstat (limited to 'src')
| -rw-r--r-- | src/pgtkim.c | 254 |
1 files changed, 148 insertions, 106 deletions
diff --git a/src/pgtkim.c b/src/pgtkim.c index d9bba7e5904..15088bc64d4 100644 --- a/src/pgtkim.c +++ b/src/pgtkim.c | |||
| @@ -24,7 +24,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 24 | 24 | ||
| 25 | #include "pgtkterm.h" | 25 | #include "pgtkterm.h" |
| 26 | 26 | ||
| 27 | static void im_context_commit_cb(GtkIMContext *imc, gchar *str, gpointer user_data) | 27 | static void |
| 28 | im_context_commit_cb (GtkIMContext * imc, gchar * str, gpointer user_data) | ||
| 28 | { | 29 | { |
| 29 | struct pgtk_display_info *dpyinfo = user_data; | 30 | struct pgtk_display_info *dpyinfo = user_data; |
| 30 | struct frame *f = dpyinfo->im.focused_frame; | 31 | struct frame *f = dpyinfo->im.focused_frame; |
| @@ -34,31 +35,34 @@ static void im_context_commit_cb(GtkIMContext *imc, gchar *str, gpointer user_da | |||
| 34 | if (f == NULL) | 35 | if (f == NULL) |
| 35 | return; | 36 | return; |
| 36 | 37 | ||
| 37 | pgtk_enqueue_string(f, str); | 38 | pgtk_enqueue_string (f, str); |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | static gboolean im_context_retrieve_surrounding_cb(GtkIMContext *imc, gpointer user_data) | 41 | static gboolean |
| 42 | im_context_retrieve_surrounding_cb (GtkIMContext * imc, gpointer user_data) | ||
| 41 | { | 43 | { |
| 42 | gtk_im_context_set_surrounding(imc, "", -1, 0); | 44 | gtk_im_context_set_surrounding (imc, "", -1, 0); |
| 43 | return TRUE; | 45 | return TRUE; |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | static gboolean im_context_delete_surrounding_cb(GtkIMContext *imc, int offset, int n_chars, gpointer user_data) | 48 | static gboolean |
| 49 | im_context_delete_surrounding_cb (GtkIMContext * imc, int offset, int n_chars, | ||
| 50 | gpointer user_data) | ||
| 47 | { | 51 | { |
| 48 | return TRUE; | 52 | return TRUE; |
| 49 | } | 53 | } |
| 50 | 54 | ||
| 51 | static Lisp_Object make_color_string(PangoAttrColor *pac) | 55 | static Lisp_Object |
| 56 | make_color_string (PangoAttrColor * pac) | ||
| 52 | { | 57 | { |
| 53 | char buf[256]; | 58 | char buf[256]; |
| 54 | sprintf(buf, "#%02x%02x%02x", | 59 | sprintf (buf, "#%02x%02x%02x", |
| 55 | pac->color.red >> 8, | 60 | pac->color.red >> 8, pac->color.green >> 8, pac->color.blue >> 8); |
| 56 | pac->color.green >> 8, | 61 | return build_string (buf); |
| 57 | pac->color.blue >> 8); | ||
| 58 | return build_string(buf); | ||
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | static void im_context_preedit_changed_cb(GtkIMContext *imc, gpointer user_data) | 64 | static void |
| 65 | im_context_preedit_changed_cb (GtkIMContext * imc, gpointer user_data) | ||
| 62 | { | 66 | { |
| 63 | struct pgtk_display_info *dpyinfo = user_data; | 67 | struct pgtk_display_info *dpyinfo = user_data; |
| 64 | struct frame *f = dpyinfo->im.focused_frame; | 68 | struct frame *f = dpyinfo->im.focused_frame; |
| @@ -71,7 +75,7 @@ static void im_context_preedit_changed_cb(GtkIMContext *imc, gpointer user_data) | |||
| 71 | if (f == NULL) | 75 | if (f == NULL) |
| 72 | return; | 76 | return; |
| 73 | 77 | ||
| 74 | gtk_im_context_get_preedit_string(imc, &str, &attrs, &pos); | 78 | gtk_im_context_get_preedit_string (imc, &str, &attrs, &pos); |
| 75 | 79 | ||
| 76 | 80 | ||
| 77 | /* | 81 | /* |
| @@ -82,58 +86,70 @@ static void im_context_preedit_changed_cb(GtkIMContext *imc, gpointer user_data) | |||
| 82 | */ | 86 | */ |
| 83 | Lisp_Object list = Qnil; | 87 | Lisp_Object list = Qnil; |
| 84 | 88 | ||
| 85 | PangoAttrIterator* iter; | 89 | PangoAttrIterator *iter; |
| 86 | iter = pango_attr_list_get_iterator(attrs); | 90 | iter = pango_attr_list_get_iterator (attrs); |
| 87 | do { | 91 | do |
| 88 | int st, ed; | 92 | { |
| 89 | int has_underline = 0; | 93 | int st, ed; |
| 90 | Lisp_Object part = Qnil; | 94 | int has_underline = 0; |
| 91 | 95 | Lisp_Object part = Qnil; | |
| 92 | pango_attr_iterator_range(iter, &st, &ed); | 96 | |
| 93 | 97 | pango_attr_iterator_range (iter, &st, &ed); | |
| 94 | if (ed > strlen(str)) | 98 | |
| 95 | ed = strlen(str); | 99 | if (ed > strlen (str)) |
| 96 | if (st >= ed) | 100 | ed = strlen (str); |
| 97 | continue; | 101 | if (st >= ed) |
| 98 | 102 | continue; | |
| 99 | Lisp_Object text = make_string(str + st, ed - st); | 103 | |
| 100 | part = Fcons(text, part); | 104 | Lisp_Object text = make_string (str + st, ed - st); |
| 101 | 105 | part = Fcons (text, part); | |
| 102 | PangoAttrInt *ul = (PangoAttrInt *) pango_attr_iterator_get(iter, PANGO_ATTR_UNDERLINE); | 106 | |
| 103 | if (ul != NULL) { | 107 | PangoAttrInt *ul = |
| 104 | if (ul->value != PANGO_UNDERLINE_NONE) | 108 | (PangoAttrInt *) pango_attr_iterator_get (iter, PANGO_ATTR_UNDERLINE); |
| 105 | has_underline = 1; | 109 | if (ul != NULL) |
| 106 | } | 110 | { |
| 107 | 111 | if (ul->value != PANGO_UNDERLINE_NONE) | |
| 108 | PangoAttrColor *pac; | 112 | has_underline = 1; |
| 109 | if (has_underline) { | 113 | } |
| 110 | pac = (PangoAttrColor *) pango_attr_iterator_get(iter, PANGO_ATTR_UNDERLINE_COLOR); | 114 | |
| 115 | PangoAttrColor *pac; | ||
| 116 | if (has_underline) | ||
| 117 | { | ||
| 118 | pac = | ||
| 119 | (PangoAttrColor *) pango_attr_iterator_get (iter, | ||
| 120 | PANGO_ATTR_UNDERLINE_COLOR); | ||
| 121 | if (pac != NULL) | ||
| 122 | part = Fcons (Fcons (Qul, make_color_string (pac)), part); | ||
| 123 | else | ||
| 124 | part = Fcons (Fcons (Qul, Qt), part); | ||
| 125 | } | ||
| 126 | |||
| 127 | pac = | ||
| 128 | (PangoAttrColor *) pango_attr_iterator_get (iter, | ||
| 129 | PANGO_ATTR_FOREGROUND); | ||
| 111 | if (pac != NULL) | 130 | if (pac != NULL) |
| 112 | part = Fcons(Fcons(Qul, make_color_string(pac)), part); | 131 | part = Fcons (Fcons (Qfg, make_color_string (pac)), part); |
| 113 | else | ||
| 114 | part = Fcons(Fcons(Qul, Qt), part); | ||
| 115 | } | ||
| 116 | |||
| 117 | pac = (PangoAttrColor *) pango_attr_iterator_get(iter, PANGO_ATTR_FOREGROUND); | ||
| 118 | if (pac != NULL) | ||
| 119 | part = Fcons(Fcons(Qfg, make_color_string(pac)), part); | ||
| 120 | 132 | ||
| 121 | pac = (PangoAttrColor *) pango_attr_iterator_get(iter, PANGO_ATTR_BACKGROUND); | 133 | pac = |
| 122 | if (pac != NULL) | 134 | (PangoAttrColor *) pango_attr_iterator_get (iter, |
| 123 | part = Fcons(Fcons(Qbg, make_color_string(pac)), part); | 135 | PANGO_ATTR_BACKGROUND); |
| 136 | if (pac != NULL) | ||
| 137 | part = Fcons (Fcons (Qbg, make_color_string (pac)), part); | ||
| 124 | 138 | ||
| 125 | part = Fnreverse(part); | 139 | part = Fnreverse (part); |
| 126 | list = Fcons(part, list); | 140 | list = Fcons (part, list); |
| 127 | } while (pango_attr_iterator_next(iter)); | 141 | } |
| 142 | while (pango_attr_iterator_next (iter)); | ||
| 128 | 143 | ||
| 129 | list = Fnreverse(list); | 144 | list = Fnreverse (list); |
| 130 | pgtk_enqueue_preedit(f, list); | 145 | pgtk_enqueue_preedit (f, list); |
| 131 | 146 | ||
| 132 | g_free(str); | 147 | g_free (str); |
| 133 | pango_attr_list_unref(attrs); | 148 | pango_attr_list_unref (attrs); |
| 134 | } | 149 | } |
| 135 | 150 | ||
| 136 | static void im_context_preedit_end_cb(GtkIMContext *imc, gpointer user_data) | 151 | static void |
| 152 | im_context_preedit_end_cb (GtkIMContext * imc, gpointer user_data) | ||
| 137 | { | 153 | { |
| 138 | struct pgtk_display_info *dpyinfo = user_data; | 154 | struct pgtk_display_info *dpyinfo = user_data; |
| 139 | struct frame *f = dpyinfo->im.focused_frame; | 155 | struct frame *f = dpyinfo->im.focused_frame; |
| @@ -143,90 +159,116 @@ static void im_context_preedit_end_cb(GtkIMContext *imc, gpointer user_data) | |||
| 143 | if (f == NULL) | 159 | if (f == NULL) |
| 144 | return; | 160 | return; |
| 145 | 161 | ||
| 146 | pgtk_enqueue_preedit(f, Qnil); | 162 | pgtk_enqueue_preedit (f, Qnil); |
| 147 | } | 163 | } |
| 148 | 164 | ||
| 149 | static void im_context_preedit_start_cb(GtkIMContext *imc, gpointer user_data) | 165 | static void |
| 166 | im_context_preedit_start_cb (GtkIMContext * imc, gpointer user_data) | ||
| 150 | { | 167 | { |
| 151 | } | 168 | } |
| 152 | 169 | ||
| 153 | void pgtk_im_focus_in(struct frame *f) | 170 | void |
| 171 | pgtk_im_focus_in (struct frame *f) | ||
| 154 | { | 172 | { |
| 155 | struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); | 173 | struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
| 156 | if (dpyinfo->im.context != NULL) { | 174 | if (dpyinfo->im.context != NULL) |
| 157 | gtk_im_context_reset (dpyinfo->im.context); | 175 | { |
| 158 | gtk_im_context_set_client_window (dpyinfo->im.context, gtk_widget_get_window (FRAME_GTK_WIDGET (f))); | 176 | gtk_im_context_reset (dpyinfo->im.context); |
| 159 | gtk_im_context_focus_in (dpyinfo->im.context); | 177 | gtk_im_context_set_client_window (dpyinfo->im.context, |
| 160 | } | 178 | gtk_widget_get_window |
| 179 | (FRAME_GTK_WIDGET (f))); | ||
| 180 | gtk_im_context_focus_in (dpyinfo->im.context); | ||
| 181 | } | ||
| 161 | dpyinfo->im.focused_frame = f; | 182 | dpyinfo->im.focused_frame = f; |
| 162 | } | 183 | } |
| 163 | 184 | ||
| 164 | void pgtk_im_focus_out(struct frame *f) | 185 | void |
| 186 | pgtk_im_focus_out (struct frame *f) | ||
| 165 | { | 187 | { |
| 166 | struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); | 188 | struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
| 167 | if (dpyinfo->im.focused_frame == f) { | 189 | if (dpyinfo->im.focused_frame == f) |
| 168 | if (dpyinfo->im.context != NULL) { | 190 | { |
| 169 | gtk_im_context_reset (dpyinfo->im.context); | 191 | if (dpyinfo->im.context != NULL) |
| 170 | gtk_im_context_focus_out (dpyinfo->im.context); | 192 | { |
| 171 | gtk_im_context_set_client_window (dpyinfo->im.context, NULL); | 193 | gtk_im_context_reset (dpyinfo->im.context); |
| 194 | gtk_im_context_focus_out (dpyinfo->im.context); | ||
| 195 | gtk_im_context_set_client_window (dpyinfo->im.context, NULL); | ||
| 196 | } | ||
| 197 | dpyinfo->im.focused_frame = NULL; | ||
| 172 | } | 198 | } |
| 173 | dpyinfo->im.focused_frame = NULL; | ||
| 174 | } | ||
| 175 | } | 199 | } |
| 176 | 200 | ||
| 177 | bool pgtk_im_filter_keypress(struct frame *f, GdkEventKey *ev) | 201 | bool |
| 202 | pgtk_im_filter_keypress (struct frame *f, GdkEventKey * ev) | ||
| 178 | { | 203 | { |
| 179 | struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); | 204 | struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
| 180 | if (dpyinfo->im.context != NULL) { | 205 | if (dpyinfo->im.context != NULL) |
| 181 | if (gtk_im_context_filter_keypress (dpyinfo->im.context, ev)) | 206 | { |
| 182 | return true; | 207 | if (gtk_im_context_filter_keypress (dpyinfo->im.context, ev)) |
| 183 | } | 208 | return true; |
| 209 | } | ||
| 184 | return false; | 210 | return false; |
| 185 | } | 211 | } |
| 186 | 212 | ||
| 187 | void pgtk_im_init(struct pgtk_display_info *dpyinfo) | 213 | void |
| 214 | pgtk_im_init (struct pgtk_display_info *dpyinfo) | ||
| 188 | { | 215 | { |
| 189 | dpyinfo->im.context = NULL; | 216 | dpyinfo->im.context = NULL; |
| 190 | } | 217 | } |
| 191 | 218 | ||
| 192 | void pgtk_im_finish(struct pgtk_display_info *dpyinfo) | 219 | void |
| 220 | pgtk_im_finish (struct pgtk_display_info *dpyinfo) | ||
| 193 | { | 221 | { |
| 194 | if (dpyinfo->im.context != NULL) | 222 | if (dpyinfo->im.context != NULL) |
| 195 | g_object_unref(dpyinfo->im.context); | 223 | g_object_unref (dpyinfo->im.context); |
| 196 | dpyinfo->im.context = NULL; | 224 | dpyinfo->im.context = NULL; |
| 197 | } | 225 | } |
| 198 | 226 | ||
| 199 | DEFUN ("pgtk-use-im-context", Fpgtk_use_im_context, Spgtk_use_im_context, | 227 | DEFUN ("pgtk-use-im-context", Fpgtk_use_im_context, Spgtk_use_im_context, 1, 2, 0, |
| 200 | 1, 2, 0, | ||
| 201 | doc: /* Set whether use Gtk's im context. */) | 228 | doc: /* Set whether use Gtk's im context. */) |
| 202 | (Lisp_Object use_p, Lisp_Object terminal) | 229 | (Lisp_Object use_p, Lisp_Object terminal) |
| 203 | { | 230 | { |
| 204 | struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal); | 231 | struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal); |
| 205 | 232 | ||
| 206 | if (NILP(use_p)) { | 233 | if (NILP (use_p)) |
| 207 | if (dpyinfo->im.context != NULL) { | 234 | { |
| 208 | gtk_im_context_reset (dpyinfo->im.context); | 235 | if (dpyinfo->im.context != NULL) |
| 209 | gtk_im_context_focus_out (dpyinfo->im.context); | 236 | { |
| 210 | gtk_im_context_set_client_window (dpyinfo->im.context, NULL); | 237 | gtk_im_context_reset (dpyinfo->im.context); |
| 211 | 238 | gtk_im_context_focus_out (dpyinfo->im.context); | |
| 212 | g_object_unref(dpyinfo->im.context); | 239 | gtk_im_context_set_client_window (dpyinfo->im.context, NULL); |
| 213 | dpyinfo->im.context = NULL; | 240 | |
| 241 | g_object_unref (dpyinfo->im.context); | ||
| 242 | dpyinfo->im.context = NULL; | ||
| 243 | } | ||
| 214 | } | 244 | } |
| 215 | } else { | 245 | else |
| 216 | if (dpyinfo->im.context == NULL) { | 246 | { |
| 217 | dpyinfo->im.context = gtk_im_multicontext_new(); | 247 | if (dpyinfo->im.context == NULL) |
| 218 | g_signal_connect(dpyinfo->im.context, "commit", G_CALLBACK(im_context_commit_cb), dpyinfo); | 248 | { |
| 219 | g_signal_connect(dpyinfo->im.context, "retrieve-surrounding", G_CALLBACK(im_context_retrieve_surrounding_cb), dpyinfo); | 249 | dpyinfo->im.context = gtk_im_multicontext_new (); |
| 220 | g_signal_connect(dpyinfo->im.context, "delete-surrounding", G_CALLBACK(im_context_delete_surrounding_cb), dpyinfo); | 250 | g_signal_connect (dpyinfo->im.context, "commit", |
| 221 | g_signal_connect(dpyinfo->im.context, "preedit-changed", G_CALLBACK(im_context_preedit_changed_cb), dpyinfo); | 251 | G_CALLBACK (im_context_commit_cb), dpyinfo); |
| 222 | g_signal_connect(dpyinfo->im.context, "preedit-end", G_CALLBACK(im_context_preedit_end_cb), dpyinfo); | 252 | g_signal_connect (dpyinfo->im.context, "retrieve-surrounding", |
| 223 | g_signal_connect(dpyinfo->im.context, "preedit-start", G_CALLBACK(im_context_preedit_start_cb), dpyinfo); | 253 | G_CALLBACK (im_context_retrieve_surrounding_cb), |
| 224 | gtk_im_context_set_use_preedit (dpyinfo->im.context, TRUE); | 254 | dpyinfo); |
| 225 | 255 | g_signal_connect (dpyinfo->im.context, "delete-surrounding", | |
| 226 | if (dpyinfo->im.focused_frame) | 256 | G_CALLBACK (im_context_delete_surrounding_cb), |
| 227 | pgtk_im_focus_in(dpyinfo->im.focused_frame); | 257 | dpyinfo); |
| 258 | g_signal_connect (dpyinfo->im.context, "preedit-changed", | ||
| 259 | G_CALLBACK (im_context_preedit_changed_cb), | ||
| 260 | dpyinfo); | ||
| 261 | g_signal_connect (dpyinfo->im.context, "preedit-end", | ||
| 262 | G_CALLBACK (im_context_preedit_end_cb), dpyinfo); | ||
| 263 | g_signal_connect (dpyinfo->im.context, "preedit-start", | ||
| 264 | G_CALLBACK (im_context_preedit_start_cb), | ||
| 265 | dpyinfo); | ||
| 266 | gtk_im_context_set_use_preedit (dpyinfo->im.context, TRUE); | ||
| 267 | |||
| 268 | if (dpyinfo->im.focused_frame) | ||
| 269 | pgtk_im_focus_in (dpyinfo->im.focused_frame); | ||
| 270 | } | ||
| 228 | } | 271 | } |
| 229 | } | ||
| 230 | 272 | ||
| 231 | return Qnil; | 273 | return Qnil; |
| 232 | } | 274 | } |