[uim-commit] r1342 - trunk/fep

yamamoto at freedesktop.org yamamoto at freedesktop.org
Sun Aug 28 00:23:26 PDT 2005


Author: yamamoto
Date: 2005-08-28 00:23:23 -0700 (Sun, 28 Aug 2005)
New Revision: 1342

Added:
   trunk/fep/helper.c
   trunk/fep/helper.h
Modified:
   trunk/fep/Makefile.am
   trunk/fep/README.ja
   trunk/fep/callbacks.c
   trunk/fep/callbacks.h
   trunk/fep/uim-fep-tick.c
   trunk/fep/uim-fep.c
   trunk/fep/uim-fep.h
Log:
* fep/uim-fep.c
  (g_context) : New global variable renamed from
    s_context.
  (main_loop) :
    Don't call draw() if the return value of press_key
      indicates there is no need to draw.
    Call focus_in when any key is pressed.
    Add helper handling code.
  (main) : Call init_helper().
  (done) : Call quit_helper().

* fep/callbacks.c
  (init_callbacks) : Remove 1st parameter.
  (press_key) : Change return type to int *.
  (START_CALLBACKS) : New macro.
  (end_callbacks) : Change return type to int.
  (activate_cb, select_cb, shift_page_cb, deactivate_cb, commit_cb,
    clear_cb, pushback_cb, mode_update_cb) : Call START_CALLBACKS first.

* helper.c : New file.

* helper.h : New file.

* Makefile.am : Add helper.c and helper.h to uim_fep_SOURCES.




Modified: trunk/fep/Makefile.am
===================================================================
--- trunk/fep/Makefile.am	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/Makefile.am	2005-08-28 07:23:23 UTC (rev 1342)
@@ -5,7 +5,7 @@
 
 bin_PROGRAMS = uim-fep uim-fep-tick
 
-uim_fep_SOURCES = uim-fep.c uim-fep.h udsock.c udsock.h str.c str.h callbacks.c callbacks.h draw.c draw.h escseq.c escseq.h key.c key.h read.c read.h
+uim_fep_SOURCES = uim-fep.c uim-fep.h udsock.c udsock.h str.c str.h callbacks.c callbacks.h draw.c draw.h escseq.c escseq.h key.c key.h read.c read.h helper.c helper.h
 uim_fep_CPPFLAGS = -I$(top_srcdir)
 uim_fep_CFLAGS =
 uim_fep_LDADD = $(top_builddir)/uim/libuim.la @FEP_LIBADD@

Modified: trunk/fep/README.ja
===================================================================
--- trunk/fep/README.ja	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/README.ja	2005-08-28 07:23:23 UTC (rev 1342)
@@ -175,6 +175,13 @@
     ¤Ë¤Ê¤ê¤Þ¤¹¡£
     ($TMP¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï/tmp¤¬»È¤ï¤ì¤ë)
 
+  o -f str
+    $UIM_FEP_SETMODE¤È$UIM_FEP_GETMODE¤Î¥Õ¥¡¥¤¥ë̾¤ò
+    uim-fep-setmode-{str}
+    uim-fep-setmode-{str}
+    ¤Ë¤·¤Þ¤¹¡£{str}¤Ï-f¥ª¥×¥·¥ç¥ó¤Î°ú¿ô¤Ç¤¹¡£
+    UIM_FEP_SETMODE¤ÈUIM_FEP_GETMODE¤¬ÃÖ¤«¤ì¤ë¥Ç¥£¥ì¥¯¥È¥ê¤Ï$TMP¤«
+    TMP¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð/tmp¤Ç¤¹¡£
 
   o -d
     ¸õÊä°ìÍ÷¤Îɽ¼¨¥¹¥¿¥¤¥ë¤òddskk¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£

Modified: trunk/fep/callbacks.c
===================================================================
--- trunk/fep/callbacks.c	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/callbacks.c	2005-08-28 07:23:23 UTC (rev 1342)
@@ -53,7 +53,6 @@
 #include "str.h"
 #include "callbacks.h"
 
