unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: =?gb18030?B?QWxiZXJ0?= <georgealbert@qq.com>
To: =?gb18030?B?RWxpIFphcmV0c2tpaQ==?= <eliz@gnu.org>
Cc: =?gb18030?B?ZW1hY3MtZGV2ZWw=?= <emacs-devel@gnu.org>
Subject: =?gb18030?B?u9i4tKO6ILvYuLSjuiC72Li0o7ogu9i4tKO6ILvYuLSjuiBbUEFUQ0hdIEFkZCBJTUUgc3RhdHVzIGNoYW5nZSBzdXBwb3J0IG9uIHdpbmRvd3MgbmF0aXZlbHk=?=
Date: Mon, 13 Apr 2020 17:22:35 +0800	[thread overview]
Message-ID: <tencent_22993BA1802FA378CEB20839A9CEF3CA1C07@qq.com> (raw)
In-Reply-To: <tencent_D79D708E4624487D9CF7E510DF1507D8180A@qq.com>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1: Type: text/plain; charset="gb18030", Size: 2073 bytes --]

Hi, Eli,


I modifed the code following your instruction.&nbsp; I added some more comments on functions. Test is done, IME status changes as expected.



I used GetFocus() in w32_msg_pump() now.


But I can't invoke GetFocus() in w32-get-ime-open-status(), because w32-get-ime-open-status() is invoked in lisp thread. I just use w32_system_caret_hwnd instead, if get_ime_context_fn(w32-get-ime-open-status) returns NULL, w32-get-ime-open-status() return nil.


Attachement is the modifed patch.



------------------&nbsp;ԭʼÓʼþ&nbsp;------------------
·¢¼þÈË:&nbsp;"Albert"<georgealbert@qq.com&gt;;
·¢ËÍʱ¼ä:&nbsp;2020Äê4ÔÂ13ÈÕ(ÐÇÆÚÒ») ÏÂÎç3:26
ÊÕ¼þÈË:&nbsp;"Eli Zaretskii"<eliz@gnu.org&gt;;
³­ËÍ:&nbsp;"emacs-devel"<emacs-devel@gnu.org&gt;;
Ö÷Ìâ:&nbsp;»Ø¸´£º »Ø¸´£º »Ø¸´£º »Ø¸´£º »Ø¸´£º [PATCH] Add IME status change support on windows natively



Hi, Eli,


I can't get the main window handle as emacs doesn't save the main window handle after invoking createWindow(). I just found w32_system_caret_hwnd did work. I will modify the code by using GetFocus().




------------------ ԭʼÓʼþ ------------------
·¢¼þÈË:&nbsp;"Eli Zaretskii"<eliz@gnu.org&gt;;
·¢ËÍʱ¼ä:&nbsp;2020Äê4ÔÂ13ÈÕ(ÐÇÆÚÒ») ÏÂÎç3:21
ÊÕ¼þÈË:&nbsp;"Albert"<georgealbert@qq.com&gt;;
³­ËÍ:&nbsp;"emacs-devel"<emacs-devel@gnu.org&gt;;
Ö÷Ìâ:&nbsp;Re: »Ø¸´£º »Ø¸´£º »Ø¸´£º »Ø¸´£º [PATCH] Add IME status change support on windows natively



&gt; From: "Albert" <georgealbert@qq.com&gt;
&gt; Cc: "emacs-devel" <emacs-devel@gnu.org&gt;
&gt; Date: Mon, 13 Apr 2020 15:07:19 +0800
&gt; 
&gt; Thanks. I'll try it.

I'm also worried by your use of w32_system_caret_hwnd as the handle of
the window for which to retrieve the input context.
w32_system_caret_hwnd is not guaranteed to be a valid handle if the
system caret is not used, i.e. if w32-use-visible-system-caret is nil
(which is the default).

So perhaps instead of using w32_system_caret_hwnd, you should use the
return value of GetFocus function, similar to what we do elsewhere in
w32_msg_pump.

