From 945b5458dd2a2081d5c6e4d45b9b92a0cd4b4fb0 Mon Sep 17 00:00:00 2001 From: David Florness Date: Sat, 25 Jul 2026 19:54:04 -0400 Subject: [PATCH] appearance: fix toggle-transparency under pgtk/Wayland The `alpha' frame parameter asks the window system to make the whole window translucent. On X11 that works because Emacs sets the _NET_WM_WINDOW_OPACITY property, which the compositor reads. Wayland has no equivalent protocol -- opacity is not something a client can request -- so on a pgtk build the parameter is accepted and then silently does nothing. That is why C-c t appeared dead under sway. Switch to `alpha-background' (new in Emacs 29), which Emacs implements itself by drawing the frame background with an alpha channel and letting the compositor blend it. That path works on pgtk/Wayland, and as a bonus keeps foreground text fully opaque instead of fading it along with the background. Because `alpha-background' is always a plain integer 0-100 (or nil), the cond that unpacked `alpha''s (ACTIVE . INACTIVE) and (ACTIVE INACTIVE) forms is no longer needed. Testing < 100 instead of a memq against '(nil 100) also lets the toggle recover from any starting value. The threshold moves into `transparent-frame-alpha' so the command and the new-frame hook share one number. Also convert the file's implicit sections to `;;;' headings, which Outline minor mode recognizes as such; see "Tips on Writing Comments" in the Elisp manual. Co-Authored-By: Claude Opus 5 --- lisp/appearance.el | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lisp/appearance.el b/lisp/appearance.el index 086172e..8e225da 100644 --- a/lisp/appearance.el +++ b/lisp/appearance.el @@ -1,7 +1,7 @@ -;; Change frame title +;;; Frame title (setq frame-title-format "emacs") -;; Font +;;; Font (setq my-font-size 17) (defun set-my-font-size (font-size) (interactive (list (read-number "size: " my-font-size))) @@ -18,9 +18,11 @@ (lambda (frame) (set-frame-font my-font nil t))) +;;; Coding systems (set-language-environment "UTF-8") (prefer-coding-system 'utf-8) +;;; General UI (blink-cursor-mode 0) ; Turn off cursor blinking (column-number-mode 1) ; Show column number next to line number in mode line (global-hi-lock-mode 1) ; Highlight stuff with M-s h @@ -31,33 +33,41 @@ (show-paren-mode 1) ; Highlight parentheses (tool-bar-mode 0) ; Disable tool bar -;; Spell check in comments and strings +;;; Spell checking in comments and strings (flyspell-prog-mode) -;; Transparency control +;;; Transparency control +(defvar transparent-frame-alpha 80 + "Background opacity, in percent, used when a frame is transparent.") + (defvar new-frames-are-transparent nil "Whether new frames should be transparent") +(defun frame-transparent-p (&optional frame) + "Return non-nil if FRAME's background is transparent." + (let ((alpha (frame-parameter frame 'alpha-background))) + (and (numberp alpha) (< alpha 100)))) + +;; `alpha' is a no-op under pgtk: it asks the window system for whole-window +;; opacity, which Wayland has no protocol for. `alpha-background' is drawn by +;; Emacs itself, and keeps foreground text opaque. (defun toggle-transparency (&optional frame) - "Toggle FRAME's transparency." + "Toggle FRAME's background transparency." (interactive) - (let ((alpha (frame-parameter frame 'alpha))) - (set-frame-parameter - frame 'alpha - (if (memq (cond ((numberp alpha) alpha) - ((numberp (cdr alpha)) (cdr alpha)) - ;; Also handle undocumented ( ) form. - ((numberp (cadr alpha)) (cadr alpha))) - '(nil 100)) - 80 100)))) + (set-frame-parameter frame 'alpha-background + (if (frame-transparent-p frame) + 100 + transparent-frame-alpha))) (global-set-key (kbd "C-c t") #'toggle-transparency) (add-to-list 'after-make-frame-functions (lambda (frame) (if new-frames-are-transparent - (set-frame-parameter frame 'alpha 80)))) + (set-frame-parameter frame 'alpha-background + transparent-frame-alpha)))) +;;; Page breaks ;; display ugly ^L page breaks as tidy horizontal lines (use-package page-break-lines :config -- 2.38.4