all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chris McMahan <cmcmahan+n@one.net>
Subject: Re: desktop height?
Date: 30 Jan 2003 09:40:57 -0500	[thread overview]
Message-ID: <uy952em4m.fsf@one.net> (raw)
In-Reply-To: eIpZ9.54420$Oj7.11699754@twister.nyc.rr.com

Bruce Ingalls <bingalls.NO_SPAM@fit-zones.com> writes:

> Does anyone know a way to calculate the height of the desktop in elisp?
> 
> I'd like Emacs to start up with maximum height.
> For that matter, I'd like XEmacs, and various OSes to work.
> 
> In Linux X Window, the following works reasonably well:
> 
> (/ (- (x-display-pixel-height) 50) (frame-char-height)))
> 
> I can get reasonably close with
> 
> (/ (x-display-pixel-height)
>   (* (/ (font-default-size-for-device) 2) 3))
> 
> which works in w32 XEmacs as
> 
> (/ (x-display-pixel-height)
>   (* (/ (string-to-number (font-default-size-for-device)) 2) 3))
> 
> or w32 Emacs as
> 
> (/ (x-display-pixel-height) 18)
> 
> I'd also like to hear of testing on other OSes.
> If someone has a better solution, please send it!
> Thanks ahead.
> 

Sorry about the length of this post. I recently rewrote these
functions, and thought I would share them within the context of this
thread :)

