all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: 24085@debbugs.gnu.org
Subject: bug#24085: 25.1.50; `make-frame' given `top' param creates frame with ~10x smaller `top'
Date: Wed, 27 Jul 2016 22:12:08 -0400	[thread overview]
Message-ID: <6dbee9a6-bfe3-7d29-d3a0-1a5521e3c73f@gmail.com> (raw)
In-Reply-To: <6336b8b4-49c0-4ce6-9044-cf558f12c16e@default>


[-- Attachment #1.1: Type: text/plain, Size: 5918 bytes --]

On 2016-07-27 16:55, Drew Adams wrote:
> Just hoping I'm missing something simple, like a function
> `screen-relative-x-y-pixels-at-point'...  Thanks, if you can
> point the way.

Hey Drew,

There was a discussion about this on the Wiki page for pos-tip (back then you suggested filing an enhancement request). The following function, from pos-tip.el, seems to do more or less what you're looking for. Does it? I'm not sure how well it works in Windows.

In any case, it would be nice if this was easily feasible.

Cheers,
Clément.

(defun pos-tip-compute-pixel-position
  (&optional pos window pixel-width pixel-height frame-coordinates dx dy)
  "Return pixel position of POS in WINDOW like (X . Y), which indicates
the absolute or relative coordinates of bottom left corner of the object.

Omitting POS and WINDOW means use current position and selected window,
respectively.

If PIXEL-WIDTH and PIXEL-HEIGHT are given, this function assumes these
values as the size of small window like tooltip which is located around the
object at POS. These values are used to adjust the location in order that
the tooltip won't disappear by sticking out of the display. By referring
the variable `pos-tip-upperside-p' after calling this function, user can
examine whether the tooltip will be located above the specified position.

If FRAME-COORDINATES is omitted or nil, automatically obtain the absolute
coordinates of the top left corner of frame which WINDOW is on. Here,
`top left corner of frame' represents the origin of `window-pixel-edges'
and its coordinates are essential for calculating the return value as
absolute coordinates. If a cons cell like (LEFT . TOP), specifies the
frame absolute location and makes the calculation slightly faster, but can
be used only when it's clear that frame is in the specified position. Users
can get the latest values of frame coordinates for using in the next call
by referring the variable `pos-tip-saved-frame-coordinates' just after
calling this function. Otherwise, FRAME-COORDINATES `relative' means return
pixel coordinates of the object relative to the top left corner of the frame.
This is the same effect as `pos-tip-use-relative-coordinates' is non-nil.

DX specifies horizontal offset in pixel.

DY specifies vertical offset in pixel. This makes the calculations done
without considering the height of object at POS, so the object might be
hidden by the tooltip."
  (let* ((frame (window-frame (or window (selected-window))))
	 (w32-frame (eq (pos-tip-window-system frame) 'w32))
	 (relative (or pos-tip-use-relative-coordinates
		       (eq frame-coordinates 'relative)
		       (and w32-frame
			    (null pos-tip-w32-saved-max-width-height))))
	 (frame-coord (or (and relative '(0 . 0))
			  frame-coordinates
			  (pos-tip-frame-top-left-coordinates frame)
			  (progn
			    (setq relative t
				  pos-tip-use-relative-coordinates t)
			  '(0 . 0))))
	 (posn (posn-at-point (or pos (window-point window)) window))
	 (line (cdr (posn-actual-col-row posn)))
	 (line-height (and line
			   (or (window-line-height line window)
			       (and (redisplay t)
				    (window-line-height line window)))))
	 (x-y (or (posn-x-y posn)
		  (let ((geom (pos-visible-in-window-p
			       (or pos (window-point window)) window t)))
		    (and geom (cons (car geom) (cadr geom))))
		  '(0 . 0)))
	 (x (+ (car frame-coord)
	       (car (window-inside-pixel-edges window))
	       (car x-y)
	       (or dx 0)))
	 (y0 (+ (cdr frame-coord)
		(cadr (window-pixel-edges window))
		(or (nth 2 line-height) (cdr x-y))))
	 (y (+ y0
	       (or dy
		   (car line-height)
		   (with-current-buffer (window-buffer window)
		     (cond
		      ;; `posn-object-width-height' returns an incorrect value
		      ;; when the header line is displayed (Emacs bug #4426).
		      ((and posn
			    (null header-line-format))
		       (cdr (posn-object-width-height posn)))
		      ((and (bound-and-true-p text-scale-mode)
			    (not (zerop (with-no-warnings
					  text-scale-mode-amount))))
		       (round (* (frame-char-height frame)
				 (with-no-warnings
				   (expt text-scale-mode-step
					 text-scale-mode-amount)))))
		      (t
		       (frame-char-height frame)))))))
	 xmax ymax)
    (cond
     (relative
      (setq xmax (frame-pixel-width frame)
	    ymax (frame-pixel-height frame)))
     (w32-frame
      (setq xmax (car pos-tip-w32-saved-max-width-height)
	    ymax (cdr pos-tip-w32-saved-max-width-height)))
     (t
      (setq xmax (x-display-pixel-width frame)
	    ymax (x-display-pixel-height frame))))
    (setq pos-tip-upperside-p (> (+ y (or pixel-height 0))
				 ymax))
    (cons (max 0 (min x (- xmax (or pixel-width 0))))
	  (max 0 (if pos-tip-upperside-p
		     (- (if dy ymax y0) (or pixel-height 0))
		   y)))))


