[uim-commit] r3155 - trunk/emacs
nosuke at freedesktop.org
nosuke at freedesktop.org
Thu Mar 2 11:17:28 PST 2006
Author: nosuke
Date: 2006-03-02 11:17:24 -0800 (Thu, 02 Mar 2006)
New Revision: 3155
Modified:
trunk/emacs/callback.c
trunk/emacs/callback.h
trunk/emacs/context.c
trunk/emacs/context.h
trunk/emacs/helper.c
trunk/emacs/helper.h
Log:
* Suppor new API for Context-originated IM switching of
other contexts
* emacs/callback.c
* emacs/callback.h
- Add switch_app_global_im_cb and switch_system_global_im_cb.
* emacs/helper.c
* emacs/helper.h
- Add helper_send_im_change_whole_desktop.
- Remove redundant function calls from helper_im_changed.
* emacs/context.c
* emacs/context.h
- Move method for burst-switching of the IM of contexts
from helper.c to new function (switch_context_im_all).
Modified: trunk/emacs/callback.c
===================================================================
--- trunk/emacs/callback.c 2006-03-02 18:50:49 UTC (rev 3154)
+++ trunk/emacs/callback.c 2006-03-02 19:17:24 UTC (rev 3155)
@@ -153,3 +153,20 @@
}
+
+void
+switch_app_global_im_cb(void *ptr, const char *name)
+{
+ helper_send_im_change_whole_desktop(name);
+}
+
+
+void
+switch_system_global_im_cb(void *ptr, const char *name)
+{
+ /* change default */
+ update_default_engine(name);
+
+ switch_context_im_all(name);
+}
+
Modified: trunk/emacs/callback.h
===================================================================
--- trunk/emacs/callback.h 2006-03-02 18:50:49 UTC (rev 3154)
+++ trunk/emacs/callback.h 2006-03-02 19:17:24 UTC (rev 3155)
@@ -51,6 +51,7 @@
#include "im.h"
#include "context.h"
#include "commit.h"
+#include "helper.h"
#include "helper-server.h"
#include "prop.h"
@@ -69,4 +70,7 @@
void configuration_changed_cb(void *ptr);
+void switch_app_global_im_cb(void *ptr, const char *name);
+void switch_system_global_im_cb(void *ptr, const char *name);
+
#endif
Modified: trunk/emacs/context.c
===================================================================
--- trunk/emacs/context.c 2006-03-02 18:50:49 UTC (rev 3154)
+++ trunk/emacs/context.c 2006-03-02 19:17:24 UTC (rev 3155)
@@ -139,8 +139,38 @@
}
+void
+switch_context_im_all(const char *im)
+{
+ char *quot_im_name;
+ uim_agent_context_list *ptr;
+ /* change default IM */
+ update_default_engine(im);
+ /* check focus state when change IM of current application */
+ quot_im_name = (char *)malloc(strlen(im) + 2);
+ quot_im_name[0] = '\'';
+ quot_im_name[1] = '\0';
+ strcat(quot_im_name, im);
+
+ if (agent_context_list_head)
+ /* update default IM name in libuim? should be called only one time? */
+ uim_prop_update_custom(agent_context_list_head->agent_context->context,
+ "custom-preserved-default-im-name",
+ quot_im_name);
+
+ for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
+ switch_context_im(ptr->agent_context, im);
+ }
+
+ free(quot_im_name);
+
+ if (current) uim_prop_list_update(current->context);
+}
+
+
+
uim_context
create_context(const char *encoding, uim_agent_context *ptr)
{
@@ -171,6 +201,11 @@
uim_set_configuration_changed_cb(context,
configuration_changed_cb);
+ uim_set_im_switch_request_cb(context,
+ switch_app_global_im_cb,
+ switch_system_global_im_cb);
+
+
return context;
}
Modified: trunk/emacs/context.h
===================================================================
--- trunk/emacs/context.h 2006-03-02 18:50:49 UTC (rev 3154)
+++ trunk/emacs/context.h 2006-03-02 19:17:24 UTC (rev 3155)
@@ -78,6 +78,7 @@
uim_agent_context *get_uim_agent_context(int id);
uim_agent_context *switch_context_im(uim_agent_context *ua, const char *im);
+void switch_context_im_all(const char *im);
int set_current_uim_agent_context(uim_agent_context *ua);
int clear_current_uim_agent_context(void);
Modified: trunk/emacs/helper.c
===================================================================
--- trunk/emacs/helper.c 2006-03-02 18:50:49 UTC (rev 3154)
+++ trunk/emacs/helper.c 2006-03-02 19:17:24 UTC (rev 3155)
@@ -76,6 +76,7 @@
buflen = snprintf(buf, len, HEADER_FORMAT, current->encoding);
+#undef HEADER_FORMAT
for (i = 0 ; i < uim_get_nr_im(current->context); i++) {
const char *name, *lang, *shortd;
@@ -103,59 +104,52 @@
}
+void
+helper_send_im_change_whole_desktop(const char *name)
+{
+ int len = 0;
+ char *buf;
+#define HEADER_FORMAT "im_change_this_application_only\n%s\n"
+
+ len += strlen(HEADER_FORMAT);
+ len += name ? strlen(name) : 0;
+
+ buf = (char *)malloc(sizeof(char) * len);
+
+ snprintf(buf, len, HEADER_FORMAT, name ? name : "");
+
+ uim_helper_send_message(helper_fd, buf);
+
+ free(buf);
+
+#undef HEADER_FORMAT
+}
+
+
void
helper_im_changed(char *request, char *engine_name)
{
- uim_agent_context_list *ptr;
debug_printf(DEBUG_NOTE, "helper_im_changed: %s\n", engine_name);
if (strcmp(request, "im_change_this_text_area_only") == 0) {
- if (current) {
- switch_context_im(current, engine_name);
- if(current->im) free(current->im);
- current->im = strdup(engine_name);
- uim_prop_list_update(current->context);
- }
+ if (current) switch_context_im(current, engine_name);
} else if (strcmp(request, "im_change_whole_desktop") == 0
|| strcmp(request, "im_change_this_application_only") == 0) {
- char *quot_engine_name;
-
/* change default */
update_default_engine(engine_name);
/* check focus state when change IM of current application */
- if (strcmp(request, "im_change_whole_desktop") == 0 || current) {
- quot_engine_name = (char *)malloc(strlen(engine_name) + 2);
- quot_engine_name[0] = '\'';
- quot_engine_name[1] = '\0';
- strcat(quot_engine_name, engine_name);
- for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
-
- switch_context_im(ptr->agent_context, engine_name);
-
- uim_prop_update_custom(ptr->agent_context->context,
- "custom-preserved-default-im-name",
- quot_engine_name);
-
- if (ptr->agent_context->im) free(ptr->agent_context->im);
- ptr->agent_context->im = strdup(engine_name);
-
- if (current && ptr->agent_context == current) {
- uim_prop_list_update(ptr->agent_context->context);
- }
- }
- free(quot_engine_name);
- }
+ if (strcmp(request, "im_change_whole_desktop") == 0 || current)
+ switch_context_im_all(engine_name);
}
}
-
/* handle messages from helper */
void
helper_handler(void)
Modified: trunk/emacs/helper.h
===================================================================
--- trunk/emacs/helper.h 2006-03-02 18:50:49 UTC (rev 3154)
+++ trunk/emacs/helper.h 2006-03-02 19:17:24 UTC (rev 3155)
@@ -52,6 +52,8 @@
#include "helper-server.h"
void helper_send_im_list(void);
+void helper_send_im_change_whole_desktop(const char *name);
+
void helper_im_changed(char *request, char *engine_name);
void helper_handler(void);
More information about the uim-commit
mailing list