all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* desktop height?
@ 2003-01-28  6:47 Bruce Ingalls
  2003-01-28 14:27 ` Phillip Lord
  2003-01-30 14:40 ` Chris McMahan
  0 siblings, 2 replies; 9+ messages in thread
From: Bruce Ingalls @ 2003-01-28  6:47 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  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-30 14:40 ` Chris McMahan
  1 sibling, 1 reply; 9+ messages in thread
From: Phillip Lord @ 2003-01-28 14:27 UTC (permalink / raw)


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

  Bruce> Does anyone know a way to calculate the height of the desktop
  Bruce> in elisp?

  Bruce> I'd like Emacs to start up with maximum height.  For that
  Bruce> matter, I'd like XEmacs, and various OSes to work.

  Bruce> In Linux X Window, the following works reasonably well:

  Bruce> (/ (- (x-display-pixel-height) 50) (frame-char-height)))

  Bruce> I can get reasonably close with

  Bruce> (/ (x-display-pixel-height)
  Bruce>   (* (/ (font-default-size-for-device) 2) 3))

  Bruce> which works in w32 XEmacs as

  Bruce> (/ (x-display-pixel-height)
  Bruce>   (* (/ (string-to-number (font-default-size-for-device)) 2)
  Bruce>   3))

  Bruce> or w32 Emacs as

  Bruce> (/ (x-display-pixel-height) 18)

  Bruce> I'd also like to hear of testing on other OSes.  If someone
  Bruce> has a better solution, please send it!  Thanks ahead.


I used to probe the display to get what is effectively a maximised
emacs, on start up. I stopped doing this because probing in this way
misses things like the Gnome toolbar (which I still want to be
visible). 

In recent years I've just gone onto setting it by hand. 

Cheers

Phil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  2003-01-28 14:27 ` Phillip Lord
@ 2003-01-28 18:32   ` Bruce Ingalls
  2003-01-28 18:48     ` Phillip Lord
  2003-01-31  8:07     ` Lee Sau Dan
  0 siblings, 2 replies; 9+ messages in thread
From: Bruce Ingalls @ 2003-01-28 18:32 UTC (permalink / raw)


Phillip Lord wrote:
> "Bruce" == Bruce Ingalls <bingalls.NO_SPAM@fit-zones.com> writes:
> 
> 
>   Bruce> Does anyone know a way to calculate the height of the desktop
>   Bruce> in elisp?
...
> I used to probe the display to get what is effectively a maximised
> emacs, on start up. I stopped doing this because probing in this way
> misses things like the Gnome toolbar (which I still want to be
> visible). 
> 
> In recent years I've just gone onto setting it by hand. 

Send me your code!
I already use `ps` to check for gnome-panel, kicker, and others.
I'm not sure how to detect a menu at the top of Sawfish, but this has a
manual override.

I'm using this for the EMacro project, where the point of its ease of 
use, is to
make the computer do the work, instead of you.

The Unux philosophy is that you have to spend hours customzing, which makes
bosses nervous, because you've started the project, and they don't see 
you getting
any work done yet.

Another philosophy sets you up, and gets you going. Just don't change 
the settings
from the way they do business in Redmond.

The EMacro philosophy is to use those smart, easy wizards to set you up, 
then gets
out of the way, to tweak like a Unix hack, should that be necessary.

Hey 5.0 * 10^0 EMacro fans must be onto something!

Here's some X Window code, which works well, but doesn't help Mac nor w32:

(/ (- (x-display-pixel-height) 50) (frame-char-height))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  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
  1 sibling, 1 reply; 9+ messages in thread
From: Phillip Lord @ 2003-01-28 18:48 UTC (permalink / raw)


>>>>> "Bruce" == Bruce Ingalls <bingalls@CUT-this-SPAM-BLOCK.fit-zones.com> writes:

  Bruce> Phillip Lord wrote:
  >> "Bruce" == Bruce Ingalls <bingalls.NO_SPAM@fit-zones.com> writes:
  Bruce> Does anyone know a way to calculate the height of the Bruce>
  >> desktop

  Bruce> in elisp?  ...  I used to probe the display to get what is
  Bruce> effectively a
  >> maximised emacs, on start up. I stopped doing this because
  >> probing in this way misses things like the Gnome toolbar (which I
  >> still want to be visible). In recent years I've just gone onto
  >> setting it by hand.


  Bruce> Send me your code! 

Well as I say, I set things up "by hand" now, so its not much use for
you. 

As I generally use only a few machines, I do this....


(add-to-list 'load-path "~/emacs/machine-config")
;;this is the config file loading function
(defun phil-load-config-for-machine(&optional suffix)
  "This function attempts to load machine specific configuration information. This
information should be placed in a lisp file called NAME-suffix.el
where NAME is the machine name, either fully qualified with the domain
name, or not. If `suffix' is not given it defaults to -config. The
variable `phil-display-is-local' will be set to true if the initial
frame is opening on a local machine"
  (interactive)
  (let* ((suf (if suffix
                  suffix
                "-config"))
         (machine-config-file-long
          (concat (system-name) suf))
         (machine-config-file-short
          (concat 
           (substring machine-config-file-long 0
                      (string-match "[.]" machine-config-file-long))
           suf)))
    ;; this part of the function is essentially a total guess. I hope
    ;; it will work but I shall have to play with it a little if it doesnt
    (setq phil-display-is-x (boundp 'x-display-name))
    (if phil-display-is-x
        (setq phil-display-is-local-x (equal x-display-name ":0"))
      (setq phil-display-is-local-x nil))
    ;; load a file named after this machine, using the fully qualified name in preference first. 
    (if (or (load machine-config-file-long 't)
            (load machine-config-file-short 't))
        ;;try the default config therefore
        (load "default-machine-config" 't))))


which loads a file based on the machine name, which just then sets the
size up by hand. It's less than perfect. In particular resizing the
main emacs frame, causes it to pop up on which ever viewport is
currently visible, so I normally have to move my emacs around to the
correct viewport after it's started. Fortunately as I use sawfish, I
can do this with a few key presses.


  Bruce> I already use `ps` to check for gnome-panel, kicker, and
  Bruce> others.  I'm not sure how to detect a menu at the top of
  Bruce> Sawfish, but this has a manual override.

Now this is a good idea. I shall have to have a look at your code. It
would probably have been too much effort to do for myself. 

I have briefly toyed with the idea of interacting with sawfish, from
within emacs, which might allow me to probe for the panel, and solve
the viewport issue. But this is probably more effort than its worth,
as getting values by hand when I use a new machine works well most of
the time. 

  Bruce> I'm using this for the EMacro project, where the point of its
  Bruce> ease of use, is to

I guessed as much!


  Bruce> The EMacro philosophy is to use those smart, easy wizards to
  Bruce> set you up, then gets

  Bruce> out of the way, to tweak like a Unix hack, should that be
  Bruce> necessary.

A good philosophy, I think.

 
Cheers

Phil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  2003-01-28 18:48     ` Phillip Lord
@ 2003-01-28 21:09       ` Bruce Ingalls
  0 siblings, 0 replies; 9+ messages in thread
From: Bruce Ingalls @ 2003-01-28 21:09 UTC (permalink / raw)


Phillip Lord wrote:
>   Bruce> Send me your code! 
> Well as I say, I set things up "by hand" now, so its not much use for
> you. 

OK. I sent you my new code, via gnu.emacs.sources, called
desktop-height-approx() or deskheight.el

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  2003-01-28  6:47 desktop height? Bruce Ingalls
  2003-01-28 14:27 ` Phillip Lord
