When enabling `xterm-mouse-mode` mouse click events can also come from non-graphical frames. This works fine, when there are only non- graphical frames, but as soon as there is a graphical frame *and* a non-graphical frame, mouse events in the non-graphical frame crash Emacs. Steps to reproduce: 1. Start Emacs daemon $ emacs -Q --fg-daemon --eval '(xterm-mouse-mode t)' 2. Start two frames, one graphical, one non-graphical $ emacsclient -c & $ emacsclient -c -t 3. Click around in both frames to provoke the crash. The problem is that `pgtk_mouse_position` calls `gtk_widget_get_window` even for mouse events that do not come from a GTK frame. #0 0x00007ffff7b58819 in gtk_widget_get_window () from /nix/store/y3c2q2c3p33qg1lnqpivji842mzd39n4-gtk+3-3.24.27/lib/libgtk-3.so.0 #1 0x00000000005c4d2d in pgtk_mouse_position (fp=0x7fffffff2580, insist=, bar_window=0x7fffffff2588, part=0x7fffffff257c, x=, y=, timestamp=) at pgtkterm.c:3354 #2 0x00000000004e8e00 in kbd_buffer_get_event (kbp=kbp@entry=0x7fffffff25e8, used_mouse_menu=used_mouse_menu@entry=0x7fffffff2b2b, end_time=end_time@entry=0x0) at keyboard.c:4087 #3 0x00000000004e8fce in read_event_from_main_queue (end_time=end_time@entry=0x0, local_getcjmp=local_getcjmp@entry=0x7fffffff28b0, used_mouse_menu=used_mouse_menu@entry=0x7fffffff2b2b) at keyboard.c:2180 #4 0x00000000004e9283 in read_decoded_event_from_main_queue (end_time=end_time@entry=0x0, local_getcjmp=local_getcjmp@entry=0x7fffffff28b0, prev_event=prev_event@entry=0x0, used_mouse_menu=used_mouse_menu@entry=0x7fffffff2b2b) at keyboard.c:2243 #5 0x00000000004ea4d4 in read_char (commandflag=1, map=map@entry=0x191c1c3, prev_event=0x0, used_mouse_menu=used_mouse_menu@entry=0x7fffffff2b2b, end_time=end_time@entry=0x0) at keyboard.c:2874 #6 0x00000000004ebb52 in read_key_sequence (keybuf=keybuf@entry=0x7fffffff2c00, prompt=prompt@entry=0x0, dont_downcase_last=dont_downcase_last@entry=false, can_return_switch_frame=can_return_switch_frame@entry=true, fix_current_buffer=fix_current_buffer@entry=true, prevent_redisplay=prevent_redisplay@entry=false) at keyboard.c:9575 #7 0x00000000004ec776 in command_loop_1 () at lisp.h:1002 #8 0x0000000000557d93 in internal_condition_case (bfun=bfun@entry=0x4ec514 , handlers=handlers@entry=0x90, hfun=hfun@entry=0x4e244d ) at eval.c:1478 #9 0x00000000004dd815 in command_loop_2 (handlers=handlers@entry=0x90) at keyboard.c:1115 #10 0x000000000055a0e0 in internal_catch (tag=tag@entry=0xe6d0, func=func@entry=0x4dd7fb , arg=arg@entry=0x90) at eval.c:1198 #11 0x00000000004dd7d7 in command_loop () at lisp.h:1002 #12 0x00000000004e2063 in recursive_edit_1 () at keyboard.c:720 #13 0x00000000004e237a in Frecursive_edit () at keyboard.c:792 #14 0x00000000004dcee2 in main (argc=5, argv=0x7fffffff2f88) at emacs.c:2325 Full backtrace in attachment gdb.log. Some stuff shows as `` unfortunately, even though I configured Emacs with `-Og -ggdb3`. Looks like there are some optimization options creeping in from elsewhere. ;;=================== In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.16.0) Repository revision: 74d017edb6717ad76d38edc02ad3210d4ad66b96 Repository branch: nixos-21.05 Windowing system distributor 'System Description: NixOS 21.05 (Okapi) Configured using: 'configure --prefix=/nix/store/p2yxdx48mqgvaflygysqz5b7p7q2bbpw-emacs-pgtkgcc-20210725.0 --disable-build-details --with-modules --with-x-toolkit=gtk3 --with-cairo --with-native-compilation --with-pgtk' Configured features: CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PGTK PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS XIM GTK3 ZLIB Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix