SUPERCILEX / gnome-clipboard-history

Gnome Clipboard History is a clipboard manager Gnome extension that saves what you've copied into an easily accessible, searchable history panel.
https://extensions.gnome.org/extension/4839/clipboard-history/
MIT License
470 stars 46 forks source link

χ ("Chi") is pasted instead of selected entry #157

Closed timo-a closed 7 months ago

timo-a commented 9 months ago

Describe the bug

"χ" is pasted instead of the selected entry. The selected entry is available with ctrl + v after that so this works, but the "χ" should not be pasted at all.

How To Reproduce

  1. place the cursor where you want to add something (e.g. firefox address bar or GNOME Terminal)
  2. open the clipboard with super + shift + v
  3. select an entry
  4. press enter

Versions

GNOME Shell 45.3 GCH Version: 34 org.gnome.shell.extensions.clipboard-history cache-only-favorites false org.gnome.shell.extensions.clipboard-history cache-size 100 org.gnome.shell.extensions.clipboard-history clear-history @as [] org.gnome.shell.extensions.clipboard-history confirm-clear true org.gnome.shell.extensions.clipboard-history disable-down-arrow true org.gnome.shell.extensions.clipboard-history display-mode 0 org.gnome.shell.extensions.clipboard-history enable-keybindings true org.gnome.shell.extensions.clipboard-history history-size 1000 org.gnome.shell.extensions.clipboard-history move-item-first true org.gnome.shell.extensions.clipboard-history next-entry @as [] org.gnome.shell.extensions.clipboard-history notify-on-copy false org.gnome.shell.extensions.clipboard-history paste-on-selection true org.gnome.shell.extensions.clipboard-history prev-entry @as [] org.gnome.shell.extensions.clipboard-history private-mode false org.gnome.shell.extensions.clipboard-history process-primary-selection false org.gnome.shell.extensions.clipboard-history strip-text false org.gnome.shell.extensions.clipboard-history toggle-menu ['V'] org.gnome.shell.extensions.clipboard-history toggle-private-mode ['P'] org.gnome.shell.extensions.clipboard-history topbar-preview-size 10 org.gnome.shell.extensions.clipboard-history window-width-percentage 20

(I'm using Fedora Linux 39)

Steps to repro

What causes the crash/bug?

Additional context (if a crash, provide stack trace)

'χ' happens with 'Gnome on Xorg" for regular 'Gnome' a 'C' is pasted.

SUPERCILEX commented 9 months ago

I'm going to guess that this is a gnome 45 bug, because it works fine for me.

timo-a commented 9 months ago

It seems to be an issue with the keyboard layout!? The bug only happens with German (Neo, QWERTZ) but the regular German has no issue.

SUPERCILEX commented 9 months ago

Oh, no that's definitely my fault. Pasting is super hacky and works by creating a virtual keyboard and then executing key presses.

Our key presses are Shift + Insert, so it must be that the neo layout remaps the insert key (I'd be surprised if shift was moved). Not sure how to fix this though. Maybe there's an API to set the language of the keyboard?

timo-a commented 9 months ago

Oh, then I closed it prematurely. I have linked this issue here to the neo keyboard layout repo: https://git.neo-layout.org/neo/neo-layout/issues/650. I have no idea what's going on here, but I hope both parties can somehow get to the bottom of this.

SUPERCILEX commented 9 months ago

Can you ask him where I can find the key codes for notify_key? I don't know what numbers map to shift and insert (and I find any information on what a key is supposed to be).

timo-a commented 9 months ago

So, per the other guy: the keycodes are in /usr/include/linux/input-event-codes.h where KEY_LEFTSHIFT is 48 and KEY_INSERT is 110. "clutter" seems to add the number 8 to them, making the result align with /usr/share/X11/xkb/keycodes/evdev (or the output of xev).

SUPERCILEX commented 9 months ago

Ok, can you try applying this patch:

Subject: [PATCH] Use linux key codes for pasting
---
Index: extension.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/extension.js b/extension.js
--- a/extension.js  (revision e46f78e7e82b8eec6d591e2a8ace2e1e9077c4f6)
+++ b/extension.js  (revision b0c198d1e9fb1095ee1d8a36586189d63e54d9ec)
@@ -616,25 +616,28 @@
     this._pasteHackCallbackId = Mainloop.timeout_add(
       1, // Just post to the end of the event loop
       () => {
+        const SHIFT_L = 42;
+        const INSERT = 110;
+
         const eventTime = Clutter.get_current_event_time() * 1000;
-        VirtualKeyboard().notify_keyval(
+        VirtualKeyboard().notify_key(
           eventTime,
-          Clutter.KEY_Shift_L,
+          SHIFT_L,
           Clutter.KeyState.PRESSED,
         );
-        VirtualKeyboard().notify_keyval(
+        VirtualKeyboard().notify_key(
           eventTime,
-          Clutter.KEY_Insert,
+          INSERT,
           Clutter.KeyState.PRESSED,
         );
-        VirtualKeyboard().notify_keyval(
+        VirtualKeyboard().notify_key(
           eventTime,
-          Clutter.KEY_Insert,
+          INSERT,
           Clutter.KeyState.RELEASED,
         );
-        VirtualKeyboard().notify_keyval(
+        VirtualKeyboard().notify_key(
           eventTime,
-          Clutter.KEY_Shift_L,
+          SHIFT_L,
           Clutter.KeyState.RELEASED,
         );
SUPERCILEX commented 7 months ago

I've been running that solution for a while now and it works fine (https://github.com/SUPERCILEX/gnome-clipboard-history/commit/be5d98cbfe76d2ad7789c2d2f51d45bc87ba3a23), so closing.

timo-a commented 7 months ago

It's working for me as well! Sorry I didn't find the time to test your patch, but I just tried the latest version and can now confirm that it works. Thanks for taking care of this issue even though it turned out to affect a rather small set of users!

SUPERCILEX commented 7 months ago

Awesome!