[-- Attachment #1.2: Type: text/html, Size: 2867 bytes --]

[-- Attachment #2: w32fns.c.patch --]
[-- Type: application/octet-stream, Size: 5267 bytes --]

diff --git a/src/w32fns.c b/src/w32fns.c
index 8d714f0b8d..04de124e42 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -166,6 +166,10 @@ DECLARE_HANDLE(HMONITOR);
 typedef BOOL (WINAPI * ImmReleaseContext_Proc) (IN HWND wnd, IN HIMC context);
 typedef BOOL (WINAPI * ImmSetCompositionWindow_Proc) (IN HIMC context,
 						      IN COMPOSITIONFORM *form);
+/* for ime switch */
+typedef BOOL (WINAPI * ImmGetOpenStatus_Proc) (IN HIMC);
+typedef BOOL (WINAPI * ImmSetOpenStatus_Proc) (IN HIMC, IN BOOL);
+
 typedef HMONITOR (WINAPI * MonitorFromPoint_Proc) (IN POINT pt, IN DWORD flags);
 typedef BOOL (WINAPI * GetMonitorInfo_Proc)
   (IN HMONITOR monitor, OUT struct MONITOR_INFO* info);
@@ -185,6 +189,8 @@ DECLARE_HANDLE(HMONITOR);
 TrackMouseEvent_Proc track_mouse_event_fn = NULL;
 ImmGetCompositionString_Proc get_composition_string_fn = NULL;
 ImmGetContext_Proc get_ime_context_fn = NULL;
+ImmGetOpenStatus_Proc get_ime_open_status_fn = NULL;
+ImmSetOpenStatus_Proc set_ime_open_status_fn = NULL;
 ImmReleaseContext_Proc release_ime_context_fn = NULL;
 ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL;
 MonitorFromPoint_Proc monitor_from_point_fn = NULL;
@@ -3305,6 +3311,7 @@ #define M(msg) { msg, # msg }
       M (WM_EMACS_SETCURSOR),
       M (WM_EMACS_SHOWCURSOR),
       M (WM_EMACS_PAINT),
+      M (WM_EMACS_IME_STATUS),
       M (WM_CHAR),
 #undef M
       { 0, 0 }
@@ -3442,6 +3449,31 @@ w32_msg_pump (deferred_msg * msg_buf)
 		  emacs_abort ();
 	      }
 	      break;
+            case WM_EMACS_IME_STATUS:
+              focus_window = GetFocus ();
+              if (focus_window == NULL)
+                break;
+
+              if (!set_ime_open_status_fn)
+                break;
+              else
+                {
+                  HIMC context;
+                  context = get_ime_context_fn (focus_window);
+                  if (!context)
+                      break;
+
+                  BOOL wParam = (BOOL) msg.wParam;
+                  BOOL ime_status = get_ime_open_status_fn (context);
+                  BOOL new_status = (wParam != 0);
+                  if (ime_status != new_status)
+                    {
+                       set_ime_open_status_fn (context, wParam);
+                       release_ime_context_fn (focus_window, context);
+                    }
+                }
+              break;
+
 #ifdef MSG_DEBUG
 	      /* Broadcast messages make it here, so you need to be looking
 		 for something in particular for this to be useful.  */
@@ -10218,6 +10250,51 @@ DEFUN ("w32-notification-close",
 
 #endif	/* WINDOWSNT && !HAVE_DBUS */
 
+DEFUN ("w32-get-ime-open-status",
+       Fw32_get_ime_open_status, Sw32_get_ime_open_status,
+       0, 0, 0,
+       doc: /* Determines whether the IME is open or closed.
+
+This function doesn't has an argument.
+If return 1, IME is open.
+If return 0, IME is closed.*/)
+  (void)
+{
+  int retval;
+
+  HIMC context = get_ime_context_fn (w32_system_caret_hwnd);
+  if (context != NULL)
+    {
+      retval = get_ime_open_status_fn (context);
+      release_ime_context_fn (w32_system_caret_hwnd, context);
+
+      return make_fixnum (retval);
+    }
+
+  return Qnil;
+}
+
+DEFUN ("w32-set-ime-open-status",
+       Fw32_set_ime_open_status, Sw32_set_ime_open_status,
+       1, 1, 0,
+       doc: /* Opens or closes the IME on Windows.
+
+This function has one argument.
+If the argument is not nil, open or enable IME.
+If the argument is nil, close or disable IME. */)
+  (Lisp_Object status)
+{
+    unsigned ime_status;
+    if (NILP (status))
+      ime_status = 0;
+    else
+      ime_status = 1;
+
+    PostThreadMessage (dwWindowsThreadId, WM_EMACS_IME_STATUS, ime_status, 0);
+
+    return Qnil;
+}
+
 \f
 #ifdef WINDOWSNT
 /***********************************************************************
@@ -10744,6 +10821,8 @@ syms_of_w32fns (void)
   defsubr (&Sw32_notification_notify);
   defsubr (&Sw32_notification_close);
 #endif
+  defsubr (&Sw32_get_ime_open_status);
+  defsubr (&Sw32_set_ime_open_status);
 
 #ifdef WINDOWSNT
   defsubr (&Sw32_read_registry);
@@ -11032,6 +11111,11 @@ globals_of_w32fns (void)
       get_proc_addr (imm32_lib, "ImmReleaseContext");
     set_ime_composition_window_fn = (ImmSetCompositionWindow_Proc)
       get_proc_addr (imm32_lib, "ImmSetCompositionWindow");
+
+    get_ime_open_status_fn = (ImmGetOpenStatus_Proc)
+      get_proc_addr (imm32_lib, "ImmGetOpenStatus");
+    set_ime_open_status_fn = (ImmSetOpenStatus_Proc)
+      get_proc_addr (imm32_lib, "ImmSetOpenStatus");
   }
 
   HMODULE hm_kernel32 = GetModuleHandle ("kernel32.dll");
diff --git a/src/w32term.h b/src/w32term.h
index f8a8a727e8..4e9234f239 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -670,7 +670,8 @@ #define WM_EMACS_PAINT                 (WM_EMACS_START + 22)
 #define WM_EMACS_BRINGTOTOP            (WM_EMACS_START + 23)
 #define WM_EMACS_INPUT_READY           (WM_EMACS_START + 24)
 #define WM_EMACS_FILENOTIFY            (WM_EMACS_START + 25)
-#define WM_EMACS_END                   (WM_EMACS_START + 26)
+#define WM_EMACS_IME_STATUS            (WM_EMACS_START + 26)
+#define WM_EMACS_END                   (WM_EMACS_START + 27)
 
 #define WND_FONTWIDTH_INDEX    (0)
 #define WND_LINEHEIGHT_INDEX   (4)

  reply	other threads:[~2020-04-13  9:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13  4:09 [PATCH] Add IME status change support on windows natively Albert
2020-04-13  4:53 ` Eli Zaretskii
2020-04-13  5:47   ` Eli Zaretskii
2020-04-13  6:06     ` =?gb18030?B?u9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  6:13       ` =?gb18030?B?u9i4tKO6?= [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13  8:50         ` 回复: " Valtteri Vuorikoski
2020-04-13  9:06           ` Eli Zaretskii
2020-04-13  9:18             ` Valtteri Vuorikoski
2020-04-13  6:12   ` =?gb18030?B?u9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  6:24     ` =?gb18030?B?u9i4tKO6?= [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13  6:27       ` =?gb18030?B?u9i4tKO6ILvYuLSjuiBbUEFUQ0hdIEFkZCBJTUUgc3RhdHVzIGNoYW5nZSBzdXBwb3J0IG9uIHdpbmRvd3MgbmF0aXZlbHk=?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  6:32         ` =?gb18030?B?u9i4tKO6ILvYuLSjuiBbUEFUQ0hdIEFkZCBJTUUgc3RhdHVzIGNoYW5nZSBzdXBwb3J0IG9uIHdpbmRvd3MgbmF0aXZlbHk=?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  6:43         ` =?gb18030?B?u9i4tKO6ILvYuLSjug==?= [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13  6:47           ` =?gb18030?B?u9i4tKO6ILvYuLSjuiC72Li0o7ogW1BBVENIXSBBZGQgSU1FIHN0YXR1cyBjaGFuZ2Ugc3VwcG9ydCBvbiB3aW5kb3dzIG5hdGl2ZWx5?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  7:05             ` 回复: 回复: 回复: [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13  7:07               ` =?gb18030?B?u9i4tKO6ILvYuLSjuiC72Li0o7ogu9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  7:21                 ` =?gb18030?B?u9i4tKO6ILvYuLSjuiC72Li0o7ogu9i4tKO6?= [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13  7:25                   ` Eli Zaretskii
2020-04-13  7:26                   ` =?gb18030?B?u9i4tKO6ILvYuLSjuiC72Li0o7ogu9i4tKO6ILvYuLSjuiBbUEFUQ0hdIEFkZCBJTUUgc3RhdHVzIGNoYW5nZSBzdXBwb3J0IG9uIHdpbmRvd3MgbmF0aXZlbHk=?= =?gb18030?B?QWxiZXJ0?=
2020-04-13  9:22                     ` =?gb18030?B?QWxiZXJ0?= [this message]
2020-04-13  9:33                       ` [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13 10:02                         ` =?gb18030?B?u9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-13 13:10                           ` [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13 13:15                             ` =?gb18030?B?u9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-13 13:44                               ` [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13 14:52                                 ` =?gb18030?B?u9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-13 15:32                                   ` =?gb18030?B?u9i4tKO6?= [PATCH] Add IME status change support on windows natively Eli Zaretskii
2020-04-13 15:01                                 ` =?gb18030?B?u9i4tKO6IFtQQVRDSF0gQWRkIElNRSBzdGF0dXMgY2hhbmdlIHN1cHBvcnQgb24gd2luZG93cyBuYXRpdmVseQ==?= =?gb18030?B?QWxiZXJ0?=
2020-04-14  2:13   ` [PATCH] Add IME status change support on windows natively Richard Stallman
2020-04-14  5:54     ` Eli Zaretskii
2020-04-15  2:56       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_22993BA1802FA378CEB20839A9CEF3CA1C07@qq.com \
    --to=georgealbert@qq.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).