-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchild-stick.el
110 lines (98 loc) · 4.45 KB
/
child-stick.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(defcustom child-stick-padding 10 "Padding value between parent window and child frame")
(defcustom child-stick-delay 0.1 "Delay between window spawn and positioning function")
(defun child-stick--title-bar-height (&optional frame)
"Get title bar height in pixels"
(cddr (assq 'title-bar-size (frame-geometry frame))))
(defun child-stick-nw (&optional frame)
"Position Child window to NW"
(interactive)
(let* ((target (or frame (selected-frame)))
(geometry (frame-geometry target))
(width (frame-pixel-width target))
(offset-x (- (+ width child-stick-padding)))
(offset-y (- (child-stick--title-bar-height target))))
(set-frame-position target offset-x offset-y)))
(defun child-stick-ne (&optional frame)
"Position Child window to NW"
(interactive)
(let* ((target (or frame (selected-frame)))
(parent (frame-parent target))
(geometry (frame-geometry target))
(parent-width (frame-pixel-width parent))
(offset-x (+ (+ parent-width child-stick-padding)))
(offset-y (- (child-stick--title-bar-height target))))
(set-frame-position target offset-x offset-y)))
(defun child-stick-sw (&optional frame)
"Position Child window to NW"
(interactive)
(let* ((target (or frame (selected-frame)))
(parent (frame-parent target))
(width (frame-pixel-width target))
(height (frame-pixel-height target))
(parent-height (frame-pixel-height parent))
(offset-x (- (+ width child-stick-padding)))
(offset-y (- parent-height (child-stick--title-bar-height) height))
)
(set-frame-position target offset-x offset-y)))
(defun child-stick-se (&optional frame)
"Position Child window to NW"
(interactive)
(let* ((target (or frame (selected-frame)))
(parent (frame-parent target))
(width (frame-pixel-width parent))
(height (frame-pixel-height target))
(parent-height (frame-pixel-height parent))
(offset-x (+ (+ width child-stick-padding)))
(offset-y (- parent-height (child-stick--title-bar-height) height)))
(set-frame-position target offset-x offset-y)))
(defun child-stick-e (&optional frame)
"Position Child window to NW"
(interactive)
(let* ((target (or frame (selected-frame)))
(parent (frame-parent target))
(parent-width (frame-pixel-width parent))
(parent-height (frame-pixel-height parent))
(offset-x (+ (+ parent-width child-stick-padding)))
(offset-y (- (cddr (assq 'title-bar-size geometry))))
)
(set-frame-position target offset-x offset-y)
(set-frame-height target (- parent-height (tab-bar-height parent t)) nil t)))
(defun child-stick-w (&optional frame)
"Stick child window to W"
(interactive)
(let* ((target (or frame (selected-frame)))
(parent (frame-parent target))
(width (frame-pixel-width target))
(parent-width (frame-pixel-width parent))
(parent-height (frame-pixel-height parent))
(offset-x (- 0 width child-stick-padding))
(offset-y (- (child-stick--title-bar-height target))))
(set-frame-position target offset-x offset-y)
(set-frame-height target (- parent-height (tab-bar-height parent t)) nil t)))
(defun child-stick-s (&optional frame)
"Stick Child window to NW"
(interactive)
(let* ((target (or frame (selected-frame)))
(parent (frame-parent target))
(width (frame-pixel-width target))
(parent-width (frame-pixel-width parent))
(parent-height (frame-pixel-height parent))
(offset-y (+ parent-height child-stick-padding)))
(set-frame-height target 15)
(set-frame-width target (- parent-width 16) nil t)
(set-frame-position target 0 offset-y)
))
(defun display-buffer-child-stick (buffer alist)
"Display BUFFER in a sticky child frame.
ALIST is an association list of action symbols and values. See
Info node `(elisp) Buffer Display Action Alists' for details of
such alists.
It shares all characteristic of `display-buffer-in-child-frame'
with an exception that it positions frame window to a direction provided
in `stick-direction' parameter in provided ALIST."
(let* ((direction (or (ignore-errors (cdr (assq 'stick-direction alist))) 'nw))
(frame (display-buffer-in-child-frame buffer alist))
(dirfun (intern (concat "child-stick-" (symbol-name direction))))
)
(message "%s" dirfun)
(run-with-timer child-stick-delay nil dirfun (window-frame frame))))