(defun pos-tip-w32-max-width-height (&optional keep-maximize)
  "Maximize the currently selected frame temporarily and set
`pos-tip-w32-saved-max-width-height' the effective display size in order
to become possible to calculate the absolute location of tooltip.

KEEP-MAXIMIZE non-nil means leave the frame maximized.

Note that this function is usable only in Emacs 23 for MS-Windows."
  (interactive)
  (unless (eq window-system 'w32)
    (error "`pos-tip-w32-max-width-height' can be used only in w32 frame."))
  ;; Maximize frame
  (with-no-warnings (w32-send-sys-command 61488))
  (sit-for 0)
  (let ((offset (pos-tip-calibrate-frame-offset)))
    (prog1
	(setq pos-tip-w32-saved-max-width-height
	      (cons (frame-pixel-width)
		    (+ (frame-pixel-height)
		       (- (cdr offset) (car offset)))))
      (if (called-interactively-p 'interactive)
	  (message "%S" pos-tip-w32-saved-max-width-height))
      (unless keep-maximize
	;; Restore frame
	(with-no-warnings (w32-send-sys-command 61728))))))


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-07-28  2:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-27  4:49 bug#24085: 25.1.50; `make-frame' given `top' param creates frame with ~10x smaller `top' Drew Adams
2016-07-27  9:19 ` martin rudalics
2016-07-27 13:29   ` Drew Adams
2016-07-27 16:23     ` Eli Zaretskii
2016-07-28  8:57     ` martin rudalics
2016-07-28 14:50       ` Eli Zaretskii
2016-07-28 19:07         ` martin rudalics
2016-07-28 16:34       ` Drew Adams
2016-07-28 19:07         ` martin rudalics
2022-04-22 13:22           ` Lars Ingebrigtsen
2022-04-22 15:28             ` Drew Adams
     [not found]   ` <<3657859c-03f1-4eca-9a78-a9be0dee6552@default>
     [not found]     ` <<83h9bbrqx5.fsf@gnu.org>
2016-07-27 16:57       ` Drew Adams
2016-07-27 17:37         ` Eli Zaretskii
     [not found]   ` <<<3657859c-03f1-4eca-9a78-a9be0dee6552@default>
     [not found]     ` <<<83h9bbrqx5.fsf@gnu.org>
     [not found]       ` <<06a3fb2a-b975-41cf-8aa3-c2cbe207057f@default>
     [not found]         ` <<838twnrngr.fsf@gnu.org>
2016-07-27 18:39           ` Drew Adams
2016-07-27 19:00             ` Eli Zaretskii
     [not found]   ` <<<<3657859c-03f1-4eca-9a78-a9be0dee6552@default>
     [not found]     ` <<<<83h9bbrqx5.fsf@gnu.org>
     [not found]       ` <<<06a3fb2a-b975-41cf-8aa3-c2cbe207057f@default>
     [not found]         ` <<<838twnrngr.fsf@gnu.org>
     [not found]           ` <<325b79e8-c40b-46f7-a89a-11f0888b0a68@default>
     [not found]             ` <<8360rqsy7i.fsf@gnu.org>
2016-07-27 20:55               ` Drew Adams
2016-07-28  2:12                 ` Clément Pit--Claudel [this message]
2016-07-28 16:35                   ` Drew Adams
2016-07-28  8:57                 ` martin rudalics
2016-07-28 16:35                   ` Drew Adams
2016-07-28 14:40                 ` Eli Zaretskii
     [not found]   ` <<<<<3657859c-03f1-4eca-9a78-a9be0dee6552@default>
     [not found]     ` <<<<<83h9bbrqx5.fsf@gnu.org>
     [not found]       ` <<<<06a3fb2a-b975-41cf-8aa3-c2cbe207057f@default>
     [not found]         ` <<<<838twnrngr.fsf@gnu.org>
     [not found]           ` <<<325b79e8-c40b-46f7-a89a-11f0888b0a68@default>
     [not found]             ` <<<8360rqsy7i.fsf@gnu.org>
     [not found]               ` <<6336b8b4-49c0-4ce6-9044-cf558f12c16e@default>
     [not found]                 ` <<8337mtsu54.fsf@gnu.org>
2016-07-28 16:36                   ` Drew Adams

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=6dbee9a6-bfe3-7d29-d3a0-1a5521e3c73f@gmail.com \
    --to=clement.pit@gmail.com \
    --cc=24085@debbugs.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.