-static uim_context s_context;
 /* ¥¹¥Æ¡¼¥¿¥¹¥é¥¤¥ó¤ÎºÇÂçÉý */
 static int s_max_width;
 static char *s_commit_str;
@@ -64,9 +63,8 @@
 static struct preedit_tag *s_preedit;
 static int s_mode;
 static char *s_nokori_str;
+static int s_start_callbacks = FALSE;
 
-static void start_callbacks(void);
-static void end_callbacks(void);
 static void activate_cb(void *ptr, int nr, int display_limit);
 static void select_cb(void *ptr, int index);
 static void shift_page_cb(void *ptr, int direction);
@@ -118,9 +116,8 @@
 /*
  * ½é´ü²½
  */
-void init_callbacks(uim_context context)
+void init_callbacks(void)
 {
-  s_context = context;
   s_max_width = g_win->ws_col;
   if (g_opt.statusline_width != UNDEFINED && g_opt.statusline_width <= s_max_width) {
     s_max_width = g_opt.statusline_width;
@@ -130,12 +127,12 @@
   s_statusline_str = strdup("");
   s_candidate_col = UNDEFINED;
   s_index_str = strdup("");
-  s_mode = uim_get_current_mode(s_context);
+  s_mode = uim_get_current_mode(g_context);
   s_preedit = create_preedit();
-  uim_set_preedit_cb(s_context, clear_cb, pushback_cb, update_cb);
-  uim_set_mode_cb(s_context, mode_update_cb);
+  uim_set_preedit_cb(g_context, clear_cb, pushback_cb, update_cb);
+  uim_set_mode_cb(g_context, mode_update_cb);
   if (g_opt.status_type != NONE) {
-    uim_set_candidate_selector_cb(s_context, activate_cb, select_cb, shift_page_cb, deactivate_cb);
+    uim_set_candidate_selector_cb(g_context, activate_cb, select_cb, shift_page_cb, deactivate_cb);
   }
 
   if (g_opt.ddskk) {
@@ -157,9 +154,9 @@
   }
 }
 
-int press_key(int key, int key_state)
+int *press_key(int key, int key_state)
 {
-  int raw;
+  static int raw_and_need_draw[2];
 #if defined DEBUG && DEBUG > 2
   if (32 <= key && key <= 127) {
     debug2(("press key = %c key_state = %d\n", key, key_state));
@@ -167,14 +164,21 @@
     debug2(("press key = %d key_state = %d\n", key, key_state));
   }
 #endif
-  start_callbacks();
-  raw = uim_press_key(s_context, key, key_state);
-  uim_release_key(s_context, key, key_state);
-  end_callbacks();
-  return raw;
+  raw_and_need_draw[0] = uim_press_key(g_context, key, key_state);
+  uim_release_key(g_context, key, key_state);
+  raw_and_need_draw[1] = end_callbacks();
+  return raw_and_need_draw;
 }
 
-static void start_callbacks(void)
+#define START_CALLBACKS                        \
+do {                                           \
+  if (!s_start_callbacks) {                    \
+    s_start_callbacks = TRUE;                  \
+    start_callbacks();                         \
+  }                                            \
+} while (FALSE)
+
+void start_callbacks(void)
 {
   debug2(("\n\nstart_callbacks()\n"));
   if (s_commit_str != NULL) {
@@ -194,12 +198,18 @@
     s_statusline_str = NULL;
   }
   s_candidate_col = UNDEFINED;
-  s_mode = uim_get_current_mode(s_context);
+  s_mode = uim_get_current_mode(g_context);
 }
 
-static void end_callbacks(void)
+int end_callbacks(void)
 {
   debug2(("end_callbacks()\n\n"));
+  if (!s_start_callbacks) {
+    return FALSE;
+  }
+
+  s_start_callbacks = FALSE;
+
   /* cursor¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¥×¥ê¥¨¥Ç¥£¥Ã¥È¤ÎËöÈø¤Ë¤¹¤ë */
   if (s_preedit->cursor == UNDEFINED) {
     s_preedit->cursor = s_preedit->width;
@@ -219,6 +229,8 @@
     s_candidate_col = UNDEFINED;
     s_index_str = strdup("");
   }
+
+  return TRUE;
 }
 
 /*
@@ -301,7 +313,7 @@
  */
 char *get_mode_str(void)
 {
-  char *mode_str = (char *)uim_get_mode_name(s_context, s_mode);
+  char *mode_str = (char *)uim_get_mode_name(g_context, s_mode);
   mode_str = strdup(mode_str != NULL ? mode_str : "");
   strhead(mode_str, s_max_width);
   return mode_str;
@@ -317,6 +329,7 @@
 static void activate_cb(void *ptr, int nr, int display_limit)
 {
   debug2(("activate_cb(nr = %d display_limit = %d)\n", nr, display_limit));
+  START_CALLBACKS;
   reset_candidate();
   s_candidate.nr = nr;
   s_candidate.limit = display_limit;
@@ -334,6 +347,7 @@
   debug2(("select_cb(index = %d)\n", index));
   return_if_fail(s_candidate.nr != UNDEFINED);
   return_if_fail(0 <= index && index < s_candidate.nr);
+  START_CALLBACKS;
   s_candidate.index = index;
   s_candidate.page = index2page(index);
 }
@@ -349,6 +363,7 @@
   int index;
   debug2(("shift_page_cb(direction = %d)\n", direction));
   return_if_fail(s_candidate.nr != UNDEFINED);
+  START_CALLBACKS;
   if (direction == 0) {
     direction = -1;
   }
@@ -357,7 +372,7 @@
   return_if_fail(0 <= index && index < s_candidate.nr);
   s_candidate.page = page;
   s_candidate.index = index;
-  uim_set_candidate_index(s_context, s_candidate.index);
+  uim_set_candidate_index(g_context, s_candidate.index);
 }
 
 /*
@@ -367,6 +382,7 @@
 static void deactivate_cb(void *ptr)
 {
   debug2(("deactivate_cb()\n"));
+  START_CALLBACKS;
   reset_candidate();
 }
 
@@ -375,12 +391,14 @@
 {
   debug2(("commit_cb(commit_str = \"%s\")\n", commit_str));
   return_if_fail(commit_str != NULL);
+  START_CALLBACKS;
   s_commit_str = realloc(s_commit_str, strlen(s_commit_str) + strlen(commit_str) + 1);
   strcat(s_commit_str, commit_str);
 }
 
 static void clear_cb(void *ptr)
 {
+  START_CALLBACKS;
   if (s_preedit != NULL) {
     free_preedit(s_preedit);
   }
@@ -399,6 +417,7 @@
   static int cursor = FALSE;
   debug2(("pushback_cb(attr = %d str = \"%s\")\n", attr, str));
   return_if_fail(str && s_preedit != NULL);
+  START_CALLBACKS;
   width = strwidth(str);
   /* UPreeditAttr_Cursor¤Î¤È¤­¤Ë¶õʸ»úÎó¤È¤Ï¸Â¤é¤Ê¤¤ */
   if (attr & UPreeditAttr_Cursor) {
@@ -457,6 +476,7 @@
 static void mode_update_cb(void *ptr, int mode)
 {
   debug2(("mode_update_cb(mode = %d)\n", mode));
+  START_CALLBACKS;
   s_mode = mode;
 }
 
@@ -538,7 +558,7 @@
     int next = FALSE;
     /* "[10/20]" ¤ÎÉý */
     int index_width;
-    uim_candidate cand = uim_get_candidate(s_context, index, index_in_page);
+    uim_candidate cand = uim_get_candidate(g_context, index, index_in_page);
     const char *cand_str_label = uim_candidate_get_heading_label(cand);
     char *cand_str_cand = tab2space(uim_candidate_get_cand_str(cand));
     int cand_label_width = strwidth(cand_str_label);
@@ -762,7 +782,7 @@
     s_candidate_str = strdup("");
     return;
   }
-  cand = uim_get_candidate(s_context, s_candidate.index, 0);
+  cand = uim_get_candidate(g_context, s_candidate.index, 0);
   if (uim_candidate_get_cand_str(cand) == NULL) {
     s_candidate_str = strdup("");
     s_candidate_col = UNDEFINED;

Modified: trunk/fep/callbacks.h
===================================================================
--- trunk/fep/callbacks.h	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/callbacks.h	2005-08-28 07:23:23 UTC (rev 1342)
@@ -50,8 +50,10 @@
   } *pseg;
 };
 
