Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add disable-w32-ime function to emacs with Windows GUI.
--- ./src/w32fns.c.orig 2015-04-02 16:23:06.000000000 +0900
+++ ./src/w32fns.c 2015-04-11 07:30:51.510841300 +0900
@@ -89,6 +89,8 @@
extern const char *map_w32_filename (const char *, const char **);
extern char * w32_strerror (int error_no);
+static int ime_disabled = 0;
+
/* If non-NULL, a handle to a frame where to display the hourglass cursor. */
static HWND hourglass_hwnd = NULL;
@@ -169,6 +171,8 @@
DECLARE_HANDLE(HMONITOR);
#endif
+typedef HIMC (WINAPI * ImmAssociateContextEx_Proc) (IN HWND wnd, IN HIMC context, IN DWORD flags);
+
typedef BOOL (WINAPI * TrackMouseEvent_Proc)
(IN OUT LPTRACKMOUSEEVENT lpEventTrack);
typedef LONG (WINAPI * ImmGetCompositionString_Proc)
@@ -187,6 +191,8 @@
typedef BOOL (WINAPI * EnumDisplayMonitors_Proc)
(IN HDC hdc, IN RECT *rcClip, IN MonitorEnum_Proc fnEnum, IN LPARAM dwData);
+ImmAssociateContextEx_Proc associate_contextex_fn = NULL;
+
TrackMouseEvent_Proc track_mouse_event_fn = NULL;
ImmGetCompositionString_Proc get_composition_string_fn = NULL;
ImmGetContext_Proc get_ime_context_fn = NULL;
@@ -3281,7 +3287,7 @@
set_ime_composition_window_fn (context, &form);
release_ime_context_fn (hwnd, context);
}
- break;
+ goto dflt;
case WM_IME_ENDCOMPOSITION:
ignore_ime_char = 0;
@@ -3772,6 +3778,11 @@
goto dflt;
case WM_SETFOCUS:
+ if (ime_disabled)
+ associate_contextex_fn (hwnd, 0, 0);
+ else
+ associate_contextex_fn (hwnd, 0, IACE_DEFAULT);
+
dpyinfo->faked_key = 0;
reset_modifiers ();
register_hot_keys (hwnd);
@@ -4075,6 +4086,10 @@
my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
return 1;
+ case WM_EMACS_IMM_ASSOCIATE_CONTEXT:
+ associate_contextex_fn (hwnd, 0, lParam);
+ break;
+
default:
/* Check for messages registered at runtime. */
if (msg == msh_mousewheel)
@@ -6894,6 +6909,47 @@
#endif /* WINDOWSNT */
+DEFUN ("disable-w32-ime", Fdisable_w32_ime, Sdisable_w32_ime,
+ 0, 0, "", doc: /* Disable W32 IME. */)
+ (void)
+{
+ struct frame *f = SELECTED_FRAME ();
+
+ if (f)
+ {
+ SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_IMM_ASSOCIATE_CONTEXT,
+ (WPARAM) 0, (LPARAM) 0);
+ ime_disabled = 1;
+ }
+
+ return Qnil;
+}
+
+DEFUN ("enable-w32-ime", Fenable_w32_ime, Senable_w32_ime,
+ 0, 0, "", doc: /* Enable W32 IME. */)
+ (void)
+{
+ struct frame *f = SELECTED_FRAME ();
+
+ if (f)
+ {
+ SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_IMM_ASSOCIATE_CONTEXT,
+ (WPARAM) 0, (LPARAM) IACE_DEFAULT);
+ ime_disabled = 0;
+ }
+
+ return Qnil;
+}
+DEFUN ("w32-ime-disabled-p", Fw32_ime_disabled_p, Sw32_ime_disabled_p,
+ 0, 0, 0, doc: /* Return t if W32 IME is disabled. */)
+ (void)
+{
+ if (ime_disabled)
+ return Qt;
+ else
+ return Qnil;
+}
+
/***********************************************************************
w32 specialized functions
***********************************************************************/
@@ -8435,6 +8491,10 @@
/* W32 specific functions */
+ defsubr (&Sdisable_w32_ime);
+ defsubr (&Senable_w32_ime);
+ defsubr (&Sw32_ime_disabled_p);
+
defsubr (&Sw32_define_rgb_color);
defsubr (&Sw32_default_color_map);
defsubr (&Sw32_display_monitor_attributes_list);
@@ -8646,6 +8706,11 @@
globals_of_w32fns (void)
{
HMODULE user32_lib = GetModuleHandle ("user32.dll");
+ {
+ HMODULE imm32_lib = GetModuleHandle ("imm32.dll");
+ associate_contextex_fn = (ImmAssociateContextEx_Proc)
+ GetProcAddress (imm32_lib, "ImmAssociateContextEx");
+ }
/*
TrackMouseEvent not available in all versions of Windows, so must load
it dynamically. Do it once, here, instead of every time it is used.
--- ./src/w32term.h.orig 2015-04-02 16:23:06.000000000 +0900
+++ ./src/w32term.h 2015-04-11 07:30:51.520839100 +0900
@@ -578,6 +578,8 @@
#define UNICODE_NOCHAR 0xFFFF
#endif
+#define WM_EMACS_IMM_ASSOCIATE_CONTEXT (WM_USER+2400)
+
#define WM_EMACS_START (WM_USER + 1)
#define WM_EMACS_KILL (WM_EMACS_START + 0)
#define WM_EMACS_CREATEWINDOW (WM_EMACS_START + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.