unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu <luangruo@yahoo.com>
To: Cecilio Pardo <cpardo@imayhem.com>
Cc: emacs-devel@gnu.org
Subject: Re: Physical keyboard events
Date: Mon, 04 Nov 2024 08:21:09 +0800	[thread overview]
Message-ID: <s1r8qtzsvbe.fsf@yahoo.com> (raw)
In-Reply-To: <31bdc55d-8c13-4de0-9cef-bd6cc4fb033f@imayhem.com> (Cecilio Pardo's message of "Mon, 4 Nov 2024 00:44:17 +0100")

Cecilio Pardo <cpardo@imayhem.com> 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.



  reply	other threads:[~2024-11-04  0:21 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28 23:15 Physical keyboard events Cecilio Pardo
2024-10-29 13:40 ` Eli Zaretskii
2024-10-29 15:07   ` Cecilio Pardo
2024-10-29 15:38     ` Peter Feigl
2024-10-29 17:54       ` Cecilio Pardo
2024-10-29 23:41       ` James Thomas
2024-10-29 16:44     ` Eli Zaretskii
2024-10-29 16:55       ` Yuri Khan
2024-10-29 17:46         ` Eli Zaretskii
2024-10-30  2:56           ` Max Nikulin
2024-10-30  6:28             ` Yuri Khan
2024-10-30  6:39               ` Peter Feigl
2024-10-30 15:27               ` Eli Zaretskii
2024-10-30 17:13                 ` Yuri Khan
2024-10-30 17:37                   ` Eli Zaretskii
2024-10-30 19:26                     ` Dov Grobgeld
2024-10-30 19:36                       ` Juri Linkov
2024-10-30 19:55                       ` Eli Zaretskii
2024-10-31  6:13                     ` Yuri Khan
2024-10-30 15:21             ` Eli Zaretskii
2024-10-30 16:59               ` Max Nikulin
2024-10-29 17:56         ` Cecilio Pardo
2024-10-29 17:52       ` Cecilio Pardo
2024-10-29 17:13 ` Alan Mackenzie
2024-10-29 18:20   ` Cecilio Pardo
2024-10-29 19:31     ` Alan Mackenzie
2024-10-29 21:45       ` Cecilio Pardo
2024-10-30  6:02         ` Yuri Khan
2024-10-30 15:23           ` Eli Zaretskii
2024-10-30 16:51             ` Yuri Khan
2024-10-30 17:25               ` Eli Zaretskii
2024-10-30  3:27       ` Eli Zaretskii
2024-11-03 23:44 ` Cecilio Pardo
2024-11-04  0:21   ` Po Lu [this message]
2024-11-04  8:03     ` Cecilio Pardo
2024-11-04  9:35       ` Po Lu
2024-11-04 11:11         ` Cecilio Pardo
2024-11-04 11:49           ` Po Lu
2024-11-04 11:59             ` Cecilio Pardo
2024-11-04 13:29               ` Eli Zaretskii
2024-11-04 13:46                 ` Cecilio Pardo
2024-11-04 13:54                 ` Po Lu
2024-11-04 13:24             ` Eli Zaretskii
2024-11-04 14:09               ` Po Lu
2024-11-04 16:46                 ` Eli Zaretskii
2024-11-05  1:31                   ` Po Lu
2024-11-05  7:15                     ` Cecilio Pardo
2024-11-05  9:03                       ` Po Lu
2024-11-05  9:20                         ` Cecilio Pardo
2024-11-05 12:21                           ` Po Lu
2024-11-05 13:30                             ` Eli Zaretskii
2024-11-05 14:27                             ` Cecilio Pardo
2024-11-06  0:10                               ` Po Lu
2024-11-06 12:49                               ` Po Lu
2024-11-06 13:31                                 ` Eli Zaretskii
2024-11-07  0:25                                   ` Po Lu
2024-11-07  6:41                                     ` Eli Zaretskii
2024-11-07 14:36                                       ` Po Lu
2024-11-07 15:47                                         ` Eli Zaretskii
2024-11-07 16:58                                           ` Cecilio Pardo
2024-11-08  0:36                                           ` Po Lu
2024-11-05 13:13                     ` Eli Zaretskii
2024-11-04 13:18         ` Eli Zaretskii
2024-11-04 14:37           ` Po Lu
2024-11-04 16:49             ` Eli Zaretskii
2024-11-05  1:03               ` Po Lu
2024-11-05  7:09                 ` Cecilio Pardo
2024-11-05 13:06                 ` Eli Zaretskii
2024-11-04 12:27     ` Eli Zaretskii
2024-11-04 13:09       ` Po Lu
2024-11-04 13:33         ` Eli Zaretskii

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=s1r8qtzsvbe.fsf@yahoo.com \
    --to=luangruo@yahoo.com \
    --cc=cpardo@imayhem.com \
    --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).