-void init_callbacks(uim_context context);
-int press_key(int key, int key_state);
+void init_callbacks(void);
+int* press_key(int key, int key_state);
+void start_callbacks(void);
+int end_callbacks(void);
 char *get_commit_str(void);
 char *get_statusline_str(void);
 char *get_candidate_str(void);

Added: trunk/fep/helper.c
===================================================================
--- trunk/fep/helper.c	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/helper.c	2005-08-28 07:23:23 UTC (rev 1342)
@@ -0,0 +1,255 @@
+/*
+
+  Copyright (c) 2003-2005 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifndef DEBUG
+#define NDEBUG
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include "uim-fep.h"
+#include "helper.h"
+#include "str.h"
+#include <uim/uim-helper.h>
+#include <uim/uim-util.h>
+#include <uim/uim-im-switcher.h>
+
+int g_focus_in = FALSE;
+int g_helper_fd = -1;
+
+static void helper_disconnected_cb(void);
+static void helper_handler_change_im(const char *str);
+static void send_im_list(void);
+static void prop_list_update_cb(void *ptr, const char *str);
+static void prop_label_update_cb(void *ptr, const char *str);
+
+void init_helper(void)
+{
+  g_helper_fd = uim_helper_init_client_fd(helper_disconnected_cb);
+  uim_set_prop_list_update_cb(g_context, prop_list_update_cb);
+  uim_set_prop_label_update_cb(g_context, prop_label_update_cb);
+}
+
+void quit_helper(void)
+{
+  if (g_helper_fd >= 0) {
+    uim_helper_close_client_fd(g_helper_fd);
+  }
+}
+
+static void helper_disconnected_cb(void)
+{
+  debug(("helper_disconnected_cb()\n"));
+  g_helper_fd = -1;
+}
+
+#define str_has_prefix(str, prefix) (strncmp((str), (prefix), strlen((prefix))) == 0)
+void helper_handler(void)
+{
+  char *message;
+  uim_helper_read_proc(g_helper_fd);
+
+  while ((message = uim_helper_get_message()) != NULL) {
+
+    if (str_has_prefix(message, "im_change")) {
+      debug(("im_change\n"));
+      helper_handler_change_im(message);
+
+    } else if (str_has_prefix(message, "prop_update_custom")) {
+      char *eol;
+      debug(("prop_update_custom\n"));
+      if ((eol = strchr(message, '\n')) != NULL) {
+        char *sym = eol + 1;
+        if ((eol = strchr(sym, '\n')) != NULL) {
+          char *value = eol + 1;
+          *eol = '\0';
+          if ((eol = strchr(value, '\n')) != NULL) {
+            *eol = '\0';
+            uim_prop_update_custom(g_context, sym, value);
+          }
+        }
+      }
+
+    } else if (str_has_prefix(message, "custom_reload_notify")) {
+      debug(("custom_reload_notify\n"));
+      uim_prop_reload_configs();
+
+    } else if (g_focus_in) {
+      if (str_has_prefix(message, "prop_list_get")) {
+        debug(("prop_list_get\n"));
+        uim_prop_list_update(g_context);
+
+      } else if (str_has_prefix(message, "prop_label_get")) {
+        debug(("prop_label_get\n"));
+        uim_prop_label_update(g_context);
+
+      } else if (str_has_prefix(message, "prop_activate")) {
+        char *eol;
+        debug(("prop_activate\n"));
+        if ((eol = strchr(message, '\n')) != NULL) {
+          char *menucommand_name = eol + 1;
+          if ((eol = strchr(menucommand_name, '\n')) != NULL) {
+            *eol = '\0';
+            uim_prop_activate(g_context, menucommand_name);
+          }
+        }
+
+      } else if (str_has_prefix(message, "im_list_get")) {
+        debug(("im_list_get\n"));
+        send_im_list();
+
+      } else if (str_has_prefix(message, "commit_string")) {
+        char *eol;
+        debug(("commit_string\n"));
+        if ((eol = strchr(message, '\n')) != NULL) {
+          char *commit_string = eol + 1;
+          if ((eol = strchr(commit_string, '\n')) != NULL) {
+            *eol = '\0';
+            commit_cb(NULL, commit_string);
+          }
+        }
+
+      } else if (str_has_prefix(message, "focus_in")) {
+        debug(("focus_in\n"));
+        g_focus_in = FALSE;
+        /* printf("focus_out\r\n"); */
+      }
+    }
+
+    free(message);
+  }
+}
+
+static void helper_handler_change_im(const char *str)
+{
+  if (str_has_prefix(str, "im_change_whole_desktop") ||
+      (g_focus_in && (
+        str_has_prefix(str, "im_change_this_text_area_only") ||
+        str_has_prefix(str, "im_change_this_application_only")))) {
+    char *eol;
+    if ((eol = strchr(str, '\n')) != NULL) {
+      char *imname = eol + 1;
+      if ((eol = strchr(imname, '\n')) != NULL) {
+        *eol = '\0';
+        uim_switch_im(g_context, imname);
+      }
+    }
+  }
+}
+
+static void send_im_list(void)
+{
+  int i;
+  int nr_im = uim_get_nr_im(g_context);
+  const char *current_im_name = uim_get_current_im_name(g_context);
+  const char *enc = get_enc();
+  char *message = malloc(strlen("im_list\ncharset=") + strlen(enc) + strlen("\n") + 1);
+  sprintf(message, "im_list\ncharset=%s\n", enc);
+
+  for (i = 0; i < nr_im; i++) {
+    const char *name = uim_get_im_name(g_context, i);
+    const char *langcode = uim_get_im_language(g_context, i);
+    const char *lang = uim_get_language_name_from_locale(langcode);
+    const char *short_desc = uim_get_im_short_desc(g_context, i);
+
+    char *im_str = malloc(strlen(name) + strlen("\t") +
+        (lang != NULL ? strlen(lang) : 0) + strlen("\t") +
+        (short_desc != NULL ? strlen(short_desc) : 0) + strlen("\t") +
+        (strcmp(name, current_im_name) == 0 ? strlen("selected") : 0) +
+        strlen("\n") + 1);
+
+    sprintf(im_str, "%s\t%s\t%s\t%s\n", name,
+        (lang != NULL ? lang : ""),
+        (short_desc != NULL ? short_desc : ""),
+        (strcmp(name, current_im_name) == 0 ? "selected" : ""));
+
+    message = realloc(message, strlen(message) + strlen(im_str) + 1);
+    strcat(message, im_str);
+  }
+  uim_helper_send_message(g_helper_fd, message);
+  free(message);
+}
+
+static void prop_list_update_cb(void *ptr, const char *str)
+{
+  const char *enc;
+  char *message_buf;
+
+  debug(("prop_list_update_cb\n"));
+  debug2(("str = %s", str));
+
+  if (!g_focus_in) {
+    return;
+  }
+
+  enc = get_enc();
+  message_buf = malloc(strlen("prop_list_update\ncharset=") + strlen(enc) + strlen("\n") + strlen(str) + 1);
+  sprintf(message_buf, "prop_list_update\ncharset=%s\n%s", enc, str);
+  uim_helper_send_message(g_helper_fd, message_buf);
+  free(message_buf);
+  debug(("prop_list_update_cb send message\n"));
+}
+
+static void prop_label_update_cb(void *ptr, const char *str)
+{
+  const char *enc;
+  char *message_buf;
+
+  debug(("prop_label_update_cb\n"));
+  debug2(("str = %s", str));
+
+  if (!g_focus_in) {
+    return;
+  }
+
+  enc = get_enc();
+  message_buf = malloc(strlen("prop_label_update\ncharset=") + strlen(enc) + strlen("\n") + strlen(str) + 1);
+  sprintf(message_buf, "prop_label_update\ncharset=%s\n%s", enc, str);
+  uim_helper_send_message(g_helper_fd, message_buf);
+  free(message_buf);
+  debug(("prop_label_update_cb send message\n"));
+}
+
+void focus_in(void)
+{
+  g_focus_in = TRUE;
+  uim_helper_client_focus_in(g_context);
+  uim_prop_list_update(g_context);
+  uim_prop_label_update(g_context);
+}

