vedang / pdf-tools

Emacs support library for PDF files.
https://pdftools.wiki
GNU General Public License v3.0
641 stars 90 forks source link

fullscreen tooltips break after loading pdf-tools on MacOS #298

Open ultronozm opened 2 months ago

ultronozm commented 2 months ago

I've tested the following setups:

(1) Emacs master, pdf-tools 1.1.0 (2) Emacs 29.4, pdf-tools 1.1.0

The issue appears with (1) but not (2), so I reported it on the Emacs bug mailing list, but was encouraged there to report it to pdf-tools first, to see if some issue with Emacs core could be identified.

Steps to reproduce:

  1. Install pdf-tools (e.g., via list-packages)

  2. Emacs -Q

  3. Evaluate the following:

(package-initialize) (use-package pdf-tools :config (pdf-tools-install :no-query))

  1. Visit any pdf file.

These steps put Emacs in a state where tooltips behave badly: when the current frame is fullscreen (via (toggle-frame-fullscreen)), tooltips display in a separate fullscreen frame rather than as a child frame.

All tooltips are affected, not just those produced by pdf-tools. For example, (x-show-tip "This is a tooltip." (selected-frame) nil 5) triggers the issue, as does mousing over any link in Help.

As noted above, I'm using pdf-tools 1.1.0. Here's the pdf-tools configuration from my init file:

(use-package pdf-tools :mode ("\.pdf\'" . pdf-view-mode) :custom (TeX-view-program-selection '((output-pdf "PDF Tools"))) (global-auto-revert-ignore-modes '(pdf-view-mode)) (pdf-view-midnight-colors '("#DCDCCC" . "#383838")) :config (pdf-tools-install :no-query) (require 'pdf-occur) :bind (:map pdf-view-mode-map ("j" . pdf-view-jump-to-register) ("y" . image-previous-line) ("" . nil) ("" . nil) (" " . pdf-view-scroll-up-or-next-page) (" " . pdf-view-scroll-down-or-previous-page)))

Here's the dump from report-emacs-bug:

In GNU Emacs 31.0.50 (build 4, aarch64-apple-darwin23.6.0, NS appkit-2487.70 Version 14.6.1 (Build 23G93)) of 2024-09-05 built on d51735 Repository revision: df57e44a08fd5c7dc159254a40f5d2e4d008e8df Repository branch: master Windowing system distributor 'Apple', version 10.3.2487 System Description: macOS 14.6.1

Configured using: 'configure --with-ns --with-native-compilation --with-tree-sitter --with-gif --with-png --with-jpeg --with-rsvg --with-tiff --with-imagemagick --with-x-toolkit=gtk3 --with-xwidgets'

Configured features: ACL DBUS GLIB GNUTLS IMAGEMAGICK LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM XWIDGETS ZLIB

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

Major mode: Text

Minor modes in effect: pdf-occur-global-minor-mode: t repeat-mode: t override-global-mode: t recentf-mode: t display-time-mode: t save-place-mode: t global-auto-revert-mode: t minibuffer-depth-indicate-mode: t electric-pair-mode: t tooltip-mode: t global-eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t tab-bar-history-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t minibuffer-regexp-mode: t column-number-mode: t line-number-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t

Load-path shadows: /Users/au710211/.emacs.d/elpa/lispy-20230314.1738/elpa hides /Users/au710211/.emacs.d/elpa/ivy-20240405.2019/elpa /Users/au710211/.emacs.d/elpa/editorconfig-20240318.2049/editorconfig hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/editorconfig /Users/au710211/.emacs.d/elpa/which-key-20240423.1320/which-key hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/which-key /Users/au710211/.emacs.d/elpa/editorconfig-20240318.2049/editorconfig-core hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/editorconfig-core /Users/au710211/.emacs.d/elpa/editorconfig-20240318.2049/editorconfig-conf-mode hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/editorconfig-conf-mode /Users/au710211/.emacs.d/elpa/ef-themes-1.7.0/theme-loaddefs hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/theme-loaddefs /Users/au710211/.emacs.d/elpa/transient-20240421.1737/transient hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/transient /Users/au710211/.emacs.d/elpa/editorconfig-20240318.2049/editorconfig-core-handle hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/editorconfig-core-handle /Users/au710211/.emacs.d/elpa/editorconfig-20240318.2049/editorconfig-fnmatch hides /Users/au710211/gnu-emacs/nextstep/Emacs.app/Contents/Resources/lisp/editorconfig-fnmatch

