I spent a day or so hacking around with kanata[0], which is a kernel level keyboard remapping tool, that lets you define[1] keyboard mapping layers in a similar way you might with QMK firmware. When I hit the control or meta/alt/option key, it activates a layer where Emacs editing keys are emulated using the GTK equivalents. For example, C-a and C-e are mapped to home/end, etc. I preserve my macOS CMD-not-control-key muscle memory this way too.
The only problem is, this is not the behavior I want in terminals or in GNU/Emacs itself. I wrote a small python daemon (managed by a systemd user service) which wakes up whenever the active window changes. Based on this info, I send a message to the TCP server that kanata (also managed by a systemd user service) provides for remote control to switch to the appropriate layer.
[0]: https://github.com/jtroo/kanata
[1]: https://gitlab.com/spudlyo/dotfiles/-/blob/master/kanata/.co...
This is so cool. Thank you!