Added: trunk/fep/helper.h
===================================================================
--- trunk/fep/helper.h	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/helper.h	2005-08-28 07:23:23 UTC (rev 1342)
@@ -0,0 +1,46 @@
+/*
+
+  Copyright (c) 2003-2005 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+
+*/
+
+#ifndef HELPER_H
+#define HELPER_H
+
+extern int g_focus_in;
+extern int g_helper_fd;
+
+void init_helper(void);
+void quit_helper(void);
+void helper_handler(void);
+void focus_in(void);
+
+#endif
+

Modified: trunk/fep/uim-fep-tick.c
===================================================================
--- trunk/fep/uim-fep-tick.c	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/uim-fep-tick.c	2005-08-28 07:23:23 UTC (rev 1342)
@@ -45,7 +45,8 @@
 #include <unistd.h>
 #endif
 #include "udsock.h"
-#include "uim-fep.h"
+#define FALSE 0
+#define TRUE 1
 #define EOT 4
 #define BUFSIZE 600
 

Modified: trunk/fep/uim-fep.c
===================================================================
--- trunk/fep/uim-fep.c	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/uim-fep.c	2005-08-28 07:23:23 UTC (rev 1342)
@@ -53,7 +53,6 @@
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
-#include <uim/uim.h>
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
@@ -117,6 +116,7 @@
 #include "escseq.h"
 #include "key.h"
 #include "read.h"
