Subject: 31.0.50; Random keyboard input detected when clicking with mouse in Emacs

From: Bartosz Kaczyński <[email-masked]>
Date: Sun, 19 Jan 2025 19:12:58 +0000

Hello,

I have encountered an issue in Emacs where random keyboard input (e.g.,
single letters like d or repeated ones like cc) is inserted into the
current buffer when I click inside the Emacs window with the mouse and
while switching focus between Emacs and other application (e.g. browser
or file manager). This behavior occurs inconsistently but is
reproducible over time.

I added the following diagnostic function to my configuration to capture
input events:

(defun my/debug-input-event ()
  (interactive)
  (let ((event (read-event)))
    (message "Event detected: %s" event)
    (push event unread-command-events)))

(global-set-key [mouse-1] 'my/debug-input-event)

Using this code, I observed the following log in the *Messages* buffer
when the issue occurred:

Event detected: 100

For context, ASCII value 100 corresponds to the letter d. However, other
times, I observe different letters like cc.

I am using openSUSE Tumbleweed GNU/Linux distro on KDE Wayland system and
running Emacs as a daemon and connecting via emacsclient.

In GNU Emacs 31.0.50 (build 2, x86_64-suse-linux-gnu, GTK+ Version
3.24.43, cairo version 1.18.2)
Windowing system distributor 'SUSE LINUX', version 11.0.12401004
System Description: openSUSE Tumbleweed

Configured using:
 'configure --disable-build-details --without-pop --with-mailutils
 --without-hesiod --with-gameuser=:games --with-kerberos
 --with-kerberos5 --with-file-notification=inotify --with-modules
 --enable-autodepend --with-gpm --prefix=/usr --mandir=/usr/share/man
 --infodir=/usr/share/info --datadir=/usr/share --localstatedir=/var
 --sharedstatedir=/var/lib --libexecdir=/usr/libexec
 --with-file-notification=yes --libdir=/usr/lib64
 --enable-locallisppath=/usr/share/emacs/31.0.50/site-lisp:/usr/share/emacs/site-lisp
 --with-x --with-xim --with-sound --with-xpm --with-jpeg --with-tiff
 --with-gif --with-png --with-rsvg --with-dbus --with-webp --with-xft
 --with-imagemagick --with-tree-sitter --with-x-toolkit=gtk3
 --without-pgtk --with-toolkit-scroll-bars --x-includes=/usr/include
 --x-libraries=/usr/lib64 --with-libotf --with-m17n-flt --with-cairo
 --with-native-compilation --build=x86_64-suse-linux
 --with-dumping=pdumper 'CFLAGS=-O2 -Wall -U_FORTIFY_SOURCE
 -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables
 -fasynchronous-unwind-tables -fstack-clash-protection
 -Werror=return-type -flto=auto -g -D_GNU_SOURCE
 -DGDK_DISABLE_DEPRECATION_WARNINGS -DGLIB_DISABLE_DEPRECATION_WARNINGS
 -pipe -Wno-pointer-sign -Wno-unused-variable -Wno-unused-label
 -DPDMP_BASE='\''"emacs-gtk"'\''' LDFLAGS=-Wl,-O2'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ
IMAGEMAGICK JPEG LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT
MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND
THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2
XPM GTK3 ZLIB

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_NUMERIC: POSIX
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Group

Minor modes in effect:
  server-mode: t
  global-company-mode: t
  company-mode: t
  doom-modeline-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  which-key-mode: t
  smartparens-global-mode: t
  global-diff-hl-mode: t
  savehist-mode: t
  recentf-mode: t
  override-global-mode: t
  gnus-topic-mode: t
  gnus-undo-mode: t
  fido-vertical-mode: t
  icomplete-vertical-mode: t
  icomplete-mode: t
  fido-mode: t
  save-place-mode: t
  global-auto-revert-mode: t
  global-hl-line-mode: t
  delete-selection-mode: t
  minibuffer-depth-indicate-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  minibuffer-regexp-mode: t
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/bartk/.emacs.d/elpa/which-key-20240620.2145/which-key hides /usr/share/emacs/31.0.50/lisp/which-key
/home/bartk/.emacs.d/elpa/ef-themes-1.9.0.0.20250110.75248/theme-loaddefs hides /usr/share/emacs/31.0.50/lisp/theme-loaddefs
/usr/share/emacs/site-lisp/compat hides /usr/share/emacs/31.0.50/lisp/emacs-lisp/compat

Features:
(shadow sort gnus-cite mail-extr emacsbug gnus-demon nndraft nnmh utf-7
epa-file network-stream nsm nnfolder nnnil gnus-agent gnus-srvr
gnus-score score-mode nnvirtual gnus-msg nntp gnus-cache go-mode
find-file ffap shortdoc help-fns radix-tree org-agenda org-indent
visual-fill-column image-file image-converter oc-basic disp-table
org-element org-persist org-id org-element-ast inline avl-tree ol-eww
eww vtable mule-util url-queue mm-url ol-rmail ol-mhe ol-irc ol-info
ol-gnus nnselect ol-docview doc-view jka-compr image-mode exif ol-bibtex
bibtex ol-bbdb ol-w3m ol-doi org-link-doi misearch multi-isearch
face-remap pulse color server display-fill-column-indicator
display-line-numbers checkdoc lisp-mnt flymake compile company-oddmuse
company-keywords company-etags etags fileloop generator xref
company-gtags company-dabbrev-code company-dabbrev company-files
company-clang company-capf company-cmake company-semantic
company-template company-bbdb company doom-modeline
doom-modeline-segments doom-modeline-env doom-modeline-core comp
comp-cstr warnings comp-run comp-common shrink-path f s nerd-icons
nerd-icons-faces nerd-icons-data nerd-icons-data-mdicon
nerd-icons-data-flicon nerd-icons-data-codicon nerd-icons-data-devicon
nerd-icons-data-sucicon nerd-icons-data-wicon nerd-icons-data-faicon
nerd-icons-data-powerline nerd-icons-data-octicon
nerd-icons-data-pomicon nerd-icons-data-ipsicon init yasnippet which-key
smartparens advice loadhist dash exec-path-from-shell diff-hl log-view
log-edit add-log pcvs-util vc-dir ewoc vc vc-dispatcher diff-mode
track-changes savehist recentf tree-widget init-org ob-C cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs ob-plantuml ob-python python project compat compat-30 pcase
ob-shell cl-extra edmacro kmacro bind-key easy-mmode init-gnus
gnus-topic gnus-icalendar org-capture org-refile org ob ob-tangle ob-ref
ob-lob ob-table ob-exp org-macro org-src sh-script smie treesit
executable ob-comint org-pcomplete org-list org-footnote org-faces
org-entities noutline outline org-version ob-emacs-lisp ob-core ob-eval
org-cycle org-table ol org-fold org-fold-core org-keys oc org-loaddefs
thingatpt find-func org-compat org-macs gnus-art mm-uu mml2015 mm-view
mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg
dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap
nnmail mail-source utf7 nnoo gnus-spec gnus-int gnus-range message
sendmail yank-media puny dired dired-loaddefs rfc822 mml mml-sec epa
derived epg rfc6068 epg-config mailabbrev mailheader gnus-win gnus
nnheader gnus-util text-property-search mail-utils range wid-edit
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr gmm-utils icalendar diary-lib diary-loaddefs
cal-menu calendar cal-loaddefs icomplete auth-source-pass saveplace
tramp-cache time-stamp tramp-sh tramp trampver tramp-integration files-x
tramp-message help-mode tramp-compat shell pcomplete comint ansi-osc
ring parse-time iso8601 time-date format-spec ansi-color tramp-loaddefs
autorevert filenotify hl-line delsel mb-depth cus-load
ef-elea-dark-theme ef-themes finder-inf 0blayout-autoloads 0x0-autoloads
ace-window-autoloads avy-autoloads chatgpt-shell-autoloads
company-autoloads devdocs-autoloads diff-hl-autoloads
doom-modeline-autoloads ef-themes-autoloads
exec-path-from-shell-autoloads flymake-ruff-autoloads go-mode-autoloads
jenkinsfile-mode-autoloads groovy-mode-autoloads json-mode-autoloads
json-snatcher-autoloads markdown-mode-autoloads mathjax-autoloads
multiple-cursors-autoloads nerd-icons-autoloads nov-autoloads
esxml-autoloads kv-autoloads pass-autoloads password-store-otp-autoloads
password-store-autoloads shell-maker-autoloads shrink-path-autoloads
f-autoloads s-autoloads smartparens-autoloads dash-autoloads
systemd-autoloads rx visual-fill-column-autoloads which-key-autoloads
info with-editor-autoloads yaml-mode-autoloads yasnippet-autoloads
package browse-url xdg url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util mailcap
url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs icons
password-cache json subr-x map byte-opt gv bytecomp byte-compile
url-vars cl-loaddefs cl-lib ispell early-init rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd touch-screen
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs theme-loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo gtk x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames native-compile emacs)

Memory information:
((conses 16 690563 563638) (symbols 48 45812 30)
 (strings 32 232349 149044) (string-bytes 1 5789622)
 (vectors 16 75590) (vector-slots 8 744362 354782) (floats 8 668 8455)
 (intervals 56 1097 1092) (buffers 992 22))