From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: Physical keyboard events Date: Mon, 04 Nov 2024 08:21:09 +0800 Message-ID: References: <31bdc55d-8c13-4de0-9cef-bd6cc4fb033f@imayhem.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27913"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org To: Cecilio Pardo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 04 01:27:09 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t7kw1-00074B-Aa for ged-emacs-devel@m.gmane-mx.org; Mon, 04 Nov 2024 01:27:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t7kqV-0003ZX-O9; Sun, 03 Nov 2024 19:21:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t7kqS-0003JR-0e for emacs-devel@gnu.org; Sun, 03 Nov 2024 19:21:24 -0500 Original-Received: from sonic305-22.consmr.mail.ne1.yahoo.com ([66.163.185.148]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t7kqP-0002g4-EI for emacs-devel@gnu.org; Sun, 03 Nov 2024 19:21:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1730679676; bh=3kkrJqfjE8KncklFG471YHcAPV8dWmmVEI1OAqnr01g=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=g6RQrVdnBpMDDfir1hmgdMx6KE7VxLZktpy0bBhQpRShWHsNhDR2/uwyRoDzUi6ybrih5qhylIhXX/fH8HcxOLDA+I+s+h0jPJR6xqkOd9CMmOjWeez3ZY5Uk5/bSft9Ssx7TIuup/MK3ZEwoRVQPnsou927dbuPTFM84OsmIiJcgkNTKUJ+5K3PiDIw77xkkhCcoXuAfeyNBhQ5QMwAxZX3/84eOV0fM3yb2GgZUHxDiz02tVwCIFY2bZqNLzt73imuSFf41ILY4ZpmA9UIQczfIePcadorcYRzxbC6cXHAN3sWr5s/5qCsb1lqtLOZCKkcNTovR+h7qsCcwew/NQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1730679676; bh=Mkc2mspbBH3bpG/SSVr6efdW1NUMGOfHaHHO7jwzaCR=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=H0YExhNElTsHSbzvXjau6zRVkuGlzsTXCvGmgklaqN+PtMogt/6TQQwHXYDzZwVQtAutRM2P3YvsC6qHtyt9IR76+kKgcPEMGg5lOsEwarbnxVRv8g/4Mu8u8/YdHDE99Kfb+TgmSjfc9sUX04grzGx7Fcv/aCbQ8DTfpHx3C/jN988pwMc11RZvQQC0M0sQ5Wv4MvMZOtfWnJpdULbOgM3kMGsdDcCckxdIlV/0zk98t5LzaVkFandANPP57OfFrW0J/j+CHGpqZ71YLv+ZweeiqDDWxAsuI9akoex1c29s33rZsIhabQhyiL5sm5gALtLYPkLrv7YN9h2NJ7NH6g== X-YMail-OSG: pgRy.UoVM1mpjwRSdB8hg1N97bZ7vKn3pNiesUsJaGEDgVgOL5gz3nfZtNgR0Lm hNFDdOhfbjAFN3b.oFL4YR55tLbMG4uP0SZJ3xFkLMazqJ3B_w1lgpVMGnfAV264KaWAeJmi.KvS go1qYx7TuavsSpFHVqzQZYmNLFleJ4yW1RThgBiLC0Qbh8SJzhDRCBTszL7DY8.LID7Zuz2R__qn ZLgMsGNyNDCA3k40.Q3Oa2vO2WxZYlxGHuRGc6Ja.pNkrHGoSicJjafJMC9sEfhB4ZTbeCnNpx5F Qv9P2Yh8T8l1N6nzSbwQyW7NKoeS34WipttSTSw3WH53BCq1uiz3VtM1KpMOiAW.TSlEsNuPI8Wh Yi6.Sij2nAVLhDdQhEOhOGgjHvzedVR8iZ_zBzL3fFvPQPEaLdYe832BV1y4uYRc3zFawoVZ41UR kOW1_wUygCe7qerWKyzAWFFicjJbZFIGZ_.fIztgSE5plKcK.YkyU8f4Cqu..efzswcp8PK2xlgF H4a8YbMqlK5i71WFAAoLrrYaufmnugJnL1fIRg.UHOVr2JnN6HC5DluFvVFGaRaGsme0xm9GuYKo o_G0dv90LMz7w5QDaleROKYl4DbOiiKaRgQRKW0pnYWK8d6TFNNVx_DoIOlr5nIoSUnG7Ee91t7G K0aAEFDsMvPyPTxIhnm.H6K4d8EDjSbmE2yBigObA4Ko72ly.EBKLJdURG4xQeewjJzn5Pd_hxq4 iAx6CCW02AhlslxrYKu145omhdq006834drrcvD_j7eZAis7mYlcL1XQUWNsrR1EIa0gqRCUQAr4 o.JL656BN33X8BowcQAiKU7XlRM93VzPX0_LmhgB_z X-Sonic-MF: X-Sonic-ID: b54cc486-ce49-4a31-a1bb-974a9ee57c68 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ne1.yahoo.com with HTTP; Mon, 4 Nov 2024 00:21:16 +0000 Original-Received: by hermes--production-sg3-5b7954b588-bfzf8 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 01fa8a69831b109a0ed96c14364aa073; Mon, 04 Nov 2024 00:21:13 +0000 (UTC) In-Reply-To: <31bdc55d-8c13-4de0-9cef-bd6cc4fb033f@imayhem.com> (Cecilio Pardo's message of "Mon, 4 Nov 2024 00:44:17 +0100") X-Mailer: WebService/1.1.22806 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.185.148; envelope-from=luangruo@yahoo.com; helo=sonic305-22.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325072 Archived-At: Cecilio Pardo writes: > +static void > +x_maybe_send_physical_key_event (struct x_display_info *dpyinfo, XEvent *event) > +{ > +#ifdef HAVE_XKB Thank you. A number of comments: this is simply unacceptable, as Emacs must not depend on XKB for such a basic feature. > + if (event->type != KeyPress && event->type != KeyRelease) > + return; > + bool keypress = (event->type == KeyPress); > + KeySym keysym = XkbKeycodeToKeysym (dpyinfo->display, event->xkey.keycode, > + 0, 0 ); > + Lisp_Object key; > + switch (keysym) > + { > + case XK_Shift_L: key = Qlshift; break; > + case XK_Shift_R: key = Qrshift; break; > + case XK_Control_L: key = Qlctrl; break; > + case XK_Control_R: key = Qrctrl; break; > + case XK_Alt_L: key = Qlalt; break; > + case XK_Alt_R: key = Qralt; break; > + default: > + return; > + } ??? Code producing such events should not relay modifier keysyms verbatim, but ought to detect the virtual modifiers to which they are mapped, and convert them into Emacs modifiers, namely, meta, alt, ctrl, hyper, super, and shift. Otherwise, Lisp will find it impossible reliably to establish a correspondence between "physical key events" and modifiers. > + struct frame *f = x_any_window_to_frame (dpyinfo, event->xkey.window); > + if (!f) > + return; > + > + struct input_event ie; > + > + EVENT_INIT (ie); > + XSETFRAME (ie.frame_or_window, f); > + ie.kind = PHYSICAL_KEY_EVENT; > + ie.timestamp = event->xkey.time; > + ie.arg = list2 (keypress ? Qt : Qnil, key); > + kbd_buffer_store_event (&ie); > +#endif > +} Please find some means of generating such events by saving them into the keyboard event buffer defined in handle_ome_xevent. > /* Filter events for the current X input method. > DPYINFO is the display this event is for. > EVENT is the X event to filter. > @@ -17859,6 +17896,8 @@ x_filter_event (struct x_display_info *dpyinfo, XEvent *event) > > struct frame *f1; > > + x_maybe_send_physical_key_event (dpyinfo, event); > + > #if defined HAVE_XINPUT2 && defined USE_GTK > bool xinput_event = false; > if (dpyinfo->supports_xi2 x_filter_events is not the proper location for this call. It is only invoked to filter an event through the active GTK or X input method context, and it is not invoked if Emacs is configured not to open input method contexts, or they are unavailable by happenstance. This call is properly placed in handle_one_xevent, beneath the labels for KeyPress, KeyRelease, XI_KeyPress, XI_KeyRelease, and the GTK keyboard callbacks in gtkutil.c. Pay attention to the different manners in which the key codes are converted into keysyms and the keysyms into modifiers, and imitate them closely or reuse them if possible. Lastly, you must decide whether to capture modifier key events before they are filtered by the input method, or after. Input methods have complete discretion over disposing of these events and will either discard them entirely or resend a possibly modified event to Emacs. In the latter scenario, you will receive duplicates of one and the same event, and in principle it is impossible to distinguish between the duplicates and the originals. Equally unsatisfactory is the option of generating these events after they are filtered by the input method, since none will be generated if the IM takes the other course. These are the same concerns that led me not to implement raw modifier key events when this feature was proposed some years ago.