+#include "helper.h"
 
 #define DEFAULT_STATUS LASTLINE
 
@@ -135,8 +135,8 @@
 int g_win_in = STDIN_FILENO;
 int g_win_out = STDOUT_FILENO;
 struct winsize *g_win;
+uim_context g_context;
 
-static uim_context s_context;
 /* µ¿»÷üËö¤Îmaster¤Î¥Õ¥¡¥¤¥ëµ­½Ò»Ò */
 static int s_master;
 /* µ¯Æ°»þ¤ÎüËö¾õÂÖ */
@@ -179,10 +179,10 @@
     printf("uim_init error\n");
     exit(EXIT_FAILURE);
   }
-  s_context = uim_create_context(NULL, get_enc(), NULL, engine, uim_iconv, commit_cb);
-  nr = uim_get_nr_im(s_context);
+  g_context = uim_create_context(NULL, get_enc(), NULL, engine, uim_iconv, commit_cb);
+  nr = uim_get_nr_im(g_context);
   for (i = 0; i < nr; i++) {
-    if (strcmp(engine, uim_get_im_name(s_context, i)) == 0) {
+    if (strcmp(engine, uim_get_im_name(g_context, i)) == 0) {
       break;
     }
   }
@@ -500,9 +500,10 @@
 
   init_uim(engine);
   if (gnu_screen) {
-    uim_set_mode(s_context, 1);
+    uim_set_mode(g_context, 1);
   }
-  init_callbacks(s_context);
+  init_helper();
+  init_callbacks();
   init_draw(s_master, s_path_getmode);
   init_escseq(&attr_uim);
   set_signal_handler();
@@ -721,6 +722,9 @@
       nfd = s_setmode_fd;
     }
   }
