all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Calculate window size in pixels
@ 2005-05-06  9:12 Mathias Dahl
  2005-05-06 10:40 ` Pascal Bourguignon
  2005-05-06 14:12 ` Stefan Monnier
  0 siblings, 2 replies; 12+ messages in thread
From: Mathias Dahl @ 2005-05-06  9:12 UTC (permalink / raw)


Is it possible to calculate an Emacs window's size in pixels?
`window-height' and `window-width' returns lines and columns.

I guess this have to do with the frame's default font or
something. Having two functions, `window-height-pixels' and
`window-width-pixels' would be nice :)

Can it be done?

The reason that I want this is to be able to figure out to what size I
have to resize an image to before inserting it into a window, so that
it fits snugly.

/Mathias

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

* Re: Calculate window size in pixels
  2005-05-06  9:12 Calculate window size in pixels Mathias Dahl
@ 2005-05-06 10:40 ` Pascal Bourguignon
  2005-05-06 14:12 ` Stefan Monnier
  1 sibling, 0 replies; 12+ messages in thread
From: Pascal Bourguignon @ 2005-05-06 10:40 UTC (permalink / raw)


Mathias Dahl <brakjoller.rem0veth1s@gmail.com> writes:

> Is it possible to calculate an Emacs window's size in pixels?
> `window-height' and `window-width' returns lines and columns.
>
> I guess this have to do with the frame's default font or
> something. Having two functions, `window-height-pixels' and
> `window-width-pixels' would be nice :)
>
> Can it be done?
>
> The reason that I want this is to be able to figure out to what size I
> have to resize an image to before inserting it into a window, so that
> it fits snugly.

It depends on the window manager.  With X, (when (eq window-system 'x) 
you'd use:
   x-display-pixel-width
   x-display-pixel-height
)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay

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

* Re: Calculate window size in pixels
  2005-05-06  9:12 Calculate window size in pixels Mathias Dahl
  2005-05-06 10:40 ` Pascal Bourguignon
@ 2005-05-06 14:12 ` Stefan Monnier
  2005-05-06 14:40   ` Klaus Straubinger
  2005-05-06 15:36   ` Mathias Dahl
  1 sibling, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2005-05-06 14:12 UTC (permalink / raw)


> Is it possible to calculate an Emacs window's size in pixels?
> `window-height' and `window-width' returns lines and columns.

There's frame-pixel-height in Emacs-CVS.
There's also window-pixel-edges if you care about windows rather
than frames.


        Stefan

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

* Re: Calculate window size in pixels
  2005-05-06 14:12 ` Stefan Monnier
@ 2005-05-06 14:40   ` Klaus Straubinger
  2005-05-06 15:36   ` Mathias Dahl
  1 sibling, 0 replies; 12+ messages in thread
From: Klaus Straubinger @ 2005-05-06 14:40 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>> Is it possible to calculate an Emacs window's size in pixels?
>> `window-height' and `window-width' returns lines and columns.
>
> There's frame-pixel-height in Emacs-CVS.

This function is even available in the released version Emacs 21.4.

> There's also window-pixel-edges if you care about windows rather
> than frames.

This seems to be a new function in the yet to be released Emacs 22.1.

-- 
Klaus Straubinger

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

* Re: Calculate window size in pixels
  2005-05-06 14:12 ` Stefan Monnier
  2005-05-06 14:40   ` Klaus Straubinger
@ 2005-05-06 15:36   ` Mathias Dahl
  2005-05-06 15:40     ` Mathias Dahl
  1 sibling, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2005-05-06 15:36 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> > Is it possible to calculate an Emacs window's size in pixels?
> > `window-height' and `window-width' returns lines and columns.
> 
> There's frame-pixel-height in Emacs-CVS.
> There's also window-pixel-edges if you care about windows rather
> than frames.

Which means I can use this:

(defun window-height-pixels ()
  (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height)))
        (column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
    (ftruncate (* (window-height) line-pixel-height-ratio))))

(defun window-width-pixels ()
  (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
    (ftruncate (* (window-width) column-pixel-width-ratio))))

I see that the frame-pixel-functions is including window
decorations and stuff, but I guess it can work for my
purposes anyway.

