Skip to content

Conversation

@savetheclocktower
Copy link

This brings master up to the version of keyboard-layout that has been used in PulsarNext since May. It delivers two major additions.

N-API rewrite

The rewrite in N-API was part of demonstrating context-awareness; could’ve opted into context-awareness while continuing to use nan, but we might as well go whole hog.

Wayland support

The much larger change snuck up on me: back in May, a French user downloaded PulsarNext in order to get Wayland support and was pleased with it… except that it assumed their keyboard was standard US QWERTY and was misinterpreting keystrokes. I discovered that this package’s keyboard detection was exclusively using X11 APIs, so when the user was on Wayland, we had no insight into their keyboard layout and fell back to a QWERTY assumption.

The next few days of code authorship were not my favorite, but eventually this got addressed. We now start out assuming the user is on Wayland, but will very quickly fall back to X11 if that assumption is violated in any way. (This also at least gives the X11 code path a chance to provide answers, since it may still be able to help us if the user is running the XWayland compatibility layer.)

I was able to do some basic sanity-checking in a Linux VM running Wayland. (Issue #3 chronicles my efforts.) I updated PulsarNext to point to this branch and the French user reported that the new version fixed their keyboard shortcuts.

So that’s where we are now. One of the big upsides of PulsarNext over mainline Pulsar for Linux users is that we inherit the Wayland support that was added to Electron itself at some point, but that support will be pretty shallow for non-US users if we can’t also detect their keystrokes properly.

Testing

Testing these changes is not easy. The existing spec suite did only basic checking of Linux. And keyboard input in particular is hard to test in a CI environment. (If anyone has bright ideas, let me know. My initial experiments were not fruitful.)

I’m hoping that @mauricioszabo has the ability to do some sanity checking in Linux. If not, we might just need to rely on the fact that this fixed layout handling for at least one Wayland user and land it for now.

Next steps

As with pathwatcher, we have never relied on our own fork of keyboard-layout, and mainline Pulsar still points to keyboard-layout from NPM. So we don't need to publish @pulsar-edit/keyboard-layout until after we land this change. But the publish workflow already exists in this repo and I'll make sure it has access to the necessary secret.

@savetheclocktower
Copy link
Author

I also must remember to chose the “squash and merge” option when landing this… or else do the squash myself locally. Lots of junky commits here.

@savetheclocktower
Copy link
Author

I'm reacquainting myself with the changes I made to CI. You can see in ci.yml that I attempted to test this in Linux by setting up a non-US keyboard layout and a French localization. But that isn't sufficient to test the new code paths (or even the old ones) without a display server running on the CI machine. So the test results reflect the fallback assumption of a US QWERTY keyboard.

This is what xvfb is for, except that the name is a hint that it's designed for X and not Wayland. I looked around for an equivalent for Wayland, something I could run headlessly in GitHub Actions; I don't remember exactly what I tried, but I know it wasn't successful. So the Linux CI workflows don't demonstrate any of the new stuff; they just assert that Linux returns something, which is the most the existing specs ever did, too.

@savetheclocktower
Copy link
Author

Much like this PR on another repo, this PR represents what's been shipping in PulsarNext for four months. I'm aware of no regressions on other platforms (macOS/Windows code isn't touched except to convert to N-API) or even on Linux with X11 (the approach we revert to as soon as any of our Wayland-specific assumptions are violated).

With this in mind, I might leave this PR open a while longer but treat it as a “speak now or forever hold your peace” PR, lest it stay open and remain a blocker for other items on the PulsarNext dependency checklist.

@savetheclocktower savetheclocktower linked an issue Sep 10, 2025 that may be closed by this pull request
1 task
Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have looked at the entire diff. Parts of it for longer than others.

Have said it elsewhere but I will say it here: I am not a C/C++ expert. And I did not dive very deep into looking over the C/C++ code. Comments below give what impression I could manage to form on that.

I had a couple of minor questions about whether some logging and a test file are still wanted, marked below with ❓ emoji. (Optional to address, and I trust your judgment on these small things -- however you resolve them (without introducing substantial new stuff, I suppose) may be considered to retain this approval.)

Other than that, looks good to me! (Unfortunately another rubber-stamp-ish review due to lack of depth of this review, but at least I've seen all the changes. Better than nothing? Heh.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that there is documentation, including helpful hints and caveats for users of this stuff. It makes me feel a bit out of depth not knowing the implications and context of some of these things I'm reading, but the comments here still seem relevant and to the point (as far as I can tell). 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have looked at (hesitate to say "looked over" due to a lot of it going over my head) all the diff in src/. The main things standing out are moving from Nan:: (and occasionally v8::) things over to Napi:: things. And "a lot of new stuff." Which one gets the impression is largely to do with the titular "add Wayland support."

Nothing bad stands out to my (somewhat under-qualified) human eyes unaided by an IDE (I wouldn't know much of where to start with this in an IDE, besides not intending to wade that far into the depths of code review for this one.)

This is my qualified (read that how you will) endorsement of the diff content in src/dir: --> 👍 (FWIW.)

(Aside: The sheer diffstat of new stuff in keyboard-layout-manager-linux.cc is quite impressive, by the way!)

Comment on lines +105 to +114
console.log('KEYMAP:', keymap);
expect(keymap.KeyG.unmodified).toBeDefined()
expect(keymap.KeyG.withShift).toBeDefined()
})
})

describe('.getCurrentKeyboardLayout()', function () {
it('returns an identifier for the current keyboard layout (basic smoke test)', function () {
expect(KeyboardLayout.getCurrentKeyboardLayout()).toBeDefined()
let layout = KeyboardLayout.getCurrentKeyboardLayout();
console.warn('Linux keyboard layout:', layout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want these console.log() / console.warn() in the spec? Probably harmless. Just something I noticed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this file?

Maybe it's only useful in development? That said, perhaps it'll be useful again for development some time in the future.

(IDK or have a strong opinion about it. Just something I noticed that stood out a bit.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point! I don't think I meant to add this to the PR in the first place. If it stays as a utility script, it should be cleaned up a bit. I'll address this.

Copy link
Member

@DeeDeeG DeeDeeG Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just add a comment that

// This test file is offered without warranty express or implied

... And/or an explanation of what it's for and what insight it gives, what it's good for debugging, etc... but I found it pretty self-explanatory that it watches for locale switches and logs about it from in a similar enough JS context to likely be relevant to how Pulsar sees such events??

I make my own little test scripts often enough that I recognized what it was pretty much right away. I don't think it necessarily needs changes, personally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using newer JS capabilities and enhancing readability. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fixes seem intuitively correct, again to my human eyeballs unaided by language-aware tooling at least. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems okay to my eyes. 👍

@DeeDeeG
Copy link
Member

DeeDeeG commented Sep 24, 2025

Aside: I am not as concerned with going out of my way to ensure keeping a copy around of all the commit history for this one. GitHub seems to do that on its own, for one thing. For another thing, the diff here is smaller and IMO fairly well-commented. I could see it landing basically in one go and not being confusing. I think.

@savetheclocktower savetheclocktower merged commit 4a8652f into pulsar-edit:master Sep 27, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Wayland environments on Linux

2 participants