all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: <emacs-devel@gnu.org>
Subject: RE: Negative positions in frame parameters
Date: Tue, 13 Apr 2010 10:02:42 -0700	[thread overview]
Message-ID: <ECF08EB5CDA74786AB494C02F05CBA19@us.oracle.com> (raw)
In-Reply-To: <4BC49C58.8050303@swipnet.se>

FWIW, I've been using the following functions forever, to make life simpler when
trying to deal with the different possible representations that Emacs functions
might return.

I use this, for example, to move frames around incrementally. (To increment a
value it needs to be in numeric form.)

The functions are also here, in case mail wraparound makes them difficult to
read:
http://www.emacswiki.org/emacs/frame-fns.el

----

(defun frame-geom-value-numeric (type value &optional frame)
  "Return equivalent geometry value for FRAME in numeric terms.
A geometry value equivalent to VALUE for FRAME is returned,
where the value is numeric, not a consp.
TYPE is the car of the original geometry spec (TYPE . VALUE).
   It is `top' or `left', depending on which edge VALUE is related to.
VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
If VALUE is a consp, then it is converted to a numeric value, perhaps
   relative to the opposite frame edge from that in the original spec.
FRAME defaults to the selected frame.

Examples (measures in pixels) -
 Assuming display height/width=1024, frame height/width=600:
 300 inside display edge:                   300  =>  300
                                        (+  300) =>  300
 300 inside opposite display edge:      (-  300) => -300
                                           -300  => -300
 300 beyond display edge
  (= 724 inside opposite display edge): (+ -300) => -724
 300 beyond display edge
  (= 724 inside opposite display edge): (- -300) =>  724

In the last two examples, the returned value is relative to the
opposite frame edge from the edge indicated in the input spec."
  (if (consp value)
      (if (natnump (cadr value))
          ;; e.g. (+ 300) or (- 300) => 300 or -300
          (funcall (car value) (cadr value))
        ;; e.g. (+ -300) or (- -300)
        (let ((oppval (- (if (eq 'left type)
                             (x-display-pixel-width)
                           (x-display-pixel-height))
                         (cadr value)
                         (if (eq 'left type)
                             (frame-pixel-width frame)
                           (frame-pixel-height frame)))))
          (if (eq '+ (car value))
              (- oppval)                ; e.g. (+ -300) => -724
            oppval)))                   ; e.g. (- -300) =>  724
    ;; e.g. 300 or -300
    value))

(defun frame-geom-spec-numeric (spec &optional frame)
  "Return equivalent geometry specification for FRAME in numeric terms.
A geometry specification equivalent to SPEC for FRAME is returned,
where the value is numeric, not a consp.
SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
If VALUE is a consp, then it is converted to a numeric value, perhaps
   relative to the opposite frame edge from that in the original SPEC.
FRAME defaults to the selected frame.

Examples (measures in pixels) -
 Assuming display height=1024, frame height=600:
 top 300 below display top:               (top .  300) => (top .  300)
                                          (top +  300) => (top .  300)
 bottom 300 above display bottom:         (top -  300) => (top . -300)
                                          (top . -300) => (top . -300)
 top 300 above display top
  (= bottom 724 above display bottom):    (top + -300) => (top . -724)
 bottom 300 below display bottom
  (= top 724 below display top):          (top - -300) => (top .  724)

In the last two examples, the returned value is relative to the
opposite frame edge from the edge indicated in the input SPEC."
  (cons (car spec) (frame-geom-value-numeric (car spec) (cdr spec))))

(defun frame-geom-value-cons (type value &optional frame)
  "Return equivalent geometry value for FRAME as a cons with car `+'.
A geometry value equivalent to VALUE for FRAME is returned,
where the value is a cons with car `+', not numeric.
TYPE is the car of the original geometry spec (TYPE . VALUE).
   It is `top' or `left', depending on which edge VALUE is related to.
VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
If VALUE is a number, then it is converted to a cons value, perhaps
   relative to the opposite frame edge from that in the original spec.
FRAME defaults to the selected frame.

Examples (measures in pixels) -
 Assuming display height/width=1024, frame height/width=600:
 300 inside display edge:                   300  => (+  300)
                                        (+  300) => (+  300)
 300 inside opposite display edge:      (-  300) => (+  124)
                                           -300  => (+  124)
 300 beyond display edge
  (= 724 inside opposite display edge): (+ -300) => (+ -300)
 300 beyond display edge
  (= 724 inside opposite display edge): (- -300) => (+  724)

In the 3rd, 4th, and 6th examples, the returned value is relative to
the opposite frame edge from the edge indicated in the input spec."
  (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
         value)
        ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
        (t                              ; e.g. -300, (- 300), (- -300)
         (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
                         (x-display-pixel-width)
                       (x-display-pixel-height))
                     (if (integerp value) (- value) (cadr value))
                     (if (eq 'left type)
                         (frame-pixel-width frame)
                       (frame-pixel-height frame)))))))

(defun frame-geom-spec-cons (spec &optional frame)
  "Return equivalent geometry spec for FRAME as a cons with car `+'.
A geometry specification equivalent to SPEC for FRAME is returned,
where the value is a cons with car `+', not numeric.
SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
If VALUE is a number, then it is converted to a cons value, perhaps
   relative to the opposite frame edge from that in the original spec.
FRAME defaults to the selected frame.

Examples (measures in pixels) -
 Assuming display height=1024, frame height=600:
 top 300 below display top:               (top .  300) => (top +  300)
                                          (top +  300) => (top +  300)
 bottom 300 above display bottom:         (top -  300) => (top +  124)
                                          (top . -300) => (top +  124)
 top 300 above display top
  (= bottom 724 above display bottom):    (top + -300) => (top + -300)
 bottom 300 below display bottom
  (= top 724 below display top):          (top - -300) => (top +  724)

In the 3rd, 4th, and 6th examples, the returned value is relative to
the opposite frame edge from the edge indicated in the input spec."
  (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec))))





  reply	other threads:[~2010-04-13 17:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-13 13:24 Negative positions in frame parameters Stefan Monnier
2010-04-13 13:33 ` Lennart Borgman
2010-04-13 14:12   ` Stephen J. Turnbull
2010-04-13 16:17     ` Jason Rumney
2010-04-13 17:14       ` Jan Djärv
2010-04-13 17:33         ` Drew Adams
2010-04-13 14:41   ` Jan Djärv
2010-04-13 15:26     ` David Kastrup
2010-04-13 16:31       ` Jan Djärv
2010-04-13 17:02         ` Drew Adams [this message]
2010-04-13 23:41         ` YAMAMOTO Mitsuharu
2010-04-14  4:51           ` Jan Djärv
2010-04-13 16:09     ` Stefan Monnier
2010-04-13 17:07       ` Jan Djärv
2010-04-13 15:18 ` Jan Djärv
2010-04-13 16:10   ` Stefan Monnier
2010-04-13 17:08     ` Jan Djärv

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=ECF08EB5CDA74786AB494C02F05CBA19@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /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.