1 ;;; $Id: maxframe.el 331 2007-02-20 16:58:21Z ryan $
2 ;; maximize the emacs frame based on display size
4 ;; Copyright (C) 2007 Ryan McGeary
5 ;; Author: Ryan McGeary
6 ;; Keywords: display frame window maximize
8 ;; This code is free; you can redistribute it and/or modify it under the
9 ;; terms of the GNU General Public License as published by the Free
10 ;; Software Foundation; either version 2, or (at your option) any later
17 ;; maxframe provides the ability to maximize the emacs frame and stay within
18 ;; the display resolution.
22 ;; Example of lines to be added to your .emacs:
24 ;; (require 'maxframe)
25 ;; (add-hook 'window-setup-hook 'maximize-frame t)
29 ;; puts the emacs frame in the top left corner of the display and calculates
30 ;; the maximum number of columns and rows that can fit in the display
34 ;; Requires Emacs 22 (for fringe support), but maximize-frame still works
35 ;; under Emacs 21 on Windows.
37 ;; Emacs does not recognize when the display's resolution is changed. This is
38 ;; a problem because I would like to be able to re-maximize the frame after
39 ;; connecting to a display with different resolution. Unfortunately,
40 ;; display-pixel-width and display-pixel-height yield the display resolution
41 ;; values from when emacs was started instead of the current display
42 ;; values. Perhaps there's a way to have emacs re-sniff these values, but I'm
46 (defgroup maxframe nil "Handle maximizing frames.")
48 (defcustom mf-display-padding-width 0
49 "*Any extra display padding that you want to account for while
50 determining the maximize number of columns to fit on a display"
54 ;; The default accounts for a Mac OS X display with a menubar
55 ;; height of 22 pixels, a titlebar of 23 pixels, and no dock.
56 (defcustom mf-display-padding-height (+ 22 23)
57 "*Any extra display padding that you want to account for while
58 determining the maximize number of rows to fit on a display"
62 (defun w32-maximize-frame ()
63 "Maximize the current frame (windows only)"
65 (w32-send-sys-command 61488))
67 (defun w32-restore-frame ()
68 "Restore a minimized/maximized frame (windows only)"
70 (w32-send-sys-command 61728))
72 (defun mf-max-columns (width)
73 "Calculates the maximum number of columns that can fit in
74 pixels specified by WIDTH."
75 (let ((scroll-bar (or (frame-parameter nil 'scroll-bar-width) 0))
76 (left-fringe (or left-fringe-width (nth 0 (window-fringes)) 0))
77 (right-fringe (or right-fringe-width (nth 1 (window-fringes)) 0)))
78 (/ (- width scroll-bar left-fringe right-fringe
79 mf-display-padding-width)
82 (defun mf-max-rows (height)
83 "Calculates the maximum number of rows that can fit in pixels
86 mf-display-padding-height)
89 (defun mf-set-frame-pixel-size (frame width height)
90 "Sets size of FRAME to WIDTH by HEIGHT, measured in pixels."
91 (set-frame-size frame (mf-max-columns width) (mf-max-rows height)))
93 (defun x-maximize-frame ()
94 "Maximize the current frame (x or mac only)"
96 (mf-set-frame-pixel-size (selected-frame)
98 (display-pixel-height))
99 (set-frame-position (selected-frame) 0 0))
101 (defun maximize-frame ()
102 "Maximizes the frame to fit the display if under a windowing
105 (cond ((eq window-system 'w32) (w32-maximize-frame))
106 ((memq window-system '(x mac)) (x-maximize-frame))))
108 (defalias 'mf 'maximize-frame)