1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include "gtk/gtkintl.h"
26 #include "gtk/gtklabel.h"
27 #include "gtk/gtksignal.h"
28 #include "gtk/gtkwindow.h"
29 #include "gtkimcontextxim.h"
31 typedef struct _StatusWindow StatusWindow;
32 typedef struct _GtkXIMInfo GtkXIMInfo;
34 struct _GtkIMContextXIM
43 GdkWindow *client_window;
44 GtkWidget *client_widget;
46 /* The status window for this input context; we claim the
47 * status window when we are focused and have created an XIC
49 StatusWindow *status_window;
53 gunichar *preedit_chars;
54 XIMFeedback *feedbacks;
58 XIMCallback preedit_start_callback;
59 XIMCallback preedit_done_callback;
60 XIMCallback preedit_draw_callback;
61 XIMCallback preedit_caret_callback;
63 XIMCallback status_start_callback;
64 XIMCallback status_done_callback;
65 XIMCallback status_draw_callback;
67 XIMCallback string_conversion_callback;
71 guint filter_key_release : 1;
72 guint use_preedit : 1;
74 guint in_toplevel : 1;
83 XIMStyle preedit_style_setting;
84 XIMStyle status_style_setting;
86 GtkSettings *settings;
89 XIMStyles *xim_styles;
92 guint reconnecting :1;
93 guint supports_string_conversion;
96 /* A context status window; these are kept in the status_windows list. */
101 /* Toplevel window to which the status window corresponds */
104 /* Currently focused GtkIMContextXIM for the toplevel, if any */
105 GtkIMContextXIM *context;
108 static void gtk_im_context_xim_class_init (GtkIMContextXIMClass *class);
109 static void gtk_im_context_xim_init (GtkIMContextXIM *im_context_xim);
110 static void gtk_im_context_xim_finalize (GObject *obj);
111 static void gtk_im_context_xim_set_client_window (GtkIMContext *context,
112 GdkWindow *client_window);
113 static gboolean gtk_im_context_xim_filter_keypress (GtkIMContext *context,
115 static void gtk_im_context_xim_reset (GtkIMContext *context);
116 static void gtk_im_context_xim_focus_in (GtkIMContext *context);
117 static void gtk_im_context_xim_focus_out (GtkIMContext *context);
118 static void gtk_im_context_xim_set_cursor_location (GtkIMContext *context,
120 static void gtk_im_context_xim_set_use_preedit (GtkIMContext *context,
121 gboolean use_preedit);
122 static void gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
124 PangoAttrList **attrs,
127 static void reinitialize_ic (GtkIMContextXIM *context_xim);
128 static void set_ic_client_window (GtkIMContextXIM *context_xim,
129 GdkWindow *client_window);
131 static void setup_styles (GtkXIMInfo *info);
133 static void update_client_widget (GtkIMContextXIM *context_xim);
134 static void update_status_window (GtkIMContextXIM *context_xim);
136 static StatusWindow *status_window_get (GtkWidget *toplevel);
137 static void status_window_free (StatusWindow *status_window);
138 static void status_window_set_text (StatusWindow *status_window,
141 static void xim_destroy_callback (XIM xim,
142 XPointer client_data,
145 static XIC gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim);
146 static GObjectClass *parent_class;
148 GType gtk_type_im_context_xim = 0;
150 static GSList *open_ims = NULL;
152 /* List of status windows for different toplevels */
153 static GSList *status_windows = NULL;
156 gtk_im_context_xim_register_type (GTypeModule *type_module)
158 static const GTypeInfo im_context_xim_info =
160 sizeof (GtkIMContextXIMClass),
161 (GBaseInitFunc) NULL,
162 (GBaseFinalizeFunc) NULL,
163 (GClassInitFunc) gtk_im_context_xim_class_init,
164 NULL, /* class_finalize */
165 NULL, /* class_data */
166 sizeof (GtkIMContextXIM),
168 (GInstanceInitFunc) gtk_im_context_xim_init,
171 gtk_type_im_context_xim =
172 g_type_module_register_type (type_module,
175 &im_context_xim_info, 0);
178 #define PREEDIT_MASK (XIMPreeditCallbacks | XIMPreeditPosition | \
179 XIMPreeditArea | XIMPreeditNothing | XIMPreeditNone)
180 #define STATUS_MASK (XIMStatusCallbacks | XIMStatusArea | \
181 XIMStatusNothing | XIMStatusNone)
182 #define ALLOWED_MASK (XIMPreeditCallbacks | XIMPreeditNothing | XIMPreeditNone | \
183 XIMStatusCallbacks | XIMStatusNothing | XIMStatusNone)
186 choose_better_style (XIMStyle style1, XIMStyle style2)
190 if (style1 == 0) return style2;
191 if (style2 == 0) return style1;
192 if ((style1 & (PREEDIT_MASK | STATUS_MASK))
193 == (style2 & (PREEDIT_MASK | STATUS_MASK)))
196 s1 = style1 & PREEDIT_MASK;
197 s2 = style2 & PREEDIT_MASK;
200 if (u & XIMPreeditCallbacks)
201 return (s1 == XIMPreeditCallbacks) ? style1 : style2;
202 else if (u & XIMPreeditPosition)
203 return (s1 == XIMPreeditPosition) ? style1 :style2;
204 else if (u & XIMPreeditArea)
205 return (s1 == XIMPreeditArea) ? style1 : style2;
206 else if (u & XIMPreeditNothing)
207 return (s1 == XIMPreeditNothing) ? style1 : style2;
208 else if (u & XIMPreeditNone)
209 return (s1 == XIMPreeditNone) ? style1 : style2;
211 s1 = style1 & STATUS_MASK;
212 s2 = style2 & STATUS_MASK;
214 if (u & XIMStatusCallbacks)
215 return (s1 == XIMStatusCallbacks) ? style1 : style2;
216 else if (u & XIMStatusArea)
217 return (s1 == XIMStatusArea) ? style1 : style2;
218 else if (u & XIMStatusNothing)
219 return (s1 == XIMStatusNothing) ? style1 : style2;
220 else if (u & XIMStatusNone)
221 return (s1 == XIMStatusNone) ? style1 : style2;
223 return 0; /* Get rid of stupid warning */
227 reinitialize_all_ics (GtkXIMInfo *info)
231 for (tmp_list = info->ics; tmp_list; tmp_list = tmp_list->next)
232 reinitialize_ic (tmp_list->data);
236 status_style_change (GtkXIMInfo *info)
238 GtkIMStatusStyle status_style;
240 g_object_get (info->settings,
241 "gtk-im-status-style", &status_style,
243 if (status_style == GTK_IM_STATUS_CALLBACK)
244 info->status_style_setting = XIMStatusCallbacks;
245 else if (status_style == GTK_IM_STATUS_NOTHING)
246 info->status_style_setting = XIMStatusNothing;
247 else if (status_style == GTK_IM_STATUS_NONE)
248 info->status_style_setting = XIMStatusNone;
254 reinitialize_all_ics (info);
258 preedit_style_change (GtkXIMInfo *info)
260 GtkIMPreeditStyle preedit_style;
261 g_object_get (info->settings,
262 "gtk-im-preedit-style", &preedit_style,
264 if (preedit_style == GTK_IM_PREEDIT_CALLBACK)
265 info->preedit_style_setting = XIMPreeditCallbacks;
266 else if (preedit_style == GTK_IM_PREEDIT_NOTHING)
267 info->preedit_style_setting = XIMPreeditNothing;
268 else if (preedit_style == GTK_IM_PREEDIT_NONE)
269 info->preedit_style_setting = XIMPreeditNone;
275 reinitialize_all_ics (info);
279 setup_styles (GtkXIMInfo *info)
282 unsigned long settings_preference;
283 XIMStyles *xim_styles = info->xim_styles;
285 settings_preference = info->status_style_setting|info->preedit_style_setting;
289 for (i = 0; i < xim_styles->count_styles; i++)
290 if ((xim_styles->supported_styles[i] & ALLOWED_MASK) == xim_styles->supported_styles[i])
292 if (settings_preference == xim_styles->supported_styles[i])
294 info->style = settings_preference;
297 info->style = choose_better_style (info->style,
298 xim_styles->supported_styles[i]);
301 if (info->style == 0)
302 info->style = XIMPreeditNothing | XIMStatusNothing;
306 setup_im (GtkXIMInfo *info)
308 XIMValuesList *ic_values = NULL;
309 XIMCallback im_destroy_callback;
311 if (info->im == NULL)
314 im_destroy_callback.client_data = (XPointer)info;
315 im_destroy_callback.callback = (XIMProc)xim_destroy_callback;
316 XSetIMValues (info->im,
317 XNDestroyCallback, &im_destroy_callback,
320 XGetIMValues (info->im,
321 XNQueryInputStyle, &info->xim_styles,
322 XNQueryICValuesList, &ic_values,
325 info->settings = gtk_settings_get_for_screen (info->screen);
327 if (!g_object_class_find_property (G_OBJECT_GET_CLASS (info->settings),
328 "gtk-im-preedit-style"))
329 gtk_settings_install_property (g_param_spec_enum ("gtk-im-preedit-style",
330 P_("IM Preedit style"),
331 P_("How to draw the input method preedit string"),
332 GTK_TYPE_IM_PREEDIT_STYLE,
333 GTK_IM_PREEDIT_CALLBACK,
336 if (!g_object_class_find_property (G_OBJECT_GET_CLASS (info->settings),
337 "gtk-im-status-style"))
338 gtk_settings_install_property (g_param_spec_enum ("gtk-im-status-style",
339 P_("IM Status style"),
340 P_("How to draw the input method statusbar"),
341 GTK_TYPE_IM_STATUS_STYLE,
342 GTK_IM_STATUS_CALLBACK,
345 info->status_set = g_signal_connect_swapped (info->settings,
346 "notify::gtk-im-status-style",
347 G_CALLBACK (status_style_change),
349 info->preedit_set = g_signal_connect_swapped (info->settings,
350 "notify::gtk-im-preedit-style",
351 G_CALLBACK (preedit_style_change),
354 info->supports_string_conversion = FALSE;
359 for (i = 0; i < ic_values->count_values; i++)
360 if (strcmp (ic_values->supported_values[i],
361 XNStringConversionCallback) == 0)
363 info->supports_string_conversion = TRUE;
368 for (i = 0; i < ic_values->count_values; i++)
369 g_print ("%s\n", ic_values->supported_values[i]);
370 for (i = 0; i < xim_styles->count_styles; i++)
371 g_print ("%#x\n", xim_styles->supported_styles[i]);
377 status_style_change (info);
378 preedit_style_change (info);
382 xim_info_display_closed (GdkDisplay *display,
386 GSList *ics, *tmp_list;
388 open_ims = g_slist_remove (open_ims, info);
393 for (tmp_list = ics; tmp_list; tmp_list = tmp_list->next)
394 set_ic_client_window (tmp_list->data, NULL);
398 g_signal_handler_disconnect (info->settings, info->status_set);
399 g_signal_handler_disconnect (info->settings, info->preedit_set);
401 XFree (info->xim_styles->supported_styles);
402 XFree (info->xim_styles);
403 g_free (info->locale);
412 xim_instantiate_callback (Display *display, XPointer client_data,
415 GtkXIMInfo *info = (GtkXIMInfo*)client_data;
418 im = XOpenIM (display, NULL, NULL, NULL);
426 XUnregisterIMInstantiateCallback (display, NULL, NULL, NULL,
427 xim_instantiate_callback,
429 info->reconnecting = FALSE;
432 /* initialize info->im */
434 xim_info_try_im (GtkXIMInfo *info)
436 GdkScreen *screen = info->screen;
437 GdkDisplay *display = gdk_screen_get_display (screen);
439 g_assert (info->im == NULL);
440 if (info->reconnecting)
443 if (XSupportsLocale ())
445 if (!XSetLocaleModifiers (""))
446 g_warning ("Unable to set locale modifiers with XSetLocaleModifiers()");
447 info->im = XOpenIM (GDK_DISPLAY_XDISPLAY (display), NULL, NULL, NULL);
450 XRegisterIMInstantiateCallback (GDK_DISPLAY_XDISPLAY(display),
452 xim_instantiate_callback,
454 info->reconnecting = TRUE;
459 g_signal_connect (display, "closed",
460 G_CALLBACK (xim_info_display_closed), info);
465 xim_destroy_callback (XIM xim,
466 XPointer client_data,
469 GtkXIMInfo *info = (GtkXIMInfo*)client_data;
473 g_signal_handler_disconnect (info->settings, info->status_set);
474 g_signal_handler_disconnect (info->settings, info->preedit_set);
476 reinitialize_all_ics (info);
477 xim_info_try_im (info);
482 get_im (GdkWindow *client_window,
487 GdkScreen *screen = gdk_drawable_get_screen (client_window);
493 GtkXIMInfo *tmp_info = tmp_list->data;
494 if (tmp_info->screen == screen &&
495 strcmp (tmp_info->locale, locale) == 0)
507 tmp_list = tmp_list->next;
512 info = g_new (GtkXIMInfo, 1);
513 open_ims = g_slist_prepend (open_ims, info);
515 info->screen = screen;
516 info->locale = g_strdup (locale);
517 info->xim_styles = NULL;
518 info->preedit_style_setting = 0;
519 info->status_style_setting = 0;
520 info->settings = NULL;
521 info->preedit_set = 0;
522 info->status_set = 0;
524 info->reconnecting = FALSE;
528 xim_info_try_im (info);
533 gtk_im_context_xim_class_init (GtkIMContextXIMClass *class)
535 GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
536 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
538 parent_class = g_type_class_peek_parent (class);
540 im_context_class->set_client_window = gtk_im_context_xim_set_client_window;
541 im_context_class->filter_keypress = gtk_im_context_xim_filter_keypress;
542 im_context_class->reset = gtk_im_context_xim_reset;
543 im_context_class->get_preedit_string = gtk_im_context_xim_get_preedit_string;
544 im_context_class->focus_in = gtk_im_context_xim_focus_in;
545 im_context_class->focus_out = gtk_im_context_xim_focus_out;
546 im_context_class->set_cursor_location = gtk_im_context_xim_set_cursor_location;
547 im_context_class->set_use_preedit = gtk_im_context_xim_set_use_preedit;
548 gobject_class->finalize = gtk_im_context_xim_finalize;
552 gtk_im_context_xim_init (GtkIMContextXIM *im_context_xim)
554 im_context_xim->use_preedit = TRUE;
555 im_context_xim->filter_key_release = FALSE;
556 im_context_xim->finalizing = FALSE;
557 im_context_xim->has_focus = FALSE;
558 im_context_xim->in_toplevel = FALSE;
562 gtk_im_context_xim_finalize (GObject *obj)
564 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (obj);
566 context_xim->finalizing = TRUE;
568 if (context_xim->im_info && !context_xim->im_info->ics->next)
570 if (context_xim->im_info->reconnecting)
574 display = gdk_screen_get_display (context_xim->im_info->screen);
575 XUnregisterIMInstantiateCallback (GDK_DISPLAY_XDISPLAY (display),
577 xim_instantiate_callback,
578 (XPointer)context_xim->im_info);
582 XIMCallback im_destroy_callback;
584 im_destroy_callback.client_data = NULL;
585 im_destroy_callback.callback = NULL;
586 XSetIMValues (context_xim->im_info->im,
587 XNDestroyCallback, &im_destroy_callback,
592 set_ic_client_window (context_xim, NULL);
594 g_free (context_xim->locale);
595 g_free (context_xim->mb_charset);
597 G_OBJECT_CLASS (parent_class)->finalize (obj);
601 reinitialize_ic (GtkIMContextXIM *context_xim)
605 XDestroyIC (context_xim->ic);
606 context_xim->ic = NULL;
607 update_status_window (context_xim);
609 if (context_xim->preedit_length)
611 context_xim->preedit_length = 0;
612 if (!context_xim->finalizing)
613 g_signal_emit_by_name (context_xim, "preedit_changed");
617 reset filter_key_release flag, otherwise keystrokes will be doubled
618 until reconnecting to XIM.
620 context_xim->filter_key_release = FALSE;
624 set_ic_client_window (GtkIMContextXIM *context_xim,
625 GdkWindow *client_window)
627 reinitialize_ic (context_xim);
628 if (context_xim->client_window)
630 context_xim->im_info->ics = g_slist_remove (context_xim->im_info->ics, context_xim);
631 context_xim->im_info = NULL;
634 context_xim->client_window = client_window;
636 if (context_xim->client_window)
638 context_xim->im_info = get_im (context_xim->client_window, context_xim->locale);
639 context_xim->im_info->ics = g_slist_prepend (context_xim->im_info->ics, context_xim);
642 update_client_widget (context_xim);
646 gtk_im_context_xim_set_client_window (GtkIMContext *context,
647 GdkWindow *client_window)
649 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
651 set_ic_client_window (context_xim, client_window);
655 gtk_im_context_xim_new (void)
657 GtkIMContextXIM *result;
658 const gchar *charset;
660 result = g_object_new (GTK_TYPE_IM_CONTEXT_XIM, NULL);
662 result->locale = g_strdup (setlocale (LC_CTYPE, NULL));
664 g_get_charset (&charset);
665 result->mb_charset = g_strdup (charset);
667 return GTK_IM_CONTEXT (result);
671 mb_to_utf8 (GtkIMContextXIM *context_xim,
674 GError *error = NULL;
677 if (strcmp (context_xim->mb_charset, "UTF-8") == 0)
678 result = g_strdup (str);
681 result = g_convert (str, -1,
682 "UTF-8", context_xim->mb_charset,
686 g_warning ("Error converting text from IM to UTF-8: %s\n", error->message);
687 g_error_free (error);
695 gtk_im_context_xim_filter_keypress (GtkIMContext *context,
698 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
699 XIC ic = gtk_im_context_xim_get_ic (context_xim);
700 gchar static_buffer[256];
701 gchar *buffer = static_buffer;
702 gint buffer_size = sizeof(static_buffer) - 1;
706 gboolean result = FALSE;
707 GdkWindow *root_window = gdk_screen_get_root_window (gdk_drawable_get_screen (event->window));
709 XKeyPressedEvent xevent;
711 if (event->type == GDK_KEY_RELEASE && !context_xim->filter_key_release)
714 xevent.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
715 xevent.serial = 0; /* hope it doesn't matter */
716 xevent.send_event = event->send_event;
717 xevent.display = GDK_DRAWABLE_XDISPLAY (event->window);
718 xevent.window = GDK_DRAWABLE_XID (event->window);
719 xevent.root = GDK_DRAWABLE_XID (root_window);
720 xevent.subwindow = xevent.window;
721 xevent.time = event->time;
722 xevent.x = xevent.x_root = 0;
723 xevent.y = xevent.y_root = 0;
724 xevent.state = event->state;
725 xevent.keycode = event->hardware_keycode;
726 xevent.same_screen = True;
728 if (XFilterEvent ((XEvent *)&xevent, GDK_DRAWABLE_XID (context_xim->client_window)))
733 num_bytes = XmbLookupString (ic, &xevent, buffer, buffer_size, &keysym, &status);
736 num_bytes = XLookupString (&xevent, buffer, buffer_size, &keysym, NULL);
737 status = XLookupBoth;
740 if (status == XBufferOverflow)
742 buffer_size = num_bytes;
743 if (buffer != static_buffer)
745 buffer = g_malloc (num_bytes + 1);
749 /* I don't know how we should properly handle XLookupKeysym or XLookupBoth
750 * here ... do input methods actually change the keysym? we can't really
751 * feed it back to accelerator processing at this point...
753 if (status == XLookupChars || status == XLookupBoth)
757 buffer[num_bytes] = '\0';
759 result_utf8 = mb_to_utf8 (context_xim, buffer);
762 if ((guchar)result_utf8[0] >= 0x20 &&
763 result_utf8[0] != 0x7f) /* Some IM have a nasty habit of converting
764 * control characters into strings
767 g_signal_emit_by_name (context, "commit", result_utf8);
771 g_free (result_utf8);
775 if (buffer != static_buffer)
782 gtk_im_context_xim_focus_in (GtkIMContext *context)
784 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
786 if (!context_xim->has_focus)
788 XIC ic = gtk_im_context_xim_get_ic (context_xim);
790 context_xim->has_focus = TRUE;
791 update_status_window (context_xim);
801 gtk_im_context_xim_focus_out (GtkIMContext *context)
803 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
805 if (context_xim->has_focus)
807 XIC ic = gtk_im_context_xim_get_ic (context_xim);
809 context_xim->has_focus = FALSE;
810 update_status_window (context_xim);
820 gtk_im_context_xim_set_cursor_location (GtkIMContext *context,
823 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
824 XIC ic = gtk_im_context_xim_get_ic (context_xim);
826 XVaNestedList preedit_attr;
835 preedit_attr = XVaCreateNestedList (0,
836 XNSpotLocation, &spot,
839 XNPreeditAttributes, preedit_attr,
847 gtk_im_context_xim_set_use_preedit (GtkIMContext *context,
848 gboolean use_preedit)
850 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
852 use_preedit = use_preedit != FALSE;
854 if (context_xim->use_preedit != use_preedit)
856 context_xim->use_preedit = use_preedit;
857 reinitialize_ic (context_xim);
864 gtk_im_context_xim_reset (GtkIMContext *context)
866 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
867 XIC ic = gtk_im_context_xim_get_ic (context_xim);
870 /* restore conversion state after resetting ic later */
871 XIMPreeditState preedit_state = XIMPreeditUnKnown;
872 XVaNestedList preedit_attr;
873 gboolean have_preedit_state = FALSE;
879 if (context_xim->preedit_length == 0)
882 preedit_attr = XVaCreateNestedList(0,
883 XNPreeditState, &preedit_state,
885 if (!XGetICValues(ic,
886 XNPreeditAttributes, preedit_attr,
888 have_preedit_state = TRUE;
892 result = XmbResetIC (ic);
894 preedit_attr = XVaCreateNestedList(0,
895 XNPreeditState, preedit_state,
897 if (have_preedit_state)
899 XNPreeditAttributes, preedit_attr,
906 char *result_utf8 = mb_to_utf8 (context_xim, result);
909 g_signal_emit_by_name (context, "commit", result_utf8);
910 g_free (result_utf8);
914 if (context_xim->preedit_length)
916 context_xim->preedit_length = 0;
917 g_signal_emit_by_name (context, "preedit_changed");
923 /* Mask of feedback bits that we render
925 #define FEEDBACK_MASK (XIMReverse | XIMUnderline)
928 add_feedback_attr (PangoAttrList *attrs,
930 XIMFeedback feedback,
934 PangoAttribute *attr;
936 gint start_index = g_utf8_offset_to_pointer (str, start_pos) - str;
937 gint end_index = g_utf8_offset_to_pointer (str, end_pos) - str;
939 if (feedback & XIMUnderline)
941 attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
942 attr->start_index = start_index;
943 attr->end_index = end_index;
945 pango_attr_list_change (attrs, attr);
948 if (feedback & XIMReverse)
950 attr = pango_attr_foreground_new (0xffff, 0xffff, 0xffff);
951 attr->start_index = start_index;
952 attr->end_index = end_index;
954 pango_attr_list_change (attrs, attr);
956 attr = pango_attr_background_new (0, 0, 0);
957 attr->start_index = start_index;
958 attr->end_index = end_index;
960 pango_attr_list_change (attrs, attr);
963 if (feedback & ~FEEDBACK_MASK)
964 g_warning ("Unrendered feedback style: %#lx", feedback & ~FEEDBACK_MASK);
968 gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
970 PangoAttrList **attrs,
973 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
974 gchar *utf8 = g_ucs4_to_utf8 (context_xim->preedit_chars, context_xim->preedit_length, NULL, NULL, NULL);
979 XIMFeedback last_feedback = 0;
982 *attrs = pango_attr_list_new ();
984 for (i = 0; i < context_xim->preedit_length; i++)
986 XIMFeedback new_feedback = context_xim->feedbacks[i] & FEEDBACK_MASK;
987 if (new_feedback != last_feedback)
990 add_feedback_attr (*attrs, utf8, last_feedback, start, i);
992 last_feedback = new_feedback;
998 add_feedback_attr (*attrs, utf8, last_feedback, start, i);
1007 *cursor_pos = context_xim->preedit_cursor;
1011 preedit_start_callback (XIC xic,
1012 XPointer client_data,
1015 GtkIMContext *context = GTK_IM_CONTEXT (client_data);
1016 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
1018 if (!context_xim->finalizing)
1019 g_signal_emit_by_name (context, "preedit_start");
1021 return -1; /* No length limit */
1025 preedit_done_callback (XIC xic,
1026 XPointer client_data,
1029 GtkIMContext *context = GTK_IM_CONTEXT (client_data);
1030 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
1032 if (context_xim->preedit_length)
1034 context_xim->preedit_length = 0;
1035 if (!context_xim->finalizing)
1036 g_signal_emit_by_name (context_xim, "preedit_changed");
1039 if (!context_xim->finalizing)
1040 g_signal_emit_by_name (context, "preedit_end");
1044 xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text)
1046 gint text_length = 0;
1047 GError *error = NULL;
1048 gchar *result = NULL;
1050 if (xim_text && xim_text->string.multi_byte)
1052 if (xim_text->encoding_is_wchar)
1054 g_warning ("Wide character return from Xlib not currently supported");
1059 if (strcmp (context->mb_charset, "UTF-8") == 0)
1060 result = g_strdup (xim_text->string.multi_byte);
1062 result = g_convert (xim_text->string.multi_byte,
1065 context->mb_charset,
1066 NULL, NULL, &error);
1070 text_length = g_utf8_strlen (result, -1);
1072 if (text_length != xim_text->length)
1074 g_warning ("Size mismatch when converting text from input method: supplied length = %d\n, result length = %d", xim_text->length, text_length);
1079 g_warning ("Error converting text from IM to UCS-4: %s", error->message);
1080 g_error_free (error);
1097 preedit_draw_callback (XIC xic,
1098 XPointer client_data,
1099 XIMPreeditDrawCallbackStruct *call_data)
1101 GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
1103 XIMText *new_xim_text = call_data->text;
1104 gint new_text_length;
1105 gunichar *new_text = NULL;
1111 gint chg_first = CLAMP (call_data->chg_first, 0, context->preedit_length);
1112 gint chg_length = CLAMP (call_data->chg_length, 0, context->preedit_length - chg_first);
1114 context->preedit_cursor = call_data->caret;
1116 if (chg_first != call_data->chg_first || chg_length != call_data->chg_length)
1117 g_warning ("Invalid change to preedit string, first=%d length=%d (orig length == %d)",
1118 call_data->chg_first, call_data->chg_length, context->preedit_length);
1120 new_text_length = xim_text_to_utf8 (context, new_xim_text, &tmp);
1123 new_text = g_utf8_to_ucs4_fast (tmp, -1, NULL);
1127 diff = new_text_length - chg_length;
1128 new_length = context->preedit_length + diff;
1130 if (new_length > context->preedit_size)
1132 context->preedit_size = new_length;
1133 context->preedit_chars = g_renew (gunichar, context->preedit_chars, new_length);
1134 context->feedbacks = g_renew (XIMFeedback, context->feedbacks, new_length);
1139 for (i = chg_first + chg_length ; i < context->preedit_length; i++)
1141 context->preedit_chars[i + diff] = context->preedit_chars[i];
1142 context->feedbacks[i + diff] = context->feedbacks[i];
1147 for (i = context->preedit_length - 1; i >= chg_first + chg_length ; i--)
1149 context->preedit_chars[i + diff] = context->preedit_chars[i];
1150 context->feedbacks[i + diff] = context->feedbacks[i];
1154 for (i = 0; i < new_text_length; i++)
1156 context->preedit_chars[chg_first + i] = new_text[i];
1157 context->feedbacks[chg_first + i] = new_xim_text->feedback[i];
1160 context->preedit_length += diff;
1165 if (!context->finalizing)
1166 g_signal_emit_by_name (context, "preedit_changed");
1171 preedit_caret_callback (XIC xic,
1172 XPointer client_data,
1173 XIMPreeditCaretCallbackStruct *call_data)
1175 GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
1177 if (call_data->direction == XIMAbsolutePosition)
1179 context->preedit_cursor = call_data->position;
1180 if (!context->finalizing)
1181 g_signal_emit_by_name (context, "preedit_changed");
1185 g_warning ("Caret movement command: %d %d %d not supported",
1186 call_data->position, call_data->direction, call_data->style);
1191 status_start_callback (XIC xic,
1192 XPointer client_data,
1199 status_done_callback (XIC xic,
1200 XPointer client_data,
1207 status_draw_callback (XIC xic,
1208 XPointer client_data,
1209 XIMStatusDrawCallbackStruct *call_data)
1211 GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
1213 if (call_data->type == XIMTextType)
1216 xim_text_to_utf8 (context, call_data->data.text, &text);
1218 if (context->status_window)
1219 status_window_set_text (context->status_window, text ? text : "");
1223 g_print ("Status drawn with bitmap - id = %#lx\n", call_data->data.bitmap);
1228 string_conversion_callback (XIC xic, XPointer client_data, XPointer call_data)
1230 GtkIMContextXIM *context_xim;
1231 XIMStringConversionCallbackStruct *conv_data;
1235 context_xim = (GtkIMContextXIM *)client_data;
1236 conv_data = (XIMStringConversionCallbackStruct *)call_data;
1238 if (gtk_im_context_get_surrounding ((GtkIMContext *)context_xim,
1239 &surrounding, &cursor_index))
1243 gint subst_offset = 0, subst_nchars = 0;
1245 gchar *p = surrounding + cursor_index, *q;
1246 gshort position = (gshort)conv_data->position;
1250 for (i = position; i > 0 && *p; --i)
1251 p = g_utf8_next_char (p);
1255 /* According to X11R6.4 Xlib - C Library Reference Manual
1256 * section 13.5.7.3 String Conversion Callback,
1257 * XIMStringConversionPosition is starting position _relative_
1258 * to current client's cursor position. So it should be able
1259 * to be negative, or referring to a position before the cursor
1260 * would be impossible. But current X protocol defines this as
1261 * unsigned short. So, compiler may warn about the value range
1262 * here. We hope the X protocol is fixed soon.
1264 else if (position < 0)
1266 for (i = position; i < 0 && p > surrounding; ++i)
1267 p = g_utf8_prev_char (p);
1272 switch (conv_data->direction)
1274 case XIMForwardChar:
1275 for (i = conv_data->factor, q = p; i > 0 && *q; --i)
1276 q = g_utf8_next_char (q);
1279 text = g_locale_from_utf8 (p, q - p, NULL, &text_len, NULL);
1280 subst_offset = position;
1281 subst_nchars = conv_data->factor;
1284 case XIMBackwardChar:
1285 for (i = conv_data->factor, q = p; i > 0 && q > surrounding; --i)
1286 q = g_utf8_prev_char (q);
1289 text = g_locale_from_utf8 (q, p - q, NULL, &text_len, NULL);
1290 subst_offset = position - conv_data->factor;
1291 subst_nchars = conv_data->factor;
1294 case XIMForwardWord:
1295 case XIMBackwardWord:
1299 case XIMPreviousLine:
1302 case XIMAbsolutePosition:
1307 /* block out any failure happenning to "text", including conversion */
1310 conv_data->text = (XIMStringConversionText *)
1311 malloc (sizeof (XIMStringConversionText));
1312 if (conv_data->text)
1314 conv_data->text->length = text_len;
1315 conv_data->text->feedback = NULL;
1316 conv_data->text->encoding_is_wchar = False;
1317 conv_data->text->string.mbs = (char *)malloc (text_len);
1318 if (conv_data->text->string.mbs)
1319 memcpy (conv_data->text->string.mbs, text, text_len);
1322 free (conv_data->text);
1323 conv_data->text = NULL;
1329 if (conv_data->operation == XIMStringConversionSubstitution
1330 && subst_nchars > 0)
1332 gtk_im_context_delete_surrounding ((GtkIMContext *)context_xim,
1333 subst_offset, subst_nchars);
1336 g_free (surrounding);
1341 static XVaNestedList
1342 set_preedit_callback (GtkIMContextXIM *context_xim)
1344 context_xim->preedit_start_callback.client_data = (XPointer)context_xim;
1345 context_xim->preedit_start_callback.callback = (XIMProc)preedit_start_callback;
1346 context_xim->preedit_done_callback.client_data = (XPointer)context_xim;
1347 context_xim->preedit_done_callback.callback = (XIMProc)preedit_done_callback;
1348 context_xim->preedit_draw_callback.client_data = (XPointer)context_xim;
1349 context_xim->preedit_draw_callback.callback = (XIMProc)preedit_draw_callback;
1350 context_xim->preedit_caret_callback.client_data = (XPointer)context_xim;
1351 context_xim->preedit_caret_callback.callback = (XIMProc)preedit_caret_callback;
1352 return XVaCreateNestedList (0,
1353 XNPreeditStartCallback, &context_xim->preedit_start_callback,
1354 XNPreeditDoneCallback, &context_xim->preedit_done_callback,
1355 XNPreeditDrawCallback, &context_xim->preedit_draw_callback,
1356 XNPreeditCaretCallback, &context_xim->preedit_caret_callback,
1360 static XVaNestedList
1361 set_status_callback (GtkIMContextXIM *context_xim)
1363 context_xim->status_start_callback.client_data = (XPointer)context_xim;
1364 context_xim->status_start_callback.callback = (XIMProc)status_start_callback;
1365 context_xim->status_done_callback.client_data = (XPointer)context_xim;
1366 context_xim->status_done_callback.callback = (XIMProc)status_done_callback;
1367 context_xim->status_draw_callback.client_data = (XPointer)context_xim;
1368 context_xim->status_draw_callback.callback = (XIMProc)status_draw_callback;
1370 return XVaCreateNestedList (0,
1371 XNStatusStartCallback, &context_xim->status_start_callback,
1372 XNStatusDoneCallback, &context_xim->status_done_callback,
1373 XNStatusDrawCallback, &context_xim->status_draw_callback,
1379 set_string_conversion_callback (GtkIMContextXIM *context_xim, XIC xic)
1381 if (!context_xim->im_info->supports_string_conversion)
1384 context_xim->string_conversion_callback.client_data = (XPointer)context_xim;
1385 context_xim->string_conversion_callback.callback = (XIMProc)string_conversion_callback;
1388 XNStringConversionCallback,
1389 (XPointer)&context_xim->string_conversion_callback,
1394 gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
1396 if (context_xim->im_info == NULL || context_xim->im_info->im == NULL)
1399 if (!context_xim->ic)
1401 const char *name1 = NULL;
1402 XVaNestedList list1 = NULL;
1403 const char *name2 = NULL;
1404 XVaNestedList list2 = NULL;
1405 XIMStyle im_style = 0;
1408 if (context_xim->use_preedit &&
1409 (context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditCallbacks)
1411 im_style |= XIMPreeditCallbacks;
1412 name1 = XNPreeditAttributes;
1413 list1 = set_preedit_callback (context_xim);
1415 else if ((context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditNone)
1416 im_style |= XIMPreeditNone;
1418 im_style |= XIMPreeditNothing;
1420 if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusCallbacks)
1422 im_style |= XIMStatusCallbacks;
1425 name1 = XNStatusAttributes;
1426 list1 = set_status_callback (context_xim);
1430 name2 = XNStatusAttributes;
1431 list2 = set_status_callback (context_xim);
1434 else if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusNone)
1435 im_style |= XIMStatusNone;
1437 im_style |= XIMStatusNothing;
1439 xic = XCreateIC (context_xim->im_info->im,
1440 XNInputStyle, im_style,
1441 XNClientWindow, GDK_DRAWABLE_XID (context_xim->client_window),
1452 /* Don't filter key released events with XFilterEvents unless
1453 * input methods ask for. This is a workaround for Solaris input
1454 * method bug in C and European locales. It doubles each key
1455 * stroke if both key pressed and released events are filtered.
1458 gulong mask = 0xaaaaaaaa;
1460 XNFilterEvents, &mask,
1462 context_xim->filter_key_release = (mask & KeyReleaseMask) != 0;
1463 set_string_conversion_callback (context_xim, xic);
1466 context_xim->ic = xic;
1468 update_status_window (context_xim);
1470 if (xic && context_xim->has_focus)
1473 return context_xim->ic;
1476 /*****************************************************************
1477 * Status Window handling
1479 * A status window is a small window attached to the toplevel
1480 * that is used to display information to the user about the
1481 * current input operation.
1483 * We claim the toplevel's status window for an input context if:
1485 * A) The input context has a toplevel
1486 * B) The input context has the focus
1487 * C) The input context has an XIC associated with it
1489 * Tracking A) and C) is pretty reliable since we
1490 * compute A) and create the XIC for C) ourselves.
1491 * For B) we basically have to depend on our callers
1492 * calling ::focus-in and ::focus-out at the right time.
1494 * The toplevel is computed by walking up the GdkWindow
1495 * hierarchy from context->client_window until we find a
1496 * window that is owned by some widget, and then calling
1497 * gtk_widget_get_toplevel() on that widget. This should
1498 * handle both cases where we might have GdkWindows without widgets,
1499 * and cases where GtkWidgets have strange window hierarchies
1500 * (like a torn off GtkHandleBox.)
1502 * The status window is visible if and only if there is text
1503 * for it; whenever a new GtkIMContextXIM claims the status
1504 * window, we blank out any existing text. We actually only
1505 * create a GtkWindow for the status window the first time
1506 * it is shown; this is an important optimization when we are
1507 * using XIM with something like a simple compose-key input
1508 * method that never needs a status window.
1509 *****************************************************************/
1511 /* Called when we no longer need a status window
1514 disclaim_status_window (GtkIMContextXIM *context_xim)
1516 if (context_xim->status_window)
1518 g_assert (context_xim->status_window->context == context_xim);
1520 status_window_set_text (context_xim->status_window, "");
1522 context_xim->status_window->context = NULL;
1523 context_xim->status_window = NULL;
1527 /* Called when we need a status window
1530 claim_status_window (GtkIMContextXIM *context_xim)
1532 if (!context_xim->status_window && context_xim->client_widget)
1534 GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget);
1535 if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel))
1537 StatusWindow *status_window = status_window_get (toplevel);
1539 if (status_window->context)
1540 disclaim_status_window (status_window->context);
1542 status_window->context = context_xim;
1543 context_xim->status_window = status_window;
1548 /* Basic call made whenever something changed that might cause
1549 * us to need, or not to need a status window.
1552 update_status_window (GtkIMContextXIM *context_xim)
1554 if (context_xim->ic && context_xim->in_toplevel && context_xim->has_focus)
1555 claim_status_window (context_xim);
1557 disclaim_status_window (context_xim);
1560 /* Updates the in_toplevel flag for @context_xim
1563 update_in_toplevel (GtkIMContextXIM *context_xim)
1565 if (context_xim->client_widget)
1567 GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget);
1569 context_xim->in_toplevel = (toplevel && GTK_WIDGET_TOPLEVEL (toplevel));
1572 context_xim->in_toplevel = FALSE;
1574 /* Some paranoia, in case we don't get a focus out */
1575 if (!context_xim->in_toplevel)
1576 context_xim->has_focus = FALSE;
1578 update_status_window (context_xim);
1581 /* Callback when @widget's toplevel changes. It will always
1582 * change from NULL to a window, or a window to NULL;
1583 * we use that intermediate NULL state to make sure
1584 * that we disclaim the toplevel status window for the old
1588 on_client_widget_hierarchy_changed (GtkWidget *widget,
1589 GtkWidget *old_toplevel,
1590 GtkIMContextXIM *context_xim)
1592 update_in_toplevel (context_xim);
1595 /* Finds the GtkWidget that owns the window, or if none, the
1596 * widget owning the nearest parent that has a widget.
1599 widget_for_window (GdkWindow *window)
1604 gdk_window_get_user_data (window, &user_data);
1608 window = gdk_window_get_parent (window);
1614 /* Called when context_xim->client_window changes; takes care of
1615 * removing and/or setting up our watches for the toplevel
1618 update_client_widget (GtkIMContextXIM *context_xim)
1620 GtkWidget *new_client_widget = widget_for_window (context_xim->client_window);
1622 if (new_client_widget != context_xim->client_widget)
1624 if (context_xim->client_widget)
1626 g_signal_handlers_disconnect_by_func (context_xim->client_widget,
1627 G_CALLBACK (on_client_widget_hierarchy_changed),
1630 context_xim->client_widget = new_client_widget;
1631 if (context_xim->client_widget)
1633 g_signal_connect (context_xim->client_widget, "hierarchy-changed",
1634 G_CALLBACK (on_client_widget_hierarchy_changed),
1638 update_in_toplevel (context_xim);
1642 /* Called when the toplevel is destroyed; frees the status window
1645 on_status_toplevel_destroy (GtkWidget *toplevel,
1646 StatusWindow *status_window)
1648 status_window_free (status_window);
1651 /* Called when the screen for the toplevel changes; updates the
1652 * screen for the status window to match.
1655 on_status_toplevel_notify_screen (GtkWindow *toplevel,
1657 StatusWindow *status_window)
1659 if (status_window->window)
1660 gtk_window_set_screen (GTK_WINDOW (status_window->window),
1661 gtk_widget_get_screen (GTK_WIDGET (toplevel)));
1664 /* Called when the toplevel window is moved; updates the position of
1665 * the status window to follow it.
1668 on_status_toplevel_configure (GtkWidget *toplevel,
1669 GdkEventConfigure *event,
1670 StatusWindow *status_window)
1673 GtkRequisition requisition;
1677 if (status_window->window)
1679 height = gdk_screen_get_height (gtk_widget_get_screen (toplevel));
1681 gdk_window_get_frame_extents (toplevel->window, &rect);
1682 gtk_widget_size_request (status_window->window, &requisition);
1684 if (rect.y + rect.height + requisition.height < height)
1685 y = rect.y + rect.height;
1687 y = height - requisition.height;
1689 gtk_window_move (GTK_WINDOW (status_window->window), rect.x, y);
1695 /* Frees a status window and removes its link from the status_windows list
1698 status_window_free (StatusWindow *status_window)
1700 status_windows = g_slist_remove (status_windows, status_window);
1702 if (status_window->context)
1703 status_window->context->status_window = NULL;
1705 g_signal_handlers_disconnect_by_func (status_window->toplevel,
1706 G_CALLBACK (on_status_toplevel_destroy),
1708 g_signal_handlers_disconnect_by_func (status_window->toplevel,
1709 G_CALLBACK (on_status_toplevel_notify_screen),
1711 g_signal_handlers_disconnect_by_func (status_window->toplevel,
1712 G_CALLBACK (on_status_toplevel_configure),
1715 if (status_window->window)
1716 gtk_widget_destroy (status_window->window);
1718 g_object_set_data (G_OBJECT (status_window->toplevel), "gtk-im-xim-status-window", NULL);
1720 g_free (status_window);
1723 /* Finds the status window object for a toplevel, creating it if necessary.
1725 static StatusWindow *
1726 status_window_get (GtkWidget *toplevel)
1728 StatusWindow *status_window;
1730 status_window = g_object_get_data (G_OBJECT (toplevel), "gtk-im-xim-status-window");
1732 return status_window;
1734 status_window = g_new0 (StatusWindow, 1);
1735 status_window->toplevel = toplevel;
1737 status_windows = g_slist_prepend (status_windows, status_window);
1739 g_signal_connect (toplevel, "destroy",
1740 G_CALLBACK (on_status_toplevel_destroy),
1742 g_signal_connect (toplevel, "configure_event",
1743 G_CALLBACK (on_status_toplevel_configure),
1745 g_signal_connect (toplevel, "notify::screen",
1746 G_CALLBACK (on_status_toplevel_notify_screen),
1749 g_object_set_data (G_OBJECT (toplevel), "gtk-im-xim-status-window", status_window);
1751 return status_window;
1754 /* Draw the background (normally white) and border for the status window
1757 on_status_window_expose_event (GtkWidget *widget,
1758 GdkEventExpose *event)
1760 gdk_draw_rectangle (widget->window,
1761 widget->style->base_gc [GTK_STATE_NORMAL],
1764 widget->allocation.width, widget->allocation.height);
1765 gdk_draw_rectangle (widget->window,
1766 widget->style->text_gc [GTK_STATE_NORMAL],
1769 widget->allocation.width - 1, widget->allocation.height - 1);
1774 /* We watch the ::style-set signal for our label widget
1775 * and use that to change it's foreground color to match
1776 * the 'text' color of the toplevel window. The text/base
1777 * pair of colors might be reversed from the fg/bg pair
1778 * that are normally used for labels.
1781 on_status_window_style_set (GtkWidget *toplevel,
1782 GtkStyle *previous_style,
1787 for (i = 0; i < 5; i++)
1788 gtk_widget_modify_fg (label, i, &toplevel->style->text[i]);
1791 /* Creates the widgets for the status window; called when we
1792 * first need to show text for the status window.
1795 status_window_make_window (StatusWindow *status_window)
1798 GtkWidget *status_label;
1800 status_window->window = gtk_window_new (GTK_WINDOW_POPUP);
1801 window = status_window->window;
1803 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
1804 gtk_widget_set_app_paintable (window, TRUE);
1806 status_label = gtk_label_new ("");
1807 gtk_misc_set_padding (GTK_MISC (status_label), 1, 1);
1808 gtk_widget_show (status_label);
1810 g_signal_connect (window, "style_set",
1811 G_CALLBACK (on_status_window_style_set), status_label);
1812 gtk_container_add (GTK_CONTAINER (window), status_label);
1814 g_signal_connect (window, "expose_event",
1815 G_CALLBACK (on_status_window_expose_event), NULL);
1817 gtk_window_set_screen (GTK_WINDOW (status_window->window),
1818 gtk_widget_get_screen (status_window->toplevel));
1820 on_status_toplevel_configure (status_window->toplevel, NULL, status_window);
1823 /* Updates the text in the status window, hiding or
1824 * showing the window as necessary.
1827 status_window_set_text (StatusWindow *status_window,
1834 if (!status_window->window)
1835 status_window_make_window (status_window);
1837 label = GTK_BIN (status_window->window)->child;
1838 gtk_label_set_text (GTK_LABEL (label), text);
1840 gtk_widget_show (status_window->window);
1844 if (status_window->window)
1845 gtk_widget_hide (status_window->window);
1850 * gtk_im_context_xim_shutdown:
1852 * Destroys all the status windows that are kept by the XIM contexts. This
1853 * function should only be called by the XIM module exit routine.
1856 gtk_im_context_xim_shutdown (void)
1858 while (status_windows)
1859 status_window_free (status_windows->data);