--- rxvt-unicode-9.12.orig/README.gcin
+++ rxvt-unicode-9.12/README.gcin
@@ -0,0 +1 @@
+./configure --disable-xim
--- rxvt-unicode-9.12.orig/src/Makefile.in
+++ rxvt-unicode-9.12/src/Makefile.in
@@ -17,8 +17,8 @@
 CXXFLAGS = @CXXFLAGS@
 CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
-DEFS = @DEFS@
-LIBS = @LIBS@
+DEFS = @DEFS@ -DUSE_GCIN -DUNIX=1
+LIBS = @LIBS@ -lgcin-im-client
 XINC = @X_CFLAGS@ @AFTERIMAGE_CFLAGS@ @PIXBUF_CFLAGS@
 XLIB = @X_LIBS@ @AFTERIMAGE_LIBS@ -lX11 @X_EXTRA_LIBS@ @PIXBUF_LIBS@
 COMPILE = $(CXX) -I.. -I$(srcdir) -I. -I$(srcdir)/../libev -I$(srcdir)/../libptytty/src -I$(srcdir)/../libecb $(DEFS) $(CPPFLAGS) $(CXXFLAGS) $(XINC)
--- rxvt-unicode-9.12.orig/src/command.C
+++ rxvt-unicode-9.12/src/command.C
@@ -475,6 +475,36 @@
       valid_keysym = status_return == XLookupKeySym
                      || status_return == XLookupBoth;
     }
+#endif
+#ifdef USE_GCIN
+  if (Gcin_Handle)
+    {
+      char *rstr = NULL;
+      len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
+      //      valid_keysym = 1;
+      valid_keysym = keysym != NoSymbol;
+      if (gcin_im_client_forward_key_press (Gcin_Handle, keysym, ev.state, &rstr))
+	{
+	  if (rstr)
+	    {
+	      len = strlen (rstr);
+	      strncpy (kbuf, rstr, len);
+	      kbuf[len] = '\0';
+	      keysym = ' ';
+	      shft = ctrl = meta = 0;
+	    }
+	  else
+	    {
+#if 0
+	      len = 0;
+	      valid_keysym = 0;
+#endif
+	      return;
+	    }
+	}
+      if (rstr)
+	free (rstr);
+    }
   else
 #endif
     {
@@ -859,10 +889,13 @@
 void
 rxvt_term::key_release (XKeyEvent &ev)
 {
-#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
+#ifdef USE_GCIN
   KeySym keysym;
 
   keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
+  char *rstr = NULL;
+  gcin_im_client_forward_key_release (Gcin_Handle, keysym, ev.state, &rstr);
+  free (rstr);
 #endif
 
 #if ENABLE_FRILLS || ISO_14755
@@ -988,7 +1021,7 @@
 
       scr_refresh ();
       scrollBar.show (1);
-#ifdef USE_XIM
+#ifdef USE_GCIN
       IMSendSpot ();
 #endif
     }
@@ -1742,6 +1775,15 @@
           XSetICFocus (Input_Context);
         }
 #endif
+#ifdef USE_GCIN
+      if (Gcin_Handle != NULL)
+	{
+#if 0
+	  IMSetPosition ();
+#endif
+	  gcin_im_client_focus_in(Gcin_Handle);
+	}
+#endif
 #if CURSOR_BLINK
       if (option (Opt_cursorBlink))
         cursor_blink_ev.again ();
@@ -1787,6 +1829,10 @@
       if (Input_Context != NULL)
         XUnsetICFocus (Input_Context);
 #endif
+#ifdef USE_GCIN
+      if (Gcin_Handle != NULL)
+	gcin_im_client_focus_out(Gcin_Handle);
+#endif
 #if CURSOR_BLINK
       if (option (Opt_cursorBlink))
         cursor_blink_ev.stop ();
