- use gtk_settings_get_for_screen () instead of gtk_settings_get_default

* modules/input/gtkimcontextxim.c:
       - use gtk_settings_get_for_screen () instead of
         gtk_settings_get_default () for multihead
       - connect property-notify signal handlers to respond runtime
         changes of status_style and preedit_style in the settings
       - Some indentation and code cleanup (#59076 - 2nd check-in)
This commit is contained in:
Hidetoshi Tajima
2002-09-26 22:51:34 +00:00
parent 1689117cf7
commit 335c622faf
7 changed files with 263 additions and 133 deletions

View File

@ -1,3 +1,12 @@
Wed Sep 25 18:23:50 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
* modules/input/gtkimcontextxim.c:
- use gtk_settings_get_for_screen () instead of
gtk_settings_get_default () for multihead
- connect property-notify signal handlers to respond runtime
changes of status_style and preedit_style in the settings
- Some indentation and code cleanup (#59076 - 2nd check-in)
2002-09-24 Havoc Pennington <hp@redhat.com> 2002-09-24 Havoc Pennington <hp@redhat.com>
* gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate * gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate

View File

@ -1,3 +1,12 @@
Wed Sep 25 18:23:50 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
* modules/input/gtkimcontextxim.c:
- use gtk_settings_get_for_screen () instead of
gtk_settings_get_default () for multihead
- connect property-notify signal handlers to respond runtime
changes of status_style and preedit_style in the settings
- Some indentation and code cleanup (#59076 - 2nd check-in)
2002-09-24 Havoc Pennington <hp@redhat.com> 2002-09-24 Havoc Pennington <hp@redhat.com>
* gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate * gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate

View File

@ -1,3 +1,12 @@
Wed Sep 25 18:23:50 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
* modules/input/gtkimcontextxim.c:
- use gtk_settings_get_for_screen () instead of
gtk_settings_get_default () for multihead
- connect property-notify signal handlers to respond runtime
changes of status_style and preedit_style in the settings
- Some indentation and code cleanup (#59076 - 2nd check-in)
2002-09-24 Havoc Pennington <hp@redhat.com> 2002-09-24 Havoc Pennington <hp@redhat.com>
* gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate * gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate

View File

@ -1,3 +1,12 @@
Wed Sep 25 18:23:50 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
* modules/input/gtkimcontextxim.c:
- use gtk_settings_get_for_screen () instead of
gtk_settings_get_default () for multihead
- connect property-notify signal handlers to respond runtime
changes of status_style and preedit_style in the settings
- Some indentation and code cleanup (#59076 - 2nd check-in)
2002-09-24 Havoc Pennington <hp@redhat.com> 2002-09-24 Havoc Pennington <hp@redhat.com>
* gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate * gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate

View File

@ -1,3 +1,12 @@
Wed Sep 25 18:23:50 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
* modules/input/gtkimcontextxim.c:
- use gtk_settings_get_for_screen () instead of
gtk_settings_get_default () for multihead
- connect property-notify signal handlers to respond runtime
changes of status_style and preedit_style in the settings
- Some indentation and code cleanup (#59076 - 2nd check-in)
2002-09-24 Havoc Pennington <hp@redhat.com> 2002-09-24 Havoc Pennington <hp@redhat.com>
* gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate * gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate

View File

@ -1,3 +1,12 @@
Wed Sep 25 18:23:50 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
* modules/input/gtkimcontextxim.c:
- use gtk_settings_get_for_screen () instead of
gtk_settings_get_default () for multihead
- connect property-notify signal handlers to respond runtime
changes of status_style and preedit_style in the settings
- Some indentation and code cleanup (#59076 - 2nd check-in)
2002-09-24 Havoc Pennington <hp@redhat.com> 2002-09-24 Havoc Pennington <hp@redhat.com>
* gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate * gtk/gtkwindow.c: fix GtkWindowMnemonic to have a separate

View File

@ -33,8 +33,13 @@ struct _GtkXIMInfo
GdkDisplay *display; GdkDisplay *display;
XIM im; XIM im;
char *locale; char *locale;
gboolean set_style; XIMStyle preedit_style_setting;
XIMStyle status_style_setting;
XIMStyle style; XIMStyle style;
GtkSettings *settings;
gulong status_set;
gulong preedit_set;
XIMStyles *xim_styles;
}; };
/* A context status window; these are kept in the status_windows list. */ /* A context status window; these are kept in the status_windows list. */
@ -69,6 +74,9 @@ static void gtk_im_context_xim_get_preedit_string (GtkIMContext *co
PangoAttrList **attrs, PangoAttrList **attrs,
gint *cursor_pos); gint *cursor_pos);
static void reinitialize_ic (GtkIMContextXIM *context_xim);
static void setup_styles (GtkXIMInfo *info);
static void status_window_show (GtkIMContextXIM *context_xim); static void status_window_show (GtkIMContextXIM *context_xim);
static void status_window_hide (GtkIMContextXIM *context_xim); static void status_window_hide (GtkIMContextXIM *context_xim);
static void status_window_set_text (GtkIMContextXIM *context_xim, static void status_window_set_text (GtkIMContextXIM *context_xim,
@ -154,73 +162,114 @@ choose_better_style (XIMStyle style1, XIMStyle style2)
} }
static void static void
setup_im (GtkXIMInfo *info) status_style_change (GtkXIMInfo *info)
{ {
XIMStyles *xim_styles = NULL; GtkIMStatusStyle status_style;
XIMValuesList *ic_values = NULL; g_object_get (info->settings,
int i; "gtk-im-status-style", &status_style,
GtkSettings *settings; NULL);
unsigned long xim_preedit_style = 0; if (status_style == GTK_IM_STATUS_CALLBACK)
unsigned long xim_status_style = 0; info->status_style_setting = XIMStatusCallbacks;
unsigned long user_preference; else if (status_style == GTK_IM_STATUS_NOTHING)
info->status_style_setting = XIMStatusNothing;
else
return;
if (info->set_style) setup_styles (info);
{ }
settings = gtk_settings_get_default ();
if (settings) static void
preedit_style_change (GtkXIMInfo *info)
{ {
GtkIMPreeditStyle preedit_style; GtkIMPreeditStyle preedit_style;
GtkIMStatusStyle status_style; g_object_get (info->settings,
g_object_get (settings,
"gtk-im-status-style", &status_style,
"gtk-im-preedit-style", &preedit_style, "gtk-im-preedit-style", &preedit_style,
NULL); NULL);
switch (preedit_style) if (preedit_style == GTK_IM_PREEDIT_CALLBACK)
{ info->preedit_style_setting = XIMPreeditCallbacks;
case GTK_IM_PREEDIT_CALLBACK: else if (preedit_style == GTK_IM_PREEDIT_NOTHING)
xim_preedit_style = XIMPreeditCallbacks; info->preedit_style_setting = XIMPreeditNothing;
break; else
case GTK_IM_PREEDIT_NOTHING: return;
xim_preedit_style = XIMPreeditNothing;
break; setup_styles (info);
}
switch (status_style)
{
case GTK_IM_STATUS_CALLBACK:
xim_status_style = XIMStatusCallbacks;
break;
case GTK_IM_STATUS_NOTHING:
xim_status_style = XIMStatusNothing;
break;
}
}
info->set_style = FALSE;
} }
XGetIMValues (info->im, static void
XNQueryInputStyle, &xim_styles, status_style_change_notify (GtkIMContextXIM *context_xim)
XNQueryICValuesList, &ic_values, {
NULL); GtkXIMInfo *info = context_xim->im_info;
status_style_change (info);
info->style = 0; reinitialize_ic (context_xim);
user_preference = (xim_status_style | xim_preedit_style); }
static void
preedit_style_change_notify (GtkIMContextXIM *context_xim)
{
GtkXIMInfo *info = context_xim->im_info;
preedit_style_change (info);
reinitialize_ic (context_xim);
}
static void
setup_styles (GtkXIMInfo *info)
{
int i;
unsigned long settings_preference;
XIMStyles *xim_styles = info->xim_styles;
settings_preference = info->status_style_setting|info->preedit_style_setting;
if (xim_styles) if (xim_styles)
{ {
for (i = 0; i < xim_styles->count_styles; i++) for (i = 0; i < xim_styles->count_styles; i++)
if ((xim_styles->supported_styles[i] & ALLOWED_MASK) == xim_styles->supported_styles[i]) if ((xim_styles->supported_styles[i] & ALLOWED_MASK) == xim_styles->supported_styles[i])
{ {
if (user_preference == xim_styles->supported_styles[i]) if (settings_preference == xim_styles->supported_styles[i])
{ {
info->style = user_preference; info->style = settings_preference;
break; break;
} }
info->style = choose_better_style (info->style, info->style = choose_better_style (info->style,
xim_styles->supported_styles[i]); xim_styles->supported_styles[i]);
} }
} }
}
static void
setup_im (GtkXIMInfo *info, GdkWindow *window)
{
XIMValuesList *ic_values = NULL;
int i;
GdkScreen *screen = gdk_drawable_get_screen (window);
XGetIMValues (info->im,
XNQueryInputStyle, &info->xim_styles,
XNQueryICValuesList, &ic_values,
NULL);
info->settings = gtk_settings_get_for_screen (screen);
if (!g_object_class_find_property (G_OBJECT_GET_CLASS (info->settings),
"gtk-im-preedit-style"))
gtk_settings_install_property (g_param_spec_enum ("gtk-im-preedit-style",
_("IM Preedit style"),
_("How to draw the input method preedit string"),
GTK_TYPE_IM_PREEDIT_STYLE,
GTK_IM_PREEDIT_CALLBACK,
G_PARAM_READWRITE));
if (!g_object_class_find_property (G_OBJECT_GET_CLASS (info->settings),
"gtk-im-status-style"))
gtk_settings_install_property (g_param_spec_enum ("gtk-im-status-style",
_("IM Status style"),
_("How to draw the input method statusbar"),
GTK_TYPE_IM_STATUS_STYLE,
GTK_IM_STATUS_CALLBACK,
G_PARAM_READWRITE));
status_style_change (info);
preedit_style_change (info);
#if 0 #if 0
if (ic_values) if (ic_values)
@ -232,19 +281,18 @@ setup_im (GtkXIMInfo *info)
} }
#endif #endif
if (xim_styles)
XFree (xim_styles);
if (ic_values) if (ic_values)
XFree (ic_values); XFree (ic_values);
} }
static GtkXIMInfo * static GtkXIMInfo *
get_im (GdkDisplay *display, get_im (GdkWindow *client_window,
const char *locale) const char *locale)
{ {
GSList *tmp_list; GSList *tmp_list;
GtkXIMInfo *info; GtkXIMInfo *info;
XIM im = NULL; XIM im = NULL;
GdkDisplay *display = gdk_drawable_get_display (client_window);
tmp_list = open_ims; tmp_list = open_ims;
while (tmp_list) while (tmp_list)
@ -277,9 +325,14 @@ get_im (GdkDisplay *display,
info->display = display; info->display = display;
info->locale = g_strdup (locale); info->locale = g_strdup (locale);
info->im = im; info->im = im;
info->set_style = TRUE; info->xim_styles = NULL;
info->preedit_style_setting = 0;
info->status_style_setting = 0;
info->settings = 0;
info->preedit_set = 0;
info->status_set = 0;
setup_im (info); setup_im (info, client_window);
} }
} }
@ -304,21 +357,6 @@ gtk_im_context_xim_class_init (GtkIMContextXIMClass *class)
im_context_class->set_use_preedit = gtk_im_context_xim_set_use_preedit; im_context_class->set_use_preedit = gtk_im_context_xim_set_use_preedit;
gobject_class->finalize = gtk_im_context_xim_finalize; gobject_class->finalize = gtk_im_context_xim_finalize;
gtk_settings_install_property (g_param_spec_enum ("gtk-im-preedit-style",
_("IM Preedit style"),
_("How to draw the input method preedit string"),
GTK_TYPE_IM_PREEDIT_STYLE,
GTK_IM_PREEDIT_CALLBACK,
G_PARAM_READWRITE));
gtk_settings_install_property (g_param_spec_enum ("gtk-im-status-style",
_("IM Status style"),
_("How to draw the input method statusbar"),
GTK_TYPE_IM_STATUS_STYLE,
GTK_IM_STATUS_CALLBACK,
G_PARAM_READWRITE));
} }
static void static void
@ -338,6 +376,16 @@ gtk_im_context_xim_finalize (GObject *obj)
XDestroyIC (context_xim->ic); XDestroyIC (context_xim->ic);
context_xim->ic = NULL; context_xim->ic = NULL;
} }
if (context_xim->im_info)
{
GtkXIMInfo *info = context_xim->im_info;
XFree (info->xim_styles->supported_styles);
XFree (info->xim_styles);
g_free (info->locale);
g_signal_handler_disconnect (info->settings, info->status_set);
g_signal_handler_disconnect (info->settings, info->preedit_set);
XCloseIM (info->im);
}
g_free (context_xim->locale); g_free (context_xim->locale);
g_free (context_xim->mb_charset); g_free (context_xim->mb_charset);
@ -369,7 +417,7 @@ gtk_im_context_xim_set_client_window (GtkIMContext *context,
context_xim->client_window = client_window; context_xim->client_window = client_window;
if (context_xim->client_window) if (context_xim->client_window)
context_xim->im_info = get_im (gdk_drawable_get_display (context_xim->client_window), context_xim->locale); context_xim->im_info = get_im (context_xim->client_window, context_xim->locale);
else else
context_xim->im_info = NULL; context_xim->im_info = NULL;
} }
@ -923,16 +971,8 @@ status_draw_callback (XIC xic,
} }
} }
static XIC static XVaNestedList
get_ic_with_preedit (GtkIMContextXIM *context_xim) set_preedit_callback (GtkIMContextXIM *context_xim)
{
XIC xic = 0;
const char *name1 = NULL;
XVaNestedList list1 = NULL;
const char *name2 = NULL;
XVaNestedList list2 = NULL;
if ((context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditCallbacks)
{ {
context_xim->preedit_start_callback.client_data = (XPointer)context_xim; context_xim->preedit_start_callback.client_data = (XPointer)context_xim;
context_xim->preedit_start_callback.callback = (XIMProc)preedit_start_callback; context_xim->preedit_start_callback.callback = (XIMProc)preedit_start_callback;
@ -942,8 +982,7 @@ get_ic_with_preedit (GtkIMContextXIM *context_xim)
context_xim->preedit_draw_callback.callback = (XIMProc)preedit_draw_callback; context_xim->preedit_draw_callback.callback = (XIMProc)preedit_draw_callback;
context_xim->preedit_caret_callback.client_data = (XPointer)context_xim; context_xim->preedit_caret_callback.client_data = (XPointer)context_xim;
context_xim->preedit_caret_callback.callback = (XIMProc)preedit_caret_callback; context_xim->preedit_caret_callback.callback = (XIMProc)preedit_caret_callback;
name1 = XNPreeditAttributes; return XVaCreateNestedList (0,
list1 = XVaCreateNestedList (0,
XNPreeditStartCallback, &context_xim->preedit_start_callback, XNPreeditStartCallback, &context_xim->preedit_start_callback,
XNPreeditDoneCallback, &context_xim->preedit_done_callback, XNPreeditDoneCallback, &context_xim->preedit_done_callback,
XNPreeditDrawCallback, &context_xim->preedit_draw_callback, XNPreeditDrawCallback, &context_xim->preedit_draw_callback,
@ -951,10 +990,9 @@ get_ic_with_preedit (GtkIMContextXIM *context_xim)
NULL); NULL);
} }
if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusCallbacks) static XVaNestedList
set_status_callback (GtkIMContextXIM *context_xim)
{ {
XVaNestedList status_attrs;
context_xim->status_start_callback.client_data = (XPointer)context_xim; context_xim->status_start_callback.client_data = (XPointer)context_xim;
context_xim->status_start_callback.callback = (XIMProc)status_start_callback; context_xim->status_start_callback.callback = (XIMProc)status_start_callback;
context_xim->status_done_callback.client_data = (XPointer)context_xim; context_xim->status_done_callback.client_data = (XPointer)context_xim;
@ -962,25 +1000,52 @@ get_ic_with_preedit (GtkIMContextXIM *context_xim)
context_xim->status_draw_callback.client_data = (XPointer)context_xim; context_xim->status_draw_callback.client_data = (XPointer)context_xim;
context_xim->status_draw_callback.callback = (XIMProc)status_draw_callback; context_xim->status_draw_callback.callback = (XIMProc)status_draw_callback;
status_attrs = XVaCreateNestedList (0, return XVaCreateNestedList (0,
XNStatusStartCallback, &context_xim->status_start_callback, XNStatusStartCallback, &context_xim->status_start_callback,
XNStatusDoneCallback, &context_xim->status_done_callback, XNStatusDoneCallback, &context_xim->status_done_callback,
XNStatusDrawCallback, &context_xim->status_draw_callback, XNStatusDrawCallback, &context_xim->status_draw_callback,
NULL); NULL);
}
static XIC
get_ic_real (GtkIMContextXIM *context_xim)
{
XIC xic = 0;
const char *name1 = NULL;
XVaNestedList list1 = NULL;
const char *name2 = NULL;
XVaNestedList list2 = NULL;
XIMStyle im_style = 0;
if (context_xim->use_preedit &&
(context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditCallbacks)
{
im_style |= XIMPreeditCallbacks;
name1 = XNPreeditAttributes;
list1 = set_preedit_callback (context_xim);
}
else
im_style |= XIMPreeditNothing;
if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusCallbacks)
{
im_style |= XIMStatusCallbacks;
if (name1 == NULL) if (name1 == NULL)
{ {
name1 = XNStatusAttributes; name1 = XNStatusAttributes;
list1 = status_attrs; list1 = set_status_callback (context_xim);
} }
else else
{ {
name2 = XNStatusAttributes; name2 = XNStatusAttributes;
list2 = status_attrs; list2 = set_status_callback (context_xim);
} }
} }
else
im_style |= XIMStatusNothing;
xic = XCreateIC (context_xim->im_info->im, xic = XCreateIC (context_xim->im_info->im,
XNInputStyle, context_xim->im_info->style, XNInputStyle, im_style,
XNClientWindow, GDK_DRAWABLE_XID (context_xim->client_window), XNClientWindow, GDK_DRAWABLE_XID (context_xim->client_window),
name1, list1, name1, list1,
name2, list2, name2, list2,
@ -990,29 +1055,7 @@ get_ic_with_preedit (GtkIMContextXIM *context_xim)
if (list2) if (list2)
XFree (list2); XFree (list2);
return xic; if (xic)
}
static XIC
get_ic_without_preedit (GtkIMContextXIM *context_xim)
{
return XCreateIC (context_xim->im_info->im,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, GDK_DRAWABLE_XID (context_xim->client_window),
NULL);
}
static XIC
gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
{
if (!context_xim->ic && context_xim->im_info)
{
if (!context_xim->use_preedit)
context_xim->ic = get_ic_without_preedit (context_xim);
else
context_xim->ic = get_ic_with_preedit (context_xim);
if (context_xim->ic)
{ {
/* Don't filter key released events with XFilterEvents unless /* Don't filter key released events with XFilterEvents unless
* input methods ask for. This is a workaround for Solaris input * input methods ask for. This is a workaround for Solaris input
@ -1026,6 +1069,38 @@ gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
NULL); NULL);
context_xim->filter_key_release = (mask & KeyReleaseMask); context_xim->filter_key_release = (mask & KeyReleaseMask);
} }
return xic;
}
static XIC
gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
{
if (!context_xim->ic && context_xim->im_info)
{
context_xim->ic = get_ic_real (context_xim);
/*
* connect property-notify signal handlers to respond runtime
* changes of status_style and preedit_style in the settings
*/
if (context_xim->im_info->settings)
{
GtkXIMInfo *info = context_xim->im_info;
if (info->status_set)
g_signal_handler_disconnect (info->settings, info->status_set);
if (info->preedit_set)
g_signal_handler_disconnect (info->settings, info->preedit_set);
info->status_set = g_signal_connect_swapped (info->settings,
"notify::gtk-im-status-style",
G_CALLBACK (status_style_change_notify),
context_xim);
info->preedit_set = g_signal_connect_swapped (info->settings,
"notify::gtk-im-preedit-style",
G_CALLBACK (preedit_style_change_notify),
context_xim);
}
} }
return context_xim->ic; return context_xim->ic;
} }
@ -1192,7 +1267,8 @@ status_window_show (GtkIMContextXIM *context_xim)
context_xim->status_visible = TRUE; context_xim->status_visible = TRUE;
if (status_window && status_window_has_text (status_window)) if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusCallbacks &&
status_window && status_window_has_text (status_window))
gtk_widget_show (status_window); gtk_widget_show (status_window);
} }