From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#19994: 25.0.50; Unicode keyboard input on Windows Date: Wed, 04 Mar 2015 20:01:01 +0200 Message-ID: <83bnk8prqa.fsf@gnu.org> References: <20150303230949.GA29784@math.berkeley.edu> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Trace: ger.gmane.org 1425492135 29416 80.91.229.3 (4 Mar 2015 18:02:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Mar 2015 18:02:15 +0000 (UTC) Cc: 19994@debbugs.gnu.org To: Ilya Zakharevich Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 04 19:02:10 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YTDcY-0004fV-AP for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Mar 2015 19:02:10 +0100 Original-Received: from localhost ([::1]:45719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTDcX-0005kR-I6 for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Mar 2015 13:02:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTDcT-0005k9-Fs for bug-gnu-emacs@gnu.org; Wed, 04 Mar 2015 13:02:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTDcQ-00010u-8Z for bug-gnu-emacs@gnu.org; Wed, 04 Mar 2015 13:02:05 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTDcQ-00010q-3V for bug-gnu-emacs@gnu.org; Wed, 04 Mar 2015 13:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YTDcP-0002PT-Q0 for bug-gnu-emacs@gnu.org; Wed, 04 Mar 2015 13:02:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 04 Mar 2015 18:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19994 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19994-submit@debbugs.gnu.org id=B19994.14254920819214 (code B ref 19994); Wed, 04 Mar 2015 18:02:01 +0000 Original-Received: (at 19994) by debbugs.gnu.org; 4 Mar 2015 18:01:21 +0000 Original-Received: from localhost ([127.0.0.1]:35229 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YTDbh-0002OV-6z for submit@debbugs.gnu.org; Wed, 04 Mar 2015 13:01:21 -0500 Original-Received: from mtaout20.012.net.il ([80.179.55.166]:34953) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YTDbb-0002OA-He for 19994@debbugs.gnu.org; Wed, 04 Mar 2015 13:01:15 -0500 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0NKP00B008HFM100@a-mtaout20.012.net.il> for 19994@debbugs.gnu.org; Wed, 04 Mar 2015 20:01:05 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NKP00BSR8PS5WC0@a-mtaout20.012.net.il>; Wed, 04 Mar 2015 20:01:05 +0200 (IST) In-reply-to: <20150303230949.GA29784@math.berkeley.edu> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:100063 Archived-At: > Date: Tue, 3 Mar 2015 15:09:49 -0800 > From: Ilya Zakharevich > > I’m working on a patch to make Unicode keyboard input to work properly on > Windows (in graphic mode). Thanks! > The patch below > > • Implements this “primacy of characters” doctrine; > > • As far as I could see, is compatible with the current work of Emacs > on “simple keyboard layouts”; > > • Worked at some moment (before I started a massive addition of > comments ;-] — and maybe it is still working, I did not touch it for a > month); > > • (Currently) ignores the indent coding rules; > > • Passes all the test thrown at it by my super-puper-all-bells-and-whistles > layouts; see e.g. > http://k.ilyaz.org/windows/izKeys-visual-maps.html#examples Any chance of coming up with a few tests for this code, and adding them to the test/ directory? > If I ever find more time to work on it, I plan to: > > 1) Add yet more documentation; > > 2) Change a little bit the logic of detection of consumed/extra > modifiers. This change may be cosmetic only — or maybe, with some > extremely devilous layouts, it may be beneficial. > > (I have not seen layouts where this change would matter, though! > And I looked though the source code of hundred(s).) > > 3) Bring it in sync with the Emacs coding style. I suggest, indeed, to clean up the code so we could commit it to the master branch. That way, it will get wider testing, and we can fix whatever problems it might cause. Any deficiencies that don't cause regressions wrt the current code can be fixed later, or even not at all (if we decide them to not be important enough). Question: did you try this code with IME input methods? > Meanwhile, I would greatly appreciate all input related to the current > state of the patch. Some of that (but not much) below. > +static int > +get_wm_chars (HWND aWnd, int *buf, int buflen, int ignore_ctrl, int ctrl, int ^^^^^^^^ Why 'int' and not 'wchar_t'? > + while (buflen && /* Should be called only when w32_unicode_gui */ > + PeekMessageW(&msg, aWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD) && Indeed, any "wide" APIs should only be called when w32_unicode_gui is on, and there should be alternative code for when w32_unicode_gui is off. We still try to support Windows 9X. > + if (msg.message == WM_UNICHAR || code_unit < 0xDC00 || code_unit > > 0xDFFF) { > + /* Mismatched first surrogate. Pass both code units as if they were > two characters. */ > + *buf++ = doubled; > + if (!--buflen) // Drop the second char if at the end of the buffer > + return i; > + } else { > + code_unit = (doubled << 10) + code_unit - 0x35FDC00; > + } > + doubled = 0; > + } else if (code_unit >= 0xD800 && code_unit <= 0xDBFF) { Either explain the "magic" constants in comments, or, better, use macros with descriptive names. > + int ctrl_cnt, buf[1024], count, is_dead; I think buf[] should be an array of wchar_t. Also, will this code work for the non-w32_unicode_gui mode? > + if (count) { > + W32Msg wmsg; > + int *b = buf, strip_Alt = 1; Likewise with 'b'. > + SHORT r = VkKeyScanW( *b ); VkKeyScanW should be called only if w32_unicode_gui is on. (Or maybe the caller is only called when w32_unicode_gui is on, in which case maybe we should have an eassert there.) > + fprintf(stderr, "VkKeyScanW %#06x %#04x\n", (int)r, wParam); > + if ((r & 0xFF) == wParam && !(r & ~0x1FF)) { /* Char available > without Alt modifier, so Alt is "on top" */ > + if (*b > 0x7f && ('A' <= wParam && wParam <= 'Z')) > + return 0; /* Another branch below > would convert it to Alt-Latin char via wParam */ > + strip_Alt = 0; > + } > + } > + if (strip_Alt) > + wmsg.dwModifiers = wmsg.dwModifiers & ~(alt_modifier | meta_modifier); > + > + signal_user_input (); > + while (count--) > + { > + fprintf(stderr, "unichar %#06x\n", *b); > + my_post_msg (&wmsg, hwnd, WM_UNICHAR, *b++, lParam); > + } > + if (!ctrl_cnt) /* Process ALSO as ctrl */ > + return 1; > + else > + fprintf(stderr, "extra ctrl char\n"); > + return -1; > + } else if (is_dead >= 0) { > + fprintf(stderr, "dead %#06x\n", is_dead); > + return 1; > + } Lots of debugging output here that should be removed. Thanks again for working on this.