I've got the following code with sets the initial height based on the
current screen's resolution (working under WindowsXP with Emacs 21.2).
This assumes the font (defined in my .emacs as MY_FONT) is already
set. This is necessary to correctly return the frame-char-height.

  ;;;------------------------------------------------------------
  ;;; initial window position settings, height and vertical position is
  ;;; automatically calculated from within the .emacs-config file 
  ;;; The top left corner is 0 0, the bottom right is -1 -1
  (defconst MY_INITIAL_WIDTH   120)
  (defconst MY_INITIAL_LEFT   -15)
  
  ;; set an adjustment to account for window manager frames and title
  ;; bar when calculating the window height. This accounts for the
  ;; menubar as well
  (defconst MY_HEIGHT_ADJUST
    (if (not menu-bar-mode)
    	(setq MY_HEIGHT_ADJUST 30)
      (setq MY_HEIGHT_ADJUST 50))
    "Arbitrary adjustment factor to account for window managers and
    menubar")
  
  ;; use the screen resolution, font height, and whether or not
  ;; there's a menubar to calculate the height and center the frame
  (defconst MY_INITIAL_HEIGHT
    (/ (- (x-display-pixel-height) MY_HEIGHT_ADJUST)
       (frame-char-height))
    "Calculate the initial height of the frame based on the screen
    resolution and character height")
  
  ;;; set the height of the frame so the top can then be calculated to
  ;;; center it
  (set-frame-height (selected-frame) MY_INITIAL_HEIGHT)
  
  ;;; calculate the top to center the frame
  (defconst MY_INITIAL_TOP
    (/ (- (x-display-pixel-height)
    	  (+ (frame-pixel-height) MY_HEIGHT_ADJUST)) 2)
    "Calculate the initial top of the frame based on the screen
    resolution and character height")
  
  ;;; now that the initial frame info is known, set the size and
  ;;; position for subsequent windows
  (defconst MY_DEFAULT_HEIGHT (- MY_INITIAL_HEIGHT 15))
  (defconst MY_DEFAULT_TOP    (+ MY_INITIAL_TOP 45))
  (defconst MY_DEFAULT_LEFT   (- MY_INITIAL_LEFT 150))
  (defconst MY_DEFAULT_WIDTH   MY_INITIAL_WIDTH)
  
    ;;; Set the font and frame size for the initial frame.
    (progn
      (setq initial-frame-alist
            `(
              (top . ,MY_INITIAL_TOP)
              (left . ,MY_INITIAL_LEFT)
              (width . ,MY_INITIAL_WIDTH)
              (height . ,MY_INITIAL_HEIGHT)
              (internal-border-width . 1)
              (cursor-type . t)
              (font . ,MY_FONT)
              )
            )
  
    ;;; Set the default font and frame size
      (setq default-frame-alist
            `(
              (top . ,MY_DEFAULT_TOP)
              (left . ,MY_DEFAULT_LEFT)
              (width . ,MY_DEFAULT_WIDTH)
              (height . ,MY_DEFAULT_HEIGHT)
              (internal-border-width . 1)
              (cursor-type . t)
              (font . ,MY_FONT)
              )
            )
      ))

  ;;;------------------------------------------------------------


Here's some macros I also have to adjust the frame when a new font is
selected, to enlarge the frame to fill most of the current screen, and
to return the frame back to its initial settings:


;;;======================================================================
;;; frame sizing functions
;;;======================================================================

;;;==============================
(defun enlarge-frame ()
  "Enlarge the selected frame to fill a sizeable portion of the screen,
based on the current screen resolution"
  (interactive)

  ;; Set the frame size
  ;; set the new width, with a little space on the sides
  (setq lframe-width
		(- (/ (x-display-pixel-width) (frame-char-width)) 10))
  
  ;; set the new height, allowing for title bars (8)
  (setq lframe-height
		(/ (- (x-display-pixel-height) MY_HEIGHT_ADJUST)
		   (frame-char-height)))

  ;; apply to the selected frame
  (set-frame-size (selected-frame)
				  lframe-width
				  lframe-height)

  ;; center the new frame horizontally and vertically
  ;; set the left position, centering the frame and allowing for frame edges (10)
  (setq lframe-left
		(/ (- (x-display-pixel-width)
			  (+ (frame-pixel-width) 10)) 2))

  ;; set the top position, centering the frame and allowing for title bars (50)
  (setq lframe-top 
	(/ (- (x-display-pixel-height)
		  (+ (frame-pixel-height) MY_HEIGHT_ADJUST)) 2))

  ;; now apply the changes
  (set-frame-position (selected-frame)
					  lframe-left
					  lframe-top)
  )

;;;==============================
(defun adjust-frame ()
  "Adjust the selected frame based to the user's initial width, but
adjust the height based on the current screen resolution"

  (interactive)
  ;; set the width and height
  (set-frame-size
    (selected-frame)
	MY_INITIAL_WIDTH
	(/ (- (x-display-pixel-height) MY_HEIGHT_ADJUST)
	   (frame-char-height)))

  ;; set the frame position
  (set-frame-position
    (selected-frame)
    MY_INITIAL_LEFT
	;; need to account for the title bar and menu when centering
	;; vertically
	(/ (- (x-display-pixel-height)
		  (+ (frame-pixel-height) MY_HEIGHT_ADJUST)) 2))
  )

;;;==============================
(defun fix-frame ()
  "Restore the frame back to the initial height, width and position as
set up in the .emacs

uses the global variables:
   MY_INITIAL_WIDTH
   MY_INITIAL_HEIGHT
   MY_INITIAL_LEFT
   MY_INITIAL_RIGHT

defined in the .emacs file"
  (interactive)
  (set-frame-size (selected-frame) MY_INITIAL_WIDTH MY_INITIAL_HEIGHT)
  (set-frame-position (selected-frame) MY_INITIAL_LEFT MY_INITIAL_TOP)
  )





-- 
     (.   .)
  =ooO=(_)=Ooo========================
  Chris McMahan | cmcmahan-AT-one.net
  ====================================

  parent reply	other threads:[~2003-01-30 14:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-28  6:47 desktop height? Bruce Ingalls
2003-01-28 14:27 ` Phillip Lord
2003-01-28 18:32   ` Bruce Ingalls
2003-01-28 18:48     ` Phillip Lord
2003-01-28 21:09       ` Bruce Ingalls
2003-01-31  8:07     ` Lee Sau Dan
2003-01-30 14:40 ` Chris McMahan [this message]
2003-01-31  0:11   ` Bruce Ingalls
2003-01-31 13:48     ` Chris McMahan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=uy952em4m.fsf@one.net \
    --to=cmcmahan+n@one.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.