From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74423: Low level key events Date: Tue, 19 Nov 2024 07:49:00 +0800 Message-ID: <87ttc4hzmb.fsf@yahoo.com> References: <31bdc55d-8c13-4de0-9cef-bd6cc4fb033f@imayhem.com> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32707"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74423@debbugs.gnu.org To: Cecilio Pardo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 19 00:50:29 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1tDBVk-0008MQ-UJ for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Nov 2024 00:50:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDBVN-0004od-KX; Mon, 18 Nov 2024 18:50:05 -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 1tDBVL-0004km-Ju for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 18:50:04 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDBVL-0001WJ-7D for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 18:50:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=ttAABeWMdbRhbjs7VJmQqYowkdTubale70Qoe3SS8cE=; b=uykh9L3/SfcX/lXCNsMuJp1Vua/wWISeaeTctYm1ncL14ImTVPq9MKvElj2Z2ak2KXllCdOp83o+lsyYEJ25cbmp514qa6qg4QAFbgIDewkhzcjeHSo7Rm4RgnCsMXqwrruQskq5Xwz1SojqTkioMMFLkxx+Cx9wBRU5acMAGT29+btUpz4nxRJ9NMs1KcJgSsBCKRNHTzC7xq8Zy+JX9FcCd4Jy0+g68p0nwG9Nf96uFnEJ/XN8NJHPca3UoN1ZrD0PUg2gwNA9kR9rX4yaVi/kEYQO8bvOnXOuqICqXLtWg+UrcS9SpMOgPQLd8xOp0doIZ3h9IAZYmk9pc9M3gQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tDBVL-0001nl-31 for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 18:50:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Nov 2024 23:50:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74423 X-GNU-PR-Package: emacs Original-Received: via spool by 74423-submit@debbugs.gnu.org id=B74423.17319737606841 (code B ref 74423); Mon, 18 Nov 2024 23:50:03 +0000 Original-Received: (at 74423) by debbugs.gnu.org; 18 Nov 2024 23:49:20 +0000 Original-Received: from localhost ([127.0.0.1]:39732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDBUd-0001mH-Ap for submit@debbugs.gnu.org; Mon, 18 Nov 2024 18:49:19 -0500 Original-Received: from sonic305-22.consmr.mail.ne1.yahoo.com ([66.163.185.148]:42475) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDBUb-0001m3-3d for 74423@debbugs.gnu.org; Mon, 18 Nov 2024 18:49:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1731973749; bh=ttAABeWMdbRhbjs7VJmQqYowkdTubale70Qoe3SS8cE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=T4NeX2OKm6CQa9H8BxXTxMEadwtDi5CHwJuGBUggV+k8LFPsa178qvXs7osYZRQRe64zELMoVmizqA+QI++UBT0zeE6Cm+e4hqXNcDKo0lcxX41PMG3r/qGSdlP6jmpMav+1ITEmd8Cdb5BECWRRV/BoJBRwII9AFaOln169prxtTBqtPsJB9VWzsRhCFXTV+bZc0nFbYSAkwd/n4rhFnfYcCew36nTAAD4NXIXElcioTM6ZhDBpWvMuBwStzkhYSOL8vLxeY7psCkwrZba0qwHZcj/Aa2SqTA+MfGzVdQohEMM159qGTQemNW//2FhGe97gatzrguiRae33ByR2ew== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1731973749; bh=3g/Vak+BIlFUa0ik4g6CjBCIllzvJ8b3MjfrvD7EjYy=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=olqugtH3IWzqiok6b5ltVF7+xDdPeAwk0r2BQoke6CoE8j4F01ApYttmkE9Y3fcxBzpjBIAsrP2FjqCWPMhgGVYXD+VQqomj/vsYDqvT7E3hUaSrw5iMBDkv+u6mFNoaI+ecBrcExa3aR6pSGe6fEyi9bnUruCQU7ZqAH/zy6zIOIrgw5fMYxF+HbM+Ro+OaRzUrZrhhk84lmsm1jUSV5gmfayOfpDUdE/rjCvN1eXy0obbCeLhRuZT78RpZaEaCe498hCTECMPt5hY+kuGD0BFm9xKwup0hs+rK3aK1x1vXBd3w4TId/SqjpChl4e5ZZzNWlyxdgwZyWBS6XqnE/g== X-YMail-OSG: JtHSyI0VM1lX7hhGFstzzjml2T0g5a3MDpKDJJ58qm0CvC0ByZIja7fhPuaGvc5 oS6zTI6CCQgZMhRv_fpijtxsnnrFpOVCmVDPLupLVuy3gCLUHd4kR18EL1MZt2BNWhfaz.mzK8u5 5AFK6f.40DbJMUfgbFowdxz7Dkico9ZPC8d1kheoTLuPF1uWfXGMaWim849_ODZkZxROyWOGza1l 1Q9UCr1K6KWKgiPoCYLMQ.6NPXCdxLPzYKV50uanXH5YnDdqypC.mu1bsKfTFYKHqOmu9Ge5XXK1 _lQxIrt2mqGmL05YJ8ZF2SERBX0O73KffwFVKFry8_ry5hYf6EsqU5OSv7o8C2BzWZqFE47SyNeq Rw8g8_rOXE9E2VdeMgQIVzRtdGOdMCf4CF7QODLKeJxPXPM_sZaQ0KEhG0V.CeiMG4xAU_vCVLxz gcAZOOMGBVteVn8frbEl4WNAtSn7VcQBsfSCzMbVplwPuAAjSA1WpX2Cy0mkXc3aA0.zG67yG8Nq mq8Sro5pq4Qvc9BW8ffm61nWodSFNR_O_qIyG9wPgJOJIxd3bE6svwkif61jy_eTPA27WB2ZGmPB pVpsdPBVnyi5wfGRgKoijNsCHnRIld19UTOXOxVwthTUs.xNmZ.HnWBoVzXBSWCcdt4WEhRvhQb9 IQnoRG3udPIY1FsYGw6gsHWL8jvK16fFIl7HPYms9QmqAIFkXR9_YvunuxZt8N9Tp8X1_cilrLDz aj32WZC82TzPOu09GCouGlh06WYsrwqfBnirvx2CLpnb_lvBRJguVz89iWgiF3s4b8jP0FtJVReN sh_p1PfOCcG47n2521jSYKKY9YtMgYI6utB8bMPJq5 X-Sonic-MF: X-Sonic-ID: 3cc06c86-8e89-47fe-a847-8c3487786ba1 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ne1.yahoo.com with HTTP; Mon, 18 Nov 2024 23:49:09 +0000 Original-Received: by hermes--production-sg3-5b7954b588-2czcw (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e1b6994a9d0bab8ead690504911ef7e4; Mon, 18 Nov 2024 23:49:04 +0000 (UTC) In-Reply-To: (Cecilio Pardo's message of "Mon, 18 Nov 2024 21:35:40 +0100") X-Mailer: WebService/1.1.22941 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295617 Archived-At: Cecilio Pardo writes: > + switch (keysym) > + { > + case GDK_KEY_Shift_L: > + case GDK_KEY_Shift_R: > + modifier = Qshift; > + break; > + case GDK_KEY_Control_L: > + case GDK_KEY_Control_R: > + modifier = Vx_ctrl_keysym; > + if (NILP (modifier)) > + modifier = Qctrl; > + break; > + case GDK_KEY_Alt_L: > + case GDK_KEY_Alt_R: > + modifier = Vx_meta_keysym; > + if (NILP (modifier)) > + modifier = Qalt; > + break; > + case GDK_KEY_Meta_L: > + case GDK_KEY_Meta_R: > + modifier = Vx_meta_keysym; > + if (NILP (modifier)) > + modifier = Qmeta; > + break; > + case GDK_KEY_Hyper_L: > + case GDK_KEY_Hyper_R: > + modifier = Vx_hyper_keysym; > + if (NILP (modifier)) > + modifier = Qhyper; > + break; > + case GDK_KEY_Super_L: > + case GDK_KEY_Super_R: > + modifier = Vx_super_keysym; > + if (NILP (modifier)) > + modifier = Qsuper; > + break; > + default: > + modifier = Qnil; > + } This is not the proper means of establishing the modifier bound to a key symbol in GTK, but I cannot immediately tell you what the alternative is. > + my_post_msg( &wmsg, hwnd, WM_EMACS_LOW_LEVEL_KEY, wParam, lParam ); > + } > + my_post_msg( &wmsg, hwnd, WM_EMACS_LOW_LEVEL_KEY, wParam, lParam ); > + } Stylistic issues. > +static void > +x_maybe_send_low_level_key_event (struct x_display_info *dpyinfo, > + const XEvent *xev) > +{ > + XKeyEvent xkey; > + bool is_press; > + KeySym keysym; > + Lisp_Object key, modifier; > + struct input_event ie; > + > + if (!Venable_low_level_key_events) > + return; > + > + switch (xev->type) > + { > + case KeyPress: > + is_press = true; > + xkey = xev->xkey; > + break; > + case KeyRelease: > + is_press = false; > + xkey = xev->xkey; > + break; > +#ifdef HAVE_XINPUT2 > + case GenericEvent: > + XIDeviceEvent *xiev = xev->xcookie.data; > + switch (xev->xgeneric.evtype) > + { > + case XI_KeyPress: > + is_press = true; > + break; > + case XI_KeyRelease: > + is_press = false; > + break; > + default: > + return; > + } > + > + xkey.serial = xiev->serial; > + xkey.send_event = xiev->send_event; > + xkey.display = xiev->display; > + xkey.window = xiev->event; > + xkey.root = xiev->root; > + xkey.subwindow = xiev->child; > + xkey.time = xiev->time; > + xkey.x = xiev->event_x; > + xkey.y = xiev->event_y; > + xkey.x_root = xiev->root_x; > + xkey.y_root = xiev->root_y; > + xkey.state = xiev->mods.effective; > + xkey.keycode = xiev->detail; > + xkey.same_screen = 1; > + break; > +#endif > + default: > + return; > + } > + > + struct frame *f = x_any_window_to_frame (dpyinfo, xkey.window); > + if (!f) > + return; > + > + XLookupString (&xkey, NULL, 0, &keysym, NULL); > + > + 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: > + key = Qnil; > + } This doesn't generate `ralt' events on my system, as that key produces the keysym ISO_Level3_Shift/ > + switch (keysym) > + { > + case XK_Shift_L: > + case XK_Shift_R: > + modifier = Qshift; > + break; > + case XK_Control_L: > + case XK_Control_R: > + modifier = Vx_ctrl_keysym; > + if (NILP (modifier)) > + modifier = Qctrl; > + break; > + case XK_Alt_L: > + case XK_Alt_R: > + modifier = Vx_meta_keysym; > + if (NILP (modifier)) > + modifier = Qalt; > + break; > + case XK_Meta_L: > + case XK_Meta_R: > + modifier = Vx_meta_keysym; > + if (NILP (modifier)) > + modifier = Qmeta; > + break; > + case XK_Hyper_L: > + case XK_Hyper_R: > + modifier = Vx_hyper_keysym; > + if (NILP (modifier)) > + modifier = Qhyper; > + break; > + case XK_Super_L: > + case XK_Super_R: > + modifier = Vx_super_keysym; > + if (NILP (modifier)) > + modifier = Qsuper; > + break; > + default: > + modifier = Qnil; > + } You are computing the modifier event to be generated incorrectly. You should search the modifier map (dpyinfo->modmap) for columns containing received keysyms, and compare modifier bits derived from the rows where they appear against meta_mod_mask, shift_lock_mask, alt_mod_mask, super_mod_mask, and hyper_mod_mask in the display structure, or CtrlMask and ShiftMask. > case KeyPress: > + x_maybe_send_low_level_key_event (dpyinfo, event); > x_display_set_last_user_time (dpyinfo, event->xkey.time, > event->xkey.send_event, > true); > @@ -20715,6 +20853,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, > #endif > > case KeyRelease: > + x_maybe_send_low_level_key_event (dpyinfo, event); > #ifdef HAVE_X_I18N > /* Don't dispatch this event since XtDispatchEvent calls > XFilterEvent, and two calls in a row may freeze the > @@ -23970,6 +24109,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, > struct xi_device_t *device, *source; > XKeyPressedEvent xkey; > > + x_maybe_send_low_level_key_event (dpyinfo, event); > + > coding = Qlatin_1; > > /* The code under this label is quite desultory. There > @@ -24586,6 +24727,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, > #endif > > case XI_KeyRelease: > + x_maybe_send_low_level_key_event (dpyinfo, event); Would you rearrange the locations of calls to x_any_window_to_frame in handle_one_xevent so that you need not redundantly call the same function in x_maybe_send_low_level_key_event? Thanks for your interest in Emacs.