Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

latest and greatest

  • Loading branch information...
commit 39988b876de87d0fb6706d982894e808c9291362 1 parent cfc6d40
Ryan McGeary authored
Showing with 90 additions and 6 deletions.
  1. +90 −6 maxframe.el
96 maxframe.el
View
@@ -1,8 +1,8 @@
-;;; $Id: maxframe.el 367 2007-03-29 19:46:23Z ryan $
;; maximize the emacs frame based on display size
;; Copyright (C) 2007 Ryan McGeary
-;; Version: 0.1 Author: Ryan McGeary
+;; Author: Ryan McGeary
+;; Version: 0.4
;; Keywords: display frame window maximize
;; This code is free; you can redistribute it and/or modify it under the
@@ -24,6 +24,19 @@
;; (require 'maxframe)
;; (add-hook 'window-setup-hook 'maximize-frame t)
;;
+;; If using two framebuffers (monitors), it might be necesssary to specify a
+;; mf-max-width value set to the pixel width of main framebuffer. This is
+;; necessary because emacs does not yet support sniffing different
+;; framebuffers. Example:
+;;
+;; (require 'maxframe)
+;; (setq mf-max-width 1600) ;; Pixel width of main monitor.
+;; (add-hook 'window-setup-hook 'maximize-frame t)
+;;
+;; To restore the frame to it's original dimensions, call restore-frame:
+;;
+;; M-x restore-frame
+;;
;; How it works
;; ------------
;; puts the emacs frame in the top left corner of the display and calculates
@@ -41,6 +54,11 @@
;; values from when emacs was started instead of the current display
;; values. Perhaps there's a way to have emacs re-sniff these values, but I'm
;; not yet sure how.
+;;
+;; Credits
+;; -------
+;; The w32 specific functions were borrowed from the Emacs Manual:
+;; http://www.gnu.org/software/emacs/windows/big.html#windows-like-window-ops
(defgroup maxframe nil "Handle maximizing frames.")
@@ -51,7 +69,7 @@ determining the maximize number of columns to fit on a display"
:type 'integer
:group 'maxframe)
-;; The default accounts for a Mac OS X display with a menubar
+;; The default accounts for a Mac OS X display with a menubar
;; height of 22 pixels, a titlebar of 23 pixels, and no dock.
(defcustom mf-display-padding-height (+ 22 23)
"*Any extra display padding that you want to account for while
@@ -59,6 +77,42 @@ determining the maximize number of rows to fit on a display"
:type 'integer
:group 'maxframe)
+(defcustom mf-offset-x 0
+ "*The x coordinate of the upper left corner of the frame.
+Negative values are interpreted relative to the rightmost
+position. See `set-frame-position'."
+ :type 'integer
+ :group 'maxframe)
+
+(defcustom mf-offset-y 0
+ "*The y coordinate of the upper left corner of the frame.
+Negative values are interpreted relative to the bottommost
+position. See `set-frame-position'."
+ :type 'integer
+ :group 'maxframe)
+
+(defcustom mf-max-width nil
+ "*The maximum display width to support. This helps better
+support the true nature of display-pixel-width. Since multiple
+monitors will result in a very large display pixel width, this
+value is used to set the stop point for maximizing the frame.
+This could also be used to set a fixed frame size without going
+over the display dimensions."
+ :type 'integer
+ :group 'maxframe)
+
+(defcustom mf-max-height nil
+ "*The maximum display height to support. This helps better
+support the true nature of display-pixel-height. See
+`mf-max-width'."
+ :type 'integer
+ :group 'maxframe)
+
+(defvar mf-restore-width nil)
+(defvar mf-restore-height nil)
+(defvar mf-restore-top nil)
+(defvar mf-restore-left nil)
+
(defun w32-maximize-frame ()
"Maximize the current frame (windows only)"
(interactive)
@@ -90,13 +144,37 @@ specified by HEIGHT."
"Sets size of FRAME to WIDTH by HEIGHT, measured in pixels."
(set-frame-size frame (mf-max-columns width) (mf-max-rows height)))
+(defun mf-max-display-pixel-width ()
+ (min (display-pixel-width)
+ (or mf-max-width (display-pixel-width))))
+
+(defun mf-max-display-pixel-height ()
+ (min (display-pixel-height)
+ (or mf-max-height (display-pixel-height))))
+
(defun x-maximize-frame ()
"Maximize the current frame (x or mac only)"
(interactive)
+ (unless (or mf-restore-width mf-restore-height mf-restore-top mf-restore-left)
+ (setq mf-restore-width (frame-width)
+ mf-restore-height (frame-height)
+ mf-restore-top (frame-parameter (selected-frame) 'top)
+ mf-restore-left (frame-parameter (selected-frame) 'left)))
(mf-set-frame-pixel-size (selected-frame)
- (display-pixel-width)
- (display-pixel-height))
- (set-frame-position (selected-frame) 0 0))
+ (mf-max-display-pixel-width)
+ (mf-max-display-pixel-height))
+ (set-frame-position (selected-frame) mf-offset-x mf-offset-y))
+
+(defun x-restore-frame ()
+ "Restore the current frame (x or mac only)"
+ (interactive)
+ (when (and mf-restore-width mf-restore-height mf-restore-top mf-restore-left)
+ (set-frame-size (selected-frame) mf-restore-width mf-restore-height)
+ (set-frame-position (selected-frame) mf-restore-left mf-restore-top))
+ (setq mf-restore-width nil
+ mf-restore-height nil
+ mf-restore-top nil
+ mf-restore-left nil))
(defun maximize-frame ()
"Maximizes the frame to fit the display if under a windowing
@@ -105,6 +183,12 @@ system."
(cond ((eq window-system 'w32) (w32-maximize-frame))
((memq window-system '(x mac)) (x-maximize-frame))))
+(defun restore-frame ()
+ "Restores a maximized frame. See `maximize-frame'."
+ (interactive)
+ (cond ((eq window-system 'w32) (w32-restore-frame))
+ ((memq window-system '(x mac)) (x-restore-frame))))
+
(defalias 'mf 'maximize-frame)
(provide 'maxframe)
Please sign in to comment.
Something went wrong with that request. Please try again.