Add support for :frame key in a view for posframe overrides

This commit is contained in:
Sameer Rahmani 2023-06-18 19:49:44 +01:00
parent f8fb71c307
commit 00e2425608
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
2 changed files with 28 additions and 22 deletions

View File

@ -112,6 +112,20 @@ key/value from the original definition."
f-props (list ,@orig-props)))))
(defvar noether--frame-defaults
(list
:min-height 1 ;; (noether--view-get view :height 1)
:min-width 10 ;; (noether--view-get view :width 10)
:position '(0 . 0) ;;(cons (- (frame-outer-width) 10) (- (frame-outer-height) 10))
;;:position (noether--view-get view :position '(0 . 0))
;;:poshandler (noether--view-get view :poshandler)
:border-width 0 ;; (noether--view-get view :border 0)
;;:border-color (noether--view-get view :border-color "#eeeefe")
:accewpt-focus nil ;;(noether--view-get view :accept-focus)
:timeout 10 ;;(noether--view-get view :timeout 5)
:refresh 1 ;;(noether--view-get view :refresh 1)))
)
)
(defun noether-show (view)
"Draw the given VIEW on the screen."
@ -120,29 +134,17 @@ key/value from the original definition."
(let* ((show-fn (noether--view-get view :show (lambda ())))
(name (noether--view-get view :name))
;; What if the user killed the buffer before?
(buf (get-buffer-create (noether--view-get view :buffer (format "*%s*" name)))))
(buf (get-buffer-create (noether--view-get view :buffer (format "*%s*" name))))
(props (noether--view-get view :frame)))
;; TODO: Check to see whether the buffer is populated. If not, it means
;; that user killed the buffer manually. We need to repopulate it
;; again
(when (noether--view-get view :managed?)
(with-current-buffer buf
(funcall show-fn)
;;(mapc #'funcall (get name :updaters))
))
(funcall show-fn)))
(posframe-show
buf
:min-height (noether--view-get view :height 1)
:min-width (noether--view-get view :width 10)
:position '(0 . 0) ;;(cons (- (frame-outer-width) 10) (- (frame-outer-height) 10))
;;:poshandler #'posframe-poshandler-frame-bottom-right-corner
:border-width (noether--view-get view :border 0)
:border-color (noether--view-get view :border-color "#eeeefe")
:accewpt-focus (noether--view-get view :accept-focus)
:timeout (noether--view-get view :timeout 5)
:refresh (noether--view-get view :refresh 0.5))))
(let ((params (append (list buf) props noether--frame-defaults)))
(apply #'posframe-show params))))
;; We need to keep this function as simple as possible
@ -229,7 +231,7 @@ E.g. the updaters list."
(binding (noether--view-get view :binding)))
(when (not (null binding))
(define-key global-noethor-mode-map binding
(define-key noether-global-mode-map binding
(lambda () (interactive) (noether-show view))))
(with-current-buffer (get-buffer-create (noether--view-get view :buffer (format "*%s*" name)))
@ -259,13 +261,13 @@ E.g. the updaters list."
(funcall (noether--view-get view :deinit (lambda ())))))
(define-minor-mode noethor-global-mode
(define-minor-mode noether-global-mode
"A minor mode that keep tracks of different status blocks.
It reports them back in a status bar like frame."
:global t
:lighter " ST42"
:keymap (make-sparse-keymap)
(if global-noethor-mode
(if noether-global-mode
(mapc #'noether--setup-views noether-views)
(mapc #'noether--teardown-views noether-views)))

View File

@ -6,7 +6,6 @@
;; URL: https://devheroes.codes/lxsameer/noether
;; Version: 0.1.0
;; Keywords: frames, modeline
;; Package-Requires: (posframe (emacs "26.1"))
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@ -78,6 +77,11 @@
:buffer "*mainview*"
:binding (kbd "C-c 1")
:separator "|"
:frame
(list
:position '(110 . 120)
:border-width 1
:border-color "#b9a388")
:units
(list
(line-unit)
@ -86,7 +90,7 @@
(setq noether-views (list example-bar))
(noethor-global-mode t)
(noether-global-mode t)
(provide 'noether.example)
;;; noether.example.el ends here