Closed Bug 2010538 Opened 10 months ago Closed 9 months ago

[Wayland] keyup event is never triggered on firefox running on wayland

Categories

(Core :: Widget: Gtk, defect, P3)

Firefox 146
defect

Tracking

()

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: holger.hees, Assigned: sinker)

References

(Blocks 1 open bug)

Details

Attachments

(10 files, 1 external file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0

Steps to reproduce:

Running the following code

<html>
<body onkeyup="console.info('up1')" onkeydown="console.info('down1')">
<form>
<input type="text" onkeyup="console.info('up2')" onkeydown="console.info('down2')">
</form>
</body>
</html>

or

https://w3c.github.io/uievents/tools/key-event-viewer.html

I'm running this on opensuse 16 and firefox 146.0.1

Actual results:

If I type some characters inside the input box, I don't get any keyup events for normal text characters like 'abcde...' but I get these events for 'backspace' or other special characters.

if I force firefox running on x11 emulation by setting 'export MOZ_ENABLE_WAYLAND=0' then everything works as excpected

Expected results:

Everytime, I type a text character like 'abcde...' inside a text input box, it should trigger a keyup event.

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Gtk' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Widget: Gtk
Product: Firefox → Core
Attached image keyevents_wrong.png —
Attached image keyevents_correct.png —

or to make the bug description a bit more understandable...

Steps to reproduce:

  1. open https://w3c.github.io/uievents/tools/key-event-viewer.html
  2. Type abcd' inside the text input box

Actual results:

  • you just get the events keydown, beforeinput and input, but no keyup event
  • check screenshot 'keyevents_wrong.png'

Expected results:

  • if you press e.g. backspace or other special characters, you get the events as they should be.
  • you get keydown, beforeinput, input and keyup
  • check screenshot 'keyevents_correct.png'

I tested the same on an ubuntu system with wayland enabled. There, everything was working as expected.

Any ideas, how to further narrow down?

You can ty to run firefox on terminal with MOZ_LOG=KeyboardHandler:4,sync env variable and check how the keys are processed on both X11 and Wayland.

sure and thanks for taking care :-)

it looks like that only non character keys are processed correctly.

Attached image wayland_not_working.png —
Attached file x11_working.log —
Attached image x11_working.png —

the only difference between wayland and x11 is that the x11 session is started with export MOZ_ENABLE_WAYLAND=0

Blocks: wayland
Summary: keyup event is never triggered on firefox running on wayland → [Wayland] keyup event is never triggered on firefox running on wayland

What is your Wayland compositor, and do you use an input method? If so, try stop your input method and see if it works.

I'm running latest kde and using the default wayland compositor from their.

To summarize, I'm running the following environment

opensuse leap 16
default wayland 1.2.0
updated to latest kde 6.5.5
running default kde wayland compositor

I mean wayland-utils 1.2.0 and libwayland 1.24.0

Is the log in comment #9 complete? It looks like missing earlier events. Could you do it again? Thanks!

Flags: needinfo?(holger.hees)
Severity: -- → S3
Flags: needinfo?(holger.hees)

sure.

the steps are

  1. the cursor enters the window
  2. click into the input field
  3. type 'abcde'
  4. type 'backspace'
  5. the cursor leaves the window

According to the log, Firefox doesn't receive any key events for these keys ("abcd"). It suggests that is intercepted by IM running wayland IM protocol. In this case, IME consumes key events, and Firefox won't receive key events.

Could you run firefox with the following env var?

   MOZ_LOG="IMEHandler:4,KeyboardHandler:4,sync" 
Flags: needinfo?(holger.hees)
Flags: needinfo?(holger.hees)

I've analyzed the issue and identified the potential root cause.

Potential Root Cause:
On Wayland with text-input protocol, printable characters arrive via commit_string in OnCommitCompositionNative() without any associated GDK key events. The existing code path only dispatches keydown and keypress events in this scenario - there's no keyup because there's no GDK_KEY_RELEASE event to trigger it.

This differs from X11 where key events go through the normal GDK key event path, which naturally provides both GDK_KEY_PRESS and GDK_KEY_RELEASE events.

Fix:
I've prepared a patch that:

  1. Detects when a simple character commit arrives via Wayland text-input protocol (when mIsKeySnooped is true and mProcessingKeyEvent is null)
  2. Synthesizes and dispatches keydown, keypress, and keyup events for characters that have a valid DOM keyCode
  3. Uses a new KeymapWrapper::InitKeyEventFromCommitString() helper to properly initialize the key event
  4. Refactors the existing dead-key handling code to share the dispatch logic

I'll submit the patch for review shortly.

via commit_string

That's why I asked if the reporter is using an input method or not. And I'm now wondering which one is used, perhaps ibus?

FYI with fcitx5 on Wayfire, I do get keyup events on each key release, even when the keydown event goes to the input method and does not reach Firefox.

I'm using a normal keyboard connected via usb as my input method.

When characters arrive via Wayland text-input protocol's commit_string without
GDK key events, synthesize keydown/keypress/keyup events so web applications
receive proper key events.

Also refactors dead key handling to share the key event dispatch logic via a
new DispatchKeyEventsForCommittedCharacter() helper method, and adds
KeymapWrapper::InitKeyEventFromCommitString() to initialize key events from
committed characters without a native GDK key event.

Attached image wayland_working.png —
Flags: needinfo?(holger.hees)

it works! :-)

Assignee: nobody → thinker.li
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Pushed by thinker.li@gmail.com: https://github.com/mozilla-firefox/firefox/commit/5f1fe2dd4501 https://hg.mozilla.org/integration/autoland/rev/2c3026093a62 Dispatch keyup events for text characters on Wayland text-input protocol. r=stransky
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: