branch: externals/posframe
commit 6368f920521df60a1c3fed9be4c17da6e9196e0f
Merge: 12f540c9ad b29af47590
Author: tumashu <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #148 from keram/text-scale
Add ability to adjust posframe text scale based on text scale of parent
frame
---
posframe.el | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/posframe.el b/posframe.el
index e75b0811f3..239ff0cd54 100644
--- a/posframe.el
+++ b/posframe.el
@@ -58,6 +58,14 @@ 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."
+ :group 'posframe
+ :type 'function)
+
(defvar-local posframe--frame nil
"Record posframe's frame.")
@@ -209,7 +217,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 +419,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 +466,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 +516,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 +603,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 +780,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)
@@ -1511,6 +1529,11 @@ window manager selects it."
(not posframe--accept-focus))
(redirect-frame-focus posframe--frame (frame-parent))))
+(defun posframe-text-scale-factor-default (parent-text-scale-mode-amount)
+ "Return PARENT-TEXT-SCALE-MODE-AMOUNT or 0 if it is nil.
+This ensures text scale factor is always a number for posframe display."
+ (or parent-text-scale-mode-amount 0))
+
(provide 'posframe)
;;; posframe.el ends here