forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-maxframe.el
57 lines (46 loc) · 2.16 KB
/
init-maxframe.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
(require-package 'maxframe)
(autoload 'mf-max-display-pixel-width "maxframe" "" nil)
(autoload 'mf-max-display-pixel-height "maxframe" "" nil)
(autoload 'maximize-frame "maxframe" "" t)
(autoload 'restore-frame "maxframe" "" t)
(when *is-a-mac*
(after-load 'maxframe
(fset 'maximize-frame 'x-maximize-frame)
(fset 'restore-frame 'x-restore-frame))
(setq mf-display-padding-width 4
mf-offset-x 0
mf-offset-y 0
mf-display-padding-height (if (when (boundp 'ns-auto-hide-menu-bar)
ns-auto-hide-menu-bar)
23
(+ 27 23))))
(defvar sanityinc/prev-frame nil "The selected frame before invoking `make-frame-command'.")
(defadvice make-frame-command (before sanityinc/note-previous-frame activate)
"Record the selected frame before creating a new one interactively."
(setq sanityinc/prev-frame (selected-frame)))
(defun sanityinc/maybe-maximize-frame (&optional frame)
(with-selected-frame (or frame (selected-frame))
(when (and window-system
sanityinc/prev-frame
(sanityinc/maximized-p sanityinc/prev-frame))
(maximize-frame))))
(add-hook 'after-make-frame-functions 'sanityinc/maybe-maximize-frame)
(add-hook 'after-init-hook 'sanityinc/maybe-maximize-frame)
(defadvice maximize-frame (around skip-if-fullscreen (&optional frame) activate)
(unless (sanityinc/maximized-p frame)
ad-do-it))
(defadvice restore-frame (around skip-if-fullscreen (&optional frame) activate)
(when (sanityinc/maximized-p frame)
ad-do-it))
(defun within-p (a b delta)
(<= (abs (- b a)) delta))
(defun sanityinc/maximized-p (&optional frame)
(or (not (with-selected-frame (or frame (selected-frame)) window-system))
(eq 'fullboth (frame-parameter frame 'fullscreen))
(and (within-p (mf-max-display-pixel-width)
(frame-pixel-width frame)
(frame-char-width frame))
(within-p (mf-max-display-pixel-height)
(+ mf-display-padding-height (frame-pixel-height frame))
(frame-char-height frame)))))
(provide 'init-maxframe)