Features: (shadow sort mail-extr emacsbug magit-base magit-section cursor-sensor crm dash compat etags fileloop generator xref shortdoc help-fns radix-tree mm-archive misearch multi-isearch package-vc lisp-mnt network-stream url-cache url-http url-auth url-gw nsm display-line-numbers add-log vc-hg vc-git diff-mode track-changes vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs log-view pcvs-util vc vc-dispatcher dired-aux ol-eww eww xdg url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect 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 parse-time gnus-spec gnus-int gnus-range message sendmail yank-media puny rfc822 mml mml-sec epa derived epg rfc6068 epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus-win gnus nnheader gnus-util mail-utils range mm-util mail-prsvr ol-docview ol-bibtex bibtex iso8601 ol-bbdb ol-w3m ol-doi org-link-doi org-capture org-refile pdf-sync pdf-annot facemenu pdf-outline pdf-links 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 pcomplete org-list org-footnote org-faces org-entities time-date ob-emacs-lisp ob-core ob-eval org-cycle org-table ol org-fold org-fold-core org-keys oc org-loaddefs thingatpt cal-menu calendar cal-loaddefs org-version org-compat org-macs pdf-history pdf-occur ibuf-ext ibuffer ibuffer-loaddefs tablist advice tablist-filter semantic/wisent/comp semantic/wisent semantic/wisent/wisent semantic/util-modes semantic/util semantic semantic/tag semantic/lex semantic/fw mode-local find-func cedet pdf-isearch let-alist pdf-misc imenu doc-view pdf-tools compile comint ansi-osc ansi-color ring cus-edit cus-start cus-load pdf-view bookmark text-property-search pp jka-compr pdf-cache pdf-info tq pdf-util format-spec pdf-macs image-mode dired dired-loaddefs exif ace-link-autoloads aggressive-indent-autoloads ai-org-chat-autoloads attrap-autoloads auctex-cont-latexmk-autoloads auctex-label-numbers-autoloads consult-company-autoloads company-autoloads copilot-autoloads czm-cpp-autoloads cmake-build-autoloads czm-misc-autoloads czm-preview-autoloads czm-spell-autoloads czm-tex-edit-autoloads czm-tex-fold-autoloads czm-tex-jump-autoloads czm-tex-ref-autoloads debbugs-autoloads define-repeat-map-autoloads diminish-autoloads dynexp-autoloads easy-kill-autoloads ediff-copy-all-autoloads editorconfig-autoloads ef-themes-autoloads eldoc-box-autoloads embark-consult-autoloads consult-autoloads embark-autoloads exec-path-from-shell-autoloads expand-region-autoloads flycheck-package-autoloads flycheck-autoloads gnu-elpa-keyring-update-autoloads go-translate-autoloads gptel-autoloads info-colors-autoloads library-autoloads czm-tex-util-autoloads lispy-autoloads hydra-autoloads iedit-autoloads ace-window-autoloads avy-autoloads llm-autoloads lv-autoloads marginalia-autoloads mmm-mode-autoloads orderless-autoloads package-lint-autoloads pdf-tools-autoloads perfect-margin-autoloads plz-autoloads pos-tip-autoloads preview-auto-autoloads preview-tailor-autoloads publish-autoloads f-autoloads repo-scan-autoloads magit-autoloads pcase magit-section-autoloads git-commit-autoloads dash-autoloads s-autoloads swiper-autoloads ivy-autoloads symbol-overlay-autoloads tablist-autoloads tex-continuous-autoloads tex-item-autoloads tex-numbers-autoloads auctex-autoloads tex-site finder-inf tex-parens-autoloads transient-autoloads vertico-autoloads which-key-autoloads info with-editor-autoloads zoutline-autoloads package browse-url 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 eieio eieio-core password-cache json map url-vars noutline outline project repeat edmacro kmacro byte-opt use-package-bind-key bind-key easy-mmode recentf tree-widget wid-edit time saveplace autorevert filenotify mb-depth elec-pair comp comp-cstr warnings icons subr-x comp-run comp-common rx cl-macs gv cl-extra help-mode use-package-ensure cl-seq use-package-core cl-loaddefs cl-lib bytecomp byte-compile rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win 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 xwidget-internal dbusbind kqueue cocoa ns lcms2 multi-tty make-network-process native-compile emacs)

