Setting frame size in Emacs on toggle out of fullscreen
I am using Carbon Emacs 23 and am trying to get the frame width to be a certain value after toggling out of a fullscreen frame (as set by a function). Actually, the weird thing is that not only is the width not set, but if you toggle out of fullscreen repeatedly the frame gets smaller and smaller, like a disappearing window. Appreciate any ideas, I have tried a few different ones. Here is the code:
(defun set-frame-size-according-to-resolution ()
(interactive)
(if window-system
(progn
;; use 120 char wide window for largeish displays
;; and smaller 80 column windows for smaller displays
;; pick whatever numbers make sense for you
(if (> (x-display-pixel-width) 1280)
(add-to-list 'default-frame-alist (cons 'width 140))
(add-to-list 'default-frame-alist (cons 'width 100)))
;; for the height, subtract a couple hundred pixels
;; from the screen height (for panels, menubars and 开发者_如何学编程
;; whatnot), then divide by the height of a char to
;; get the height we want
(add-to-list 'default-frame-alist
(cons 'height (/ (- (x-display-pixel-height) 200) (frame-char-height)))))))
;;; This used to be in Carbon Emacs, puttin' it back in with my own twist
(defun mac-toggle-max-window ()
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen)
(progn
(scroll-bar-mode 1) ;; turn on scrollbars when not in fullscreen mode
(set-frame-size-according-to-resolution)
nil)
(progn
(scroll-bar-mode -1) ;; turn off scrollbars when in fullscreen mode
'fullboth))))
;;; Toggle full screen via CMD-Return (my meta key is mapped to command on OS X
(define-key global-map [(meta return)]
'mac-toggle-max-window)
Never mind, I figured it out a few minutes later.
Here is the answer:
;;; Set frame width - used on toggle out of fullscreen mode
(defun default-frame-width ()
"Set width of selected frame."
(modify-frame-parameters
(selected-frame)
(list (cons 'width 140))))
;;; This used to be in Carbon Emacs, puttin' it back in with my own twist
(defun mac-toggle-max-window ()
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen)
(progn
(scroll-bar-mode 1) ;; turn on scrollbars when not in fullscreen mode
(default-frame-width)
nil)
(progn
(scroll-bar-mode -1) ;; turn off scrollbars when in fullscreen mode
'fullboth))))
;;; Toggle full screen via CMD-Return (my meta key is mapped to command on OS X
(define-key global-map [(meta return)]
'mac-toggle-max-window)
精彩评论