@ 2003-01-30 14:40 ` Chris McMahan
  2003-01-31  0:11   ` Bruce Ingalls
  1 sibling, 1 reply; 9+ messages in thread
From: Chris McMahan @ 2003-01-30 14:40 UTC (permalink / raw)


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
  ====================================

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  2003-01-30 14:40 ` Chris McMahan
@ 2003-01-31  0:11   ` Bruce Ingalls
  2003-01-31 13:48     ` Chris McMahan
  0 siblings, 1 reply; 9+ messages in thread
From: Bruce Ingalls @ 2003-01-31  0:11 UTC (permalink / raw)


Chris McMahan wrote:
> Bruce Ingalls <bingalls.NO_SPAM@fit-zones.com> writes:
>>Does anyone know a way to calculate the height of the desktop in elisp?
...
> 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.
Would be nice to see the syntax to set MY_FONT

...> ;;; frame sizing functions
...> (defun fix-frame ()
...
Very nice. Worked on my Linux box, which makes me believe that your code is
more portable. I did need to adjust it for the 
tray/panel/taskbar/statusbar, as
you indicated.

Consider renaming your functions, so that you can more easily remember them
with sentence completion, and so that they better fit a name space.
Instead of fix-frame, etc. try:
frame-adjust
frame-fix
frame-enlarge

While your code worked perfectly for Emacs, I had to adjust XEmacs. I 
also do this
(already) in desktop-height-approx().

I'd like to hear from the community, as to which code works better for them.
I remind users to adjust for their XEmacs & taskbars, when using your 
code, before
making judgement.

One last tradeoff with your code: the use of set-frame-height() is nice, 
in that it
can change an already running Emacs, but, as opposed to 
frame-initial-frame-plist()
or  setq default-frame-plist(), it appears to be capable to screw up an 
emacs -nw
and perhaps other console modes of Emacs/XEmacs.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  2003-01-28 18:32   ` Bruce Ingalls
  2003-01-28 18:48     ` Phillip Lord
@ 2003-01-31  8:07     ` Lee Sau Dan
  1 sibling, 0 replies; 9+ messages in thread