Memory information: ((conses 16 692070 125304) (symbols 48 42961 0) (strings 32 173681 11296) (string-bytes 1 5072351) (vectors 16 68177) (vector-slots 8 753335 54362) (floats 8 713 600) (intervals 56 26364 0) (buffers 992 30))

aikrahguzar commented 2 months ago

This is strange. pdf-tools does mess with tooltips a little but I don't see how it can cause some problems.

My first (and so far only) guess was that this is related to pdf-annot changing the value of use-system-tooltips to nil. But the documentation states that the option is only meaningful for GTK+ or haiku builds so this shouldn't change anything for macos. You can try setting use-system-tooltips to nil and see if that resolves the problem.

ultronozm commented 2 months ago

Thanks for your response.

Indeed, changing use-system-tooltips back to its default value of t makes the issue go away. I also noticed just now that although the versions of pdf-tools that I've used with the two Emacs setups have the same version number 1.1.0, they are slightly different. The one that breaks (pulled from github rather than elpa) contains in pdf-util.el

(when (and (> emacs-major-version 28)
           (not (boundp 'x-gtk-use-system-tooltips)))
  ;; The x-gtk prefix has been dropped Emacs 29
  (defvaralias 'x-gtk-use-system-tooltips 'use-system-tooltips))

This causes the code

      (when (boundp 'x-gtk-use-system-tooltips)
        (setq x-gtk-use-system-tooltips nil))

from pdf-annot.el to set use-system-tooltips to nil.

I guess it resolves the issue for me, but maybe something should be adjusted to make it not arise for other users?

aikrahguzar commented 2 months ago

Indeed, changing use-system-tooltips back to its default value of t makes the issue go away. I also noticed just now that although the versions of pdf-tools that I've used with the two Emacs setups have the same version number 1.1.0, they are slightly different. The one that breaks (pulled from github rather than elpa) contains in pdf-util.el

(when (and (> emacs-major-version 28)
           (not (boundp 'x-gtk-use-system-tooltips)))
  ;; The x-gtk prefix has been dropped Emacs 29
  (defvaralias 'x-gtk-use-system-tooltips 'use-system-tooltips))

I guess this was added because x-gtk-use-system-tooltips is not defined on some builds (not sure about this, it is defined as an alias on pgtk at least) but as a side effect this caused problems on window systems other than x.

This causes the code

      (when (boundp 'x-gtk-use-system-tooltips)
        (setq x-gtk-use-system-tooltips nil))

from pdf-annot.el to set use-system-tooltips to nil.

This is predicated on pdf-annot-tweak-tooltips so easiest thing for now is to set it to nil. I don't like that this snippet causes a global option to be set during turning on a local minor mode. It would be better to change the value of x-gtk-use-system-tooltips using a setter for pdf-annot-tweak-tooltips.

In any case use-system-tooltips causing this behavior seems like an emacs bug to me. By my reading setting it to nil should be harmless on builds other than GTK+ or haiku.

I guess it resolves the issue for me, but maybe something should be adjusted to make it not arise for other users?

Yes, we should define the alias in more restrictive circumstances. I am actually surprised that defining it is necessary considering the Emacs deprecation policies.