+  if (g_helper_fd > nfd) {
+    nfd = g_helper_fd;
+  }
   nfd++;
 
   while (TRUE) {
@@ -748,6 +752,9 @@
     if (s_setmode_fd >= 0) {
       FD_SET(s_setmode_fd, &fds);
     }
+    if (g_helper_fd >= 0) {
+      FD_SET(g_helper_fd, &fds);
+    }
     if (my_select(nfd, &fds, NULL) <= 0) {
       /* signal¤Ç³ä¤ê¹þ¤Þ¤ì¤¿¤È¤­¤Ë¤¯¤ë¡£select¤ÎÊÖ¤êÃͤÏ-1¤Çerrno==EINTR */
       continue;
@@ -773,10 +780,10 @@
         for (start = end; start > 0 && isdigit((unsigned char)buf[start - 1]); --start);
         buf[end + 1] = '\0';
         mode = atoi(&buf[start]);
-        if (mode != uim_get_current_mode(s_context)) {
+        if (mode != uim_get_current_mode(g_context)) {
           debug2(("mode change %d\n", mode));
-          uim_set_mode(s_context, mode);
-          callbacks_set_mode(uim_get_current_mode(s_context));
+          uim_set_mode(g_context, mode);
+          callbacks_set_mode(uim_get_current_mode(g_context));
           draw_statusline_restore();
         }
       }
@@ -786,6 +793,9 @@
     /* ¥­¡¼¥Ü¡¼¥É(stdin)¤«¤é¤ÎÆþÎÏ */
     if (FD_ISSET(g_win_in, &fds)) {
       int key_state = 0;
+      if (!g_focus_in) {
+        focus_in();
+      }
 
       if ((len = read_stdin(buf, sizeof(buf) - 1)) <= 0) {
         /* ¤³¤³¤Ë¤Ï¤³¤Ê¤¤¤È»×¤¦ */
@@ -848,8 +858,12 @@
           if (g_opt.print_key) {
             print_key(key, key_state);
           } else {
-            int raw = press_key(key, key_state);
-            draw();
+            int *raw_and_need_draw = press_key(key, key_state);
+            int raw = raw_and_need_draw[0];
+            int need_draw = raw_and_need_draw[1];
+            if (need_draw) {
+              draw();
+            }
             if (raw && !g_start_preedit) {
               if (key_state & UMod_Alt) {
                 write(s_master, buf + i - 1, key_len + 1);
@@ -895,6 +909,15 @@
         put_pty_str(buf, len);
       }
     }
+
+    if (g_helper_fd >= 0 && FD_ISSET(g_helper_fd, &fds)) {
+      int need_draw;
+      helper_handler();
+      need_draw = end_callbacks();
+      if (need_draw) {
+        draw();
+      }
+    }
   }
 }
 
@@ -1060,6 +1083,7 @@
 {
   uim_quit();
   quit_escseq();
+  quit_helper();
   if (g_opt.status_type == BACKTICK) {
     clear_backtick();
   }

Modified: trunk/fep/uim-fep.h
===================================================================
--- trunk/fep/uim-fep.h	2005-08-28 06:36:37 UTC (rev 1341)
+++ trunk/fep/uim-fep.h	2005-08-28 07:23:23 UTC (rev 1342)
@@ -34,12 +34,16 @@
 #ifndef UIM_FEP_H
 #define UIM_FEP_H
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 #ifdef HAVE_TERMIOS_H
 #include <termios.h>
 #endif
+#include <uim/uim.h>
 
 #define FALSE 0
 #define TRUE 1
@@ -76,6 +80,7 @@
 extern int g_win_in;
 extern int g_win_out;
 extern struct winsize *g_win;
+extern uim_context g_context;
 
 void done(int exit_value);
 



More information about the uim-commit mailing list