--- rxvt-unicode-9.12.orig/src/init.C
+++ rxvt-unicode-9.12/src/init.C
@@ -1011,7 +1011,7 @@
 {
   set_environ (envv);
 
-#ifdef USE_XIM
+#ifdef USE_GCIN
   if (!locale)
     rxvt_warn ("setting locale failed, working without locale support.\n");
   else
@@ -1525,7 +1525,7 @@
 
   XSelectInput (dpy, top,
                 KeyPressMask
-#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ENABLE_FRILLS || ISO_14755
+#ifdef USE_GCIN
                 | KeyReleaseMask
 #endif
                 | FocusChangeMask | VisibilityChangeMask
@@ -1656,6 +1656,9 @@
                 if ((*t)->pty->pty > 2) close ((*t)->pty->pty);
                 if ((*t)->pty->tty > 2) close ((*t)->pty->tty);
               }
+#ifdef USE_GCIN
+	    close (Gcin_Handle->fd);
+#endif
 
             run_child (argv);
             fprintf (stderr, "%s: unable to exec child.", RESNAME);
--- rxvt-unicode-9.12.orig/src/main.C
+++ rxvt-unicode-9.12/src/main.C
@@ -176,7 +176,7 @@
   rootwin_ev.set          <rxvt_term, &rxvt_term::rootwin_cb> (this),
 #endif
   scrollbar_ev.set        <rxvt_term, &rxvt_term::x_cb>       (this),
-#ifdef USE_XIM
+#ifdef USE_GCIN
   im_ev.set               <rxvt_term, &rxvt_term::im_cb>      (this),
 #endif
 #ifdef POINTER_BLANK
@@ -314,7 +314,7 @@
 
   if (display)
     {
-#if USE_XIM
+#ifdef USE_GCIN
       im_ev.stop (display);
 #endif
       scrollbar_ev.stop (display);
@@ -1114,7 +1114,7 @@
 /* -------------------------------------------------------------------- *
  * -                      X INPUT METHOD ROUTINES                     - *
  * -------------------------------------------------------------------- */
-#ifdef USE_XIM
+#ifdef USE_GCIN
 
 void
 rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
@@ -1157,6 +1157,11 @@
   Window win;
   char server[IMBUFSIZ];
 
+#ifdef USE_GCIN
+  if (Gcin_Handle)
+    return True;
+#endif
+#ifdef USE_XIM
   /* get current locale modifier */
   if (char *p = XSetLocaleModifiers (0))
     {
@@ -1172,6 +1177,7 @@
       if (win != None)
         return true;
     }
+#endif
 
   return false;
 }
@@ -1182,9 +1188,7 @@
   XPoint nspot;
   XVaNestedList preedit_attr;
 
-  if (!Input_Context
-      || !focus
-      || !(input_style & (XIMPreeditPosition | XIMPreeditCallbacks)))
+  if (!focus || !Gcin_Handle)
     return;
 
   im_set_position (nspot);
@@ -1194,11 +1198,13 @@
 
   spot = nspot;
 
-  preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
-  XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
-  XFree (preedit_attr);
+#ifdef USE_GCIN
+  if (Gcin_Handle)
+      gcin_im_client_set_cursor_location(Gcin_Handle, nspot.x, nspot.y);
+#endif
 }
 
+#ifdef USE_XIM
 void
 rxvt_term::im_destroy ()
 {
@@ -1213,6 +1219,7 @@
 
   Input_Context = 0;
 }
+#endif
 
 #ifdef ENABLE_XIM_ONTHESPOT
 
@@ -1295,6 +1302,10 @@
 bool
 rxvt_term::IM_get_IC (const char *modifiers)
 {
+#ifdef USE_GCIN
+  Gcin_Handle = gcin_im_client_open(display->dpy);
+  gcin_im_client_set_window(Gcin_Handle, parent);
+#else
   int i, j, found;
   XIM xim;
   XPoint spot;
@@ -1503,6 +1514,7 @@
 #endif
 
   IMSetPosition ();
+#endif
 
   return true;
 }
@@ -1510,6 +1522,7 @@
 void
 rxvt_term::im_cb ()
 {
+#ifdef USE_XIM
   int i;
   const char *p;
   char **s;
@@ -1553,6 +1566,7 @@
       if (found)
         goto done;
     }
+#endif
 
   /* try with XMODIFIERS env. var. */
   if (IM_get_IC (""))
@@ -1569,6 +1583,7 @@
 #endif
 }
 
+#ifdef USE_XIM
 void
 rxvt_term::IMSetPosition ()
 {
@@ -1612,6 +1627,7 @@
 
    XFree (preedit_attr);
 }
+#endif
 #endif /* USE_XIM */
 
 void
