Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(patches/alpha-background): add experimental alpha-background patch #129

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

jimeh
Copy link
Owner

@jimeh jimeh commented Dec 7, 2024

Resolves #111

@jimeh
Copy link
Owner Author

jimeh commented Dec 7, 2024

@jonrubens I hope you don't mind if I borrow the changes in your ns-alpha-background branch as a optional patch for use in my build script. If you have any objections, I'm happy to drop it.

The patch feature includes a static *.patch file for Emacs 29.x, and dynamically downloads a patch for Emacs 30.x and 31.x from GitHub.

If you don't mind others making use of your alpha-background changes, I think it'd be nice to get a patch submitted to emacs-plus as well. They already maintain a number of very nice patches.

@jonrubens
Copy link

You can absolutely include my change as a patch.

FYI, I have submitted the code to the Emacs master branch, so hopefully it will get pulled in for Emacs 31.

@jimeh jimeh merged commit c53c398 into master Dec 7, 2024
4 checks passed
@jimeh jimeh deleted the experimental-alpha-background-patch branch December 7, 2024 21:00
@jimeh
Copy link
Owner Author

jimeh commented Dec 8, 2024

@jonrubens Not sure if you've noticed, but when stepping through alpha-background with +1 or -1, I notice some odd flickering and color changes with my config. Essentially, every second or third value yields a slightly more yellowish background color than others, making it look like a slight flicker when quickly stepping up/down the alpha-background one value at a time.

I'm not sure if it's simply how the math works out when applying transparency to the colors of my theme, or if it's some odd bug with alpha-background. A similar thing seems to happen when setting alpha as well, but it's harder to tell cause the intensity curve is much stronger in the 90-100 range than it is for alpha-background.

If you're curious to dig deeper, I've got screenshots ranging with values 70 to 100 for both alpha-background and alpha, with Emacs placed in front of a solid white background:

I used my transparency helpers for quickly changing the value, and here's a variant that uses alpha-background instead of alpha:

siren-transparency.el:
;;; siren-transparency.el --- jimeh's Emacs Siren: Emacs Frame transparency.

;;; Commentary:

;; Basic helpers and configuration for frame transparency.

;;; Code:

(require 'siren-ui)

(defgroup siren-transparency nil
  "Options for the Siren transparency."
  :group 'siren-ui)

(defcustom siren-transparency-default-level 90
  "The default frame transparency level for Emacs frames."
  :type 'number
  :set (lambda (symbol value)
         (set-default symbol value)
         (setf (alist-get 'alpha-background default-frame-alist) value))
  :group 'siren)

(defun siren-transparency-decrease ()
  "Decrease level of transparency for the current frame."
  (interactive)
  (let ((current (or (frame-parameter nil 'alpha-background) 100)))
    (if (> current 0)
        (let ((new-level (+ current -1)))
          (siren-transparency new-level)
          (message "Frame transparency set to %s" new-level))
      (message "This is a minimum value of transparency!"))))

(defun siren-transparency-increase ()
  "Increase level of transparency for the current frame."
  (interactive)
  (let ((current (or (frame-parameter nil 'alpha-background) 100)))
    (if (< current 100)
        (let ((new-level (+ current +1)))
          (siren-transparency new-level)
          (message "Frame transparency set to %s" new-level))
      (message "This is a minimum value of transparency!"))))

(defun siren-transparency (num)
  "Set level of transparency for the current frame by providing NUM."
  (interactive "nEnter transparency level in range 0-100: ")
  (set-frame-parameter nil 'alpha-background (cond ((> num 100) 100)
                                                   ((< num 0) 0)
                                                   (t num))))

;; Keybindings
(siren-general-define-key
 "C-M-|" 'siren-transparency
 "C-M-<" 'siren-transparency-decrease
 "C-M->" 'siren-transparency-increase)

(provide 'siren-transparency)
;;; siren-transparency.el ends here

@jonrubens
Copy link

I haven't ever noticed the color flicker. It's been a while since I wrote the code but my first pass guess is that it is something in how MacOS does transparency and not on the emacs side of things. I might dig into that further but I don't think there is anything in what I wrote that breaks down the color values to RGB besides simply applying the alpha component. It could be a consequence of how MacOS rounds when taking a 0-100 multiplier and converts to 0-255.

As for the intensity curve, that is something that bothered me and it never felt right. I wanted the transparency at 90% alpha to match 90% alpha-background but I couldn't figure out why it doesn't. I had an idea to fix it by translating the alpha-background curve to match, but it felt to hacky when there must be some layer being drawn that should be able to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add patch for alpha-background support
2 participants