From: Lee Sau Dan @ 2003-01-31  8:07 UTC (permalink / raw)


>>>>> "Bruce" == Bruce Ingalls <bingalls@CUT-this-SPAM-BLOCK.fit-zones.com> writes:

    Bruce> The Unux philosophy is that you have to spend hours
    Bruce> customzing, which makes bosses nervous, because you've
    Bruce> started the project, and they don't see you getting any
    Bruce> work done yet.

You should teach such bosses a Chinese proverb:

        To do  job(s) well, polish the  tool(s) first.

(I put  (s) here because Chinese doesn't  distinguish between singular
and plural.)



-- 
Lee Sau Dan                     李守敦(Big5)                    ~{@nJX6X~}(HZ) 

E-mail: danlee@informatik.uni-freiburg.de
Home page: http://www.informatik.uni-freiburg.de/~danlee

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: desktop height?
  2003-01-31  0:11   ` Bruce Ingalls
@ 2003-01-31 13:48     ` Chris McMahan
  0 siblings, 0 replies; 9+ messages in thread
From: Chris McMahan @ 2003-01-31 13:48 UTC (permalink / raw)


Thanks! Your suggestion on the name changes is excellent. I'll make
that change here as well.

As for setting MY_FONT, here's the code (with some more context around it):
;;;===================================================
;;; Set the default font and frame size for all frames
;;;===================================================
(defconst MY_FONT "-*-Lucida Console-normal-r-*-*-11-*-*-*-c-*-iso8859-15")

;;; Set the default font to return the appropriate character height
;;; for the initial height calculation
(set-frame-font MY_FONT)

;;; 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)


The reason I do it with the consts is that I place all of the settings
(email, proxy, directory locations and such) within my .emacs file,
then call a .emacs-config file from there to do the actual
configurations based on the settings.

 - Chris

Bruce Ingalls <bingalls@CUT-this-SPAM-BLOCK.fit-zones.com> writes:

> Chris McMahan wrote:
> > Bruce Ingalls <bingalls.NO_SPAM@fit-zones.com> writes:
> >>Does anyone know a way to calculate the height of the desktop in elisp?
> ...
> > 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.
> Would be nice to see the syntax to set MY_FONT
> 
> ...> ;;; frame sizing functions
> ...> (defun fix-frame ()
> ...
> Very nice. Worked on my Linux box, which makes me believe that your code is
> more portable. I did need to adjust it for the
> tray/panel/taskbar/statusbar, as
> 
> you indicated.
> 
> Consider renaming your functions, so that you can more easily remember them
> with sentence completion, and so that they better fit a name space.
> Instead of fix-frame, etc. try:
> frame-adjust
> frame-fix
> frame-enlarge
> 
> While your code worked perfectly for Emacs, I had to adjust XEmacs. I
> also do this
> 
> (already) in desktop-height-approx().
> 
> I'd like to hear from the community, as to which code works better for them.
> I remind users to adjust for their XEmacs & taskbars, when using your
> code, before
> 
> making judgement.
> 
> One last tradeoff with your code: the use of set-frame-height() is
> nice, in that it
> 
> can change an already running Emacs, but, as opposed to
> frame-initial-frame-plist()
> 
> or setq default-frame-plist(), it appears to be capable to screw up an
> emacs -nw
> 
> and perhaps other console modes of Emacs/XEmacs.
> 

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-01-31 13:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2003-01-31  0:11   ` Bruce Ingalls
2003-01-31 13:48     ` Chris McMahan

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.