--- rxvt-unicode-9.12.orig/src/rxvt.h
+++ rxvt-unicode-9.12/src/rxvt.h
@@ -90,6 +90,10 @@
 # define HAVE_BG_PIXMAP 1
 #endif
 
+#ifdef USE_GCIN
+#include <gcin-im-client.h>
+#endif
+
 #include "encoding.h"
 #include "rxvtutil.h"
 #include "rxvtfont.h"
@@ -1334,6 +1338,8 @@
   rxvt_xim *input_method;
   XIC      Input_Context;
   XIMStyle input_style;
+#endif
+#ifdef USE_GCIN
   XPoint   spot; // most recently sent spot position
 
   void im_destroy ();
@@ -1348,6 +1354,9 @@
   bool IM_get_IC (const char *modifiers);
   void IMSetPosition ();
 #endif
+#ifdef USE_GCIN
+  GCIN_client_handle *Gcin_Handle;
+#endif
 
   // command.C
   void key_press (XKeyEvent &ev);
--- rxvt-unicode-9.12.orig/src/rxvttoolkit.C
+++ rxvt-unicode-9.12/src/rxvttoolkit.C
@@ -64,8 +64,10 @@
   "_NET_WM_PING",
   "_NET_WM_ICON",
 #endif
-#if USE_XIM
+#ifdef USE_GCIN
   "WM_LOCALE_NAME",
+#endif
+#ifdef USE_XIM
   "XIM_SERVERS",
 #endif
 #ifdef ENABLE_TRANSPARENCY
@@ -520,13 +522,15 @@
   XCloseDisplay (dpy);
 }
 
-#ifdef USE_XIM
+#ifdef USE_GCIN
 void rxvt_display::im_change_cb ()
 {
   for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
     (*i)->call ();
 }
+#endif
 
+#ifdef USE_XIM
 void rxvt_display::im_change_check ()
 {
   // try to only call im_change_cb when a new input method
@@ -625,7 +629,7 @@
   cur_owner = owner;
 }
 
-#ifdef USE_XIM
+#ifdef USE_GCIN
 
 void rxvt_display::reg (im_watcher *w)
 {
@@ -636,7 +640,9 @@
 {
   imw.erase (find (imw.begin (), imw.end (), w));
 }
+#endif
 
+#ifdef USE_XIM
 rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers)
 {
   char *id;
--- rxvt-unicode-9.12.orig/src/rxvttoolkit.h
+++ rxvt-unicode-9.12/src/rxvttoolkit.h
@@ -64,8 +64,10 @@
   XA_NET_WM_PING,
   XA_NET_WM_ICON,
 #endif
-#if USE_XIM
+#ifdef USE_GCIN
   XA_WM_LOCALE_NAME,
+#endif
+#ifdef USE_XIM
   XA_XIM_SERVERS,
 #endif
 #if ENABLE_TRANSPARENCY
@@ -227,9 +229,13 @@
 
 #ifdef USE_XIM
   refcache<rxvt_xim> xims;
+#endif
+#ifdef USE_GCIN
   vector<im_watcher *> imw;
 
   void im_change_cb ();
+#endif
+#ifdef USE_XIM
   void im_change_check ();
 #endif
 
@@ -262,16 +268,18 @@
   void reg (xevent_watcher *w);
   void unreg (xevent_watcher *w);
 
-#ifdef USE_XIM
+#ifdef USE_GCIN
   void reg (im_watcher *w);
   void unreg (im_watcher *w);
+#endif
 
+#ifdef USE_XIM
   rxvt_xim *get_xim (const char *locale, const char *modifiers);
   void put_xim (rxvt_xim *xim);
 #endif
 };
 
-#ifdef USE_XIM
+#ifdef USE_GCIN
 struct im_watcher : rxvt_watcher, callback<void (void)>
 {
   void start (rxvt_display *display)
--- rxvt-unicode-9.12.orig/src/screen.C
+++ rxvt-unicode-9.12/src/screen.C
@@ -3543,7 +3543,7 @@
 }
 
 /* ------------------------------------------------------------------------- */
-#ifdef USE_XIM
+#ifdef USE_GCIN
 void
 rxvt_term::im_set_position (XPoint &pos) NOTHROW
 {