Thanks!

/Mathias

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

* Re: Calculate window size in pixels
  2005-05-06 15:36   ` Mathias Dahl
@ 2005-05-06 15:40     ` Mathias Dahl
  2005-05-06 17:12       ` Mathias Dahl
                         ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Mathias Dahl @ 2005-05-06 15:40 UTC (permalink / raw)


Mathias Dahl <brakjoller@hotmail.com> writes:

 
> Which means I can use this:
> 
> (defun window-height-pixels ()
>   (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height)))
>         (column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
>     (ftruncate (* (window-height) line-pixel-height-ratio))))
> 
> (defun window-width-pixels ()
>   (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
>     (ftruncate (* (window-width) column-pixel-width-ratio))))

And even better:

(defun window-height-pixels ()
  (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height))))
    (truncate (* (window-height) line-pixel-height-ratio))))

(defun window-width-pixels ()
  (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
    (truncate (* (window-width) column-pixel-width-ratio))))

/Mathias

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

* Re: Calculate window size in pixels
  2005-05-06 15:40     ` Mathias Dahl
@ 2005-05-06 17:12       ` Mathias Dahl
  2005-05-06 17:55       ` Kevin Rodgers
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2005-05-06 17:12 UTC (permalink / raw)


Mathias Dahl <brakjoller@hotmail.com> writes:

> And even better:
> 
> (defun window-height-pixels ()
>   (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height))))
>     (truncate (* (window-height) line-pixel-height-ratio))))
> 
> (defun window-width-pixels ()
>   (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
>     (truncate (* (window-width) column-pixel-width-ratio))))

Shameful plug:

You can now see this in action in `tumme-display-image' in
the newest version of tumme.el:

 http://www.emacswiki.org/cgi-bin/wiki/Tumme

/Mathias

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

* Re: Calculate window size in pixels
  2005-05-06 15:40     ` Mathias Dahl
  2005-05-06 17:12       ` Mathias Dahl
@ 2005-05-06 17:55       ` Kevin Rodgers
       [not found]       ` <mailman.3776.1115402969.2819.help-gnu-emacs@gnu.org>
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Kevin Rodgers @ 2005-05-06 17:55 UTC (permalink / raw)


Mathias Dahl wrote:
> (defun window-height-pixels ()
>   (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height))))
>     (truncate (* (window-height) line-pixel-height-ratio))))
> 
> (defun window-width-pixels ()
>   (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
>     (truncate (* (window-width) column-pixel-width-ratio))))

I think (+ (frame-pixel-DIMENSION) 0.0) can be replaced by
(float (frame-pixel-DIMENSION))

-- 
Kevin Rodgers

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

* Re: Calculate window size in pixels
       [not found]       ` <mailman.3776.1115402969.2819.help-gnu-emacs@gnu.org>
@ 2005-05-07 17:51         ` Mathias Dahl
  0 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2005-05-07 17:51 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Mathias Dahl wrote:
> > (defun window-height-pixels ()
> >   (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height))))
> >     (truncate (* (window-height) line-pixel-height-ratio))))
> > (defun window-width-pixels ()
> >   (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
> >     (truncate (* (window-width) column-pixel-width-ratio))))
> 
> I think (+ (frame-pixel-DIMENSION) 0.0) can be replaced by
> (float (frame-pixel-DIMENSION))

It can :), thanks! Looks better.

/Mathias

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

* Re: Calculate window size in pixels
  2005-05-06 15:40     ` Mathias Dahl
                         ` (2 preceding siblings ...)
       [not found]       ` <mailman.3776.1115402969.2819.help-gnu-emacs@gnu.org>
@ 2005-05-09 11:02       ` Ehud Karni
       [not found]       ` <mailman.4226.1115637000.2819.help-gnu-emacs@gnu.org>
  4 siblings, 0 replies; 12+ messages in thread
From: Ehud Karni @ 2005-05-09 11:02 UTC (permalink / raw)
  Cc: help-gnu-emacs

On 06 May 2005 17:40:41 +0200, Mathias Dahl wrote:
>
> (defun window-height-pixels ()
>   (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height))))
>     (truncate (* (window-height) line-pixel-height-ratio))))
>
> (defun window-width-pixels ()
>   (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
>     (truncate (* (window-width) column-pixel-width-ratio))))

