branch: externals/posframe
commit 6dcf17f8b73208c2613a0029117ac5897926c06a
Author: Marek L <[email protected]>
Commit: Marek L <[email protected]>
Add ability to adjust posframe text scale based on
text scale of parent frame.
Why:
Previously posframe always used text-scale 0 regardless of
user specified text scale on parent frame.
This lead to inconsistent UI and even worse bad user experience
affecting accessibility of the editor.
This changesi the default behaviour of posframe to match text-scale
of parent frame with option for user to customise this behaviour
using `posframe-text-scale-factor-function` variable.
Example:
```
(setopt posframe-text-scale-factor-function (lambda (_v) 0))
```
Replicates old behaviour.
```
(setopt posframe-text-scale-factor-function
(lambda (v)
(+ (or v 0) 2)))
```
will increase text-scale of posframe by two of parent frame.
---
posframe.el | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/posframe.el b/posframe.el
index e75b0811f3..3753eb57d7 100644
--- a/posframe.el
+++ b/posframe.el
@@ -58,6 +58,17 @@ case, but suggest use function
`posframe-mouse-banish-simple' or
custom function for EXWM users."
:type 'function)
+(defcustom posframe-text-scale-factor-function
#'posframe-text-scale-factor-default
+ "The function to adjust value of text-scale of posframe buffer.
+
+Accepts single argument which is the value of parent buffer
`text-scale-mode-amount'
+or nil if the `text-scale-mode' is disabled in the parent buffer.
+`posframe-text-scale-factor-default' is an alias for `identity' function."
+ :group 'posframe
+ :type 'function)
+
+(defalias #'posframe-text-scale-factor-default #'identity)
+
(defvar-local posframe--frame nil
"Record posframe's frame.")
@@ -209,7 +220,8 @@ position. Its argument is a plist of the following form:
:header-line-height xxx
:tab-line-height xxx
:x-pixel-offset xxx
- :y-pixel-offset xxx)
+ :y-pixel-offset xxx
+ :parent-text-scale-mode-amount xxx)
By default, poshandler is auto-selected based on the type of POSITION,
but the selection can be overridden using the POSHANDLER argument.
@@ -410,6 +422,8 @@ You can use `posframe-delete-all' to delete all posframes."
(font-width (default-font-width))
(font-height (with-current-buffer (window-buffer parent-window)
(posframe--get-font-height position)))
+ (parent-text-scale-mode-amount (with-current-buffer (window-buffer
parent-window)
+ (and text-scale-mode
text-scale-mode-amount)))
(mode-line-height (window-mode-line-height
(and (window-minibuffer-p)
(ignore-errors (window-in-direction
'above)))))
@@ -455,7 +469,8 @@ You can use `posframe-delete-all' to delete all posframes."
:respect-header-line respect-header-line
:respect-mode-line respect-mode-line
:override-parameters override-parameters
- :accept-focus accept-focus))
+ :accept-focus accept-focus
+ :parent-text-scale-mode-amount parent-text-scale-mode-amount))
;; Insert string into the posframe buffer
(posframe--insert-string string no-properties)
@@ -504,7 +519,8 @@ You can use `posframe-delete-all' to delete all posframes."
:header-line-height header-line-height
:tab-line-height tab-line-height
:x-pixel-offset x-pixel-offset
- :y-pixel-offset y-pixel-offset))))
+ :y-pixel-offset y-pixel-offset
+ :parent-text-scale-mode-amount
parent-text-scale-mode-amount))))
;; Move posframe
(posframe--set-frame-position
@@ -590,7 +606,8 @@ You can use `posframe-delete-all' to delete all posframes."
override-parameters
respect-header-line
respect-mode-line
- accept-focus)
+ accept-focus
+ parent-text-scale-mode-amount)
"Create and return a posframe child frame.
This posframe's buffer is BUFFER-OR-NAME.
@@ -766,6 +783,10 @@ ACCEPT-FOCUS."
;; so we should force set parent-frame again in this place.
(set-frame-parameter posframe--frame 'parent-frame parent-frame)
+ ;; Set text scale based on the parent frame text scale.
+ (text-scale-set
+ (funcall posframe-text-scale-factor-function
parent-text-scale-mode-amount))
+
posframe--frame)))
(defun posframe--find-existing-posframe (buffer &optional last-args)