I think that `frame-char-height' and `frame-char-width' is what you
are looking for.

I use the following to change the font without resizing the frames. This uses
only the `editable' part of the frame - without the border and menus areas.

(defun set-font-keep-size (font)
  "set font to use, keep window size"
       (let ((fht (* (frame-parameter nil 'height) (frame-char-height)))
             (fwd (* (frame-parameter nil 'width)  (frame-char-width))))
           (set-default-font font)
           (set-frame-value-all 'font font)
           (set-frame-value-all 'height (/ fht (frame-char-height)))
           (set-frame-value-all 'width  (/ fwd (frame-char-width)))))

`set-frame-value-all is my function to set a value on all frames.

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

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

* Re: Calculate window size in pixels
       [not found]       ` <mailman.4226.1115637000.2819.help-gnu-emacs@gnu.org>
@ 2005-05-10 10:28         ` Mathias Dahl
  2005-05-11  6:36           ` Mathias Dahl
  0 siblings, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2005-05-10 10:28 UTC (permalink / raw)


"Ehud Karni" <ehud@unix.mvs.co.il> writes:

> On 06 May 2005 17:40:41 +0200, Mathias Dahl wrote:
>>
>> (defun window-height-pixels ()
>>   (let ((line-pixel-height-ratio (/ (+ (frame-pixel-height) 0.0) (frame-height))))
>>     (truncate (* (window-height) line-pixel-height-ratio))))
>>
>> (defun window-width-pixels ()
>>   (let ((column-pixel-width-ratio (/ (+ (frame-pixel-width) 0.0) (frame-width))))
>>     (truncate (* (window-width) column-pixel-width-ratio))))
>
> I think that `frame-char-height' and `frame-char-width' is what you
> are looking for.
>
> I use the following to change the font without resizing the frames. This uses
> only the `editable' part of the frame - without the border and menus areas.
>
> (defun set-font-keep-size (font)
>   "set font to use, keep window size"
>        (let ((fht (* (frame-parameter nil 'height) (frame-char-height)))
>              (fwd (* (frame-parameter nil 'width)  (frame-char-width))))
>            (set-default-font font)
>            (set-frame-value-all 'font font)
>            (set-frame-value-all 'height (/ fht (frame-char-height)))
>            (set-frame-value-all 'width  (/ fwd (frame-char-width)))))
>
> `set-frame-value-all is my function to set a value on all frames.

That seems to be exactly what I wanted. Strange I missed it. I will
try using that instead and see how it works.

Thanks!

/Mathias

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

* Re: Calculate window size in pixels
  2005-05-10 10:28         ` Mathias Dahl
@ 2005-05-11  6:36           ` Mathias Dahl
  0 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2005-05-11  6:36 UTC (permalink / raw)


Mathias Dahl <brakjoller.rem0veth1s@gmail.com> writes:

>> I think that `frame-char-height' and `frame-char-width' is what you
>> are looking for.

> That seems to be exactly what I wanted. Strange I missed it. I will
> try using that instead and see how it works.

It worked very well and feels much better than trying to calculate the
pixel/character ratio myself.

Thanks again!

/Mathias

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

end of thread, other threads:[~2005-05-11  6:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-06  9:12 Calculate window size in pixels Mathias Dahl
2005-05-06 10:40 ` Pascal Bourguignon
2005-05-06 14:12 ` Stefan Monnier
2005-05-06 14:40   ` Klaus Straubinger
2005-05-06 15:36   ` Mathias Dahl
2005-05-06 15:40     ` Mathias Dahl
2005-05-06 17:12       ` Mathias Dahl
2005-05-06 17:55       ` Kevin Rodgers
     [not found]       ` <mailman.3776.1115402969.2819.help-gnu-emacs@gnu.org>
2005-05-07 17:51         ` Mathias Dahl
2005-05-09 11:02       ` Ehud Karni
     [not found]       ` <mailman.4226.1115637000.2819.help-gnu-emacs@gnu.org>
2005-05-10 10:28         ` Mathias Dahl
2005-05-11  6:36           ` Mathias Dahl

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.